forked from dkolom/GALA2D
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
139 lines (115 loc) · 4.71 KB
/
main.cpp
File metadata and controls
139 lines (115 loc) · 4.71 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*************************************************************************************************************************
*
*
* Gradient-Augmented Level set Adaptive method for 2D advection equation
*
* Reference [1]: Dmitry Kolomenskiy, Jean-Christophe Nave and Kai Schneider
* "Adaptive gradient-augmented levet set method with multiresolution error estimation"
*
* Notations are different in the code and in [1]; see comments
*
*
*************************************************************************************************************************/
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cmath>
#include "QuadNode.h"
#include "QuadTree.h"
#include "Solver.h"
#include "Point.h"
using namespace std;
int main(){
// This is a sample hi-level call sequence for a typical numerical simulation.
// In this example, the swirl test described in section 3.2 in [1] is computed.
// Create a new solver
Solver* asolver = new Solver();
// Output file for number of nodes vs time
ofstream fnumnodes;
fnumnodes.open ("numnodes.dat", ios::out);
// Define parameters of the swirl test
// Algorithm in Section 2.5 in [1], steps 1a-1b
char lmin = 1; // m in [1]
char lmax = 11; // M in [1]
double tolerance = 5e-3; // epsilon in [1]
double tmax = 10.0; // T in [1]
double size = 1.0; // L in [1]
// Set parameters
asolver->setParams(lmin,lmax,size,tmax,tolerance);
// Initialize tree data structure
// Step 1c
// Here we assume l_init = m = 1
asolver->startupTree(0,0,0);
asolver->getTree()->createListLeaves();
// Initial multiresolution analysis that generates the initial mesh
for (int imra=lmin; imra<lmax; imra++) {
// List of grid points, step 1d
asolver->createMesh();
// Evaluate the initial condition, step 1e
asolver->initPointData();
// Remesh, step 1f
asolver->remesh();
}
// Output for figures 3.4(a) and 3.5(a)
// Save the initial mesh in a file
asolver->saveMeshCoords();
// Save the initial condition in a file
//asolver->saveCart(); // uncomment (may be slow)
system("mv meshfile.dat meshfile_t0.dat");
system("mv pointfile.dat pointfile_t0.dat");
//system("mv cartfile.dat cartfile_t0.dat"); // uncomment (may be slow)
// Begin time stepping, step 2 in [1], Section 2.5
cout << "begin iterations" << endl;
// Initialize iteration counter
int it = 0;
// Iterate until final time is reached
while (asolver->m_time < tmax) {
// Create list of grid points,
// step 2a
asolver->createMesh();
// Find minimum, maximum and median levels in the mesh, for diagnostics
unsigned char lleafmin,lleafmax,lleafmed;
asolver->getTree()->levelStats(asolver->getTree()->getRoot(),lleafmin,lleafmax);
lleafmed = (lleafmin+lleafmax)/2;
// Find the number of the tree structure nodes. It gives the number of grid points shown in figure 3.7(a) in [1]
unsigned int counter = 0;
asolver->getTree()->countNodes(asolver->getTree()->getRoot(),counter);
// Steps 2b-2i of the algorithm
asolver->timeStep();
// Remeshing, step 2j
asolver->remesh();
// Print diagnostics
cout << "end it=" << ++it << " time=" << asolver->m_time << " lleafmin=" << int(lleafmin)
<< " lleafmax=" << int(lleafmax) << " lleafmed=" << int(lleafmed) << endl;
// Output at t=5, figures 3.4(b) and 3.5(b)
if ( abs(asolver->m_time-5.0)<1e-12 ) {
// Save mesh
asolver->saveMeshCoords();
// Save solution
//asolver->saveCart(); // uncomment (may be slow)
system("mv meshfile.dat meshfile_t5.dat");
system("mv pointfile.dat pointfile_t5.dat");
//system("mv cartfile.dat cartfile_t5.dat"); // uncomment (may be slow)
}
// Output for figure 3.7
fnumnodes << it << " " << asolver->m_time << " " << counter << endl;
}
// Output at t=10, figures 3.4(c) and 3.5(c)
// Save mesh
asolver->saveMeshCoords();
// Save solution
//asolver->saveCart(); // uncomment (may be slow)
system("mv meshfile.dat meshfile_t10.dat");
system("mv pointfile.dat pointfile_t10.dat");
//system("mv cartfile.dat cartfile_t10.dat"); // uncomment (may be slow)
// Compute the error in L^\infty norm
double linferr;
linferr = asolver->linfError();
cout << "Linfty error = " << linferr << endl;
// Delete the solver
delete asolver;
// Close output file
fnumnodes.close();
// End computation
return 0;
}