26template <MInt nDim,
class ppType>
49 template <MInt nDim_, MInt nDist,
class SysEqn>
52 template <MInt nDim_, MInt nDist,
class SysEqn>
55 template <MInt nDim_,
class ppType>
66 using Grid =
typename CartesianSolver::Grid;
67 using GridProxy =
typename CartesianSolver::GridProxy;
70 using CartesianSolver::c_globalGridId;
71 using CartesianSolver::domainId;
72 using CartesianSolver::domainOffset;
73 using CartesianSolver::exchangeData;
74 using CartesianSolver::getIdentifier;
75 using CartesianSolver::grid;
76 using CartesianSolver::haloCell;
77 using CartesianSolver::haloCellId;
78 using CartesianSolver::isActive;
79 using CartesianSolver::m_bandWidth;
80 using CartesianSolver::m_freeIndices;
81 using CartesianSolver::m_initFromRestartFile;
82 using CartesianSolver::m_innerBandWidth;
83 using CartesianSolver::m_Ma;
84 using CartesianSolver::m_outerBandWidth;
85 using CartesianSolver::m_Re;
86 using CartesianSolver::m_residualInterval;
87 using CartesianSolver::m_restartFile;
88 using CartesianSolver::m_restartInterval;
89 using CartesianSolver::m_restartTimeStep;
90 using CartesianSolver::m_solutionInterval;
91 using CartesianSolver::m_solverId;
92 using CartesianSolver::maxLevel;
93 using CartesianSolver::maxNoGridCells;
94 using CartesianSolver::maxRefinementLevel;
95 using CartesianSolver::maxUniformRefinementLevel;
96 using CartesianSolver::minLevel;
97 using CartesianSolver::mpiComm;
98 using CartesianSolver::neighborDomain;
99 using CartesianSolver::noDomains;
100 using CartesianSolver::noHaloCells;
101 using CartesianSolver::noNeighborDomains;
102 using CartesianSolver::noWindowCells;
103 using CartesianSolver::outputDir;
104 using CartesianSolver::readSolverSamplingVarNames;
105 using CartesianSolver::reductionFactor;
106 using CartesianSolver::restartDir;
107 using CartesianSolver::solverId;
108 using CartesianSolver::solverMethod;
109 using CartesianSolver::updateDomainInfo;
110 using CartesianSolver::windowCell;
111 using CartesianSolver::windowCellId;
116 MBool isCompressible() {
return m_isCompressible; }
119 MBool a_isBndryCell(
const MInt cellId)
const {
return a_hasProperty(cellId, SolverCell::IsBndryCell); }
122 maia::lb::cell::BitsetType::reference a_isBndryCell(
const MInt cellId) {
123 return a_hasProperty(cellId, SolverCell::IsBndryCell);
127 MBool a_isBndryGhostCell(
const MInt cellId)
const {
return a_hasProperty(cellId, SolverCell::IsGhost); }
130 MBool a_isInterface(
const MInt cellId)
const {
return m_cells.hasProperty(cellId, SolverCell::IsInterface); }
133 maia::lb::cell::BitsetType::reference a_isInterface(
const MInt cellId) {
134 return m_cells.hasProperty(cellId, SolverCell::IsInterface);
138 maia::lb::cell::BitsetType::reference a_onlyBoundary(
const MInt cellId) {
139 return a_hasProperty(cellId, SolverCell::OnlyBoundary);
143 MBool a_onlyBoundary(
const MInt cellId)
const {
return a_hasProperty(cellId, SolverCell::OnlyBoundary); }
146 MFloat& a_kappa(
const MInt cellId) {
return m_cells.kappa(cellId); }
149 MFloat a_kappa(
const MInt cellId)
const {
return m_cells.kappa(cellId); }
152 MFloat& a_diffusivity(
const MInt cellId) {
return m_cells.diffusivity(cellId); }
155 MFloat a_diffusivity(
const MInt cellId)
const {
return m_cells.diffusivity(cellId); }
158 MFloat& a_nu(
const MInt cellId) {
return m_cells.nu(cellId); }
161 MFloat& a_oldNu(
const MInt cellId) {
return m_cells.oldNu(cellId); }
164 const MFloat& a_coordinate(
const MInt cellId,
const MInt dir)
const {
return grid().tree().coordinate(cellId, dir); }
167 MFloat c_coordinate(
const MInt cellId,
const MInt dir)
const {
return grid().tree().coordinate(cellId, dir); }
170 MFloat& a_distribution(
const MInt cellId,
const MInt dir) {
return m_cells.distributions(cellId, dir); }
173 MFloat a_distribution(
const MInt cellId,
const MInt dir)
const {
return m_cells.distributions(cellId, dir); }
176 MFloat& a_oldDistribution(
const MInt cellId,
const MInt dir) {
return m_cells.oldDistributions(cellId, dir); }
179 MFloat a_oldDistribution(
const MInt cellId,
const MInt dir)
const {
return m_cells.oldDistributions(cellId, dir); }
182 MFloat& a_externalForces(
const MInt cellId,
const MInt dim) {
return m_cells.externalForces(cellId, dim); }
185 MFloat a_externalForces(
const MInt cellId,
const MInt dim)
const {
return m_cells.externalForces(cellId, dim); }
187 MFloat& a_previousDistribution(
const MInt cellId,
const MInt distr) {
188 return m_cells.previousDistribution(cellId, distr);
191 MFloat a_previousDistribution(
const MInt cellId,
const MInt distr)
const {
192 return m_cells.previousDistribution(cellId, distr);
195 MFloat& a_previousVariable(
const MInt cellId,
const MInt varId) {
return m_cells.previousVariable(cellId, varId); }
197 MFloat a_previousVariable(
const MInt cellId,
const MInt varId)
const {
198 return m_cells.previousVariable(cellId, varId);
202 MFloat& a_nuT(
const MInt cellId) {
return m_cells.nuT(cellId); }
205 MFloat a_nuT(
const MInt cellId)
const {
return m_cells.nuT(cellId); }
208 MFloat& a_oldNuT(
const MInt cellId) {
return m_cells.oldNuT(cellId); }
211 MFloat a_oldNuT(
const MInt cellId)
const {
return m_cells.oldNuT(cellId); }
214 MFloat a_nu(
const MInt cellId)
const {
return m_cells.nu(cellId); }
217 MFloat a_oldNu(
const MInt cellId)
const {
return m_cells.oldNu(cellId); }
220 maia::lb::cell::BitsetType::reference a_isInterfaceChild(
const MInt cellId) {
221 return a_hasProperty(cellId, SolverCell::IsInterfaceChild);
225 MBool a_isInterfaceChild(
const MInt cellId)
const {
return a_hasProperty(cellId, SolverCell::IsInterfaceChild); }
228 maia::lb::cell::BitsetType::reference a_isInterfaceParent(
const MInt cellId) {
229 return a_hasProperty(cellId, SolverCell::IsInterfaceParent);
233 MBool a_isInterfaceParent(
const MInt cellId)
const {
return a_hasProperty(cellId, SolverCell::IsInterfaceParent); }
236 MFloat& a_distributionThermal(
const MInt cellId,
const MInt dir) {
return m_cells.distributionsThermal(cellId, dir); }
239 MFloat a_distributionThermal(
const MInt cellId,
const MInt dir)
const {
240 return m_cells.distributionsThermal(cellId, dir);
244 MFloat& a_oldDistributionThermal(
const MInt cellId,
const MInt dir) {
245 return m_cells.oldDistributionsThermal(cellId, dir);
249 MFloat a_oldDistributionThermal(
const MInt cellId,
const MInt dir)
const {
250 return m_cells.oldDistributionsThermal(cellId, dir);
254 MFloat& a_distributionTransport(
const MInt cellId,
const MInt dir) {
255 return m_cells.distributionsTransport(cellId, dir);
259 MFloat a_distributionTransport(
const MInt cellId,
const MInt dir)
const {
260 return m_cells.distributionsTransport(cellId, dir);
264 MFloat& a_oldDistributionTransport(
const MInt cellId,
const MInt dir) {
265 return m_cells.oldDistributionsTransport(cellId, dir);
269 MFloat a_oldDistributionTransport(
const MInt cellId,
const MInt dir)
const {
270 return m_cells.oldDistributionsTransport(cellId, dir);
274 MFloat& a_variable(
const MInt cellId,
const MInt varId) {
return m_cells.variables(cellId, varId); }
277 MFloat a_variable(
const MInt cellId,
const MInt varId)
const {
return m_cells.variables(cellId, varId); }
280 MFloat& a_oldVariable(
const MInt cellId,
const MInt varId) {
return m_cells.oldVariables(cellId, varId); }
283 MFloat a_oldVariable(
const MInt cellId,
const MInt varId)
const {
return m_cells.oldVariables(cellId, varId); }
290 template <MBool
interpolate = true>
291 MFloat a_interpolatedVariable(
const MInt cellId,
const MInt varId,
const MFloat dt = 0.0)
const {
292 IF_CONSTEXPR(interpolate) {
return (1.0 + dt) * a_variable(cellId, varId) - dt * a_oldVariable(cellId, varId); }
294 return a_variable(cellId, varId);
299 MBool a_hasProperty(
const MInt cellId,
const Cell p)
const {
return grid().tree().hasProperty(cellId, p); }
302 maia::lb::cell::BitsetType::reference a_hasProperty(
const MInt cellId,
const SolverCell p) {
303 return m_cells.hasProperty(cellId, p);
307 MBool a_hasProperty(
const MInt cellId,
const SolverCell p)
const {
return m_cells.hasProperty(cellId, p); }
310 MInt& a_bndId(
const MInt cellId) {
return m_cells.bndId(cellId); }
313 MInt a_bndId(
const MInt cellId)
const {
return m_cells.bndId(cellId); }
317 virtual void initInterpolationForCell(
const MInt NotUsed(cellId)){};
319 MFloat c_cellLengthAtLevel(
const MInt level)
const {
return grid().cellLengthAtLevel(level); }
321 MFloat c_cellLengthAtCell(
const MInt cellId)
const {
return grid().cellLengthAtLevel(a_level(cellId)); }
326 return grid().neighborList(cellId, dir);
330 MInt c_neighborId(
const MInt cellId,
const MInt dir)
const {
332 return grid().neighborList(cellId, dir);
336 MInt a_hasNeighbor(
const MInt cellId,
const MInt dir)
const {
338 return static_cast<MInt>(grid().neighborList(cellId, dir) > -1);
341 MBool a_isHalo(
const MInt cellId)
const {
return m_cells.hasProperty(cellId, SolverCell::IsHalo); }
343 maia::lb::cell::BitsetType::reference a_isHalo(
const MInt cellId) {
345 return m_cells.hasProperty(cellId, SolverCell::IsHalo);
348 MBool a_isWindow(
const MInt cellId)
const {
return m_cells.hasProperty(cellId, SolverCell::IsWindow); }
350 maia::lb::cell::BitsetType::reference a_isWindow(
const MInt cellId) {
352 return m_cells.hasProperty(cellId, SolverCell::IsWindow);
355 void a_resetPropertiesSolver(
const MInt cellId) { m_cells.resetProperties(cellId); }
357 MFloat* a_variables_ptr(
MInt pCellId) {
return &a_variable(pCellId, 0); }
359 MFloat* a_oldVariables_ptr(
MInt pCellId) {
return &a_oldVariable(pCellId, 0); }
361 MInt c_globalId(
const MInt cellId)
const {
return grid().tree().globalId(cellId); }
363 MInt a_level(
const MInt cellId)
const {
return m_cells.level(cellId); }
365 MInt& a_level(
const MInt cellId) {
return m_cells.level(cellId); }
367 MFloat a_alphaGas(
const MInt cellId)
const {
return m_cells.invVolumeFraction(cellId); }
369 MFloat a_alphaGasLim(
const MInt cellId)
const {
return mMax(
mMin(m_cells.invVolumeFraction(cellId), 1.0), 0.0); }
371 MFloat& a_alphaGas(
const MInt cellId) {
return m_cells.invVolumeFraction(cellId); }
373 MFloat a_uOtherPhase(
const MInt cellId,
const MInt dir)
const {
return m_cells.uOtherPhase(cellId, dir); }
375 MFloat& a_uOtherPhase(
const MInt cellId,
const MInt dir) {
return m_cells.uOtherPhase(cellId, dir); }
377 MInt getIdAtPoint(
const MFloat* point, [[maybe_unused]]
MBool globalUnique =
false) {
378 return grid().findContainingLeafCell(point);
382 MInt c_noCells()
const {
return grid().tree().size(); }
384 MInt c_level(
const MInt cellId)
const {
return grid().tree().level(cellId); }
386 MInt c_noChildren(
const MInt cellId)
const {
return grid().tree().noChildren(cellId); }
388 MBool c_isLeafCell(
const MInt cellId)
const {
return grid().tree().isLeafCell(cellId); }
390 MInt c_childId(
const MInt cellId,
const MInt childNumber)
const {
return grid().tree().child(cellId, childNumber); }
392 MInt c_parentId(
const MInt cellId)
const {
return grid().tree().parent(cellId); }
399 const MInt pos = (
cellId * m_noLevelSetsUsedForMb) + set;
400 return m_levelSetValues[pos];
402 return m_levelSetValues[IDX_LSSETMB(cellId, set)];
407 MFloat a_levelSetFunctionMB(
const MInt cellId,
const MInt set)
const {
409 const MInt pos = (
cellId * m_noLevelSetsUsedForMb) + set;
410 return m_levelSetValues[pos];
412 return m_levelSetValues[IDX_LSSETMB(cellId, set)];
417 MInt& a_associatedBodyIds(
const MInt cellId,
const MInt set) {
419 const MInt pos = (
cellId * m_noLevelSetsUsedForMb) + set;
420 return m_associatedBodyIds[pos];
422 return m_associatedBodyIds[IDX_LSSETMB(cellId, set)];
427 MInt a_associatedBodyIds(
const MInt cellId,
const MInt set)
const {
429 const MInt pos = (
cellId * m_noLevelSetsUsedForMb) + set;
430 return m_associatedBodyIds[pos];
432 return m_associatedBodyIds[IDX_LSSETMB(cellId, set)];
437 MBool& a_isG0CandidateOfSet(
const MInt cellId,
const MInt set) {
return m_isG0CandidateOfSet[
cellId][set]; }
440 MBool a_isG0CandidateOfSet(
const MInt cellId,
const MInt set)
const {
return m_isG0CandidateOfSet[
cellId][set]; }
443 MBool a_isActive(
const MInt cellId)
const {
return a_hasProperty(cellId, SolverCell::IsActive); }
446 maia::lb::cell::BitsetType::reference a_isActive(
const MInt cellId) {
447 return a_hasProperty(cellId, SolverCell::IsActive);
451 MBool a_wasActive(
const MInt cellId)
const {
return a_hasProperty(cellId, SolverCell::WasActive); }
454 maia::lb::cell::BitsetType::reference a_wasActive(
const MInt cellId) {
455 return a_hasProperty(cellId, SolverCell::WasActive);
462 void swap_variables(
MInt pCellId) {
464 for(
MInt varId = 0; varId < m_noVariables; ++varId) {
466 for(
MInt varId = 0; varId < noVariables(); ++varId) {
468 std::swap(a_variable(pCellId, varId), a_oldVariable(pCellId, varId));
474 MBool isActive()
const override {
return grid().isActive(); }
475 void updateCellCollectorFromGrid();
477 virtual void activateAllCells(){};
478 virtual void activateInnerCells();
479 virtual void activateWindowCells();
480 virtual void activateAllButHaloCells();
481 virtual void propagation_step() = 0;
482 virtual void propagation_step_vol() = 0;
483 virtual void propagation_step_thermal() = 0;
484 virtual void propagation_step_thermal_vol() = 0;
485 virtual void propagation_step_transport() = 0;
486 virtual void propagation_step_transport_vol() = 0;
487 virtual void propagation_step_thermaltransport() = 0;
488 virtual void propagation_step_thermaltransport_vol() = 0;
490 virtual void volumeForces() = 0;
492 virtual void exchange(
MInt mode = 1);
493 virtual void exchangeLb(
MInt mode);
494 virtual void exchangeLbNB(
MInt mode);
495 virtual void exchangeOldDistributions();
498 void (
LbSolver::*m_receiveMethod)();
499 virtual void sendNormal();
500 virtual void receiveNormal();
501 virtual void sendReduced();
502 virtual void receiveReduced();
505 virtual void removeChildsLb(
const MInt parentId) = 0;
506 virtual void refineCellLb(
const MInt parentId,
const MInt* childIds) = 0;
507 virtual void restartBndCnd() = 0;
508 virtual void prolongation() = 0;
510 void initializeRefinedCellsPerLevel();
511 void initializeNewInterfaceParents();
513 void computeFFTStatistics();
514 void saveAdaptedGridFile(
MInt*
const p_recalcCellIds);
517 void (
LbSolver::*m_scatterMethod)();
518 inline void gatherNormal();
519 inline void scatterNormal();
520 inline void gatherReduced();
521 inline void scatterReduced();
523 void printCommunicationMethod();
526 void exchangeG0Candidates();
527 void preCoupleLs(std::vector<MInt>& maxGCellLevels);
530 void findG0Candidates(std::vector<MInt>& maxGCellLevels);
531 MInt setUpLbInterpolationStencil(
const MInt cellId,
MInt* interpolationCells,
MFloat* point);
534 void initializeMovingBoundaries();
538 void resetActiveCellList(
MInt mode = 0);
539 void resetExternalSources();
540 void exchangeExternalSources();
542 void prepareCommunication();
543 void prepareCommunicationNormal();
544 void prepareCommunicationReduced();
545 void markCellsForAdditionalComm();
547 void resetCellLists(
MBool resize =
true);
548 void loadRestartFile()
override;
549 virtual void saveRestartFile();
550 void copyGridProperties();
551 void returnCellInfo(
MInt cellId);
553 void initSolver()
override;
554 void finalizeInitSolver()
override;
555 void preTimeStep()
override;
556 MBool solutionStep()
override;
557 void saveSolverSolution(
MBool forceOutput,
const MBool finalTimeStep)
override;
558 virtual MBool maxResidual() {
559 m_log <<
"Called LbSolver::maxResidual without Implementation" << std::endl;
562 void outputInitSummary();
564 virtual void cleanUp(){};
566 void postTimeStep() {}
568 void storeOldDistributions();
569 void storeOldVariables();
570 void initNu(
const MInt cellId,
const MFloat nu);
573 virtual void clb_collision_step() = 0;
574 virtual void clb_smagorinsky_collision_step() = 0;
575 virtual void cumulant_collision_step() = 0;
576 virtual void bgki_collision_step(){};
577 virtual void bgki_collision_step_mb(){};
578 virtual void bgki_collision_step_mb_thermal(){};
579 virtual void bgki_collision_step_Guo_forcing(){};
580 virtual void bgki_init_collision_step(){};
581 virtual void bgkc_collision_step(){};
582 virtual void bgki_smagorinsky_collision_step(){};
583 virtual void bgki_smagorinsky_collision_step2(){};
584 virtual void bgki_smago_wall_collision_step(){};
585 virtual void bgki_dynamic_smago_collision_step(){};
586 virtual void bgki_euler_collision_step(){};
587 virtual void bgki_thermal_collision_step(){};
588 virtual void bgki_innerEnergy_collision_step(){};
589 virtual void bgki_totalEnergy_collision_step(){};
590 virtual void bgkc_transport_collision_step(){};
591 virtual void bgkc_thermal_transport_collision_step(){};
592 virtual void bgkc_innerenergy_transport_collision_step(){};
593 virtual void bgkc_totalenergy_transport_collision_step(){};
594 virtual void mrt_collision_step() = 0;
595 virtual void mrt2_collision_step() = 0;
596 virtual void mrt_smagorinsky_collision_step() = 0;
597 virtual void rbgk_collision_step() = 0;
598 virtual void rbgk_dynamic_smago_collision_step() = 0;
599 virtual void rbgk_smagorinsky_collision_step() = 0;
601 virtual void initializeLatticeBgk(){};
602 virtual void initializeLatticeBgkThermal(){};
603 virtual void initializeLatticeBgkTransport(){};
604 virtual void initializeLatticeBgkThermalTransport(){};
605 virtual void restartInitLb(){};
607 virtual void initSrcTermController() = 0;
608 virtual void initSrcTerms() = 0;
609 virtual void preCollisionSrcTerm() = 0;
610 virtual void postCollisionSrcTerm() = 0;
611 virtual void postPropagationSrcTerm() = 0;
612 virtual void postCollisionBc() = 0;
613 virtual void postPropagationBc() = 0;
614 virtual void updateVariablesFromOldDist() = 0;
615 virtual void updateVariablesFromOldDist_preCollision() = 0;
616 virtual void updateViscosity() = 0;
618 virtual void calcNodalLsValues(){};
620 inline void setIsActiveDefaultStates();
621 inline void setInActiveBndryCells();
622 inline void setInActiveMBCells();
623 inline void fillActiveCellList();
624 void getReLambdaAndUrmsInit();
627 MBool m_isInitSamplingVars =
false;
628 std::vector<MFloat**> m_samplingVariables{};
631 void (
LbSolver::*m_propagationStepMethod)();
632 void (
LbSolver::*m_solutionStepMethod)();
633 void (
LbSolver::*m_initializeMethod)();
634 void (
LbSolver::*m_restartInitLbMethod)();
650 void getDerivativeStencilAndCoefficient(std::array<MInt, 5>& cellIds, std::array<MFloat, 5>& coef) {
652 if(cellIds[0] > -1) {
654 if(cellIds[4] > -1) {
661 }
else if(cellIds[3] > -1) {
676 }
else if(cellIds[4] > -1) {
678 if(cellIds[1] > -1) {
695 if(cellIds[1] > -1) {
697 if(cellIds[3] > -1) {
712 }
else if(cellIds[3] > -1) {
731 void printScalingVariables();
734 MBool m_calculateDissipation;
739 MBool m_initFromCoarse;
742 MFloat** m_sendBuffers =
nullptr;
743 MFloat** m_receiveBuffers =
nullptr;
744 MInt** m_nghbrOffsetsWindow =
nullptr;
745 MInt** m_nghbrOffsetsHalo =
nullptr;
746 MFloat** m_baseAddresses =
nullptr;
747 MInt m_noVarsTransfer{};
748 MInt m_noElementsTransfer{};
749 MInt m_noDistsTransfer{};
750 MInt m_dataBlockSizeTotal{};
751 MInt* m_dataBlockSizes =
nullptr;
754 MBool m_reducedComm{};
755 MInt* m_noWindowDistDataPerDomain{};
756 MInt* m_noHaloDistDataPerDomain{};
757 MFloat*** m_commPtWindow{};
759 MInt* m_orderedNeighbors{};
760 MInt* m_needsFurtherExchange{};
761 MInt** m_windowDistsForExchange{};
762 MInt** m_haloDistsForExchange{};
764 MBool m_isRefined =
false;
765 MFloat m_interfaceCellSize{};
766 MBool nonBlockingComm()
const {
return m_nonBlockingComm; }
769 MBool m_setCellDataFinished =
false;
772 MInt m_currentNoG0Cells;
773 MFloat** m_nodalGValues{};
774 MInt* m_G0CellList{};
775 MInt* m_G0CellMapping{};
777 std::vector<CutCandidate<nDim>> m_G0Candidates;
778 MInt* m_sendBufferMB{};
779 MInt* m_receiveBufferMB{};
780 MInt m_maxNoSets = -1;
781 MInt m_levelSetId = 0;
782 MFloat* m_levelSetValues{};
783 MInt* m_associatedBodyIds{};
784 MBool** m_isG0CandidateOfSet{};
785 MInt m_noLevelSetsUsedForMb;
787 MInt m_noEmbeddedBodies;
788 MBool m_constructGField;
789 MBool m_useOnlyCollectedLS =
false;
790 MBool m_allowBndryAsG0 =
false;
792 MFloat* m_bodyVelocity =
nullptr;
793 MBool m_trackMovingBndry;
796 MInt m_noG0CandidatesTotal;
797 MInt* m_initialActiveCells =
nullptr;
800 MInt m_resTimestepPos;
804 MInt m_solutionOffset;
806 MFloat m_referenceLengthSTL;
808 MFloat m_noOuterBndryCells;
812 MBool m_nonNewtonian =
false;
815 MInt noVariables()
const override {
return m_noVariables; }
816 MInt noDistributions()
const {
return m_noDistributions; }
817 MFloat time()
const override {
return m_time; }
822 constexpr const Geom& geometry()
const {
return *m_geometry; }
828 MBool m_nonBlockingComm =
false;
830 Geom& geometry() {
return *m_geometry; }
850 MInt a_noCells()
const {
return m_cells.
size(); }
852 MFloat a_Nu()
const {
return m_nu; }
853 MInt a_FFTInterval()
const {
return m_fftInterval; }
856 MPI_Request* mpi_request{};
857 MPI_Request* mpi_requestR{};
858 MPI_Request* mpi_requestS{};
871 MInt m_arraySize[nDim];
872 MFloat* m_domainBoundaries{};
884 MFloat m_densityGradient{};
888 MInt m_currentMaxNoCells{};
889 MInt m_initialNoCells[3]{};
891 MBool m_densityFluctuations;
899 MInt m_noDistributions;
911 MFloat m_pulsatileFrequency;
913 MBool m_isInitRun =
false;
918 MInt m_initStartTime;
936 MInt* m_startLevel{};
939 MBool m_externalForcing;
941 MBool m_particleMomentumCoupling;
943 MBool m_saveExternalForces;
945 MBool m_updateAfterPropagation;
947 MBool m_initDensityGradient;
948 MFloat m_volumeAccel[3] = {};
949 MFloat m_volumeAccelBase[3] = {};
950 MBool m_controlVelocity =
false;
957 MFloat lastGlobalAvgV = -1.0;
958 MFloat integratedError = 0.0;
959 MFloat derivedError = 0.0;
960 MFloat previousError = 0.0;
961 MBool restart =
false;
966 MBool restartWithoutAlpha;
974 MFloat* m_residual =
nullptr;
975 MFloat* m_tmpResidual =
nullptr;
976 MInt* m_tmpResidualLvl =
nullptr;
977 MInt* m_maxResId =
nullptr;
978 MFloat** m_rescoordinates =
nullptr;
981 MFloat** m_momentumFlux =
nullptr;
982 MFloat* m_MijMij =
nullptr;
983 MFloat* m_MijLij =
nullptr;
988 MInt m_referenceLengthSegId;
989 MBool m_refineDiagonals =
true;
995 MFloat m_initTemperatureKelvin;
998 MBool m_isCompressible =
false;
999 MInt m_isThermal = 0;
1000 MInt m_innerEnergy = 0;
1001 MInt m_totalEnergy = 0;
1002 MFloat m_CouettePoiseuilleRatio = F0;
1003 MInt m_calcTotalPressureGradient = 0;
1010 MInt m_isTransport = 0;
1012 MFloat* m_cellLength =
nullptr;
1014 virtual void treatInterfaceCells();
1015 void correctInterfaceBcCells();
1016 virtual void setActiveCellList();
1019 virtual void initializeInterfaceCells();
1020 virtual void buildInterfaceCells();
1021 virtual void resetInterfaceCells();
1024 virtual void setInterpolationNeighbors();
1025 virtual void setInterpolationCoefficients();
1026 void setInterpolationNeighborsBC();
1027 void setInterpolationCoefficientsBC();
1029 std::vector<Collector<LbInterfaceCell>*> m_interfaceChildren;
1030 std::vector<Collector<LbParentCell>*> m_interfaceParents;
1032 MInt* m_noInterfaceChildren =
nullptr;
1033 MInt* m_noInterfaceParents =
nullptr;
1035 MBool m_correctInterfaceBcCells =
false;
1036 struct InterfaceLink {
1040 std::vector<InterfaceLink> m_interfaceChildrenBc;
1042 MBool m_saveDerivatives;
1043 MBool m_initRestart;
1046 MInt* m_activeCellList =
nullptr;
1047 MInt* m_activeCellListLvlOffset =
nullptr;
1050 virtual void writeGridToTecFile(
const MChar* fileName);
1051 virtual void writeGridToVtkFile(
const MChar* fileName);
1052 virtual void writeGridToVtkFileAscii(
const MChar* fileName);
1053 virtual void initPressureForce() = 0;
1054 virtual void initVolumeForces() = 0;
1055 virtual void initRunCorrection() = 0;
1056 void determineEqualDiagonals();
1059 void saveUVWRhoTOnlyPar(
const MChar* fileName,
const MChar* gridInputFileName,
MInt* recalcIdTree =
nullptr);
1060 void saveRestartWithDistributionsPar(
const MChar* fileName,
const MChar* gridInputFileName,
1061 MInt* recalcIdTree =
nullptr);
1062 void loadRestartWithDistributionsPar(
const MChar* fileName);
1063 void loadRestartWithoutDistributionsPar(
const MChar* fileName);
1064 void loadRestartWithoutDistributionsParFromCoarse(
const MChar* fileName);
1066 void calculateVelocityDerivative(
const MInt cellId,
MFloat (&gradient)[nDim][nDim]);
1067 template <MBool tI = false>
1069 MFloat calculateInterpolatedDerivative(
const MInt cellId,
const MInt velComp,
const MInt spaceDir,
const MFloat dt) {
1070 return calculateDerivative<true>(cellId, velComp, spaceDir, dt);
1072 inline MFloat calculatePressureDerivative(
MInt cellId,
MInt spaceDir);
1077 void accessSampleVariables(
MInt cellId,
MFloat*& vars);
1078 void interpolateToParentCells(
MInt parentlevel);
1079 void saveCoarseSolution();
1081 void createMPIComm(
const MInt* ranks,
MInt noRanks, MPI_Comm* comm);
1082 inline void writeSegmentBoundaryVTK(
MFloat** bndVs,
MInt num);
1086 virtual MFloat calculateReferenceLength(
MInt segmentId);
1087 inline MFloat calcCharLenAll(
MInt segmentId);
1088 inline MFloat calcCharLenParallelSplit(
MInt segmentId);
1091 virtual void getSolverSamplingProperties(std::vector<MInt>& samplingVars, std::vector<MInt>& noSamplingVars,
1092 std::vector<std::vector<MString>>& samplingVarNames,
1093 const MString featureName =
"");
1094 virtual void initSolverSamplingVariables(
const std::vector<MInt>& varIds,
const std::vector<MInt>& noSamplingVars);
1095 virtual void calcSamplingVariables(
const std::vector<MInt>& varIds,
const MBool exchange);
1096 void interpolateVariablesInCell(
const MInt cellId,
const MFloat* position,
MFloat* interpolationResult);
1098 void calcSamplingVarAtPoint(
const MFloat* point,
const MInt id,
const MInt sampleVarId,
MFloat* state,
1099 const MBool interpolate =
false);
1100 void loadSampleVariables(
MInt timeStep);
1101 void getSampleVariables(
MInt cellId,
const MFloat*& vars);
1102 void getSampleVariables(
const MInt cellId, std::vector<MFloat>& vars);
1103 MBool getSampleVarsDerivatives(
const MInt cellId, std::vector<MFloat>& vars);
1104 void calculateHeatRelease() { std::cerr <<
"calculateHeatRelease LbSolver " << std::endl; }
1105 void getHeatRelease(
MFloat*& heatRelease) { std::cerr <<
"getHeatRelease LbSolver " << heatRelease << std::endl; }
1108 void prepareAdaptation(std::vector<std::vector<MFloat>>& NotUsed(sensors),
1109 std::vector<MFloat>& NotUsed(sensorWeight),
1110 std::vector<std::bitset<64>>& NotUsed(sensorCellFlag),
1111 std::vector<MInt>& NotUsed(sensorSolverId))
override{};
1112 void prepareAdaptation()
override;
1113 void setSensors(std::vector<std::vector<MFloat>>& sensors, std::vector<MFloat>& sensorWeight,
1114 std::vector<std::bitset<64>>& sensorCellFlag, std::vector<MInt>& sensorSolverId)
override;
1115 void reinitAfterAdaptation()
override{};
1116 void postAdaptation()
override;
1117 void finalizeAdaptation()
override;
1118 void removeChilds(
const MInt)
override;
1119 void removeCell(
const MInt)
override;
1120 void refineCell(
const MInt)
override;
1121 void swapCells(
const MInt,
const MInt)
override;
1122 void swapProxy(
const MInt cellId0,
const MInt cellId1)
override;
1123 void resizeGridMap()
override;
1124 MBool prepareRestart(
MBool writeRestart,
MBool& writeGridRestart)
override;
1125 void reIntAfterRestart(
MBool doneRestart);
1126 void writeRestartFile(
const MBool writeRestart,
const MBool writeBackup,
const MString gridFileName,
1127 MInt* recalcIdTree)
override;
1130 void balance(
const MInt*
const ,
const MInt*
const ,
1131 const MInt*
const ,
const MInt )
override {
1132 TERMM(1,
"Use split balancing methods for LB solver instead of balance().");
1134 void setCellWeights(
MFloat* solverCellWeight)
override;
1135 void resetSolver()
override{};
1136 void finalizeBalance()
override{};
1139 MInt noLoadTypes()
const override;
1140 void getLoadQuantities(
MInt*
const loadQuantities)
const override;
1141 void getDefaultWeights(
MFloat* weights, std::vector<MString>& names)
const override;
1142 MFloat getCellLoad(
const MInt cellId,
const MFloat*
const weights)
const override;
1145 MBool hasSplitBalancing()
const override {
return true; }
1146 void balancePre()
override;
1147 void balancePost()
override;
1152 MInt noCellDataDlb()
const override {
1153 if(grid().isActive()) {
1154 return noSolverCellData();
1161 MInt cellDataTypeDlb(
const MInt dataId)
const {
1165 TERMM(1,
"Error: cellDataTypeDlb() might give wrong results on inactive ranks.");
1170 if(dataId > -1 && dataId < noSolverCellData()) {
1172 dataType = s_cellDataTypeDlb[dataId];
1174 TERMM(1,
"The requested dataId is not valid: " + std::to_string(dataId) +
" ("
1175 + std::to_string(noSolverCellData()) +
", " + std::to_string(noCellDataDlb()) +
")");
1182 MInt cellDataSizeDlb(
const MInt dataId,
const MInt gridCellId) {
1191 const MInt cellId = grid().tree().grid2solver(gridCellId);
1198 if(dataId > -1 && dataId < noSolverCellData()) {
1201 case CellData::VARIABLES:
1202 case CellData::OLD_VARIABLES:
1203 dataSize = noVariables();
1205 case CellData::DISTRIBUTIONS:
1206 case CellData::OLD_DISTRIBUTIONS:
1207 dataSize = noDistributions();
1210 case CellData::IS_ACTIVE:
1214 TERMM(1,
"Unknown data id. (" + std::to_string(dataId) +
")");
1218 TERMM(1,
"The requested dataId is not valid.");
1225 void getCellDataDlb(
const MInt dataId,
const MInt oldNoCells,
const MInt*
const bufferIdToCellId,
1226 MInt*
const data)
override {
1227 getCellDataDlb_(dataId, oldNoCells, bufferIdToCellId, data);
1231 void getCellDataDlb(
const MInt dataId,
const MInt oldNoCells,
const MInt*
const bufferIdToCellId,
1232 MFloat*
const data)
override {
1233 getCellDataDlb_(dataId, oldNoCells, bufferIdToCellId, data);
1237 void setCellDataDlb(
const MInt dataId,
const MInt*
const data)
override { setCellDataDlb_(dataId, data); };
1240 void setCellDataDlb(
const MInt dataId,
const MFloat*
const data)
override { setCellDataDlb_(dataId, data); };
1251 template <
typename DataType>
1252 void setCellDataDlb_(
const MInt dataId,
const DataType*
const data) {
1255#ifdef LBCOLLECTOR_SOA_MEMORY_LAYOUT
1256 TERMM(1,
"Balance data accessor not defined for SOA cell collector");
1260 if(m_setCellDataFinished) {
1265 if(!grid().isActive()) {
1269 const MInt noCells = m_cells.
size();
1271 if(dataId > -1 && dataId < noSolverCellData()) {
1274 case CellData::VARIABLES:
1275 std::copy_n(data, noCells * noVariables(), &m_cells.
variables(0, 0));
1277 case CellData::OLD_VARIABLES:
1278 std::copy_n(data, noCells * noVariables(), &m_cells.
oldVariables(0, 0));
1280 case CellData::DISTRIBUTIONS:
1281 std::copy_n(data, noCells * noDistributions(), &m_cells.
distributions(0, 0));
1283 case CellData::OLD_DISTRIBUTIONS:
1284 std::copy_n(data, noCells * noDistributions(), &m_cells.
oldDistributions(0, 0));
1287 std::copy_n(data, noCells, &m_cells.
nu(0));
1289 case CellData::IS_ACTIVE:
1290 for(
MInt i = 0; i < noCells; i++) {
1291 a_isActive(i) = (
MInt)data[i];
1295 TERMM(1,
"Unknown data id (" + std::to_string(dataId) +
").");
1299 TERMM(1,
"Invalid dataId: " + std::to_string(dataId));
1314 template <
typename DataType>
1315 void getCellDataDlb_(
const MInt dataId,
const MInt oldNoCells,
const MInt*
const bufferIdToCellId,
1316 DataType*
const data) {
1319#ifdef LBCOLLECTOR_SOA_MEMORY_LAYOUT
1320 TERMM(1,
"Balance data accessor not defined for SOA cell collector");
1323 ASSERT((dataId > -1 && dataId < noSolverCellData()),
"Invalid dataId in getCellData!");
1325 MInt localBufferId = 0;
1326 for(
MInt i = 0; i < oldNoCells; i++) {
1327 const MInt gridCellId = bufferIdToCellId[i];
1328 if(gridCellId < 0) {
1332 const MInt cellId = grid().tree().grid2solver(gridCellId);
1333 if(cellId < 0 || cellId >= noInternalCells()) {
1339 case CellData::VARIABLES: {
1340 const MInt dataSize = noVariables();
1341 std::copy_n(&m_cells.
variables(cellId, 0), dataSize, &data[localBufferId * dataSize]);
1344 case CellData::OLD_VARIABLES: {
1345 const MInt dataSize = noVariables();
1346 std::copy_n(&m_cells.
oldVariables(cellId, 0), dataSize, &data[localBufferId * dataSize]);
1349 case CellData::DISTRIBUTIONS: {
1350 const MInt dataSize = noDistributions();
1351 std::copy_n(&m_cells.
distributions(cellId, 0), dataSize, &data[localBufferId * dataSize]);
1354 case CellData::OLD_DISTRIBUTIONS: {
1355 const MInt dataSize = noDistributions();
1356 std::copy_n(&m_cells.
oldDistributions(cellId, 0), dataSize, &data[localBufferId * dataSize]);
1359 case CellData::NU: {
1360 const MInt dataSize = 1;
1361 std::copy_n(&m_cells.
nu(cellId), dataSize, &data[localBufferId * dataSize]);
1364 case CellData::IS_ACTIVE: {
1365 const MInt dataSize = 1;
1366 data[localBufferId * dataSize] = a_isActive(cellId);
1370 TERMM(1,
"Unknown data id (" + std::to_string(dataId) +
").");
1380 static constexpr const MInt count = 6;
1382 static constexpr const MInt VARIABLES = 0;
1383 static constexpr const MInt OLD_VARIABLES = 1;
1384 static constexpr const MInt DISTRIBUTIONS = 2;
1385 static constexpr const MInt OLD_DISTRIBUTIONS = 3;
1386 static constexpr const MInt NU = 4;
1387 static constexpr const MInt IS_ACTIVE = 5;
1394 MInt noSolverCellData()
const {
return CellData::count; };
1415 MInt findG0Candidates;
1418 MInt calcNodalValues;
1427 MBool m_adaptationSinceLastRestart;
1428 MBool m_adaptationSinceLastSolution;
1431#ifdef WAR_NVHPC_PSTL
1432 std::array<MFloat, 50> m_faculty;
1433 std::array<MInt, 27> m_nFld;
1434 std::array<MInt, 27> m_pFld;
1436 std::array<MInt, 24> m_mFld1;
1437 std::array<MInt, 24> m_mFld2;
1438 std::array<MInt, 27> m_oppositeDist;
1439 std::array<MFloat, 81> m_ppdfDir;
1440 std::array<MFloat, 4> m_tp;
1441 std::array<MInt, 3> m_distFld;
1442 std::array<MInt, 27> m_distType;
1450 MString m_adaptationInitMethod;
1451 std::set<MInt> m_refinedParents;
1452 MBool m_solidLayerExtension =
false;
1453 MBool m_writeLsData =
false;
1479 const MInt lbdir1 = 2 * spaceDir;
1480 const MInt lbdir2 = lbdir1 + 1;
1482 const MInt left = c_neighborId(cellId, lbdir1);
1483 const MInt right = c_neighborId(cellId, lbdir2);
1484 const MInt leftleft = (left > -1) ? c_neighborId(left, lbdir1) : -1;
1485 const MInt rightright = (right > -1) ? c_neighborId(right, lbdir2) : -1;
1489 if((left > -1) && (right > -1)) {
1490 if(leftleft > -1 && rightright > -1) {
1491 gradient = (-a_interpolatedVariable<tI>(rightright, comp, dt) + 8.0 * a_interpolatedVariable<tI>(right, comp, dt)
1492 - 8.0 * a_interpolatedVariable<tI>(left, comp, dt) + a_interpolatedVariable<tI>(leftleft, comp, dt))
1497 (2.0 * a_interpolatedVariable<tI>(right, comp, dt) + 3.0 * a_interpolatedVariable<tI>(cellId, comp, dt)
1498 - 6.0 * a_interpolatedVariable<tI>(left, comp, dt) + a_interpolatedVariable<tI>(leftleft, comp, dt))
1500 }
else if(rightright > -1) {
1502 (-a_interpolatedVariable<tI>(rightright, comp, dt) + 6.0 * a_interpolatedVariable<tI>(right, comp, dt)
1503 - 3.0 * a_interpolatedVariable<tI>(cellId, comp, dt) - 2.0 * a_interpolatedVariable<tI>(left, comp, dt))
1506 gradient = (a_interpolatedVariable<tI>(right, comp, dt) - a_interpolatedVariable<tI>(left, comp, dt)) / 2.0;
1512 gradient = a_interpolatedVariable<tI>(cellId, comp, dt) - a_interpolatedVariable<tI>(left, comp, dt);
1515 else if(right > -1) {
1516 gradient = a_interpolatedVariable<tI>(right, comp, dt) - a_interpolatedVariable<tI>(cellId, comp, dt);
1531 const MFloat F1bdx =
FFPOW2(maxLevel() - a_level(cellId));
1532 for(
MInt dir = 0; dir < nDim; dir++) {
1533 const MInt dir0 = 2 * dir;
1534 const MInt dir1 = 2 * dir + 1;
1536 auto isValid = [&](
const MInt l_cellId,
const MInt l_dir) ->
MInt {
1537 if(l_cellId != -1) {
1538 const MInt nghbrId = c_neighborId(l_cellId, l_dir);
1539 if(nghbrId > -1 && a_isActive(nghbrId)) {
1546 constexpr MInt noCellsInStencil = 5;
1547 std::array<MFloat, noCellsInStencil> coef;
1548 std::array<MInt, noCellsInStencil> cellIds;
1550 cellIds[1] = isValid(cellId, dir0);
1551 cellIds[0] = isValid(cellIds[1], dir0);
1553 cellIds[3] = isValid(cellId, dir1);
1554 cellIds[4] = isValid(cellIds[3], dir1);
1555 getDerivativeStencilAndCoefficient(cellIds, coef);
1557 for(
MInt i = 0; i < noCellsInStencil; i++) {
1561 for(
MInt veloId = 0; veloId < nDim; veloId++) {
1562 gradient[veloId][dir] = 0.0;
1563 for(
MInt i = 0; i < noCellsInStencil; i++) {
1564 gradient[veloId][dir] += cellIds[i] < 0 ? 0.0 : coef[i] * a_variable(cellIds[i], veloId);
GridCell
Grid cell Property Labels.
Storage of the Position of the Conservative Variables (RHO, RHO_VV, RHO_E) in the value vectors of th...
Storage of the Position of the Primitive Variables (u, v, w, T, p) in the value vectors of the solver...
This class is a ScratchSpace.
virtual MInt noInternalCells() const =0
Return the number of internal cells within this solver.
constexpr MInt size() const
Return size (i.e., currently used number of nodes)
Class that represents LB cell collector.
MFloat & variables(const MInt id, const MInt eid)
MFloat & nu(const MInt id)
Accessor for nu.
MFloat & oldVariables(const MInt id, const MInt eid)
MFloat & distributions(const MInt id, const MInt eid)
MFloat & oldDistributions(const MInt id, const MInt eid)
constexpr T mMin(const T &x, const T &y)
T constexpr POWX(T base, MUint exponent)
Compile time power calculation.
constexpr T mMax(const T &x, const T &y)
LbCell
LB cell Property Labels.
constexpr MFloat FFPOW2(MInt x)
std::basic_string< char > MString
IdType index(const FloatType *const x, const IdType level)
Return Hilbert index for given location and level in 2D or 3D.
GridCell Cell
Underlying enum type for property access.
MFloat dist(const Point< DIM > &p, const Point< DIM > &q)
Multi-to-multi mapping class.