MAIA bb96820c
Multiphysics at AIA
Loading...
Searching...
No Matches
lbsrctermsponge.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
7#include "lbsrctermsponge.h"
8
9#include "UTIL/parallelfor.h"
10#include "lbsrctermcontroller.h"
11#include "lbsyseqn.h"
12
13namespace maia::lb {
14
15//---LbSrcTerm_spongeRhoConst---------------------------------------------------
24template <MInt nDim, MInt nDist, class SysEqn>
25class LbSrcTerm_spongeRhoConst : public LbSrcTerm_sponge<nDim, nDist, SysEqn> {
26 public:
29 void apply_preCollision() override{};
30 void apply_postCollision() override;
31 void apply_postPropagation() override{};
32
33 private:
34};
35
36template <MInt nDim, MInt nDist, class SysEqn>
38 TRACE();
39 LbSolverDxQy<nDim, nDist, SysEqn>* const s = this->m_solver; // alias for readability
41
42 const MInt timeStep = s->getCurrentTimeStep();
43 const MUint noSpongeCells = this->m_spongeCells.size();
44 maia::parallelFor<true>(0, noSpongeCells, [=](MInt spongeCellId) {
45 auto& cell = this->m_spongeCells[spongeCellId];
46 const MInt cellId = cell.cellId;
47 if((timeStep - 1) % IPOW2(s->maxLevel() - s->a_level(cellId)) != 0) return;
48 // compute the forcing term for the density
49 const MFloat deltaRho = s->a_variable(cellId, s->PV->RHO) - this->m_trgRho;
50 s->a_variable(cellId, s->PV->RHO) -= cell.spongeFactor * deltaRho;
51
52 // prescribe new density
53 s->a_distribution(cellId, Ld::lastId()) = s->a_variable(cellId, s->PV->RHO);
54 for(MInt dist = 0; dist < nDist - 1; dist++) {
55 s->a_distribution(cellId, nDist - 1) -= s->a_distribution(cellId, dist);
56 }
57 });
58}
59
60//---LbSrcTerm_spongeEqConst----------------------------------------------------
72template <MInt nDim, MInt nDist, class SysEqn>
73class LbSrcTerm_spongeEqConst : public LbSrcTerm_sponge<nDim, nDist, SysEqn> {
74 public:
77 void init() override;
78 void apply_preCollision() override{};
79 void apply_postCollision() override;
80 void apply_postPropagation() override{};
81
82 private:
83 std::array<MFloat, nDist> m_trgEq{};
84};
85
86template <MInt nDim, MInt nDist, class SysEqn>
88 LbSolverDxQy<nDim, nDist, SysEqn>& s = *(this->m_solver); // alias for readability
89 Base::init();
90 m_trgEq = s.getEqDists(this->m_trgRho, this->m_trgU.data());
91}
92
93template <MInt nDim, MInt nDist, class SysEqn>
95 TRACE();
96 LbSolverDxQy<nDim, nDist, SysEqn>* const s = this->m_solver; // alias for readability
97
98 const MInt timeStep = s->getCurrentTimeStep();
99 const MUint noSpongeCells = this->m_spongeCells.size();
100 maia::parallelFor<true>(0, noSpongeCells, [=](MInt spongeCellId) {
101 auto& cell = this->m_spongeCells[spongeCellId];
102 const MInt cellId = cell.cellId;
103 if((timeStep - 1) % IPOW2(s->maxLevel() - s->a_level(cellId)) != 0) return;
104 std::array<MFloat, nDim> u{};
105 for(MInt d = 0; d < nDim; d++) {
106 u[d] = s->a_variable(cellId, d);
107 }
108 std::array<MFloat, nDist> eqDist = s->getEqDists(s->a_variable(cellId, s->PV->RHO), u.data());
109 for(MInt i = 0; i < nDist; i++) {
110 s->a_distribution(cellId, i) -= cell.spongeFactor * (eqDist[i] - m_trgEq[i]);
111 }
112 });
113}
114
115//---LbSrcTerm_spongeViscosity--------------------------------------------------
122template <MInt nDim, MInt nDist, class SysEqn>
123class LbSrcTerm_spongeVisocity : public LbSrcTerm_sponge<nDim, nDist, SysEqn> {
124 public:
127 void apply_preCollision() override;
128 void apply_postCollision() override{};
129 void apply_postPropagation() override{};
130
131 private:
132};
133
134template <MInt nDim, MInt nDist, class SysEqn>
136 TRACE();
137 LbSolverDxQy<nDim, nDist, SysEqn>* const s = this->m_solver; // alias for readability
138
139 const MInt timeStep = s->getCurrentTimeStep();
140 const MUint noSpongeCells = this->m_spongeCells.size();
141 maia::parallelFor<true>(0, noSpongeCells, [=](MInt spongeCellId) {
142 auto& cell = this->m_spongeCells[spongeCellId];
143 const MInt cellId = cell.cellId;
144 if((timeStep - 1) % IPOW2(s->maxLevel() - s->a_level(cellId)) != 0) return;
145 s->a_nu(cellId) *= (1.0 + cell.spongeFactor);
146 });
147}
148
149//---registration for LbSrcTermFactory class------------------------------------
151 reg_SpongeRhoConstd2q9C("LB_SPONGE_RHOCONST");
153 reg_SpongeRhoConstd2q9("LB_SPONGE_RHOCONST");
155 reg_SpongeRhoConstd3q27C("LB_SPONGE_RHOCONST");
157 reg_SpongeRhoConstd3q27("LB_SPONGE_RHOCONST");
158
160 reg_SpongeEqConstd2q9C("LB_SPONGE_EQCONST");
162 reg_SpongeEqConstd2q9("LB_SPONGE_EQCONST");
164 reg_SpongeEqConstd3q27C("LB_SPONGE_EQCONST");
166 reg_SpongeEqConstd3q27("LB_SPONGE_EQCONST");
167
169 reg_SpongeViscoisty2q9C("LB_SPONGE_VISCOSITY");
171 reg_SpongeViscoisty2q9("LB_SPONGE_VISCOSITY");
172
173} // namespace maia::lb
This class represents all LB models.
Definition: lbsolverdxqy.h:29
std::array< MFloat, nDist > getEqDists(const MFloat rho, const MFloat *const velocity)
Calls function to return the equilibrium distribution.
Definition: lbsolverdxqy.h:668
Class for registering a source term to the factory registry.
LB sponge source term : sponge towards const target f_eq(rho_trg, u_trg)
LbSrcTerm_spongeEqConst(LbSolverDxQy< nDim, nDist, SysEqn > *p_solver)
std::array< MFloat, nDist > m_trgEq
Base class for lb sponge layers.
LB sponge source term : sponge towards const target f_eq(rho_trg, u)
LbSrcTerm_spongeRhoConst(LbSolverDxQy< nDim, nDist, SysEqn > *p_solver)
LB sponge source term : sponge viscosity towards outside.
LbSrcTerm_spongeVisocity(LbSolverDxQy< nDim, nDist, SysEqn > *p_solver)
constexpr MLong IPOW2(MInt x)
int32_t MInt
Definition: maiatypes.h:62
uint32_t MUint
Definition: maiatypes.h:63
double MFloat
Definition: maiatypes.h:52
MFloat dist(const Point< DIM > &p, const Point< DIM > &q)
Definition: pointbox.h:54
LB lattice descriptor for arrays depending on D and Q.