source: CIVL/examples/arithmetic/laplace.cvl@ 7de7353

1.23 2.0 acw/focus-triggers main test-branch
Last change on this file since 7de7353 was 95a2a9e, checked in by Tim Zirkel <zirkeltk@…>, 13 years ago

Added new examples.

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

  • Property mode set to 100644
File size: 1.3 KB
Line 
1int NX_BOUND = 2;
2int NY_BOUND = 2;
3int TIME_BOUND = 2;
4int nx = 2; // number of x coordinates (including boundary)
5int ny = 2; // number of rows including boundary
6double epsilon = 0.01; // total error tolerance
7$input double initialValues[ny][nx]; // initial values
8$output int t;
9$output double out[ny][nx];
10
11double grid[ny][nx]; // holds values of current iteration
12
13double square(double x) { return x * x; }
14
15void init() {
16 int row;
17 int col;
18
19 for (row=0; row<ny; row++)
20 for (col=0; col<nx; col++)
21 grid[row][col] = initialValues[row][col];
22}
23
24void write_result(int time, double** data) {
25 int row;
26 int col;
27
28 t = time;
29 for (row=ny-1; row>=0; row--)
30 for (col=0; col<nx; col++)
31 out[row][col] = data[row][col];
32}
33
34void main() {
35 double error = epsilon;
36 int row;
37 int col;
38 int time = 0;
39 double result;
40 double tmp[ny][nx];
41
42 init();
43 while (error >= epsilon && time < TIME_BOUND) {
44 error = 0.0;
45 for (row=1; row<ny-1; row++) {
46 for (col=1; col<nx-1; col++) {
47 tmp[row][col] = (grid[row-1][col]+grid[row+1][col]+
48 grid[row][col-1]+grid[row][col+1])/4.0;
49 result = square(grid[row][col] - tmp[row][col]);
50 error += result;
51 }
52 }
53 for (row=1; row<ny-1; row++)
54 for (col=1; col<nx-1; col++)
55 grid[row][col] = tmp[row][col];
56 time++;
57 }
58 write_result(time, grid);
59}
Note: See TracBrowser for help on using the repository browser.