source: CIVL/examples/arithmetic/laplace.cvl

main
Last change on this file 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.3 KB
RevLine 
[89b55f5]1/* Commandline execution:
2 * civl verify laplace.cvl
3 */
[95a2a9e]4int TIME_BOUND = 2;
[56e078f]5#define nx 3 // number of x coordinates (including boundary)
6#define ny 3 // number of rows including boundary
[95a2a9e]7double epsilon = 0.01; // total error tolerance
8$input double initialValues[ny][nx]; // initial values
9$output int t;
10$output double out[ny][nx];
11
12double grid[ny][nx]; // holds values of current iteration
13
14double square(double x) { return x * x; }
15
16void init() {
[9bcb8b8e]17 for (int row=0; row<ny; row++)
18 for (int col=0; col<nx; col++)
[95a2a9e]19 grid[row][col] = initialValues[row][col];
20}
21
[56e078f]22void write_result(int time, double data[ny][nx]) {
[95a2a9e]23 t = time;
[9bcb8b8e]24 for (int row=ny-1; row>=0; row--)
25 for (int col=0; col<nx; col++)
[95a2a9e]26 out[row][col] = data[row][col];
27}
28
29void main() {
30 double error = epsilon;
31 int time = 0;
32 double result;
33 double tmp[ny][nx];
34
35 init();
36 while (error >= epsilon && time < TIME_BOUND) {
37 error = 0.0;
[9bcb8b8e]38 for (int row=1; row<ny-1; row++) {
39 for (int col=1; col<nx-1; col++) {
[95a2a9e]40 tmp[row][col] = (grid[row-1][col]+grid[row+1][col]+
41 grid[row][col-1]+grid[row][col+1])/4.0;
42 result = square(grid[row][col] - tmp[row][col]);
43 error += result;
44 }
45 }
[9bcb8b8e]46 for (int row=1; row<ny-1; row++)
47 for (int col=1; col<nx-1; col++)
[95a2a9e]48 grid[row][col] = tmp[row][col];
49 time++;
50 }
51 write_result(time, grid);
52}
Note: See TracBrowser for help on using the repository browser.