chombo-discharge
Loading...
Searching...
No Matches
CD_ItoSolverImplem.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
14#ifndef CD_ITOSOLVERIMPLEM_H
15#define CD_ITOSOLVERIMPLEM_H
16
17// Std includes
18#include <chrono>
19
20// Chombo includes
21#include <EBAlias.H>
22#include <PolyGeom.H>
23
24// Our includes
25#include <CD_ItoSolver.H>
26#include <CD_DataOps.H>
27#include <CD_Random.H>
28#include <CD_EBParticleMesh.H>
29#include <CD_NamespaceHeader.H>
30
31inline RealVect
33{
34 // TLDR: We draw a random number from a Gaussian distribution for each coordinate, and truncate the distribution at
35 // m_normalDistributionTruncation.
36
37 auto sign = [](const Real& a) -> Real {
38 return (a > 0) - (a < 0);
39 };
40
41 RealVect r = RealVect::Zero;
42 for (int i = 0; i < SpaceDim; i++) {
43 r[i] = Random::getNormal01();
44
45 r[i] = sign(r[i]) * std::min(std::abs(r[i]), m_normalDistributionTruncation);
46 }
47
48 return r;
49}
50
51template <typename P, typename Traits>
52void
53ItoSolver::depositWeight(EBAMRCellData& a_phi,
54 const ParticleContainer<P, Traits>& a_particles,
55 const DepositionType a_deposition,
56 const CoarseFineDeposition a_coarseFineDeposition) const
57{
58 CH_TIME("ItoSolver::depositWeight");
59 if (m_verbosity > 5) {
60 pout() << m_name + "::depositWeight" << endl;
61 }
62
63 CH_assert(a_phi[0]->nComp() == 1);
64 CH_assert(a_phi.getRealm() == m_realm);
65 CH_assert(a_particles.getRealm() == m_realm);
66 CH_assert(!a_particles.isOrganizedByCell());
67
68 // Deposit the weight column onto the mesh (resets a_phi internally), then redistribute. Redistribution belongs
69 // here because it decides what the valid-cell values are; coarsening and ghost filling are the caller's, see
70 // coarsenAndFillGhosts().
71 m_amr->depositWeight(a_phi,
72 m_realm,
73 m_phase,
74 a_particles,
75 a_deposition,
76 a_coarseFineDeposition,
78
79 this->redistributeAMR(a_phi);
80}
81
82template <typename Gather>
83void
84ItoSolver::depositGatheredNGP(LevelData<EBCellFAB>& a_output,
85 const ParticleContainer<ItoParticle>& a_particles,
86 const int a_level,
87 Gather a_gather) const noexcept
88{
89 CH_TIME("ItoSolver::depositGatheredNGP");
90 if (m_verbosity > 5) {
91 pout() << m_name + "::depositGatheredNGP" << endl;
92 }
93
94 CH_assert(a_level >= 0);
95 CH_assert(a_level <= m_amr->getFinestLevel());
96
97 const ProblemDomain& domain = m_amr->getDomains()[a_level];
98 const DisjointBoxLayout& dbl = m_amr->getGrids(a_particles.getRealm())[a_level];
99 const DataIterator& dit = dbl.dataIterator();
100 const EBISLayout& ebisl = m_amr->getEBISLayout(a_particles.getRealm(), m_phase)[a_level];
101 const Real dx = m_amr->getDx()[a_level];
102 const RealVect probLo = m_amr->getProbLo();
103
104 CH_assert(a_output.disjointBoxLayout() == dbl);
105
106 const int nbox = dit.size();
107
108#pragma omp parallel for schedule(runtime)
109 for (int mybox = 0; mybox < nbox; mybox++) {
110 const DataIndex& din = dit[mybox];
111
112 const Box cellBox = dbl[din];
113 const EBISBox& ebisbox = ebisl[din];
114
115 EBParticleMesh particleMesh(domain, cellBox, ebisbox, dx * RealVect::Unit, probLo);
116
117 EBCellFAB& output = a_output[din];
118 const ParticleSoA<ItoParticle>& leaf = a_particles[a_level][din];
119
120 // The per-patch deposit INCREMENTS, so start from a clean slate.
121 output.setVal(0.0);
122
123 particleMesh
124 .depositGathered(output, 0, leaf, DepositionType::NGP, 1.0, true, [&](const std::size_t a_i, Real* a_out) {
125 a_out[0] = a_gather(leaf, a_i);
126 });
127 }
128}
129
130template <typename Gather>
131void
132ItoSolver::depositGathered(EBAMRCellData& a_phi,
133 const ParticleContainer<ItoParticle>& a_particles,
134 const DepositionType a_deposition,
135 const CoarseFineDeposition a_coarseFineDeposition,
136 Gather a_gather) const
137{
138 CH_TIME("ItoSolver::depositGathered");
139 if (m_verbosity > 5) {
140 pout() << m_name + "::depositGathered" << endl;
141 }
142
143 CH_assert(a_phi[0]->nComp() == 1);
144 CH_assert(!a_particles.isOrganizedByCell());
145
146 // Deposit the gathered quantity onto the mesh (resets a_phi internally), then redistribute. Coarsening and ghost
147 // filling are the caller's, see coarsenAndFillGhosts().
148 m_amr->depositGathered(a_phi,
149 m_realm,
150 m_phase,
151 a_particles,
152 a_deposition,
153 a_coarseFineDeposition,
155 a_gather);
156
157 this->redistributeAMR(a_phi);
158}
159
160#include <CD_NamespaceFooter.H>
161
162#endif
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.
Declaration of solver class for Ito diffusion.
File containing some useful static methods related to random number generation.
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
bool m_forceIrregDepositionNGP
NGP deposition in cut cells or not.
Definition CD_ItoSolver.H:1323
std::string m_realm
Realm where this solve lives.
Definition CD_ItoSolver.H:1255
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:53
std::string m_name
Solver name.
Definition CD_ItoSolver.H:1280
RealVect randomGaussian() const
Draw a random N-dimensional Gaussian number from a normal distribution with zero with and unit standa...
Definition CD_ItoSolverImplem.H:32
int m_verbosity
Verbosity level for this solver.
Definition CD_ItoSolver.H:1303
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:132
Real m_normalDistributionTruncation
Truncation value for normal distribution.
Definition CD_ItoSolver.H:1293
RefCountedPtr< AmrMesh > m_amr
AMR; needed for grid stuff.
Definition CD_ItoSolver.H:1265
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:84
virtual void redistributeAMR(EBAMRCellData &a_phi) const
Redistribute mass in an AMR context.
Definition CD_ItoSolver.cpp:2133
phase::which_phase m_phase
Phase where this solver lives.
Definition CD_ItoSolver.H:1275
AMR-hierarchy container of computational particles, stored per patch in Struct-of-Arrays form.
Definition CD_ParticleContainer.H:123
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
Arena-backed Struct-of-Arrays particle container for a single grid patch.
Definition CD_ParticleSoA.H:655
static Real getNormal01()
Get a number from a normal distribution centered on zero and variance 1.
Definition CD_RandomImplem.H:172