MAIA bb96820c
Multiphysics at AIA
Loading...
Searching...
No Matches
postdata.h
Go to the documentation of this file.
1// Copyright (C) 2024 The m-AIA AUTHORS
2//
3// This file is part of m-AIA (https://git.rwth-aachen.de/aia/m-AIA/m-AIA)
4//
5// SPDX-License-Identifier: LGPL-3.0-only
6
7#ifndef POSTDATA_H
8#define POSTDATA_H
9
10#include <algorithm>
13#include "GRID/cartesiangrid.h"
14#include "cartesiansolver.h"
15#include "compiler_config.h"
16#include "enums.h"
18
19template <MInt nDim, class SysEqn>
21
22template <MInt nDim_>
23class PostData : public maia::CartesianSolver<nDim_, PostData<nDim_>> {
24 public:
25 static constexpr MInt nDim = nDim_;
26
28 using Grid = typename CartesianSolver::Grid;
29 using GridProxy = typename CartesianSolver::GridProxy;
32
35
36
37 // used CartesianSolver
38 using CartesianSolver::domainId;
39 using CartesianSolver::domainOffset;
40 using CartesianSolver::grid;
41 using CartesianSolver::haloCellId;
42 using CartesianSolver::isActive;
43 using CartesianSolver::m_freeIndices;
44 using CartesianSolver::m_recalcIds;
45 using CartesianSolver::m_restart;
46 using CartesianSolver::m_restartFile;
47 using CartesianSolver::m_restartInterval;
48 using CartesianSolver::m_restartOffset;
49 using CartesianSolver::m_restartTimeStep;
50 using CartesianSolver::m_solutionInterval;
51 using CartesianSolver::m_solutionOffset;
52 using CartesianSolver::m_solutionOutput;
53 using CartesianSolver::m_solutionTimeSteps;
54 using CartesianSolver::m_solverId;
55 using CartesianSolver::maxLevel;
56 using CartesianSolver::maxNoGridCells;
57 using CartesianSolver::maxRefinementLevel;
58 using CartesianSolver::maxUniformRefinementLevel;
59 using CartesianSolver::minLevel;
60 using CartesianSolver::mpiComm;
61 using CartesianSolver::noHaloCells;
62 using CartesianSolver::noNeighborDomains;
63 using CartesianSolver::noWindowCells;
64 using CartesianSolver::outputDir;
65 using CartesianSolver::restartDir;
66 using CartesianSolver::returnIdleRecord;
67 using CartesianSolver::returnLoadRecord;
68 using CartesianSolver::saveGridFlowVars;
69 using CartesianSolver::solverId;
70 using CartesianSolver::updateDomainInfo;
71 using CartesianSolver::windowCellId;
72
74
75 PostData(MInt, GridProxy& gridProxy_, Geom& geometry_, const MPI_Comm comm);
76
78
80
82 Geom& geometry() const { return *m_geometry; }
83
84 MInt noInternalCells() const override { return grid().noInternalCells(); }
85 MFloat timeStep() const { return m_timeStep; }
86 MFloat time() const override { return globalTimeStep; }
87
88 void preTimeStep() override{};
89 void postTimeStep() override{};
90 MBool solutionStep() override { return true; };
91 void initSolver() override;
92 void finalizeInitSolver() override;
93 MBool prepareRestart(MBool, MBool&) override;
94
95 void writeRestartFile(const MBool, const MBool, const MString, MInt*) override;
96 void writeRestartFile(MBool) override{};
97 void saveDataFile(const MBool writeBackup,
98 const MString fileName,
99 const MInt noVars,
100 std::vector<MString>& variablesName,
101 MFloat* variables);
102 void saveRestartFile(const MBool writeBackup);
103 void loadRestartFile();
104 void loadMeanFile(const MString fileName);
105 void loadGridFlowVars(const MChar* fileName, MInt noVariables, std::vector<MString> name);
106 void saveSolverSolution(const MBool, const MBool);
108 void prepareAdaptation() override;
109 void postAdaptation() override;
110 void finalizeAdaptation() override;
111 // Sensors
112 void setSensors(std::vector<std::vector<MFloat>>& sensors,
113 std::vector<MFloat>& sensorWeight,
114 std::vector<std::bitset<64>>& sensorCellFlag,
115 std::vector<MInt>& sensorSolverId) override;
116
117 void removeChilds(const MInt) override;
118 void removeCell(const MInt) override;
119 void refineCell(const MInt) override;
120 void swapCells(const MInt, const MInt) override;
121 void swapProxy(const MInt cellId0, const MInt cellId1) override;
122 MInt cellOutside(const MFloat*, const MInt, const MInt) override;
123 void resizeGridMap() override;
124
125 virtual void cleanUp(){};
126
127 void copyGridProperties();
129 void setVariableNames();
130
132 MInt c_noCells() const { return grid().tree().size(); }
133
134 MInt a_noCells() const { return m_cells.size(); }
135
137 MInt a_hasNeighbor(const MInt cellId, const MInt dir) const {
138 if(cellId > (m_cells.size() - 1)) return -1;
139 return grid().tree().hasNeighbor(cellId, dir);
140 }
141
143 const MFloat& c_coordinate(const MInt cellId, const MInt dim) { return grid().tree().coordinate(cellId, dim); }
144
146 MFloat c_coordinate(const MInt cellId, const MInt dim) const { return grid().tree().coordinate(cellId, dim); }
147
149 MInt c_level(const MInt cellId) const { return grid().tree().level(cellId); }
150
151 // This method is necessary for the postprocessing instance to compile
152 MInt a_level(const MInt) const { TERMM(1, "Make this function return something meaningful in future!"); }
154 MInt c_noChildren(const MInt cellId) const { return grid().tree().noChildren(cellId); }
155
157 MLong c_parentId(const MInt cellId) const { return grid().tree().parent(cellId); }
158
160 MLong c_globalId(const MInt cellId) const { return grid().tree().globalId(cellId); }
161
162 MLong c_childId(const MInt cellId, const MInt pos) const { return grid().tree().child(cellId, pos); }
163
165 MInt noVariables() const { return m_noVariables; };
166
168 MFloat& a_variable(const MInt cellId, const MInt varId) { return m_cells.variable(cellId, varId); }
169
171 MFloat a_variable(const MInt cellId, const MInt varId) const { return m_cells.variable(cellId, varId); }
172
173 MFloat& a_averagedVariable(const MInt cellId, const MInt varId) { return m_averagedVars[cellId][varId]; }
174
176
177 MBool isMeanFile() const { return m_isMeanFile; }
178 MInt fileNoVars() const { return m_fileNoVars; }
179 std::vector<MString> fileVarNames() const { return m_fileVarNames; }
180
182 MBool a_isHalo(const MInt cellId) const { return m_cells.hasProperty(cellId, SolverCell::IsHalo); }
183
185 maia::post::cell::BitsetType::reference a_isHalo(const MInt cellId) {
186 return m_cells.hasProperty(cellId, SolverCell::IsHalo);
187 }
188
190 MBool a_isWindow(const MInt cellId) const { return m_cells.hasProperty(cellId, SolverCell::IsWindow); }
191
193 maia::post::cell::BitsetType::reference a_isWindow(const MInt cellId) {
194 return m_cells.hasProperty(cellId, SolverCell::IsWindow);
195 }
196
198 void a_resetPropertiesSolver(const MInt cellId) { m_cells.resetProperties(cellId); }
199
200 // time related
203
204 // restart/output related properties
206
207 std::pair<MInt, MInt> getPropertyVariableOffset(MString s) {
209 return (index > -1) ? m_variableOffset[index]
210 : std::make_pair(std::numeric_limits<MInt>::max(), std::numeric_limits<MInt>::min());
211 }
212
215 if(index > -1) {
216 m_variableOffset[index].first = start;
217 m_variableOffset[index].second = start + length;
218 }
219 }
220
222
224
225 // Partitioning
226 void setCellWeights(MFloat*) override;
227 MInt noLoadTypes() const override;
228 void getDefaultWeights(MFloat* weights, std::vector<MString>& names) const;
229 void getLoadQuantities(MInt* const loadQuantities) const override;
230 MFloat getCellLoad(const MInt cellId, const MFloat* const weights) const override;
231 void getDomainDecompositionInformation(std::vector<std::pair<MString, MInt>>& domainInfo) override;
232 void getSolverTimings(std::vector<std::pair<MString, MFloat>>& solverTimings, const MBool) override;
233
235 MInt noCellDataDlb() const override { return 1; }; // communicated data: variables
236 MInt cellDataTypeDlb(const MInt dataId) const override {
237 if(dataId == 0) {
238 return MFLOAT;
239 } else {
240 TERMM(1, "solverCelldataType: invalid data id " + std::to_string(dataId));
241 }
242 };
243 MInt cellDataSizeDlb(const MInt dataId, const MInt gridCellId) override;
244
245 void getCellDataDlb(const MInt dataId, const MInt oldNoCells, const MInt* const bufferIdToCellId,
246 MFloat* const data) override {
247 getCellDataDlb_(dataId, oldNoCells, bufferIdToCellId, data);
248 };
249
251 void setCellDataDlb(const MInt dataId, const MFloat* const data) override { setCellDataDlb_(dataId, data); };
252
253 public:
254 std::vector<MString> m_variablesName;
255
256 // Optional storage location for computed/loaded mean variables
258
259 protected:
262 auto entry = std::find(m_propertyName.begin(), m_propertyName.end(), s);
263 if(entry != m_propertyName.end()) {
264 return std::distance(m_propertyName.begin(), entry);
265 } else {
266 return -1;
267 }
268 };
269
270 const std::vector<MString> m_propertyName = {"primitive",
271 "square",
272 "kurtosis",
273 "skewness",
274 "statisticCombustionAnalysis",
275 "averageVorticity",
276 "averageSpeedOfSound",
277 "lamb0",
278 "du",
279 "drho",
280 "dp",
281 "gradu",
282 "ugradu",
283 "ugradrho",
284 "gradprho",
285 "rhodivu",
286 "correlation"};
287
288 static const std::vector<std::vector<MString>> m_averageVariableName;
289
290 std::vector<std::pair<MInt, MInt>> m_variableOffset;
291
292 // MFloat** m_variables_ = nullptr;
297
299
301
302
303 // balancing:
304 MBool hasSplitBalancing() const override { return true; }
306 void resetSolver() override;
307 void balancePre() override;
308 void balancePost() override;
309 void finalizeBalance() override;
310
311
312 // Indicator if a loaded file contains computed mean variables etc.
314 // Number of variables in loaded file
316 // Variable names from loaded file
317 std::vector<MString> m_fileVarNames{};
318
319
320 private:
322 template <typename dataType>
323 void setCellDataDlb_(const MInt dataId, const dataType* const data) {
324 TRACE();
325
326 // Nothing to do if solver is not active
327 if(!isActive()) {
328 return;
329 }
330
331 // Set the variables if this is the correct reinitialization stage
332 if(dataId == 0) {
334 std::copy_n(data, noInternalCells() * noVariables(), &a_variable(0, 0));
335 }
336 } else {
337 TERMM(1, "Unknown data id.");
338 }
339 }
340
341
343 template <typename dataType>
344 void getCellDataDlb_(const MInt dataId, const MInt oldNoCells, const MInt* const bufferIdToCellId,
345 dataType* const data) {
346 TRACE();
347
348 MInt localBufferId = 0;
349 for(MInt i = 0; i < oldNoCells; i++) {
350 const MInt gridCellId = bufferIdToCellId[i];
351
352 if(gridCellId < 0) continue;
353
354 const MInt cellId = grid().tree().grid2solver(gridCellId);
355 if(cellId < 0 || cellId >= noInternalCells()) {
356 continue;
357 }
358
359 switch(dataId) {
360 case 0: {
361 const MInt dataSize = noVariables();
362 std::copy_n(&a_variable(cellId, 0), dataSize, &data[localBufferId * dataSize]);
363 break;
364 }
365 default:
366 TERMM(1, "Unknown data id.");
367 break;
368 }
369 localBufferId++;
370 }
371 }
372
375 static constexpr std::array<MInt, nDim> getArray012() {
376 IF_CONSTEXPR(nDim == 2) {
377 std::array<MInt, 2> a = {0, 1};
378 return a;
379 }
380 else {
381 std::array<MInt, 3> a = {0, 1, 2};
382 return a;
383 }
384 }
385};
386
387#endif // POSTDATA_H
GridCell
Grid cell Property Labels.
Definition: postdata.h:23
MFloat getCellLoad(const MInt cellId, const MFloat *const weights) const override
Return the load of a single cell (given computational weights).
Definition: postdata.cpp:770
MInt cellDataSizeDlb(const MInt dataId, const MInt gridCellId) override
Return data size to be communicated during DLB for a grid cell and given data id.
Definition: postdata.cpp:1113
void readProperties()
void setVariableNames()
Definition: postdata.cpp:181
void prepareAdaptation() override
prepare solver adaptation
Definition: postdata.cpp:800
void postAdaptation() override
reinit the solver after a single adaptation step
Definition: postdata.cpp:854
MString m_outputFormat
Definition: postdata.h:205
MBool hasSplitBalancing() const override
Return if load balancing for solver is split into multiple methods or implemented in balance()
Definition: postdata.h:304
void finalizeInitSolver() override
Definition: postdata.cpp:276
MFloat timeStep() const
Definition: postdata.h:85
MInt noInternalCells() const override
Return the number of internal cells within this solver.
Definition: postdata.h:84
void setCellDataDlb_(const MInt dataId, const dataType *const data)
Set the solver cell data after DLB.
Definition: postdata.h:323
MBool m_adaptationSinceLastRestart
Definition: postdata.h:296
void getDefaultWeights(MFloat *weights, std::vector< MString > &names) const
Return the default weights for all load quantities.
Definition: postdata.cpp:683
MInt m_fileNoVars
Definition: postdata.h:315
MBool solutionStep() override
Definition: postdata.h:90
void refineCell(const MInt) override
Definition: postdata.cpp:894
MFloat m_timeStep
Definition: postdata.h:201
MInt noLoadTypes() const override
Return the number of Ls load types.
Definition: postdata.cpp:670
void getCellDataDlb(const MInt dataId, const MInt oldNoCells, const MInt *const bufferIdToCellId, MFloat *const data) override
Definition: postdata.h:245
void writeRestartFile(MBool) override
Definition: postdata.h:96
void resizeGridMap() override
Swap the given cells.
Definition: postdata.cpp:984
void setCellWeights(MFloat *) override
sets the cell-weight for balancing and a restarting
Definition: postdata.cpp:721
MInt c_noCells() const
Returns the number of grid-cells.
Definition: postdata.h:132
typename CartesianSolver::GridProxy GridProxy
Definition: postdata.h:29
MFloat time() const override
Return the time.
Definition: postdata.h:86
void getDomainDecompositionInformation(std::vector< std::pair< MString, MInt > > &domainInfo) override
Return decomposition information, i.e. number of local elements,...
Definition: postdata.cpp:703
void setPropertyVariableOffset(MString s, MInt start, MInt length)
Definition: postdata.h:213
void loadGridFlowVars(const MChar *fileName, MInt noVariables, std::vector< MString > name)
This function reads the parallel Netcdf cartesian grid cell based solution/restart file currently use...
Definition: postdata.cpp:545
MInt getVariablePropertyIndex(MString s)
Return the number of primitive variables.
Definition: postdata.h:261
void finalizeAdaptation() override
reinit the solver after the full adaptation loop!
Definition: postdata.cpp:882
MInt noCellDataDlb() const override
Methods to inquire solver data information.
Definition: postdata.h:235
void saveRestartFile(const MBool writeBackup)
Definition: postdata.cpp:356
static constexpr MInt nDim
Definition: postdata.h:25
Geom & geometry() const
Access the solver's geometry.
Definition: postdata.h:82
maia::post::cell::BitsetType::reference a_isHalo(const MInt cellId)
Returns IsHalo of the cell cellId.
Definition: postdata.h:185
MInt fileNoVars() const
Definition: postdata.h:178
std::vector< std::pair< MInt, MInt > > m_variableOffset
Definition: postdata.h:290
MBool prepareRestart(MBool, MBool &) override
Prepare the solvers for a grid-restart.
Definition: postdata.cpp:312
maia::post::cell::BitsetType::reference a_isWindow(const MInt cellId)
Returns IsWindow of the cell cellId.
Definition: postdata.h:193
MInt a_level(const MInt) const
Definition: postdata.h:152
MInt cellOutside(const MFloat *, const MInt, const MInt) override
checks if a child lies outSide of the domain! necessary for refinement at the bndry!
Definition: postdata.cpp:1025
void saveDataFile(const MBool writeBackup, const MString fileName, const MInt noVars, std::vector< MString > &variablesName, MFloat *variables)
Definition: postdata.cpp:372
MInt cellDataTypeDlb(const MInt dataId) const override
Definition: postdata.h:236
MFloat & a_variable(const MInt cellId, const MInt varId)
Returns conservative variable v of the cell cellId for variables varId.
Definition: postdata.h:168
const std::vector< MString > m_propertyName
Definition: postdata.h:270
MFloat c_coordinate(const MInt cellId, const MInt dim) const
Returns the coordinate of the cell from the grid().tree() cellId for dimension dir.
Definition: postdata.h:146
MBool isMeanFile() const
Definition: postdata.h:177
void getCellDataDlb_(const MInt dataId, const MInt oldNoCells, const MInt *const bufferIdToCellId, dataType *const data)
Store the solver data for a given data id ordered in the given buffer for DLB.
Definition: postdata.h:344
MLong c_childId(const MInt cellId, const MInt pos) const
Definition: postdata.h:162
MFloat a_variable(const MInt cellId, const MInt varId) const
Returns conservative variable v of the cell cellId for variables varId.
Definition: postdata.h:171
Geom * m_geometry
Definition: postdata.h:79
MBool a_isWindow(const MInt cellId) const
Returns IsWindow of the cell cellId.
Definition: postdata.h:190
void removeChilds(const MInt) override
Coarsen the given cell.
Definition: postdata.cpp:937
MInt a_hasNeighbor(const MInt cellId, const MInt dir) const
Returns wether cell cellId has a neighbor in dir dir.
Definition: postdata.h:137
MInt c_noChildren(const MInt cellId) const
Returns the number of children of the cell cellId.
Definition: postdata.h:154
void balancePre() override
Reinitialize solver for DLB prior to setting solution data.
Definition: postdata.cpp:1046
void finalizeBalance() override
Reinitialize solver after all data structures have been recreated.
Definition: postdata.cpp:1102
MLong c_parentId(const MInt cellId) const
Returns the grid parent id of the cell cellId.
Definition: postdata.h:157
MFloat ** m_averagedVars
Definition: postdata.h:257
MBool m_forceAdaptation
Definition: postdata.h:295
void initSolver() override
Definition: postdata.cpp:135
void setSensors(std::vector< std::vector< MFloat > > &sensors, std::vector< MFloat > &sensorWeight, std::vector< std::bitset< 64 > > &sensorCellFlag, std::vector< MInt > &sensorSolverId) override
set the sensors for a single adaptation step
Definition: postdata.cpp:815
std::pair< MInt, MInt > getPropertyVariableOffset(MString s)
Definition: postdata.h:207
void getSolverTimings(std::vector< std::pair< MString, MFloat > > &solverTimings, const MBool) override
Get solver timings.
Definition: postdata.cpp:648
MInt m_loadBalancingReinitStage
Definition: postdata.h:305
MInt c_level(const MInt cellId) const
Returns the grid level of the cell cellId.
Definition: postdata.h:149
MBool m_isMeanFile
Definition: postdata.h:313
void removeCell(const MInt) override
Remove the given cell.
Definition: postdata.cpp:966
void swapCells(const MInt, const MInt) override
Definition: postdata.cpp:994
MString getVariableName(MInt offset)
Definition: postdata.cpp:197
typename maia::grid::tree::Tree< nDim >::Cell Cell
Definition: postdata.h:31
MInt noVariables() const
Return the number of primitive variables.
Definition: postdata.h:165
MInt m_noVariables
Definition: postdata.h:293
MBool m_forceWriteRestart
Definition: postdata.h:175
MLong c_globalId(const MInt cellId) const
Returns the global grid id of the grid cell cellId.
Definition: postdata.h:160
std::vector< MString > m_variablesName
Definition: postdata.h:254
void preTimeStep() override
Definition: postdata.h:88
void setAndAllocateSolverData(const MBool)
Definition: postdata.cpp:150
std::vector< MString > m_fileVarNames
Definition: postdata.h:317
void resetSolver() override
Reset the solver prior to load balancing.
Definition: postdata.cpp:1037
void saveSolverSolution(const MBool, const MBool)
Definition: postdata.cpp:575
MFloat m_time
Definition: postdata.h:202
maia::post::collector::PostCellCollector< nDim > m_cells
Collector for POST data.
Definition: postdata.h:34
typename maia::CartesianSolver< nDim, PostData > CartesianSolver
Definition: postdata.h:27
void reIntAfterRestart(MBool)
This function resets the grid-trigger after a restart that is handled by the grid-controller!
Definition: postdata.cpp:345
static constexpr std::array< MInt, nDim > getArray012()
Static indices for accessing post variables in nDim spatial dimensions.
Definition: postdata.h:375
MInt m_sourceVarsIndex
Definition: postdata.h:223
void postTimeStep() override
Definition: postdata.h:89
static const std::vector< std::vector< MString > > m_averageVariableName
Definition: postdata.h:288
void copyGridProperties()
Definition: postdata.cpp:112
typename CartesianSolver::Grid Grid
Definition: postdata.h:28
void setCellDataDlb(const MInt dataId, const MFloat *const data) override
Set solver data for DLB.
Definition: postdata.h:251
void loadMeanFile(const MString fileName)
load a file for averaging
Definition: postdata.cpp:488
MFloat & a_averagedVariable(const MInt cellId, const MInt varId)
Definition: postdata.h:173
MString m_currentGridFileName
Definition: postdata.h:300
void balancePost() override
Reinitialize solver for DLB after to setting solution data.
Definition: postdata.cpp:1087
MInt a_noCells() const
Definition: postdata.h:134
void writeRestartFile(const MBool, const MBool, const MString, MInt *) override
Definition: postdata.cpp:290
std::vector< MString > fileVarNames() const
Definition: postdata.h:179
const MFloat & c_coordinate(const MInt cellId, const MInt dim)
Returns the coordinate of the cell from the grid().tree() cellId for dimension dir.
Definition: postdata.h:143
MBool a_isHalo(const MInt cellId) const
Returns IsHalo of the cell cellId.
Definition: postdata.h:182
void swapProxy(const MInt cellId0, const MInt cellId1) override
Definition: postdata.cpp:1013
void getLoadQuantities(MInt *const loadQuantities) const override
Return the cumulative load quantities on this domain.
Definition: postdata.cpp:742
void a_resetPropertiesSolver(const MInt cellId)
Returns property p of the cell cellId.
Definition: postdata.h:198
~PostData()
Definition: postdata.h:77
virtual void cleanUp()
Definition: postdata.h:125
void loadRestartFile()
Definition: postdata.cpp:454
MInt m_adaptationLevel
Definition: postdata.h:294
Class that represents Post cell collector.
@ MFLOAT
Definition: enums.h:269
MInt globalTimeStep
int32_t MInt
Definition: maiatypes.h:62
std::basic_string< char > MString
Definition: maiatypes.h:55
double MFloat
Definition: maiatypes.h:52
int64_t MLong
Definition: maiatypes.h:64
bool MBool
Definition: maiatypes.h:58
char MChar
Definition: maiatypes.h:56
PostCell
POST cell Property Labels.
Definition: contexttypes.h:19