-
Notifications
You must be signed in to change notification settings - Fork 3
/
RKDG2D.cpp
executable file
·103 lines (63 loc) · 1.98 KB
/
RKDG2D.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
97
98
99
100
101
102
103
//- RKDG 2D v.0.1
// Structured rectangular mesh
#include <stdio.h>
#include <iostream>
#include <sstream>
#include "Mesh2D.h"
#include "Problem.h"
#include "fluxllf.h"
#include "defs.h"
int main(int argc, char** argv)
{
// Mesh parameters
int nx = 20;
int ny = 20;
double Lx = 4.0;
double Ly = 4.0;
// Courant number
double Co = 0.25;
// Get mesh
Mesh2D mesh(nx, ny, Lx, Ly);
mesh.exportMesh();
// Get solver
Problem problem(mesh);
problem.setInitialConditions();
problem.applyBoundary(problem.alphaPrev);
//Get flux
FluxLLF numFlux (problem);
// time cycle
// TODO: dynamic time step!!!
double tau = min(mesh.hx,mesh.hy) * Co; // sound speed = 1 --- const in acoustic problems
double tEnd = 2.01;
vector<numvector<double, 5*nShapes>> k1, k2;
int nCells = mesh.nInternalCells + mesh.nGhostCells ;
k1.resize(nCells);
k2.resize(nCells);
// open ofstream for coeffs
string fileName = "alphaCoeffs/" + to_string(0.0);
ofstream output;
output.open(fileName);
problem.write(output,problem.alphaPrev);
output.close();
// run Runge --- Kutta 2 TVD
for (double t = tau; t < tEnd; t += tau)
{
string fileName = "alphaCoeffs/" + to_string(t);
ofstream output;
output.open(fileName);
cout << "t = " << t << endl;
k1 = numFlux.getRHS(problem.alphaPrev);
problem.alphaNext = problem.alphaPrev + k1 * tau;
problem.applyBoundary(problem.alphaNext);
k2 = numFlux.getRHS(problem.alphaNext);
problem.alphaNext = problem.alphaPrev + (k1 + k2) * 0.5 * tau;
problem.applyBoundary(problem.alphaNext);
problem.write(output,problem.alphaNext);
problem.alphaPrev = problem.alphaNext;
output.close();
}
cout << "END \n";
//int aaa;
//cin >> aaa;
return 0;
}