forked from inmeso/mplb
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathevolution3d.cpp
More file actions
307 lines (294 loc) · 14.5 KB
/
Copy pathevolution3d.cpp
File metadata and controls
307 lines (294 loc) · 14.5 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
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
/**
* Copyright 2019 United Kingdom Research and Innovation
*
* Authors: See AUTHORS
*
* Contact: [jianping.meng@stfc.ac.uk and/or jpmeng@gmail.com]
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice
* this list of conditions and the following disclaimer in the documentation
* and or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* ANDANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*!
* @brief Wrap functions for main evolution cycle.
* @author Jianping Meng
* @details Define wrap functions for implementing the main evolution
* cycle
*/
#include "evolution3d.h"
#include "hilemms.h"
#include "model.h"
/*
* In the following routines, there are some variables are defined
* for the convenience of the translator which may not be able to
* understand a function parameter in the ops_par_loop call
* Even though, a variable rather than a numerical literacy will need
* some modifications in the Python translator.
*/
#ifdef OPS_3D
void UpdateTau3D() {
for (int blockIndex = 0; blockIndex < BlockNum(); blockIndex++) {
int* iterRng = BlockIterRng(blockIndex, IterRngWhole());
ops_par_loop(KerCalcTau3D, "KerCalcTau3D", g_Block[blockIndex],
SPACEDIM, iterRng,
ops_arg_dat(g_NodeType[blockIndex], NUMCOMPONENTS,
LOCALSTENCIL, "int", OPS_READ),
ops_arg_gbl(TauRef(), NUMCOMPONENTS, "double", OPS_READ),
ops_arg_dat(g_MacroVars[blockIndex], NUMMACROVAR,
LOCALSTENCIL, "double", OPS_READ),
ops_arg_dat(g_Tau[blockIndex], NUMCOMPONENTS, LOCALSTENCIL,
"double", OPS_RW));
}
}
void Collision3D() {
for (int blockIndex = 0; blockIndex < BlockNum(); blockIndex++) {
int* iterRng = BlockIterRng(blockIndex, IterRngWhole());
ops_par_loop(KerCollide3D, "KerCollide3D", g_Block[blockIndex],
SPACEDIM, iterRng,
ops_arg_gbl(pTimeStep(), 1, "double", OPS_READ),
ops_arg_dat(g_NodeType[blockIndex], NUMCOMPONENTS,
LOCALSTENCIL, "int", OPS_READ),
ops_arg_dat(g_f[blockIndex], NUMXI, LOCALSTENCIL, "double",
OPS_READ),
ops_arg_dat(g_feq[blockIndex], NUMXI, LOCALSTENCIL,
"double", OPS_READ),
ops_arg_dat(g_Tau[blockIndex], NUMCOMPONENTS, LOCALSTENCIL,
"double", OPS_READ),
ops_arg_dat(g_Bodyforce[blockIndex], NUMXI, LOCALSTENCIL,
"double", OPS_READ),
ops_arg_dat(g_fStage[blockIndex], NUMXI, LOCALSTENCIL,
"double", OPS_WRITE));
}
}
void Stream3D() {
for (int blockIndex = 0; blockIndex < BlockNum(); blockIndex++) {
int* iterRng = BlockIterRng(blockIndex, IterRngWhole());
ops_par_loop(KerStream3D, "KerStream3D", g_Block[blockIndex], SPACEDIM,
iterRng,
ops_arg_dat(g_NodeType[blockIndex], NUMCOMPONENTS,
LOCALSTENCIL, "int", OPS_READ),
ops_arg_dat(g_GeometryProperty[blockIndex], 1,
LOCALSTENCIL, "int", OPS_READ),
ops_arg_dat(g_fStage[blockIndex], NUMXI,
ONEPTLATTICESTENCIL, "double", OPS_READ),
ops_arg_dat(g_f[blockIndex], NUMXI, LOCALSTENCIL, "double",
OPS_RW));
}
}
void UpdateMacroVars3D() {
for (int blockIndex = 0; blockIndex < BlockNum(); blockIndex++) {
int* iterRng = BlockIterRng(blockIndex, IterRngWhole());
ops_par_loop(KerCalcMacroVars3D, "KerCalcMacroVars3D",
g_Block[blockIndex], SPACEDIM, iterRng,
ops_arg_gbl(pTimeStep(), 1, "double", OPS_READ),
ops_arg_dat(g_NodeType[blockIndex], NUMCOMPONENTS,
LOCALSTENCIL, "int", OPS_READ),
ops_arg_dat(g_CoordinateXYZ[blockIndex], SPACEDIM,
LOCALSTENCIL, "double", OPS_READ),
ops_arg_dat(g_f[blockIndex], NUMXI, LOCALSTENCIL, "double",
OPS_READ),
ops_arg_dat(g_MacroVars[blockIndex], NUMMACROVAR,
LOCALSTENCIL, "double", OPS_RW));
}
}
void UpdateFeqandBodyforce3D() {
for (int blockIndex = 0; blockIndex < BlockNum(); blockIndex++) {
int* iterRng = BlockIterRng(blockIndex, IterRngWhole());
ops_par_loop(KerCalcFeq3D, "KerCalcFeq3D", g_Block[blockIndex],
SPACEDIM, iterRng,
ops_arg_dat(g_NodeType[blockIndex], NUMCOMPONENTS,
LOCALSTENCIL, "int", OPS_READ),
ops_arg_dat(g_MacroVars[blockIndex], NUMMACROVAR,
LOCALSTENCIL, "double", OPS_READ),
ops_arg_dat(g_feq[blockIndex], NUMXI, LOCALSTENCIL,
"double", OPS_RW));
// time is not used in the current force
Real* timeF{0};
ops_par_loop(KerCalcBodyForce3D, "KerCalcBodyForce3D",
g_Block[blockIndex], SPACEDIM, iterRng,
ops_arg_gbl(&timeF, 1, "double", OPS_READ),
ops_arg_dat(g_NodeType[blockIndex], NUMCOMPONENTS,
LOCALSTENCIL, "int", OPS_READ),
ops_arg_dat(g_CoordinateXYZ[blockIndex], SPACEDIM,
LOCALSTENCIL, "double", OPS_READ),
ops_arg_dat(g_MacroVars[blockIndex], NUMMACROVAR,
LOCALSTENCIL, "double", OPS_READ),
ops_arg_dat(g_Bodyforce[blockIndex], NUMXI, LOCALSTENCIL,
"double", OPS_RW));
}
}
void TreatBlockBoundary3D(const int blockIndex, const int componentID,
const Real* givenVars, int* range,
const VertexTypes boundaryType) {
switch (boundaryType) {
case Vertex_ExtrapolPressure1ST: {
ops_par_loop(
KerCutCellExtrapolPressure1ST3D,
"KerCutCellExtrapolPressure1ST3D", g_Block[blockIndex],
SPACEDIM, range,
ops_arg_gbl(givenVars, NUMMACROVAR, "double", OPS_READ),
ops_arg_dat(g_NodeType[blockIndex], NUMCOMPONENTS,
ONEPTREGULARSTENCIL, "int", OPS_READ),
ops_arg_dat(g_GeometryProperty[blockIndex], 1, LOCALSTENCIL,
"int", OPS_READ),
ops_arg_dat(g_f[blockIndex], NUMXI, ONEPTREGULARSTENCIL,
"double", OPS_RW));
} break;
case Vertex_EQMDiffuseRefl: {
ops_par_loop(
KerCutCellEQMDiffuseRefl3D, "KerCutCellEQMDiffuseRefl3D",
g_Block[blockIndex], SPACEDIM, range,
ops_arg_dat(g_f[blockIndex], NUMXI, LOCALSTENCIL, "double",
OPS_RW),
ops_arg_dat(g_NodeType[blockIndex], NUMCOMPONENTS, LOCALSTENCIL,
"int", OPS_READ),
ops_arg_dat(g_GeometryProperty[blockIndex], 1, LOCALSTENCIL,
"int", OPS_READ),
ops_arg_gbl(givenVars, NUMMACROVAR, "double", OPS_READ),
ops_arg_gbl(&componentID, 1, "int", OPS_READ));
} break;
case Vertex_Periodic: {
ops_par_loop(KerCutCellPeriodic3D, "KerCutCellPeriodic3D",
g_Block[blockIndex], SPACEDIM, range,
ops_arg_dat(g_f[blockIndex], NUMXI, LOCALSTENCIL,
"double", OPS_RW),
ops_arg_dat(g_NodeType[blockIndex], NUMCOMPONENTS,
LOCALSTENCIL, "int", OPS_READ),
ops_arg_dat(g_GeometryProperty[blockIndex], 1,
LOCALSTENCIL, "int", OPS_READ),
ops_arg_gbl(&componentID, 1, "int", OPS_READ));
} break;
default:
break;
}
}
void InitialiseSolution3D() {
UpdateFeqandBodyforce3D();
CopyDistribution3D(g_feq, g_f);
}
void CopyDistribution3D(const ops_dat* fSrc, ops_dat* fDest) {
for (int blockIndex = 0; blockIndex < BlockNum(); blockIndex++) {
int* iterRng = BlockIterRng(blockIndex, IterRngWhole());
ops_par_loop(KerCopyf, "KerCopyf", g_Block[blockIndex], SPACEDIM,
iterRng,
ops_arg_dat(fSrc[blockIndex], NUMXI, LOCALSTENCIL,
"double", OPS_READ),
ops_arg_dat(fDest[blockIndex], NUMXI, LOCALSTENCIL,
"double", OPS_WRITE));
}
}
void CalcResidualError3D() {
for (int macroVarIdx = 0; macroVarIdx < MacroVarsNum(); macroVarIdx++) {
for (int blockIdx = 0; blockIdx < BlockNum(); blockIdx++) {
int* iterRng = BlockIterRng(blockIdx, IterRngWhole());
ops_par_loop(KerCalcMacroVarSquareofDifference,
"KerCalcMacroVarSquareofDifference", g_Block[blockIdx],
SPACEDIM, iterRng,
ops_arg_dat(g_MacroVars[blockIdx], NUMMACROVAR,
LOCALSTENCIL, "double", OPS_READ),
ops_arg_dat(g_MacroVarsCopy[blockIdx], NUMMACROVAR,
LOCALSTENCIL, "double", OPS_READ),
ops_arg_gbl(¯oVarIdx, 1, "int", OPS_READ),
ops_arg_reduce(g_ResidualErrorHandle[macroVarIdx], 1,
"double", OPS_INC));
}
}
for (int macroVarIdx = 0; macroVarIdx < MacroVarsNum(); macroVarIdx++) {
ops_reduction_result(g_ResidualErrorHandle[macroVarIdx],
(double*)&g_ResidualError[2 * macroVarIdx]);
}
for (int blockIdx = 0; blockIdx < BlockNum(); blockIdx++) {
int* iterRng = BlockIterRng(blockIdx, IterRngWhole());
ops_par_loop(KerCopyMacroVars, "KerCopyMacroVars3D", g_Block[blockIdx],
SPACEDIM, iterRng,
ops_arg_dat(g_MacroVars[blockIdx], NUMMACROVAR,
LOCALSTENCIL, "double", OPS_READ),
ops_arg_dat(g_MacroVarsCopy[blockIdx], NUMMACROVAR,
LOCALSTENCIL, "double", OPS_RW));
}
for (int macroVarIdx = 0; macroVarIdx < MacroVarsNum(); macroVarIdx++) {
for (int blockIdx = 0; blockIdx < BlockNum(); blockIdx++) {
int* iterRng = BlockIterRng(blockIdx, IterRngWhole());
ops_par_loop(KerCalcMacroVarSquare, "KerCalcMacroVarSquare3D",
g_Block[blockIdx], SPACEDIM, iterRng,
ops_arg_dat(g_MacroVars[blockIdx], NUMMACROVAR,
LOCALSTENCIL, "double", OPS_READ),
ops_arg_gbl(¯oVarIdx, 1, "int", OPS_READ),
ops_arg_reduce(g_ResidualErrorHandle[macroVarIdx], 1,
"double", OPS_INC));
}
}
for (int macroVarIdx = 0; macroVarIdx < MacroVarsNum(); macroVarIdx++) {
ops_reduction_result(g_ResidualErrorHandle[macroVarIdx],
(double*)&g_ResidualError[2 * macroVarIdx + 1]);
}
}
void DispResidualError3D(const int iter, const Real checkPeriod) {
ops_printf("##########Residual Error at %i time step##########\n", iter);
for (int macroVarIdx = 0; macroVarIdx < MacroVarsNum(); macroVarIdx++) {
Real residualError = g_ResidualError[2 * macroVarIdx] /
g_ResidualError[2 * macroVarIdx + 1] /
(checkPeriod * TimeStep());
ops_printf("Residual of %s = %.17g\n",
MacroVarName()[macroVarIdx].c_str(), residualError);
}
}
void StreamCollision3D() {
#if DebugLevel >= 1
ops_printf("Calculating the macroscopic variables...\n");
#endif
UpdateMacroVars3D();
// Real TotalMass{0};
// CalcTotalMass(&TotalMass);
// Real Ratio{TotalMass/TotalMeshSize()};
// NormaliseF(&Ratio);
// UpdateMacroVars();
CopyDistribution3D(g_f, g_fStage);
#if DebugLevel >= 1
ops_printf("Calculating the equilibrium function and the body force term...\n");
#endif
UpdateFeqandBodyforce3D();
#if DebugLevel >= 1
ops_printf("Calculating the relaxation time...\n");
#endif
UpdateTau3D();
#if DebugLevel >= 1
ops_printf("Colliding...\n");
#endif
Collision3D();
#if DebugLevel >= 1
ops_printf("Streaming...\n");
#endif
Stream3D();
#if DebugLevel >= 1
ops_printf("Updating the halos...\n");
#endif
if (nullptr != HaloGroup()) {
ops_halo_transfer(HaloGroup());
}
#if DebugLevel >= 1
ops_printf("Implementing the boundary conditions...\n");
#endif
ImplementBoundaryConditions();
}
#endif /* OPS_3D */