chombo-discharge
Loading...
Searching...
No Matches
CD_CellCentroidInterpolationImplem.H
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2021-2026 SINTEF Energy Research
3 *
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 */
6
13#ifndef CD_CELLCENTROIDINTERPOLATIONIMPLEM_H
14#define CD_CELLCENTROIDINTERPOLATIONIMPLEM_H
15
16// Chombo includes
17#include <CH_Timer.H>
18
19// Our includes
21#include <CD_BoxLoops.H>
22#include <CD_NamespaceHeader.H>
23
24template <typename T>
25void
27 const EBCellFAB& a_cellData,
28 const DataIndex& a_din) const noexcept
29{
30 CH_TIME("CellCentroidInterpolation::interpolate<T>)");
31
32 CH_assert(m_isDefined);
33 CH_assert(a_centroidData.isDefined());
34 CH_assert(a_cellData.isDefined());
35 CH_assert(a_centroidData.nComp() == a_cellData.nComp());
36
37 const DisjointBoxLayout& dbl = m_eblg.getDBL();
38 const ProblemDomain& domain = m_eblg.getDomain();
39 const EBISLayout& ebisl = m_eblg.getEBISL();
40 const Box& domainBox = domain.domainBox();
41
42 const EBISBox& ebisBox = ebisl[a_din];
43 const Box& cellBox = dbl[a_din];
44 const BaseIVFAB<VoFStencil>& stencils = m_interpStencils[a_din];
45
46 const int nComp = a_cellData.nComp();
47
48 for (int comp = 0; comp < nComp; comp++) {
49
50 // This is the kernel that is used when the interpolation is expressible as a stencil.
51 auto stencilKernel = [&](const VolIndex& vof) -> void {
52 a_centroidData(vof, comp) = 0.0;
53
54 const VoFStencil& stencil = stencils(vof, 0);
55 for (int i = 0; i < stencil.size(); i++) {
56 const VolIndex& ivof = stencil.vof(i);
57 const Real& iweight = stencil.weight(i);
58
60 }
61 };
62
63 // Kernel used when interpolation is done with a slope limiter.
64 auto slopeKernel = [&](const VolIndex& vof) -> void {
65 const IntVect iv = vof.gridIndex();
66
68
69 for (int dir = 0; dir < SpaceDim; dir++) {
70 Real slope = 0.0;
71
72 const bool onLoSide = (iv[dir] == domainBox.smallEnd(dir));
73 const bool onHiSide = (iv[dir] == domainBox.bigEnd(dir));
74
75 const bool hasFacesLeft = (ebisBox.numFaces(vof, dir, Side::Lo) == 1) && !onLoSide;
76 const bool hasFacesRight = (ebisBox.numFaces(vof, dir, Side::Hi) == 1) && !onHiSide;
77
80
83
84 Real dwl = 0.0;
85 Real dwr = 0.0;
86
87 // Compute left and right slope
88 if (hasFacesLeft) {
89 facesLeft = ebisBox.getFaces(vof, dir, Side::Lo);
90 vofLeft = facesLeft[0].getVoF(Side::Lo);
92 }
93 if (hasFacesRight) {
94 facesRight = ebisBox.getFaces(vof, dir, Side::Hi);
95 vofRight = facesRight[0].getVoF(Side::Hi);
97 }
98
100 dwl = dwr;
101 }
102 else if (hasFacesLeft && !hasFacesRight) {
103 dwr = dwl;
104 }
105
106 // Limit the slopes.
107 switch (m_interpolationType) {
108 case Type::MinMod: {
109 slope = this->MinMod(dwl, dwr);
110
111 break;
112 }
113 case Type::MonotonizedCentral: {
114 slope = this->MonotonizedCentral(dwl, dwr);
115
116 break;
117 }
118 case Type::Superbee: {
119 slope = this->Superbee(dwl, dwr);
120
121 break;
122 }
123 default: {
124 MayDay::Abort("CD_CellCentroidInterpolation::interpolate(BaseIVFAB) - logic bust");
125
126 break;
127 }
128 }
129
130 const Real dx = ebisBox.centroid(vof)[dir];
131
133 }
134 };
135
136 switch (m_interpolationType) {
137 case Type::MinMod: {
138 BoxLoops::loop(m_vofIterator[a_din], slopeKernel);
139
140 break;
141 }
142 case Type::MonotonizedCentral: {
143 BoxLoops::loop(m_vofIterator[a_din], slopeKernel);
144
145 break;
146 }
147 case Type::Superbee: {
148 BoxLoops::loop(m_vofIterator[a_din], slopeKernel);
149
150 break;
151 }
152 default: {
153 BoxLoops::loop(m_vofIterator[a_din], stencilKernel);
154
155 break;
156 }
157 }
158 }
159}
160
161inline Real
163{
164 Real slope = 0.0;
165
166 if (a_dwl * a_dwr > 0.0) {
168 }
169
170 return slope;
171}
172
173inline Real
175{
176 Real slope = 0.0;
177
178 if (a_dwl * a_dwr > 0.0) {
179 const Real dwc = a_dwl + a_dwr;
180 const Real sgn = Real((dwc > 0.0) - (dwc < 0.0));
181
182 slope = sgn * std::min(0.5 * std::abs(dwc), 2.0 * std::min(std::abs(a_dwl), std::abs(a_dwr)));
183 }
184
185 return slope;
186}
187
188inline Real
190{
191 Real slope = 0.0;
192
193 if (a_dwl * a_dwr > 0.0) {
194 const Real s1 = this->MinMod(a_dwl, 2 * a_dwr);
195 const Real s2 = this->MinMod(a_dwr, 2 * a_dwl);
196
197 if (s1 * s2 > 0.0) {
198 slope = std::abs(s1) > std::abs(s2) ? s1 : s2;
199 }
200 }
201
202 return slope;
203}
204
205#include <CD_NamespaceFooter.H>
206
207#endif
Declaration of a namespace for proto-typing grid and EB loops.
Declaration of class for interpolating cell-centered data to cell centroids.
virtual void interpolate(LevelData< BaseIVFAB< Real > > &a_centroidData, const LevelData< EBCellFAB > &a_cellData) const noexcept
Function for interpolating data.
Definition CD_CellCentroidInterpolation.cpp:272
Real MonotonizedCentral(const Real &a_dwl, const Real &a_dwr) const noexcept
Monotonized central difference slope limiter.
Definition CD_CellCentroidInterpolationImplem.H:174
Real Superbee(const Real &a_dwl, const Real &a_dwr) const noexcept
Superbee slope limiter.
Definition CD_CellCentroidInterpolationImplem.H:189
Real MinMod(const Real &a_dwl, const Real &a_dwr) const noexcept
Minmod slope function.
Definition CD_CellCentroidInterpolationImplem.H:162
Base class for a tracer particle solver. This solver can advance particles in a pre-defined velocity ...
Definition CD_TracerParticleSolver.H:38
TracerParticleSolver()
Default constructor.
Definition CD_TracerParticleSolverImplem.H:26
ALWAYS_INLINE void loop(const Box &a_computeBox, Functor &&kernel)
Launch a C++ kernel over a regular grid with compile-time per-dimension strides.
Definition CD_BoxLoopsImplem.H:39