MAIA bb96820c
Multiphysics at AIA
Loading...
Searching...
No Matches
postprocessingfvlpt.cpp
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
8#include "IO/cpptoml.h"
9#include "postdata.h"
10#include "postprocessing.cpp"
11
12
13using namespace std;
14
15template <MInt nDim, class SysEqn>
17 PostData<nDim>* data,
19 LPT<nDim>* ppLptSolver_)
20 : PostProcessingInterface(postprocessingId_),
21 PostProcessingLPT<nDim>(postprocessingId_, data, ppLptSolver_),
22 PostProcessingFv<nDim, SysEqn>(postprocessingId_, data, ppFvSolver_) {
23 m_ppSolverLpt = ppLptSolver_;
24 m_ppSolverFv = ppFvSolver_;
25
27 m_fvLPTSpeciesId = Context::getSolverProperty<MInt>("fvLptSpeciesId", lpt().solverId(), AT_, &m_fvLPTSpeciesId);
28}
29
36template <MInt nDim, class SysEqn>
38 TRACE();
39
40
41 if(globalTimeStep % this->m_sprayComputeInterval == 0) {
42 updateData();
43 advanceDataStep();
44 }
45
46
47 if(globalTimeStep % this->m_sprayWriteInterval == 0) {
48 writeSprayData();
49 resetDataStep();
50 }
51}
52
59template <MInt nDim, class SysEqn>
61 TRACE();
62
63
64 m_sprayTimes[m_sprayDataStep][0] = globalTimeStep;
65 m_sprayTimes[m_sprayDataStep][1] = fvSolver().physicalTime();
66 m_sprayTimes[m_sprayDataStep][2] = fvSolver().crankAngle(fvSolver().physicalTime(), 0);
67
68 fvSolver().stopLoadTimer(AT_);
69 if(lpt().isActive()) {
70 lpt().startLoadTimer(AT_);
71 this->particleMass();
72 this->particlePenetration();
73 this->parcelStatistics();
74 lpt().stopLoadTimer(AT_);
75 }
76
77 fvSolver().startLoadTimer(AT_);
78
79 if(fvSolver().isActive()) {
80 this->vapourMass(m_fvLPTSpeciesId);
81 this->vapourPenetration(lpt().m_spawnCoord);
82 }
83}
84
85template <MInt nDim, class SysEqn>
87 TRACE();
88
89 static MBool firstTime = true;
90
91 if(this->m_finalTimeStep && fvSolver().domainId() == 0) {
92 cerr << "Writing final postProcessing Data" << endl;
93 }
94
95 if(firstTime && fvSolver().domainId() == 0) {
96 cerr0 << "Writing first postProcessing Data" << endl;
97 }
98
99 fvSolver().stopLoadTimer(AT_);
100
101 const MBool timerEnabled = fvSolver().dlbTimersEnabled();
102
103 if(timerEnabled) {
105 }
106
107 const MBool hasInjection = lpt().m_sprayModel != nullptr ? true : false;
108 MInt injDataSize = this->getInjectionData();
109 MPI_Allreduce(MPI_IN_PLACE, &injDataSize, 1, MPI_INT, MPI_MAX, fvSolver().mpiComm(), AT_, "INPLACE", "injDataSize");
110 const MInt dataSize = (this->m_finalTimeStep || firstTime) ? m_sprayDataStep : m_sprayDataSize;
111 const MInt vapourPenSize = nDim == 3 ? 16 : 12;
112
113 // rank with injector writes data
114 const MInt injectorCellId = lpt().isActive() ? lpt().injectorCellId() : -1;
115
116 if(hasInjection && injDataSize != dataSize) {
117 cerr0 << "Spray-PP data differs: " << injDataSize << " inj-Size " << dataSize << " sprayData-Size" << endl;
118 }
119
120 if(dataSize > 0) {
121 // exchange data:
122 MPI_Allreduce(MPI_IN_PLACE, &m_particleCV[0][0], m_sprayDataSize * (2 + nDim), MPI_DOUBLE, MPI_SUM,
123 fvSolver().mpiComm(), AT_, "INPLACE", "m_particleCV");
124
125 MPI_Allreduce(MPI_IN_PLACE, &m_sprayStat[0][0], m_sprayDataSize * 5, MPI_DOUBLE, MPI_SUM, fvSolver().mpiComm(), AT_,
126 "INPLACE", "m_sprayStat");
127
128 MPI_Allreduce(MPI_IN_PLACE, &m_particlePen[0][0], m_sprayDataSize * 19, MPI_DOUBLE, MPI_MAX, fvSolver().mpiComm(),
129 AT_, "INPLACE", "m_particlePen");
130
131 MPI_Allreduce(MPI_IN_PLACE, &m_vapourCV[0][0], m_sprayDataSize * (5 + 2 * nDim), MPI_DOUBLE, MPI_SUM,
132 fvSolver().mpiComm(), AT_, "INPLACE", "m_vapourCV");
133
134 MPI_Allreduce(MPI_IN_PLACE, &m_vapourPen[0][0], m_sprayDataSize * vapourPenSize, MPI_DOUBLE, MPI_MAX,
135 fvSolver().mpiComm(), AT_, "INPLACE", "m_vapourPen");
136 }
137
138 if(injectorCellId >= 0) {
139
140 ofstream ofl;
141
142 // backup a few older files
143 if(firstTime) {
144 // file with conservation variables
145 MString fileNameCheck = lpt().outputDir() + "sprayCons";
146 if(fileExists(fileNameCheck)) {
147 const MString fileName = lpt().outputDir() + "sprayCons_" + to_string(lpt().m_restartTimeStep);
148 if(!fileExists(fileName)) copyFile(fileNameCheck, fileName);
149 }
150 if(!lpt().m_restartFile) {
151 ofl.open(fileNameCheck, ios_base::out | ios_base::trunc);
152 ofl << "#0:ts 1:time 2:CAD 3:pMass 4:pEnergy 5-7:pMomentum 8:vMass 9:aMass 10:gMass 11:gEnergy 12:gMomX "
153 "13:gMomY 14:gMomZ";
154 ofl << endl;
155 ofl.close();
156 }
157
158 // file with liquid penetration lengths
159 fileNameCheck = lpt().outputDir() + "liquidPen";
160 if(fileExists(fileNameCheck)) {
161 const MString fileName = lpt().outputDir() + "liquidPen_" + to_string(lpt().m_restartTimeStep);
162 if(!fileExists(fileName)) copyFile(fileNameCheck, fileName);
163 }
164 if(!lpt().m_restartFile) {
165 ofl.open(fileNameCheck, ios_base::out | ios_base::trunc);
166 ofl << "#0:ts 1:time 2:CAD 3-5:liquidPen"
167 "6-8:liquidWidth";
168 ofl << endl;
169 ofl.close();
170 }
171
172 // file with vapour penetration lengths
173 fileNameCheck = lpt().outputDir() + "vapourPen";
174 if(fileExists(fileNameCheck)) {
175 const MString fileName = lpt().outputDir() + "vapourPen_" + to_string(lpt().m_restartTimeStep);
176 if(!fileExists(fileName)) copyFile(fileNameCheck, fileName);
177 }
178 if(!lpt().m_restartFile) {
179 ofl.open(fileNameCheck, ios_base::out | ios_base::trunc);
180 ofl << "#0:ts 1:time 2:CAD 3-5:v01Pen 6-8:v1Pen 9-11:v5Pen";
181 ofl << endl;
182 ofl.close();
183 }
184
185 // file with spray statistics
186 fileNameCheck = lpt().outputDir() + "sprayStats";
187 if(fileExists(fileNameCheck)) {
188 const MString fileName = lpt().outputDir() + "sprayStats_" + to_string(lpt().m_restartTimeStep);
189 if(!fileExists(fileName)) copyFile(fileNameCheck, fileName);
190 }
191
192 if(!lpt().m_restartFile) {
193 ofl.open(fileNameCheck, ios_base::out | ios_base::trunc);
194 ofl << "#0:ts 1:time 2:CAD 3:noParcles 4:noDroplets 5:SMS 6:avgDiameter";
195 ofl << endl;
196 ofl.close();
197 }
198
199 // file with injection statistics
200 if(hasInjection) {
201 fileNameCheck = lpt().outputDir() + "injStats";
202 if(fileExists(fileNameCheck)) {
203 const MString fileName = lpt().outputDir() + "injStats_" + to_string(lpt().m_restartTimeStep);
204 if(!fileExists(fileName)) copyFile(fileNameCheck, fileName);
205 }
206 if(!lpt().m_restartFile) {
207 ofl.open(fileNameCheck, ios_base::out | ios_base::trunc);
208 ofl << "#0:ts 1:timeSinceSOI 2:injProgress 3:rampFactor 4:noInjPart 5:noInjDrop 6:injDiameter 7:injMass "
209 "8:injXMom 9:injYMom 10:injZMom 11:injEnergy";
210 ofl << endl;
211 ofl.close();
212 }
213
214 // file with sum of conservative variables from injection
215 fileNameCheck = lpt().outputDir() + "injSums";
216 if(fileExists(fileNameCheck)) {
217 const MString fileName = lpt().outputDir() + "injSums_" + to_string(lpt().m_restartTimeStep);
218 if(!fileExists(fileName)) copyFile(fileNameCheck, fileName);
219 }
220 if(!lpt().m_restartFile) {
221 ofl.open(fileNameCheck, ios_base::out | ios_base::trunc);
222 ofl << "#0:ts 1:injMass 2-4:injMomentum 5:injEnergy 6:evapMass";
223 ofl << endl;
224 ofl.close();
225 }
226 }
227 }
228
229
230 MString fileName = lpt().outputDir() + "sprayCons";
231 ofl.open(fileName, ios_base::out | ios_base::app);
232
233 if(ofl.is_open() && ofl.good()) {
234 for(MInt i = 0; i < dataSize; i++) {
235 ofl << m_sprayTimes[i][0] << setprecision(7) << " " << m_sprayTimes[i][1] << " " << m_sprayTimes[i][2] << " "
236 << setprecision(12);
237 for(MInt v = 0; v < 2 + nDim; v++) {
238 ofl << m_particleCV[i][v] << " ";
239 }
240 for(MInt v = 0; v < 5 + 2 * nDim; v++) {
241 ofl << m_vapourCV[i][v] << " ";
242 }
243 ofl << endl;
244 }
245 }
246 ofl.close();
247
248 fileName = lpt().outputDir() + "liquidPen";
249 ofl.open(fileName, ios_base::out | ios_base::app);
250 if(ofl.is_open() && ofl.good()) {
251 for(MInt i = 0; i < dataSize; i++) {
252 ofl << m_sprayTimes[i][0] << setprecision(7) << " " << m_sprayTimes[i][1] << " " << setprecision(7)
253 << m_sprayTimes[i][2] << " " << setprecision(8);
254 for(MInt j = 0; j < 19; j++) {
255 ofl << m_particlePen[i][j] << " ";
256 }
257 ofl << endl;
258 }
259 }
260 ofl.close();
261
262 fileName = lpt().outputDir() + "vapourPen";
263 ofl.open(fileName, ios_base::out | ios_base::app);
264 if(ofl.is_open() && ofl.good()) {
265 for(MInt i = 0; i < dataSize; i++) {
266 ofl << m_sprayTimes[i][0] << setprecision(7) << " " << m_sprayTimes[i][1] << " " << setprecision(7)
267 << m_sprayTimes[i][2] << " " << setprecision(8);
268 for(MInt j = 0; j < vapourPenSize; j++) {
269 ofl << m_vapourPen[i][j] << " ";
270 }
271 ofl << endl;
272 }
273 }
274 ofl.close();
275
276 fileName = lpt().outputDir() + "sprayStats";
277 ofl.open(fileName, ios_base::out | ios_base::app);
278 if(ofl.is_open() && ofl.good()) {
279 for(MInt i = 0; i < dataSize; i++) {
280 ofl << m_sprayTimes[i][0] << setprecision(7) << " " << m_sprayTimes[i][1] << " " << m_sprayTimes[i][2] << " "
281 << setprecision(12);
282 for(MInt j = 0; j < 5; j++) {
283 ofl << m_sprayStat[i][j] << " ";
284 }
285 ofl << endl;
286 }
287 }
288 ofl.close();
289
290 if(hasInjection) {
291 fileName = lpt().outputDir() + "injStats";
292 ofl.open(fileName, ios_base::out | ios_base::app);
293 if(ofl.is_open() && ofl.good()) {
294 for(MInt i = 0; i < injDataSize; i++) {
295 ofl << setprecision(12);
296 for(MInt j = 0; j < 15; j++) {
297 ofl << m_injectionData[i][j] << " ";
298 }
299 ofl << endl;
300 }
301 }
302 ofl.close();
303
304 fileName = lpt().outputDir() + "injSums";
305 ofl.open(fileName, ios_base::out | ios_base::app);
306 if(ofl.is_open() && ofl.good()) {
307 for(MInt i = 0; i < injDataSize; i++) {
308 ofl << m_injectionData[i][0] << " " << setprecision(12);
309 for(MInt j = 0; j < nDim + 5; j++) {
310 ofl << m_cInjData[i][j] << " ";
311 }
312 ofl << endl;
313 }
314 }
315 ofl.close();
316 }
317 }
318 firstTime = false;
319
320 // reset data
321 for(MInt i = 0; i < m_sprayDataSize; i++) {
322 for(MInt j = 0; j < 5; j++) {
323 m_sprayStat[i][j] = 0;
324 }
325 for(MInt j = 0; j < 2 + nDim; j++) {
326 m_particleCV[i][j] = 0;
327 }
328 for(MInt j = 0; j < 19; j++) {
329 m_particlePen[i][j] = 0;
330 }
331 if(hasInjection) {
332 for(MInt j = 0; j < 15; j++) {
333 m_injectionData[i][j] = 0;
334 }
335 }
336 }
337
338 if(timerEnabled) {
340 }
341 fvSolver().startLoadTimer(AT_);
342}
343
void enableAllDlbTimers(const MBool *const wasEnabled=nullptr)
Enable all DLB timers (or those given by the array wasEnabled)
Definition: dlbtimer.h:265
void disableAllDlbTimers(MBool *const wasEnabled=nullptr)
Disable all (enabled) DLB timers.
Definition: dlbtimer.h:300
Definition: lpt.h:82
Definition: postdata.h:23
fv * m_ppSolverFv
void writeSprayData() override
lptSolver * m_ppSolverLpt
lptSolver & lpt() const
MInt m_fvLPTSpeciesId
PostProcessingFvLPT(MInt postprocessingId_, PostData< nDim > *data, fv *ppFvSolver_, lptSolver *ppLptSolver_)
void computeSprayData() override
base function which is called every time-Step in postprocessInSolve
void updateData()
updates all post-processing data from postprocessing-fv or postprocessing-lpt
MInt copyFile(const MString &fromName, const MString &toName)
Copies file fromName to file toName.
Definition: functions.cpp:83
MBool fileExists(const MString &fileName)
Returns true if the file fileName exists, false otherwise.
Definition: functions.cpp:73
MInt globalTimeStep
std::ostream cerr0
int32_t MInt
Definition: maiatypes.h:62
std::basic_string< char > MString
Definition: maiatypes.h:55
bool MBool
Definition: maiatypes.h:58
int MPI_Allreduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm, const MString &name, const MString &sndvarname, const MString &rcvvarname)
same as MPI_Allreduce
DlbTimerController g_dlbTimerController