source: CIVL/examples/diffusion_seq.cvl@ 364cc7e

1.23 2.0 main test-branch
Last change on this file since 364cc7e was 364cc7e, checked in by Tim Zirkel <zirkeltk@…>, 13 years ago

Added sequential diffusion and matmat examples.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@54 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 580 bytes
Line 
1int nx;
2double u0[2];
3int nsteps;
4double kappa;
5double data[3][2];
6double u[2];
7
8void init() {
9 nx = 2;
10 nsteps = 2;
11 kappa = 0.1;
12 for (int i = 0; i < nx; i++) {
13 u[i] = u0[i];
14 }
15}
16
17void write(int time) {
18 for (int i = 0; i < nx; i++) {
19 data[time][i] = u[i];
20 }
21}
22
23void update() {
24 double u_new[nx];
25
26 for (int i=1; i<nx-1; i++) {
27 u_new[i] = u[i] + kappa*(u[i+1] + u[i-1] - 2*u[i]);
28 }
29 for (int i=1; i<nx-1; i++) {
30 u[i] = u_new[i];
31 }
32}
33
34void main() {
35 init();
36 write(0);
37 for (int iter = 1; iter <= nsteps; iter++) {
38 update();
39 write(iter);
40 }
41}
Note: See TracBrowser for help on using the repository browser.