-
Notifications
You must be signed in to change notification settings - Fork 0
/
QuadTest.cpp
96 lines (78 loc) · 2.07 KB
/
QuadTest.cpp
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <iostream>
#include <cstdlib>
#include <cmath>
#include "Edge.h"
#include "Triangle.h"
#include "Polygon.h"
#include "Basis.h"
#include "Grid.h"
#include "Field.h"
#include "LinAlg.h"
#include "CFA.h"
#include "CDG.h"
using namespace std;
#define QUAD_ORDER 8
#define BASIS_ORDER 2
typedef double ( Func ) ( double* x );
double func( double* x ) {
return cos( 0.5*M_PI*x[0] )*cos( 0.5*M_PI*x[1] );
}
double Integrate( Field* field, Func* func ) {
double vol = 0.0;
int pi, ti, qi;
Grid* grid = field->grid;
Polygon* poly;
Triangle* tri;
for( pi = 0; pi < grid->nPolys; pi++ ) {
poly = grid->polys[pi];
for( ti = 0; ti < poly->n; ti++ ) {
tri = poly->tris[ti];
for( qi = 0; qi < tri->nq; qi++ ) {
vol += tri->wi[qi]*func( tri->qi[qi] )*tri->area;
}
}
}
return vol;
}
int main() {
int nx = 1;
int ny = 1;
int i, j;
Grid* grid;
Field* field;
CDG* cdg;
double vol;
double ans = 16.0/M_PI/M_PI;
/* test convergence of errors with increased resolution for given quadrature order */
cout << "testing quadrature, order: " << QUAD_ORDER << endl;
for( i = 0; i < 8; i++ ) {
grid = new Grid( nx, ny, -1.0, -1.0, +1.0, +1.0, QUAD_ORDER, BASIS_ORDER, true );
field = new Field( grid );
for( j = 0; j < grid->nPolys; j++ ) {
field->basis[j]->ci[0] = func( grid->polys[j]->origin );
}
vol = Integrate( field, func );
cout << fabs( 1.0 - vol/ans ) << endl;
nx *= 2;
ny *= 2;
delete field;
delete grid;
}
/* now test with the basis functions */
nx = ny = 1;
cout << "testing basis function setup and integration" << endl;
for( i = 0; i < 8; i++ ) {
grid = new Grid( nx, ny, -1.0, -1.0, +1.0, +1.0, QUAD_ORDER, BASIS_ORDER, true );
field = new Field( grid );
cdg = new CDG( field, NULL, NULL, NULL, NULL );
cdg->InitBetaIJInv( func );
vol = field->Integrate();
cout << fabs( 1.0 - vol/ans ) << endl;
nx *= 2;
ny *= 2;
delete cdg;
delete field;
delete grid;
}
return 1;
}