source: CIVL/examples/arithmetic/diffusion.cvl@ bd7a43e

main test-branch
Last change on this file since bd7a43e was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

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

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