source: CIVL/examples/experimental/diff1d_spec.c@ 83af34d

1.23 2.0 main test-branch
Last change on this file since 83af34d was d5abab8, checked in by Ziqing Luo <ziqing@…>, 11 years ago

add a broken test for compare diffusion1d

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

  • Property mode set to 100644
File size: 1.5 KB
RevLine 
[d5abab8]1#include <stdlib.h>
2#include <stdio.h>
3#include <assert.h>
4#include <string.h>
5
6$input int NXB = 5; // upper bound on nx
7$input int nx; // global number of points excl. boundary
8$assume 1<=nx && nx<=NXB;
9$input double U_INIT[nx+2]; // initial values for temperature incl. boundary
10$input double k; // the constant D*dt/(dx*dx)
11$assume k>0 && k<.5;
12$input int NSTEPS_BOUND=5; // upper bound on nsteps
13$input int nsteps; // number of time steps
14$assume 1<=nsteps && nsteps<=NSTEPS_BOUND;
15$input int wstep = 1; // write frame every this many time steps
16//$assume 1<=wstep && wstep<=nsteps;
17//$assume nsteps%wstep == 0 && wstep != 0;
18$output double output[nsteps][nx+2]; // solution computed sequentially, proc 0 only
19
20/* Global variables */
21double lbound; /* left fixed boundary value */
22double rbound; /* right fixed boundary value */
23
24int main() {
25 //elaborate nx to concrete value...
26 elaborate(nx);
27 elaborate(nsteps);
28 double u[nsteps][nx+2];
29 int counter = 0;
30
31 lbound = U_INIT[0];
32 rbound = U_INIT[nx+1];
33 for (int i=0; i<nx+2; i++)
34 u[0][i]=U_INIT[i];
35 memcpy(&output[0][0], &u[0][0], (nx + 2)*sizeof(double));
36 for (int t=1; t<nsteps; t++) {
37 u[t][0] = lbound;
38 for (int i=1; i<=nx; i++)
39 u[t][i] = u[t-1][i] +
40 k*(u[t-1][i+1] + u[t-1][i-1]
41 - 2*u[t-1][i]);
42 u[t][nx+1] = rbound;
43 if(t%wstep == 0) {
44 memcpy(&output[counter][0], &u[t][0], (nx + 2)*sizeof(double));
45 counter++;
46 }
47 }
48}
49
Note: See TracBrowser for help on using the repository browser.