14#ifndef CD_ITOSOLVERIMPLEM_H
15#define CD_ITOSOLVERIMPLEM_H
32#include <CD_NamespaceHeader.H>
40 auto sign = [](
const Real& a) -> Real {
41 return (a > 0) - (a < 0);
44 RealVect r = RealVect::Zero;
45 for (
int i = 0; i < SpaceDim; i++) {
54template <
typename P,
typename Traits>
61 CH_TIME(
"ItoSolver::depositWeight");
63 pout() <<
m_name +
"::depositWeight" << endl;
66 CH_assert(a_phi[0]->nComp() == 1);
67 CH_assert(a_phi.getRealm() ==
m_realm);
81 a_coarseFineDeposition,
83 return a_leaf.
weight(a_index);
90template <
typename Gather>
95 Gather a_gather)
const noexcept
97 CH_TIME(
"ItoSolver::depositGatheredNGP");
98 if (m_verbosity > 5) {
99 pout() << m_name +
"::depositGatheredNGP" << endl;
102 CH_assert(a_level >= 0);
103 CH_assert(a_level <= m_amr->getFinestLevel());
105 const ProblemDomain& domain = m_amr->getDomains()[a_level];
106 const DisjointBoxLayout& dbl = m_amr->getGrids(a_particles.getRealm())[a_level];
107 const DataIterator& dit = dbl.dataIterator();
108 const EBISLayout& ebisl = m_amr->getEBISLayout(a_particles.getRealm(), m_phase)[a_level];
109 const Real dx = m_amr->getDx()[a_level];
110 const RealVect probLo = m_amr->getProbLo();
112 CH_assert(a_output.disjointBoxLayout() == dbl);
114 const int nbox = dit.size();
116#pragma omp parallel for schedule(runtime)
117 for (
int mybox = 0; mybox < nbox; mybox++) {
118 const DataIndex& din = dit[mybox];
120 const Box cellBox = dbl[din];
121 const EBISBox& ebisbox = ebisl[din];
123 EBParticleMesh particleMesh(domain, cellBox, ebisbox, dx * RealVect::Unit, probLo);
125 EBCellFAB& output = a_output[din];
132 .
depositGathered(output, 0, leaf, DepositionType::NGP, 1.0,
true, [&](
const std::size_t a_i, Real* a_out) {
133 a_out[0] = a_gather(leaf, a_i);
138template <
typename Gather>
144 Gather a_gather)
const
146 CH_TIME(
"ItoSolver::depositGathered");
148 pout() <<
m_name +
"::depositGathered" << endl;
151 CH_assert(a_phi[0]->nComp() == 1);
156 m_amr->depositGathered(a_phi,
161 a_coarseFineDeposition,
166 this->
mirrorPass(a_phi, a_particles, a_deposition, a_coarseFineDeposition, a_gather);
174template <
typename P,
typename Traits,
typename Strength>
180 const Strength a_strength)
const
182 CH_TIME(
"ItoSolver::mirrorPass");
184 pout() <<
m_name +
"::mirrorPass" << endl;
192 bool anyCutCells =
false;
193 for (
int lvl = 0; lvl <=
m_amr->getFinestLevel(); lvl++) {
194 anyCutCells = anyCutCells || (hasCutCells[lvl] != 0);
202 const RealVect probLo =
m_amr->getProbLo();
203 const Real maxJacobian =
m_amr->getMirrorMaxJacobian();
204 const Real minDenom =
m_amr->getMirrorMinDenominator();
218 long long numImages = 0;
219 long long numNoData = 0;
220 long long numInside = 0;
221 long long numSmallDenom = 0;
222 long long numLargeJac = 0;
223 long long numNonPositiveJ = 0;
225 for (
int lvl = 0; lvl <=
m_amr->getFinestLevel(); lvl++) {
226 const DisjointBoxLayout& dbl =
m_amr->getGrids(
m_realm)[lvl];
227 const DataIterator& dit = dbl.dataIterator();
228 const Real dx =
m_amr->getDx()[lvl];
230 const int nbox = dit.size();
234#pragma omp parallel for schedule(runtime) \
235 reduction(+ : numImages, numNoData, numInside, numSmallDenom, numLargeJac, numNonPositiveJ)
236 for (
int mybox = 0; mybox < nbox; mybox++) {
237 const DataIndex& din = dit[mybox];
239 const EBCellFAB& surf = (*surfaceData[lvl])[din];
240 const BaseFab<Real>& surfReg = surf.getSingleValuedFAB();
245 const std::size_t numParticles = leaf.
size();
247 for (std::size_t i = 0; i < numParticles; i++) {
248 const RealVect pos = leaf.
position(i);
262 surfaceComponents[c] = surfReg(iv, c);
304 images.
append(image, a_strength(leaf, i) * jacobian);
319 a_coarseFineDeposition,
335 pout() <<
m_name +
"::mirrorPass - " << numImages <<
" images; skipped " << numNoData <<
" outside the band, "
336 << numInside <<
" at d <= 0; refused (J = 1, the FLAT mirror) " << numSmallDenom <<
" small denominator, "
337 << numLargeJac <<
" large Jacobian, " << numNonPositiveJ <<
" non-positive Jacobian" << endl;
341#include <CD_NamespaceFooter.H>
CoarseFineDeposition
Coarse-fine deposition types (see CD_EBAMRParticleMesh for how these are handled).
Definition CD_CoarseFineDeposition.H:28
Agglomeration of useful data operations.
DepositionType
Deposition types.
Definition CD_DepositionType.H:24
Single-patch ParticleSoA deposit/interpolate onto an embedded-boundary mesh.
@ Mirror
Even extension of the density about the embedded boundary: deposit each particle's cloud and the clou...
@ Native
Deposit as-is, with no cut-cell treatment at all.
Declaration of solver class for Ito diffusion.
Namespace containing the geometry used by mirrored cut-cell deposition.
Agglomeration of basic MPI reductions.
Declaration of a static class containing some common useful particle routines that would otherwise be...
File containing some useful static methods related to random number generation.
static void incr(MFAMRCellData &a_lhs, const MFAMRCellData &a_rhs, const Real a_scale) noexcept
Function which increments data in the form a_lhs = a_lhs + a_rhs*a_scale for all components.
Definition CD_DataOps.cpp:881
Deposits/interpolates ParticleSoA leaves on a single patch, with embedded-boundary (cut-cell) awarene...
Definition CD_EBParticleMesh.H:71
void depositGathered(EBCellFAB &a_meshData, const int a_comp, const ParticleSoA< P, Traits > &a_particles, const DepositionType a_depositionType, const Real a_widthScale, const bool a_forceIrregNGP, GatherFunc &&a_gather) const
Deposit a custom per-particle scalar (computed by a_gather) onto mesh component a_comp.
Definition CD_EBParticleMesh.H:263
ParticleContainer< NoPayload > m_mirrorImages
Reflected images of the band particles, for IrregularDeposition::Mirror.
Definition CD_ItoSolver.H:1623
EBAMRCellData m_mirrorScratch
Mesh scratch the mirror images deposit into, before being added to the real field.
Definition CD_ItoSolver.H:1634
void mirrorPass(EBAMRCellData &a_phi, const ParticleContainer< P, Traits > &a_particles, const DepositionType a_deposition, const CoarseFineDeposition a_coarseFineDeposition, const Strength a_strength) const
Add the mirrored contribution of the band particles to an already-deposited field.
Definition CD_ItoSolverImplem.H:176
std::string m_realm
Realm where this solve lives.
Definition CD_ItoSolver.H:1390
void depositWeight(EBAMRCellData &a_phi, const ParticleContainer< P, Traits > &a_particles, DepositionType a_deposition, CoarseFineDeposition a_coarseFineDeposition) const
Deposit the SoA weight column on the mesh (kappa-conservative + redistribution).
Definition CD_ItoSolverImplem.H:56
std::string m_name
Solver name.
Definition CD_ItoSolver.H:1415
IrregularDeposition m_irregularDeposition
How the cut cells are treated when depositing.
Definition CD_ItoSolver.H:1460
RealVect randomGaussian() const
Draw a random N-dimensional Gaussian number from a normal distribution with zero with and unit standa...
Definition CD_ItoSolverImplem.H:35
int m_verbosity
Verbosity level for this solver.
Definition CD_ItoSolver.H:1438
void depositGathered(EBAMRCellData &a_phi, const ParticleContainer< ItoParticle > &a_particles, DepositionType a_deposition, CoarseFineDeposition a_coarseFineDeposition, Gather a_gather) const
Deposit a gathered per-particle quantity on the mesh (kappa-conservative + redistribution).
Definition CD_ItoSolverImplem.H:140
Real m_normalDistributionTruncation
Truncation value for normal distribution.
Definition CD_ItoSolver.H:1428
RefCountedPtr< AmrMesh > m_amr
AMR; needed for grid stuff.
Definition CD_ItoSolver.H:1400
void depositGatheredNGP(LevelData< EBCellFAB > &a_output, const ParticleContainer< ItoParticle > &a_particles, int a_level, Gather a_gather) const noexcept
Do an NGP deposit of a gathered per-particle quantity on a specific grid level. Used for IO.
Definition CD_ItoSolverImplem.H:92
virtual void redistributeAMR(EBAMRCellData &a_phi) const
Redistribute mass in an AMR context.
Definition CD_ItoSolver.cpp:2240
phase::which_phase m_phase
Phase where this solver lives.
Definition CD_ItoSolver.H:1410
AMR-hierarchy container of computational particles, stored per patch in Struct-of-Arrays form.
Definition CD_ParticleContainer.H:123
void clearParticles()
Drop all valid particles on every level (keeps each leaf's arena capacity).
Definition CD_ParticleContainer.H:442
bool isOrganizedByCell() const
Whether the valid leaves are currently cell-sorted.
Definition CD_ParticleContainer.H:416
std::string getRealm() const
Realm label.
Definition CD_ParticleContainer.H:300
void remap()
Redistribute every valid particle to the patch/level/rank that owns its cell.
Definition CD_ParticleContainerImplem.H:494
static IntVect getParticleCellIndex(const RealVect &a_particlePosition, const RealVect &a_probLo, const Real &a_dx) noexcept
Get the cell index corresponding to the particle position.
Definition CD_ParticleOpsImplem.H:32
Arena-backed Struct-of-Arrays particle container for a single grid patch.
Definition CD_ParticleSoA.H:655
void append(const RealVect &a_position, const double a_weight)
Append one particle with a default-constructed payload.
Definition CD_ParticleSoA.H:962
RealVect position(const std::size_t a_index) const noexcept
Position of particle i as a RealVect (by value, assembled from the scalar columns).
Definition CD_ParticleSoA.H:1195
double & weight(const std::size_t a_index) noexcept
Weight of particle i.
Definition CD_ParticleSoA.H:1229
std::size_t size() const noexcept
Number of particles currently stored.
Definition CD_ParticleSoA.H:882
static Real getNormal01()
Get a number from a normal distribution centered on zero and variance 1.
Definition CD_RandomImplem.H:174
constexpr int compStatus
Component holding the band cell's status. See MirrorDeposition::Status.
Definition CD_MirrorDeposition.H:53
Refusal
Why reflect() refused to trust its Jacobian.
Definition CD_MirrorDeposition.H:108
@ NonPositiveJacobian
The Jacobian came out non-positive, i.e. the reflection is past the surface's centre of curvature.
@ SmallDenominator
The Jacobian's denominator came too close to zero.
@ LargeJacobian
The Jacobian exceeded the permitted magnitude.
@ None
No refusal; the Jacobian was accepted.
bool reflect(const RealVect &a_pos, const Real *a_surfaceData, const Real a_maxJacobian, const Real a_minDenominator, RealVect &a_image, Real &a_jacobian, Real &a_signedDistance, Refusal &a_refusal) noexcept
Reflect a position across the quadratic surface patch stored for its cell, and weight the image.
Definition CD_MirrorDepositionImplem.H:124
constexpr int numComp
Total number of components in the surface-data holder. Eight in 2-D, thirteen in 3-D.
Definition CD_MirrorDeposition.H:73
Real sum(const Real &a_value) noexcept
Compute the sum across all MPI ranks.
Definition CD_ParallelOpsImplem.H:354