MAIA bb96820c
Multiphysics at AIA
Loading...
Searching...
No Matches
lbdgape.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 "lbdgape.h"
8
9//--
10//--public
11//--
12
13template <MInt nDim, MInt nDist, class SysEqn>
15 TRACE();
16 // TODO labels:COUPLER,LB,DG for now, DG does the same time step as LB on finest level
17 this->dgSolver().forceTimeStep(m_conversionLb2Dg.time * 1.0);
18}
19
20//--
21//--private
22//--
23
24template <MInt nDim, MInt nDist, class SysEqn>
26 // TODO labels:lb Miro: document why conversion factors are needed for inactive solver
27 TRACE();
28
29 // Description: for generic variable phi conversion factor C_phi is defined as
30 // phi_dg = phi_lb * C_phi
31 // base units
32 constexpr MFloat dgGamma = 1.4;
33 MFloat maSq = this->a_Ma() * this->a_Ma(); // Note: Ma is present in inactive LB solver
34
35 // Inactive donor solver does not know the maxLevel
36 const MBool hasLbSolver = this->lbSolver().isActive();
37 MFloat dxLb =
38 (hasLbSolver) ? this->a_cellLengthAtLevel(donorSolver().maxLevel()) : std::numeric_limits<MFloat>::max();
39 MPI_Allreduce(MPI_IN_PLACE,
40 &dxLb,
41 1,
43 MPI_MIN,
44 this->dgSolver().grid().raw().mpiComm(),
45 AT_,
46 "MPI_IN_PLACE",
47 "dxLb");
48
49 m_conversionLb2Dg.length = dxLb;
50 m_conversionLb2Dg.density = pow(1.0 + 0.5 * (dgGamma - 1.0) * maSq, 1.0 / (1.0 - dgGamma));
51 m_conversionLb2Dg.time = dxLb * LBCS * sqrt(1.0 + 0.5 * (dgGamma - 1.0) * maSq); // sqrt-term: a_0 / a_inf
52 // derived units
53 m_conversionLb2Dg.velocity = m_conversionLb2Dg.length / m_conversionLb2Dg.time;
54 m_conversionLb2Dg.vorticity = 1.0 / m_conversionLb2Dg.time;
55 m_conversionLb2Dg.lamb = m_conversionLb2Dg.vorticity * m_conversionLb2Dg.velocity;
56}
57
69template <MInt nDim, MInt nDist, class SysEqn>
70void LbDgApe<nDim, nDist, SysEqn>::getDonorVelocityAndVorticity(const std::vector<MInt>& donorCellIds,
71 MFloatScratchSpace& p_velocity,
72 MFloatScratchSpace& p_vorticity) {
73 TRACE();
74 if(this->m_hasDonorCartesianSolver) {
75 // Velocity
76 for(auto donorId : donorCellIds) {
77 const MFloat* cellVars = nullptr;
78 this->donorSolver().getSampleVariables(donorId, cellVars);
79 for(MInt dirId = 0; dirId < this->noVelocities(); dirId++) {
80 p_velocity(donorId, dirId) = cellVars[this->donorSolver().PV->VV[dirId]] * m_conversionLb2Dg.velocity;
81 }
82 }
83 // Vorticity
84 for(auto donorId : donorCellIds) {
85 MFloat velocityGradient[nDim][nDim];
86 this->donorSolver().calculateVelocityDerivative(donorId, velocityGradient);
87 if constexpr(nDim == 2) {
88 p_vorticity(donorId, 0) = (velocityGradient[1][0] - velocityGradient[0][1]) * m_conversionLb2Dg.vorticity;
89 } else if(nDim == 3) {
90 p_vorticity(donorId, 0) = (velocityGradient[2][1] - velocityGradient[1][2]) * m_conversionLb2Dg.vorticity;
91 p_vorticity(donorId, 1) = (velocityGradient[0][2] - velocityGradient[2][0]) * m_conversionLb2Dg.vorticity;
92 p_vorticity(donorId, 2) = (velocityGradient[1][0] - velocityGradient[0][1]) * m_conversionLb2Dg.vorticity;
93 }
94 }
95 }
96}
97
104template <MInt nDim, MInt nDist, class SysEqn>
106 const MInt count,
107 const MInt stride,
108 MFloat* data) {
109 TRACE();
110 // Determine corresponding conversion factor
111 std::map<MString, MFloat> conversionMap;
112 conversionMap["wxv_x"] = m_conversionLb2Dg.lamb;
113 conversionMap["wxv_y"] = m_conversionLb2Dg.lamb;
114 conversionMap["wxv_z"] = m_conversionLb2Dg.lamb;
115 conversionMap["um"] = m_conversionLb2Dg.velocity;
116 conversionMap["vm"] = m_conversionLb2Dg.velocity;
117 conversionMap["wm"] = m_conversionLb2Dg.velocity;
118 conversionMap["rhom"] = m_conversionLb2Dg.density;
119 conversionMap["c0"] = m_conversionLb2Dg.velocity;
120 conversionMap["dc0_dx"] = m_conversionLb2Dg.vorticity;
121 conversionMap["dc0_dy"] = m_conversionLb2Dg.vorticity;
122 conversionMap["dc0_dz"] = m_conversionLb2Dg.vorticity;
123 conversionMap["vort_x"] = m_conversionLb2Dg.vorticity;
124 conversionMap["vort_y"] = m_conversionLb2Dg.vorticity;
125 conversionMap["vort_z"] = m_conversionLb2Dg.vorticity;
126
127 auto search = conversionMap.find(name);
128 if(search == conversionMap.end()) {
129 std::stringstream ss;
130 ss << "ERROR: No unit type found for " << name << " ." << std::endl;
131 TERMM(1, ss.str());
132 }
133 const MFloat conversionFactor = conversionMap[name];
134 for(MInt i = 0; i < count; i++) {
135 const MInt j = i * stride;
136 data[j] *= conversionFactor;
137 }
138}
139
140template <MInt nDim, MInt nDist, class SysEqn>
142 const MFloat* const vorticity,
143 MFloat* const sourceTerms) {
144 TRACE();
145 RECORD_TIMER_START(this->m_timers[BaseDg::Timers::CalcSourceLamb]);
146 // Index of first lamb vector component in m_meanVars
147 const MInt lambIndex = this->m_meanVarsIndex[BaseDg::MV::LAMB0[0]];
148 // Calculate source terms on all 'active' donor leaf cells, i.e. that are
149 // mapped to elements with nonzero filter values
150 for(MInt donorIndex = 0; donorIndex < this->m_noActiveDonorCells; donorIndex++) {
151 const MInt donorId = this->m_calcSourceDonorCells[donorIndex];
152 // Create convenience pointers
153 const MFloat* const meanVars = &this->m_meanVars[donorIndex * this->noMeanVars()];
154 const MFloat* const velo = &velocity[donorId * this->noVelocities()];
155 const MFloat* const vort = &vorticity[donorId * this->noVorticities()];
156 // Compute instantaneous Lamb vector
157 MFloat lambVector[nDim];
158 if(nDim == 2) {
159 lambVector[0] = -vort[0] * velo[1];
160 lambVector[1] = vort[0] * velo[0];
161 } else {
162 lambVector[0] = vort[1] * velo[2] - vort[2] * velo[1];
163 lambVector[1] = vort[2] * velo[0] - vort[0] * velo[2];
164 lambVector[2] = vort[0] * velo[1] - vort[1] * velo[0];
165 }
166 // The complete source term is:
167 // S = -L' = -(w x u - bar(w x u))
168 const MInt offset = donorId * SysEqnDg::noVars() + BaseDg::CV::UU[0];
169 for(MInt dim = 0; dim < nDim; dim++) {
170 sourceTerms[offset + dim] += -(lambVector[dim] - meanVars[lambIndex + dim]);
171 }
172 }
173 RECORD_TIMER_STOP(this->m_timers[BaseDg::Timers::CalcSourceLamb]);
174}
175
176//--
177//--explicit instantiations
178//--
virtual void performUnitConversion(const MString &, const MInt, const MInt, MFloat *) override
Transform data from donor solver unit system into DG unit system.
Definition: lbdgape.cpp:105
void getDonorVelocityAndVorticity(const std::vector< MInt > &donorCellIds, MFloatScratchSpace &p_velocity, MFloatScratchSpace &p_vorticity) override
Get velocity and vorticity of donor solver.
Definition: lbdgape.cpp:70
void calcSourceLambNonlinear(const MFloat *const velocity, const MFloat *const vorticity, MFloat *const sourceTerms) override
Definition: lbdgape.cpp:141
void finalizeCouplerInit() override
Definition: lbdgape.cpp:14
void initConversionFactors()
Definition: lbdgape.cpp:25
This class is a ScratchSpace.
Definition: scratch.h:758
int32_t MInt
Definition: maiatypes.h:62
std::basic_string< char > MString
Definition: maiatypes.h:55
double MFloat
Definition: maiatypes.h:52
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