source: CIVL/examples/arithmetic/diffusion.cvl

main
Last change on this file was b689afd, checked in by Stephen Siegel <siegel@…>, 4 weeks ago

Getting rid of unused examples that are not good and starting to clean
up others.

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

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