File: ex4.c

package info (click to toggle)
swig 1.1p5-1
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 9,448 kB
  • ctags: 5,025
  • sloc: cpp: 21,599; ansic: 13,333; yacc: 3,297; python: 2,794; makefile: 2,197; perl: 1,984; tcl: 1,583; sh: 736; lisp: 201; objc: 143
file content (45 lines) | stat: -rw-r--r-- 753 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Test performance of just straight C++

#include "pde.h"
#include <stdio.h>

void initcond(Heat2d *h) {
  int i;
  h->set_temp(0.0);
  
  for (i = 0; i < h->grid->xpoints; i++)
    h->grid->data[i][0] = 1.0;

}
  
void dump(Heat2d *h, char *filename) {
  FILE *f;
  int   i,j;

  f = fopen(filename,"w");
  
  for (i = 0; i < h->grid->xpoints; i++)
    for (j = 0; j < h->grid->ypoints; j++)
      fprintf(f,"%0.17f\n",h->grid->data[i][j]);

  fclose(f);

}

int main(int argc, char **argv) {

  Heat2d *h;
  char    fname[256];
  int     fileno;

  h = new Heat2d(50,50);
  initcond(h);

  for (int i = 0; i < 25; i++) {
    h->solve(100);
    sprintf(fname,"Dat%d",fileno);
    dump(h,fname);
    printf("time = %g\n", h->time);
    fileno++;
  }
}