main
test-branch
|
Last change
on this file since 397ae5f 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.5 KB
|
| Line | |
|---|
| 1 | #include <assert.h>
|
|---|
| 2 | #include <civlc.cvh>
|
|---|
| 3 | #include <stdlib.h>
|
|---|
| 4 |
|
|---|
| 5 | $input int NXB = 5; // upper bound on nx
|
|---|
| 6 | $input int nx; // global number of points excl. boundary
|
|---|
| 7 | $assume(1<=nx && nx<=NXB);
|
|---|
| 8 | $input double U_INIT[nx+2]; // initial values for temperature incl. boundary
|
|---|
| 9 | $input double k; // the constant D*dt/(dx*dx)
|
|---|
| 10 | $assume(k>0 && k<.5);
|
|---|
| 11 | $input int NSTEPS_BOUND=5; // upper bound on nsteps
|
|---|
| 12 | $input int nsteps; // number of time steps
|
|---|
| 13 | $assume(1<=nsteps && nsteps<=NSTEPS_BOUND);
|
|---|
| 14 | $input int wstep; // write frame every this many time steps
|
|---|
| 15 | $assume(1<=wstep && wstep<=nsteps);
|
|---|
| 16 | $output double output[nsteps][nx+2]; // solution computed sequentially, proc 0 only
|
|---|
| 17 |
|
|---|
| 18 | double *u; /* temperature function, local */
|
|---|
| 19 | double *u_new; /* second copy of temperature function, local */
|
|---|
| 20 |
|
|---|
| 21 | int initialize() {
|
|---|
| 22 | u = (double*)malloc((nx+2)*sizeof(double));
|
|---|
| 23 | assert(u);
|
|---|
| 24 | u_new = (double*)malloc((nx+2)*sizeof(double));
|
|---|
| 25 | assert(u_new);
|
|---|
| 26 | for (int i=1; i<nx+1; i++)
|
|---|
| 27 | u[i] = U_INIT[i];
|
|---|
| 28 | u[0] = u_new[0] = U_INIT[0];
|
|---|
| 29 | u[nx+1] = u_new[nx+1] = U_INIT[nx+1];
|
|---|
| 30 | }
|
|---|
| 31 |
|
|---|
| 32 | void update() {
|
|---|
| 33 | double * tmp;
|
|---|
| 34 |
|
|---|
| 35 | for(int i = 1; i <= nx; i++)
|
|---|
| 36 | u_new[i] = u[i] + k * (u[i+1] + u[i-1] - 2 * u[i]);
|
|---|
| 37 | tmp = u;
|
|---|
| 38 | u = u_new;
|
|---|
| 39 | u_new = tmp;
|
|---|
| 40 | }
|
|---|
| 41 |
|
|---|
| 42 | void write_frame(int time) {
|
|---|
| 43 | for(int i = 0; i <nx+2; i++)
|
|---|
| 44 | output[time][i] = u[i];
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | int main() {
|
|---|
| 48 | int time = 0;
|
|---|
| 49 |
|
|---|
| 50 | initialize();
|
|---|
| 51 | write_frame(time);
|
|---|
| 52 | for(time=1; time<nsteps; time++) {
|
|---|
| 53 | update();
|
|---|
| 54 | if (time%wstep==0)
|
|---|
| 55 | write_frame(time);
|
|---|
| 56 | }
|
|---|
| 57 | free(u);
|
|---|
| 58 | free(u_new);
|
|---|
| 59 | return 0;
|
|---|
| 60 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.