-
Notifications
You must be signed in to change notification settings - Fork 2
/
FluxFcnLLF.h
186 lines (146 loc) · 6.46 KB
/
FluxFcnLLF.h
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/************************************************************************
* Copyright © 2020 The Multiphysics Modeling and Computation (M2C) Lab
* <kevin.wgy@gmail.com> <kevinw3@vt.edu>
************************************************************************/
#ifndef _FLUX_FCN_LLF_H_
#define _FLUX_FCN_LLF_H_
#include <FluxFcnBase.h>
#include <math.h>
using std::fabs;
using std::max;
/****************************************************************************************
* The local Lax-Friedrichs Flux (a.k.a. Rusanov's method), for general EOS. Ref: Leveque, Chap 12.5
***************************************************************************************/
class FluxFcnLLF : public FluxFcnBase {
public:
FluxFcnLLF(std::vector<VarFcnBase*> &varFcn, [[maybe_unused]] IoData &iod) : FluxFcnBase(varFcn) { }
~FluxFcnLLF() {}
inline void ComputeNumericalFluxAtCellInterface(int dir /*0~x, 1~y, 2~z*/, double *Vm/*minus*/,
double *Vp/*plus*/, int id, double *flux/*F,G,or H*/);
inline void ComputeNumericalFluxAtMaterialInterface(int dir/*0~x,1~y,2~z*/, double *Vminus/*left*/, int idm,
double *Vplus/*right*/, int idp, double *F);
private:
inline void ComputeMaxEigenvalue(int dir /*0~x, 1~y, 2~z*/, double *Vm, double *Vp, int id, double &a);
inline void ComputeMaxEigenvalueAtMaterialInterface(int dir /*0~x, 1~y, 2~z*/, double *Vm, int idm,
double *Vp, int idp, double &a);
};
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
// Internal function, Used only within this file
//----------------------------------------------------------------------------------------
inline
void FluxFcnLLF::ComputeMaxEigenvalue(int dir /*0~x, 1~y, 2~z*/, double *Vm, double *Vp, int id, double &a)
{
double velocity_m, velocity_p;
if (dir==0) {velocity_m = Vm[1]; velocity_p = Vp[1];} //x --> u;
else if(dir==1) {velocity_m = Vm[2]; velocity_p = Vp[2];} //y --> v;
else {velocity_m = Vm[3]; velocity_p = Vp[3];} //z --> w;
double e_m = vf[id]->GetInternalEnergyPerUnitMass(Vm[0], Vm[4]);
double e_p = vf[id]->GetInternalEnergyPerUnitMass(Vp[0], Vp[4]);
double c_m = vf[id]->ComputeSoundSpeedSquare(Vm[0], e_m);
if(c_m<0) {
fprintf(stdout,"*** Error: c^2 (square of sound speed) = %e in LLF flux function. Vm = %e, %e, %e, %e, %e, ID = %d.\n",
c_m, Vm[0], Vm[1], Vm[2], Vm[3], Vm[4], id);
exit(-1);
} else
c_m = sqrt(c_m);
double c_p = vf[id]->ComputeSoundSpeedSquare(Vp[0], e_p);
if(c_p<0) {
fprintf(stdout,"*** Error: c^2 (square of sound speed) = %e in LLF flux function. Vp = %e, %e, %e, %e, %e, ID = %d.\n",
c_p, Vp[0], Vp[1], Vp[2], Vp[3], Vp[4], id);
exit(-1);
} else
c_p = sqrt(c_p);
a = max( fabs(velocity_m) + c_m,
fabs(velocity_p) + c_p );
}
//----------------------------------------------------------------------------------------
inline
void FluxFcnLLF::ComputeNumericalFluxAtCellInterface(int dir, double *Vm, double *Vp, int id, double *flux)
{
// Compute lambda, alpha, and R
int nDOF = 5;
double a;
ComputeMaxEigenvalue(dir/*0~x,1~y,2~z*/, Vm, Vp, id, a);
//LLF flux
double fm[5], fp[5];
if(dir==0) {
EvaluateFluxFunction_F(Vm, id, fm);
EvaluateFluxFunction_F(Vp, id, fp);
} else if (dir==1) {
EvaluateFluxFunction_G(Vm, id, fm);
EvaluateFluxFunction_G(Vp, id, fp);
} else if (dir==2) {
EvaluateFluxFunction_H(Vm, id, fm);
EvaluateFluxFunction_H(Vp, id, fp);
} else {
fprintf(stdout, "*** Error: Dir. (%d) not recognized.\n", dir);
exit(-1);
}
double Um[5], Up[5];
vf[id]->PrimitiveToConservative(Vm, Um);
vf[id]->PrimitiveToConservative(Vp, Up);
for(int i=0; i<nDOF; i++)
flux[i] = 0.5*( (fm[i]+fp[i]) - a*(Up[i]-Um[i]) );
}
//----------------------------------------------------------------------------------------
// Internal function, Used only within this file
//----------------------------------------------------------------------------------------
inline
void FluxFcnLLF::ComputeMaxEigenvalueAtMaterialInterface(int dir, double *Vm, int idm,
double *Vp, int idp, double &a)
{
double velocity_m, velocity_p;
if (dir==0) {velocity_m = Vm[1]; velocity_p = Vp[1];} //x --> u;
else if(dir==1) {velocity_m = Vm[2]; velocity_p = Vp[2];} //y --> v;
else {velocity_m = Vm[3]; velocity_p = Vp[3];} //z --> w;
double e_m = vf[idm]->GetInternalEnergyPerUnitMass(Vm[0], Vm[4]);
double e_p = vf[idp]->GetInternalEnergyPerUnitMass(Vp[0], Vp[4]);
double c_m = vf[idm]->ComputeSoundSpeedSquare(Vm[0], e_m);
if(c_m<0) {
fprintf(stdout,"*** Error: c^2 (square of sound speed) = %e in LLF flux function. Vm = %e, %e, %e, %e, %e, ID = %d.\n",
c_m, Vm[0], Vm[1], Vm[2], Vm[3], Vm[4], idm);
exit(-1);
} else
c_m = sqrt(c_m);
double c_p = vf[idp]->ComputeSoundSpeedSquare(Vp[0], e_p);
if(c_p<0) {
fprintf(stdout,"*** Error: c^2 (square of sound speed) = %e in LLF flux function. Vp = %e, %e, %e, %e, %e, ID = %d.\n",
c_p, Vp[0], Vp[1], Vp[2], Vp[3], Vp[4], idp);
exit(-1);
} else
c_p = sqrt(c_p);
a = max( fabs(velocity_m) + c_m,
fabs(velocity_p) + c_p );
}
//----------------------------------------------------------------------------------------
inline
void FluxFcnLLF::ComputeNumericalFluxAtMaterialInterface(int dir, double *Vm, int idm,
double *Vp, int idp, double *flux)
{
// Compute lambda, alpha, and R
int nDOF = 5;
double a;
ComputeMaxEigenvalueAtMaterialInterface(dir/*0~x,1~y,2~z*/, Vm, idm, Vp, idp, a);
//LLF flux
double fm[5], fp[5];
if(dir==0) {
EvaluateFluxFunction_F(Vm, idm, fm);
EvaluateFluxFunction_F(Vp, idp, fp);
} else if (dir==1) {
EvaluateFluxFunction_G(Vm, idm, fm);
EvaluateFluxFunction_G(Vp, idp, fp);
} else if (dir==2) {
EvaluateFluxFunction_H(Vm, idm, fm);
EvaluateFluxFunction_H(Vp, idp, fp);
} else {
fprintf(stdout, "*** Error: Dir. (%d) not recognized.\n", dir);
exit(-1);
}
double Um[5], Up[5];
vf[idm]->PrimitiveToConservative(Vm, Um);
vf[idp]->PrimitiveToConservative(Vp, Up);
for(int i=0; i<nDOF; i++)
flux[i] = 0.5*( (fm[i]+fp[i]) - a*(Up[i]-Um[i]) );
}
#endif