source: CIVL/examples/diffusion_seq.cvl@ 8bd0ed8

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

Updated Makefile. Changed examples to use civlc.h and $ instead of \ at beginning of CIVL keywords.

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

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