-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalcErrors.cpp
More file actions
100 lines (82 loc) · 2.28 KB
/
CalcErrors.cpp
File metadata and controls
100 lines (82 loc) · 2.28 KB
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
97
98
99
100
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <cmath>
#include "Edge.h"
#include "Triangle.h"
#include "Polygon.h"
#include "Grid.h"
#include "Basis.h"
#include "Field.h"
#include "LinAlg.h"
#include "CFA.h"
#include "CDG.h"
using namespace std;
#define QUAD_ORDER 6
#define BASIS_ORDER 3
double p1( double* p ) {
double xo = 0.5*cos( 0.75*M_PI );
double yo = 0.5*sin( 0.75*M_PI );
double r2 = ( p[0] - xo )*( p[0] - xo ) + ( p[1] - yo )*( p[1] - yo );
if( sqrt( r2 ) < 0.40 ) return exp(-40.0*r2);
return 0.0;
}
void WriteDifference( Field* phi, Field* ans, int nx ) {
Grid* grid = phi->grid;
char filename[50];
ofstream file;
int i, j, k, l;
int n = 2;
double point[2], val;
sprintf( filename, "output/diff_%.3u.txt", nx );
file.open( filename );
for( i = 0; i < grid->ny; i++ ) {
for( j = 0; j < n; j++ ) {
for( k = 0; k < grid->nx; k++ ) {
for( l = 0; l < n; l++ ) {
point[0] = grid->minx + k*grid->dx + (0.5 + l)*grid->dx/n;
point[1] = grid->miny + i*grid->dy + (0.5 + j)*grid->dy/n;
val = ans->basis[i*grid->nx+k]->EvalFull( point ) - phi->basis[i*grid->nx+k]->EvalFull( point );
file << val << endl;
}
}
}
file << endl;
}
file.close();
}
int main( int argc, char** argv ) {
int nx, i;
Grid* grid;
Field* phi;
char filename[80];
double l1[3], l2[3], l1_norm[3], l2_norm[3];
i = 0;
for( nx = 64; nx < 512; nx *= 2 ) {
cout << "nx: " << nx << endl;
grid = new Grid( nx, nx, -2.0, -2.0, +2.0, +2.0, QUAD_ORDER, BASIS_ORDER, true );
phi = new Field( grid );
sprintf( filename, "input/Q%uB%u_basis_%.3u.txt", QUAD_ORDER, BASIS_ORDER, nx );
phi->ReadBasis( filename, 0 );
l1_norm[i] = phi->L1Error( p1, true );
l2_norm[i] = phi->L2Error( p1, true );
l1[i] = phi->L1Error( p1, false );
l2[i] = phi->L2Error( p1, false );
i++;
delete phi;
delete grid;
}
cout << "\nL_1 (un-normalized): ";
for( i = 0; i < 3; i++ ) { cout << l1[i] << "\t"; }
cout << endl;
cout << "\nL_2 (un-normalized): ";
for( i = 0; i < 3; i++ ) { cout << l2[i] << "\t"; }
cout << endl;
cout << "\nL_1 (normalized): ";
for( i = 0; i < 3; i++ ) { cout << l1_norm[i] << "\t"; }
cout << endl;
cout << "\nL_2 (normalized): ";
for( i = 0; i < 3; i++ ) { cout << l2_norm[i] << "\t"; }
cout << endl;
return 1;
}