MAIA bb96820c
Multiphysics at AIA
Loading...
Searching...
No Matches
maia::lb::LbSrcTerm_monopole< nDim, nDist, SysEqn > Class Template Reference

Class to handle acoustic monopole source terms in lb solver. More...

Inheritance diagram for maia::lb::LbSrcTerm_monopole< nDim, nDist, SysEqn >:
[legend]
Collaboration diagram for maia::lb::LbSrcTerm_monopole< nDim, nDist, SysEqn >:
[legend]

Classes

struct  MonopoleInfo
 

Public Member Functions

 LbSrcTerm_monopole (LbSolverDxQy< nDim, nDist, SysEqn > *p_solver)
 
void init () override
 
void apply_preCollision () override
 
void apply_postCollision () override
 
void apply_postPropagation () override
 
- Public Member Functions inherited from maia::lb::LbSrcTerm< nDim, nDist, SysEqn >
virtual void init ()=0
 
virtual void apply_preCollision ()=0
 
virtual void apply_postCollision ()=0
 
virtual void apply_postPropagation ()=0
 
virtual ~LbSrcTerm ()=default
 

Protected Member Functions

void readProperties () override
 
virtual void readProperties ()=0
 

Private Attributes

LbSolverDxQy< nDim, nDist, SysEqn > * m_solver
 
std::vector< MonopoleInfom_monopole
 

Additional Inherited Members

- Public Types inherited from maia::lb::LbSrcTerm< nDim, nDist, SysEqn >
using SysEqn = SysEqn
 
- Static Public Attributes inherited from maia::lb::LbSrcTerm< nDim, nDist, SysEqn >
static constexpr MInt nDim
 
static constexpr MInt nDist
 

Detailed Description

template<MInt nDim, MInt nDist, class SysEqn>
class maia::lb::LbSrcTerm_monopole< nDim, nDist, SysEqn >
Author
Miro Gondrum, Benyamin Krisna
Date
01.02.2022

Definition at line 25 of file lbsrcterm.cpp.

Constructor & Destructor Documentation

◆ LbSrcTerm_monopole()

template<MInt nDim, MInt nDist, class SysEqn >
maia::lb::LbSrcTerm_monopole< nDim, nDist, SysEqn >::LbSrcTerm_monopole ( LbSolverDxQy< nDim, nDist, SysEqn > *  p_solver)
inline

Definition at line 51 of file lbsrcterm.cpp.

51: m_solver(p_solver) { readProperties(); };
LbSolverDxQy< nDim, nDist, SysEqn > * m_solver
Definition: lbsrcterm.cpp:27
void readProperties() override
Definition: lbsrcterm.cpp:61

Member Function Documentation

◆ apply_postCollision()

template<MInt nDim, MInt nDist, class SysEqn >
void maia::lb::LbSrcTerm_monopole< nDim, nDist, SysEqn >::apply_postCollision
overridevirtual

Implements maia::lb::LbSrcTerm< nDim, nDist, SysEqn >.

Definition at line 164 of file lbsrcterm.cpp.

164 {
166 TRACE();
167 for(auto& monopole : m_monopole) {
168 if(!monopole.isActive) continue;
169 const MInt noSrcTermCells = monopole.cellIds.size();
170 for(MInt i = 0; i < noSrcTermCells; i++) {
171 //-update source term
172 monopole.srcTerms[i] =
173 -monopole.rhoFluct * monopole.omega * sin((monopole.omega + monopole.phaseShift) * globalTimeStep);
174 if(monopole.windowing) {
175 // Windowing shall be performed for the first wave length
176 if(globalTimeStep < 2 * PI / (monopole.omega)) {
177 const MFloat S = (globalTimeStep == 0 ? 0.5 : 1);
178 const MFloat hannHalfWindow = S * 0.5 * (1 - cos(monopole.omega * globalTimeStep / 2.0));
179 monopole.srcTerms[i] *= hannHalfWindow;
180 }
181 }
182
183 //-apply source term in solver
184 const MInt cellId = monopole.cellIds[i];
185 for(MInt j = 0; j < nDist; j++) {
186 m_solver->a_distribution(cellId, j) += Ld::tp(Ld::distType(j)) * monopole.srcTerms[i];
187 }
188 }
189 }
190}
std::vector< MonopoleInfo > m_monopole
Definition: lbsrcterm.cpp:43
MInt globalTimeStep
int32_t MInt
Definition: maiatypes.h:62
double MFloat
Definition: maiatypes.h:52
void const MInt cellId
Definition: collector.h:239
T cos(const T a, const T b, const T x)
Cosine slope filter.
Definition: filter.h:125
LB lattice descriptor for arrays depending on D and Q.

◆ apply_postPropagation()

template<MInt nDim, MInt nDist, class SysEqn >
void maia::lb::LbSrcTerm_monopole< nDim, nDist, SysEqn >::apply_postPropagation ( )
inlineoverridevirtual

Implements maia::lb::LbSrcTerm< nDim, nDist, SysEqn >.

Definition at line 56 of file lbsrcterm.cpp.

56{};

◆ apply_preCollision()

template<MInt nDim, MInt nDist, class SysEqn >
void maia::lb::LbSrcTerm_monopole< nDim, nDist, SysEqn >::apply_preCollision ( )
inlineoverridevirtual

Implements maia::lb::LbSrcTerm< nDim, nDist, SysEqn >.

Definition at line 54 of file lbsrcterm.cpp.

54{/*UNUSED FOR FIRST ORDER IMPLEMENTATION*/};

◆ init()

template<MInt nDim, MInt nDist, class SysEqn >
void maia::lb::LbSrcTerm_monopole< nDim, nDist, SysEqn >::init
overridevirtual

Implements maia::lb::LbSrcTerm< nDim, nDist, SysEqn >.

Definition at line 109 of file lbsrcterm.cpp.

109 {
110 TRACE();
111 for(auto& monopole : m_monopole) {
112 // First, clear everything -> usable to reinit
113 monopole.cellIds.clear();
114 monopole.srcTerms.clear();
115 // Now initialize
116 if(monopole.radius < 0.0) {
117 const MInt monopoleCellId = m_solver->getIdAtPoint(monopole.position.data());
118 if(monopoleCellId != -1) {
119 monopole.isActive = true;
120 monopole.cellIds.push_back(monopoleCellId);
121 }
122 } else {
123 const MFloat radiusSq = POW2(monopole.radius);
124 for(MInt i = 0; i < m_solver->m_currentMaxNoCells; i++) {
125 const MInt cellId = m_solver->m_activeCellList[i];
126 MFloat radiusSq_ = 0.0;
127 for(MInt d = 0; d < nDim; d++) {
128 radiusSq_ += POW2(monopole.position[d] - m_solver->a_coordinate(cellId, d));
129 }
130 if(radiusSq_ < radiusSq) {
131 monopole.isActive = true;
132 monopole.cellIds.push_back(cellId);
133 }
134 }
135 }
136 const MInt noSrcTermCells = monopole.cellIds.size();
137 monopole.srcTerms.resize(noSrcTermCells, 0.0);
138 //- info output
139 MInt noSrcTermCellsGlobal = noSrcTermCells;
140 MPI_Allreduce(MPI_IN_PLACE, &noSrcTermCellsGlobal, 1, MPI_INT, MPI_SUM, m_solver->mpiComm(), AT_, "MPI_IN_PLACE",
141 "noSrcTermCellsGlobal");
142 const MFloat ppw = 2 * PI * LBCS / monopole.omega; // ppw = lambda in LB units
143 const MFloat periode = m_solver->m_referenceLength / (monopole.strouhal * m_solver->m_Ma * LBCS);
144 std::stringstream ss;
145 ss << "INFO: LbSrcTerm_monopole " << monopole.id << ":" << std::endl;
146 ss << " amplitude :" << monopole.amplitude << std::endl;
147 ss << " rhoFluct :" << monopole.rhoFluct << std::endl;
148 ss << " radius :" << monopole.radius << std::endl;
149 ss << " strouhal :" << monopole.strouhal << std::endl;
150 ss << " omega :" << monopole.omega << std::endl;
151 ss << " phaseShift :" << monopole.phaseShift << std::endl;
152 ss << " windowing :" << monopole.windowing << std::endl;
153 ss << " noSrcTermCells :" << noSrcTermCellsGlobal << std::endl;
154 ss << " points per wave :" << ppw << std::endl;
155 ss << " timesteps per periode :" << periode << std::endl;
156 if(m_solver->domainId() == 0) {
157 std::cout << ss.str();
158 }
159 m_log << ss.str();
160 }
161}
constexpr Real POW2(const Real x)
Definition: functions.h:119
InfoOutFile m_log
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

◆ readProperties()

template<MInt nDim, MInt nDist, class SysEqn >
void maia::lb::LbSrcTerm_monopole< nDim, nDist, SysEqn >::readProperties
overrideprotectedvirtual

Implements maia::lb::LbSrcTerm< nDim, nDist, SysEqn >.

Definition at line 61 of file lbsrcterm.cpp.

61 {
62 TRACE();
63 const MInt solverId = m_solver->m_solverId;
64 MInt noMonopole = 0;
65 for(MInt id = 0;; id++) {
66 if(!Context::propertyExists("monopoleAmplitude_" + std::to_string(id))) {
67 break;
68 }
69 noMonopole++;
70 auto& monopole = m_monopole.emplace_back();
71 monopole.id = id;
72 for(MInt d = 0; d < nDim; d++) {
73 monopole.position[d] = Context::getSolverProperty<MFloat>("monopolePos_" + std::to_string(id), solverId, AT_);
74 }
75 monopole.amplitude = Context::getSolverProperty<MFloat>("monopoleAmplitude_" + std::to_string(id), solverId, AT_);
76 monopole.strouhal = Context::getSolverProperty<MFloat>("monopoleStrouhal_" + std::to_string(id), solverId, AT_);
77 monopole.radius =
78 Context::getSolverProperty<MFloat>("monopoleRadius_" + std::to_string(id), solverId, AT_, &monopole.radius);
79 monopole.windowing = Context::getSolverProperty<MBool>("monopoleWindowing_" + std::to_string(id), solverId, AT_,
80 &monopole.windowing);
81 const MFloat phaseShiftStrouhal = Context::getSolverProperty<MFloat>("monopolePhaseShift_" + std::to_string(id),
82 solverId, AT_, &monopole.phaseShift);
83 if(monopole.radius < m_solver->c_cellLengthAtLevel(m_solver->maxLevel())) {
84 m_log << "monopoleRadius < max level cell length: Hence, it is clipped to max level cell length" << std::endl;
85 monopole.radius = m_solver->c_cellLengthAtLevel(m_solver->maxLevel());
86 }
87 const MFloat u_infty = m_solver->m_Ma * LBCS;
88 const MFloat dxLb = m_solver->c_cellLengthAtLevel(m_solver->maxLevel());
89 const MFloat massAmp = monopole.amplitude * (POW3(1.0 / dxLb)); // from STL to LB units m=rho*L^3
90 const MFloat densityAmp = massAmp / (F4B3 * PI * POW3(monopole.radius / dxLb));
91 monopole.omega = 2.0 * PI * (monopole.strouhal * u_infty / m_solver->m_referenceLength);
92 monopole.rhoFluct = densityAmp;
93 monopole.phaseShift = 2.0 * PI * (phaseShiftStrouhal * u_infty / m_solver->m_referenceLength);
94 if(m_solver->domainId() == 0) {
95 std::stringstream ss;
96 ss << "INFO: LbSrcTerm_monopole " << monopole.id << " analytical solution:" << std::endl;
97 ss << "rho(r,t)= 1.0 -" << (massAmp * POW2(monopole.omega)) / (4 * PI * POW2(LBCS)) << "/ (mag(coords)/" << dxLb
98 << ") * cos(" << monopole.omega << "* (" << g_timeSteps - 1 << " - mag(coords)/" << dxLb << "/" << LBCS << "))"
99 << std::endl;
100 std::cout << ss.str();
101 }
102 }
103 if(noMonopole == 0) {
104 TERMM(1, "Property monopoleAmplitude_0 is missing!");
105 }
106}
static MBool propertyExists(const MString &name, MInt solver=m_noSolvers)
This function checks if a property exists in general.
Definition: context.cpp:494
constexpr Real POW3(const Real x)
Definition: functions.h:123
MInt g_timeSteps
MInt id
Definition: maiatypes.h:71

Member Data Documentation

◆ m_monopole

template<MInt nDim, MInt nDist, class SysEqn >
std::vector<MonopoleInfo> maia::lb::LbSrcTerm_monopole< nDim, nDist, SysEqn >::m_monopole
private

Definition at line 43 of file lbsrcterm.cpp.

◆ m_solver

template<MInt nDim, MInt nDist, class SysEqn >
LbSolverDxQy<nDim, nDist, SysEqn>* maia::lb::LbSrcTerm_monopole< nDim, nDist, SysEqn >::m_solver
private

Definition at line 27 of file lbsrcterm.cpp.


The documentation for this class was generated from the following file: