source: CIVL/examples/experimental/diff1d_spec.c@ 367a390

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