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_NamespaceHeader.H>
29
30inline RealVect
32{
33 // TLDR: We draw a random number from a Gaussian distribution for each coordinate, and truncate the distribution at m_normalDistributionTruncation.
34
35 auto sign = [](const Real& a) -> Real {
36 return (a > 0) - (a < 0);
37 };
38
40 for (int i = 0; i < SpaceDim; i++) {
42
43 r[i] = sign(r[i]) * std::min(std::abs(r[i]), m_normalDistributionTruncation);
44 }
45
46 return r;
47}
48
49template <ItoSolver::WhichContainer C>
50void
52 const int a_lvl,
53 const DataIndex& a_dit,
54 const bool a_destructive)
55{
56 CH_TIME("ItoSolver::addParticles");
57 if (m_verbosity > 5) {
58 pout() << m_name + "::addParticles" << endl;
59 }
60
62
64 if (a_destructive) {
65 my_particles.addItemsDestructive(a_inputParticles.listItems());
66 }
67 else {
68 my_particles.addItems(a_inputParticles.listItems());
69 }
70}
71
72template <class P, class Ret, Ret (P ::*MemberFunc)() const>
73void
75{
76 CH_TIME("ItoSolver::depositParticles");
77 if (m_verbosity > 5) {
78 pout() << m_name + "::depositParticles" << endl;
79 }
80
82}
83
84template <class P, class Ret, Ret (P ::*MemberFunc)() const>
85void
88 const int a_level) const noexcept
89{
90 CH_TIME("ItoSolver::depositParticlesNGP");
91 if (m_verbosity > 5) {
92 pout() << m_name + "::depositParticlesNGP" << endl;
93 }
94
95 CH_assert(a_level >= 0);
96 CH_assert(a_level <= m_amr->getFinestLevel());
97
98 const ProblemDomain& domain = m_amr->getDomains()[a_level];
99 const DisjointBoxLayout& dbl = m_amr->getGrids(a_particles.getRealm())[a_level];
100 const DataIterator& dit = dbl.dataIterator();
101 const EBISLayout& ebisl = m_amr->getEBISLayout(a_particles.getRealm(), m_phase)[a_level];
102 const Real dx = m_amr->getDx()[a_level];
103 const RealVect probLo = m_amr->getProbLo();
104
105 CH_assert(a_output.disjointBoxLayout() == dbl);
106
107 const int nbox = dit.size();
108
109#pragma omp parallel for schedule(runtime)
110 for (int mybox = 0; mybox < nbox; mybox++) {
111 const DataIndex& din = dit[mybox];
112
113 const Box cellBox = dbl[din];
114 const EBISBox& ebisbox = ebisl[din];
115
117
119 const List<P>& particles = a_particles[a_level][din].listItems();
120
121 particleMesh.deposit<P, Ret, MemberFunc>(output, particles, DepositionType::NGP, 1.0, true);
122 }
123}
124
125template <class P, class Ret, Ret (P ::*MemberFunc)() const>
126void
131{
132 CH_TIME("ItoSolver::depositParticles");
133 if (m_verbosity > 5) {
134 pout() << m_name + "::depositParticles" << endl;
135 }
136
137 CH_assert(a_phi[0]->nComp() == 1);
138 CH_assert(!a_particles.isOrganizedByCell());
139
140 // TLDR: First, deposit onto the mesh as usual (as if the EB wasn't there). If the user asks for it, he can redistribute mass in order to
141 // conserve total mass (if that is important). But the corresponding scheme will be O(1) accurate.
143
144 // Redistribution magic.
145 this->redistributeAMR(a_phi);
146
147 // Average down and interpolate
148 m_amr->conservativeAverage(a_phi, m_realm, m_phase);
149 m_amr->interpGhost(a_phi, m_realm, m_phase);
150}
151
152template <class P, class Ret, Ret (P ::*MemberFunc)() const>
153void
158{
159 CH_TIME("ItoSolver::depositKappaConservative");
160 if (m_verbosity > 5) {
161 pout() << m_name + "::depositKappaConservative" << endl;
162 }
163
164 CH_assert(a_phi[0]->nComp() == 1);
165
167 m_realm,
168 m_phase,
173}
174
175#include <CD_NamespaceFooter.H>
176
177#endif
CoarseFineDeposition
Coarse-fine deposition types (see CD_EBAMRParticleMesh for how these are handled).
Definition CD_CoarseFineDeposition.H:27
Agglomeration of useful data operations.
DepositionType
Deposition types.
Definition CD_DepositionType.H:24
Declaration of solver class for Ito diffusion.
File containing some useful static methods related to random number generation.
A class for depositing and interpolating particles on a single grid patch.
Definition CD_EBParticleMesh.H:35
CoarseFineDeposition m_coarseFineDeposition
Coarse-fine deposition strategy.
Definition CD_ItoSolver.H:1267
void depositKappaConservative(EBAMRCellData &a_phi, ParticleContainer< P > &a_particles, DepositionType a_deposition, CoarseFineDeposition a_coarseFineDeposition) const
Compute the cell-centered deposition – this is the main deposition function.
Definition CD_ItoSolverImplem.H:154
virtual void depositParticles()
Deposit particles onto mesh.
Definition CD_ItoSolver.cpp:1833
void depositParticlesNGP(LevelData< EBCellFAB > &a_output, const ParticleContainer< P > &a_particles, int a_level) const noexcept
Do an NGP deposit on a specific grid level. Used for IO.
Definition CD_ItoSolverImplem.H:86
bool m_forceIrregDepositionNGP
NGP deposition in cut cells or not.
Definition CD_ItoSolver.H:1177
std::string m_realm
Realm where this solve lives.
Definition CD_ItoSolver.H:1110
DepositionType m_deposition
Deposition method when depositing particles to the mesh.
Definition CD_ItoSolver.H:1262
std::string m_name
Solver name.
Definition CD_ItoSolver.H:1135
RealVect randomGaussian() const
Draw a random N-dimensional Gaussian number from a normal distribution with zero with and unit standa...
Definition CD_ItoSolverImplem.H:31
std::map< WhichContainer, ParticleContainer< ItoParticle > > m_particleContainers
Various particle containers with identifiers.
Definition CD_ItoSolver.H:1307
int m_verbosity
Verbosity level for this solver.
Definition CD_ItoSolver.H:1157
Real m_normalDistributionTruncation
Truncation value for normal distribution.
Definition CD_ItoSolver.H:1147
RefCountedPtr< AmrMesh > m_amr
AMR; needed for grid stuff.
Definition CD_ItoSolver.H:1120
virtual void redistributeAMR(EBAMRCellData &a_phi) const
Redistribute mass in an AMR context.
Definition CD_ItoSolver.cpp:1858
phase::which_phase m_phase
Phase where this solver lives.
Definition CD_ItoSolver.H:1130
void addParticles(ListBox< ItoParticle > &a_inputParticles, int a_lvl, const DataIndex &a_dit, bool a_destructive)
Add particles to a contain. This adds into a specific grid level and patch. The user can delete the i...
Definition CD_ItoSolverImplem.H:51
static Real getNormal01()
Get a number from a normal distribution centered on zero and variance 1.
Definition CD_RandomImplem.H:172
Base class for a tracer particle solver. This solver can advance particles in a pre-defined velocity ...
Definition CD_TracerParticleSolver.H:38
void depositParticles(EBAMRCellData &a_phi, const ParticleContainer< T > &a_particles, const DepositionType a_baseDeposition, const CoarseFineDeposition a_coarseFineDeposition) const noexcept
Generic particle deposition method for putting a scalar field onto the mesh.
Definition CD_TracerParticleSolverImplem.H:736
TracerParticleSolver()
Default constructor.
Definition CD_TracerParticleSolverImplem.H:26
virtual void deposit(EBAMRCellData &a_phi) const noexcept
Deposit particle weight on mesh.
Definition CD_TracerParticleSolverImplem.H:363