-
Notifications
You must be signed in to change notification settings - Fork 0
/
RadMom1D_Mesh.h
354 lines (295 loc) · 13 KB
/
RadMom1D_Mesh.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
/*!\file RadMom1D_Mesh.h
\brief Header file defining 1D RadMom Solution Classes. */
#ifndef _RADMOM1D_MESH_INCLUDED
#define _RADMOM1D_MESH_INCLUDED
/* Include 1D RadMom state and cell header files. */
#ifndef _RADMOM1D_STATE_INCLUDED
#include "RadMom1D_Flux_Functions.h"
#endif // _RADMOM1D_STATE_INCLUDED
#ifndef _CELL1D_INCLUDED
#include "./Grid/Cell1D.h"
#endif // _CELL1D_INCLUDED
#ifndef _RADMOM1D_INPUT_INCLUDED
#include "RadMom1DInput.h"
#endif // _RADMOM1D_INPUT_INCLUDED
template<class cState, class pState>
class RadMom1D_UniformMesh;
/* Relational operators. */
template<class cState, class pState>
int operator ==(const RadMom1D_UniformMesh<cState, pState> &Soln1,
const RadMom1D_UniformMesh<cState, pState> &Soln2);
template<class cState, class pState>
int operator !=(const RadMom1D_UniformMesh<cState, pState> &Soln1,
const RadMom1D_UniformMesh<cState, pState> &Soln2);
/* Input-output operators. */
template<class cState, class pState>
ostream &operator << (ostream &out_file,
const RadMom1D_UniformMesh<cState, pState> &Soln);
template<class cState, class pState>
istream &operator >> (istream &in_file,
RadMom1D_UniformMesh<cState, pState> &Soln);
/* Define the classes. */
/******************************************************//**
* Class: RadMom1D_UniformMesh
*
* @brief Class definition of the 1D RadMom computational cell (i.e. solution + geometry)
*
* Member functions
* - W -- Return primitive solution state.
* - U -- Return conserved solution state.
* - X -- Return cell geometry.
* - dt -- Return local time step.
* - dUdt -- Return the solution residual.
* - dUdx -- Return the unlimited solution
* - gradient.
* - phi -- Return the solution slope limiters.
* - Uo -- Return initial solution state.
* - Nghost -- Number of ghost cells (!= 1 for
* - high-order)
*
* Member operators \n
* S -- a 1D RadMom solution
*
* - S = S;
* - S = S + S;
* - S = S - S;
* - S = +S;
* - S = -S;
* - S += S;
* - S -= S;
* - S == S;
* - S != S;
* - cout << S; (output function)
* - cin >> S; (input function)
*
********************************************************/
template<class cState, class pState>
class RadMom1D_UniformMesh{
public:
// typedef HighOrder1D<pState> HighOrderType; //!< high-order variable data type
typedef pState SOLN_pSTATE; //!< primitive solution state type
typedef cState SOLN_cSTATE; //!< conserved solution state type
pState W; //!< Primitive solution state.
cState U; //!< Conserved solution state.
Medium1D_State M; ; //!< Participating medium state.
Cell1D_Uniform X; //!< Cell geometry.
double dt; //!< Local time step.
cState dUdt; //!< Solution residual.
cState TotaldUdt; //!< Solution residual. Used for RK4
pState dWdx; //!< Unlimited solution gradient.
pState phi; //!< Solution slope limiter.
cState Uo; //!< Initial solution state.
static int residual_variable; //!< Indicates which variable is used
// Made public so can access them.
int Nghost; //!< Number of ghost cells(!= 1 for high-order)
int NCi; //!< Number of cells
int ICl, ICu; //!< Indexes (Start & End)
/* Creation, copy, and assignment constructors. */
RadMom1D_UniformMesh(void);
RadMom1D_UniformMesh(const RadMom1D_UniformMesh &Soln);
RadMom1D_UniformMesh(const pState &W0, const cState &U0, const Medium1D_State &M0, const Cell1D_Uniform &X0);
RadMom1D_UniformMesh(const pState &W0, const Medium1D_State &M0, const Cell1D_Uniform &X0);
RadMom1D_UniformMesh(const cState &U0, const Medium1D_State &M0, const Cell1D_Uniform &X0);
/* Evaluate source term */
cState Evaluate_Source_Term( void );
/* Field access */
const double & CellCenter(void) const {return X.x;} //!< return cell center
const double & CellDelta (void) {return X.dx;} //!< return cell delta
/* Operating functions */
double SolutionAtCoordinates_PWL (const double & X_Coord, const unsigned parameter) ;
/* Relational operators. */
friend int operator == <cState, pState> (const RadMom1D_UniformMesh<cState, pState> &Soln1,
const RadMom1D_UniformMesh<cState, pState> &Soln2);
friend int operator != <cState, pState> (const RadMom1D_UniformMesh<cState, pState> &Soln1,
const RadMom1D_UniformMesh<cState, pState> &Soln2);
/* Input-output operators. */
friend ostream &operator << <cState, pState> (ostream &out_file,
const RadMom1D_UniformMesh<cState, pState> &Soln);
friend istream &operator >> <cState, pState> (istream &in_file,
RadMom1D_UniformMesh<cState, pState> &Soln);
private:
};
/**********************************************************************
* RadMom1D_UniformMesh -- Create storage for the static variables. *
**********************************************************************/
// Initialize residual_variable
template<class cState, class pState>
int RadMom1D_UniformMesh<cState, pState>::residual_variable = 1;
/*******************************************************
* RadMom1D_UniformMesh<cState, pState>::MemberFunctions() *
******************************************************/
/* Constructor */
template<class cState, class pState>
inline RadMom1D_UniformMesh<cState, pState>::RadMom1D_UniformMesh(void) {
W.Vacuum(), M.Nullify(), U.Vacuum();
X = Cell1D_Uniform_ONE; dt = ZERO;
dUdt.Vacuum();
dWdx.Vacuum(); phi.Vacuum();
Uo.Vacuum();
residual_variable = 1;
}
template<class cState, class pState>
inline RadMom1D_UniformMesh<cState, pState>::RadMom1D_UniformMesh(const RadMom1D_UniformMesh &Soln) {
W = Soln.W; U = Soln.U; M = Soln.M; X = Soln.X;
dt = Soln.dt; dUdt = Soln.dUdt; dWdx = Soln.dWdx;
phi = Soln.phi; Uo = Soln.Uo;
NCi = Soln.NCi; Nghost = Soln.Nghost; ICl = Soln.ICl; ICu = Soln.ICu;
residual_variable = Soln.residual_variable;
}
template<class cState, class pState>
inline RadMom1D_UniformMesh<cState, pState>::RadMom1D_UniformMesh(const pState &W0,
const cState &U0,
const Medium1D_State &M0,
const Cell1D_Uniform &X0) {
W = W0; U = U0; M = M0; X = X0;
dt = ZERO; dUdt.Vacuum();
dWdx.Vacuum(); phi.Vacuum();
Uo.Vacuum();
residual_variable = 1;
}
template<class cState, class pState>
inline RadMom1D_UniformMesh<cState, pState>::RadMom1D_UniformMesh(const pState &W0,
const Medium1D_State &M0,
const Cell1D_Uniform &X0) {
W = W0; U = W0.U(); M = M0; X = X0;
dt = ZERO; dUdt.Vacuum();
dWdx.Vacuum(); phi.Vacuum();
Uo.Vacuum();
residual_variable = 1;
}
template<class cState, class pState>
inline RadMom1D_UniformMesh<cState, pState>::RadMom1D_UniformMesh(const cState &U0,
const Medium1D_State &M0,
const Cell1D_Uniform &X0) {
W = U0.W(); U = U0; M = M0; X = X0;
dt = ZERO; dUdt.Vacuum();
dWdx.Vacuum(); phi.Vacuum();
Uo.Vacuum();
residual_variable = 1;
}
//! Return the solution of the piecewise limited linear reconstruction at the coordinate X_Coord,
// for the required parameter.
template<class cState, class pState>
inline double RadMom1D_UniformMesh<cState, pState>::SolutionAtCoordinates_PWL (const double & X_Coord, const unsigned parameter) {
SOLN_pSTATE W_Temp;
double Distance(X_Coord - X.x);
W_Temp = W + (phi^dWdx)*Distance;
return W_Temp[parameter];
}
/********************************************************
* RadMom1D_UniformMesh -- Relational operators. *
********************************************************/
template<class cState, class pState>
inline int operator ==(const RadMom1D_UniformMesh<cState, pState> &Soln1,
const RadMom1D_UniformMesh<cState, pState> &Soln2) {
return (Soln1.W == Soln2.W && Soln1.U == Soln2.U && Soln1.M == Soln2.M &&
Soln1.X == Soln2.X && Soln1.dt == Soln2.dt &&
Soln1.dUdt == Soln2.dUdt && Soln1.dWdx == Soln2.dWdx &&
Soln1.phi == Soln2.phi && Soln1.Uo == Soln2.Uo );
}
template<class cState, class pState>
inline int operator !=(const RadMom1D_UniformMesh<cState, pState> &Soln1,
const RadMom1D_UniformMesh<cState, pState> &Soln2) {
return (Soln1.W != Soln2.W || Soln1.U != Soln2.U || Soln1.M != Soln2.M ||
Soln1.X != Soln2.X || Soln1.dt != Soln2.dt ||
Soln1.dUdt != Soln2.dUdt || Soln1.dWdx != Soln2.dWdx ||
Soln1.phi != Soln2.phi || Soln1.Uo != Soln2.Uo );
}
/********************************************************
* RadMom1D_UniformMesh -- Input-output operators. *
********************************************************/
template<class cState, class pState>
inline ostream &operator << (ostream &out_file,
const RadMom1D_UniformMesh<cState, pState> &Soln) {
out_file << Soln.X << Soln.M << Soln.U;
out_file.setf(ios::scientific);
return (out_file);
}
template<class cState, class pState>
inline istream &operator >> (istream &in_file,
RadMom1D_UniformMesh<cState, pState> &Soln) {
in_file >> Soln.X >> Soln.M >> Soln.U;
Soln.W = Soln.U.W();
return (in_file);
}
/**************************************************************************
* RadMom1D_UniformMesh::Evaluate_Source_Term. *
**************************************************************************/
template<class cState, class pState>
inline cState RadMom1D_UniformMesh<cState, pState>::Evaluate_Source_Term(void) {
cState Source;
// Include general source term.
Source = U.S(M);
return Source;
}
/******************************************************//**
* Routine: Allocate
*
* Allocate memory for 1D RadMom equation solution.
*
********************************************************/
template<class cState, class pState>
RadMom1D_UniformMesh<cState, pState>* Allocate(RadMom1D_UniformMesh<cState, pState> *Soln_ptr,
const RadMom1D_Input_Parameters<cState, pState> &IP) {
int NC; // number of cells in the computational domain
int Nghost; // number of ghost cells
int NCi; // number of ghost cells
/* Calculate the total number of computational cells */
Nghost = IP.Number_of_Ghost_Cells;
NCi = IP.Number_of_Cells_Idir;
NC = IP.Number_of_Cells_Idir + 2 * Nghost;
/* Allocate memory. */
Soln_ptr = new RadMom1D_UniformMesh<cState, pState>[NC];
/* Set preliminary mesh parameters */
for (int i=0; i<= NC-1; ++i){
// store domain indexes in each cell
Soln_ptr[i].Nghost = Nghost;
Soln_ptr[i].NCi = NCi;
Soln_ptr[i].ICl = Nghost;
Soln_ptr[i].ICu = NC - 1 - Nghost;
}//endfor
/* Return memory location. */
return(Soln_ptr);
}
/******************************************************//**
* Routine: Deallocate
*
* Deallocate memory for 1D RadMom equation solution.
*
********************************************************/
template<class cState, class pState>
RadMom1D_UniformMesh<cState, pState>* Deallocate(RadMom1D_UniformMesh<cState, pState> *Soln_ptr) {
/* Deallocate memory. */
delete []Soln_ptr;
Soln_ptr = NULL;
/* Return memory location. */
return(Soln_ptr);
}
/******************************************************//**
* Routine: Grid
*
* Generates a uniform mesh and assign the locations of
* the cell centers to appropriate solution variables.
*
********************************************************/
template<class cState, class pState>
void Grid(RadMom1D_UniformMesh<cState, pState> *Soln,
const double &xMin,
const double &xMax,
const int Number_of_Cells) {
int i;
double delta_x;
int TC;
TC = Number_of_Cells+2*Soln[0].Nghost; // total number of cells
/* Determine the mesh spacing. */
delta_x = (xMax - xMin)/double(Number_of_Cells);
Soln[0].X.setsize(delta_x);
/* Create the cells. */
Soln[0].X.x = xMin - (Soln[0].Nghost - HALF)*delta_x;
// Soln[0].CellHighOrder().AssociateGeometry(Soln[0].X); // Associate geometry with high-order solution variables
for ( i = 1 ; i <= TC-1 ; ++i ) {
// Initialize the coordinate of the centroids
Soln[i].X.x = Soln[0].X.x + double(i)*delta_x;
} /* endfor */
}
#endif /* _RADMOM1D_MESH_INCLUDED */