This repository has been archived by the owner on Dec 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathio.cpp
83 lines (66 loc) · 1.85 KB
/
io.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
#include <iomanip>
#include "common.h"
using namespace std;
#define DIG 7 // number of digits after the decimal point
void readEdges()
{
std::ifstream input("edgeTypes.txt");
for (i = 0; i < 4; i++)
input >> edges[i];
input.close();
}
void readSize()
{
std::ifstream input("size.txt");
input >> nX >> nY;
input.close();
N = nX * nY;
}
void readGrid()
{
int i;
ifstream inputX("nodesX.txt");
for (i = 0; i < nX; i++)
inputX >> gridX[i];
inputX.close();
ifstream inputY("nodesY.txt");
for (i = 0; i < nY; i++)
inputY >> gridY[i];
inputY.close();
}
void printResult()
{
int n = 0;
double tmpNormErr = 0.0, tmpNormAn = 0.0;
double xPoint, yPoint, analytical, error, relNorm;
ofstream output("result.txt");
output << setprecision(DIG) << setw(DIG + 10)
<< "Numerical" << setw(DIG + 20)
<< "Analytical" << setw(DIG + 20)
<< "Error" << setw(DIG + 17)
<< "x y\n"
<< endl;
for (k = 0; k < nY; k++)
for (i = 0; i < nX; i++)
{
xPoint = gridX[i];
yPoint = gridY[k];
analytical = getAnalytical(xPoint, yPoint);
error = std::abs(x[n] - analytical);
output
<< setw(DIG + 10) << x[n]
<< setw(DIG + 20) << analytical
<< setw(DIG + 20) << error
<< setw(DIG + 10) << xPoint
<< setw(6) << yPoint
<< endl;
tmpNormErr += error * error;
tmpNormAn += analytical * analytical;
n++;
}
relNorm = sqrt(tmpNormErr / tmpNormAn);
output << setprecision(5) << "\n" << setw(DIG + 43) <<
"||u - u*|| / ||u*|| = " << relNorm
<< endl;
output.close();
}