chombo-discharge
Loading...
Searching...
No Matches
CD_ItoSolverImplem.H
Go to the documentation of this file.
1/* chombo-discharge
2 * Copyright © 2021 SINTEF Energy Research.
3 * Please refer to Copyright.txt and LICENSE in the chombo-discharge root directory.
4 */
5
13#ifndef CD_ItoSolverImplem_H
14#define CD_ItoSolverImplem_H
15
16// Std includes
17#include <chrono>
18
19// Chombo includes
20#include <EBAlias.H>
21#include <PolyGeom.H>
22
23// Our includes
24#include <CD_ItoSolver.H>
25#include <CD_DataOps.H>
26#include <CD_Random.H>
27#include <CD_NamespaceHeader.H>
28
29inline RealVect
31{
32 // TLDR: We draw a random number from a Gaussian distribution for each coordinate, and truncate the distribution at m_normalDistributionTruncation.
33
34 auto sign = [](const Real& a) -> Real {
35 return (a > 0) - (a < 0);
36 };
37
39 for (int i = 0; i < SpaceDim; i++) {
41
42 r[i] = sign(r[i]) * std::min(std::abs(r[i]), m_normalDistributionTruncation);
43 }
44
45 return r;
46}
47
48template <ItoSolver::WhichContainer C>
49void
51 const int a_lvl,
52 const DataIndex a_dit,
53 const bool a_destructive)
54{
55 CH_TIME("ItoSolver::addParticles");
56 if (m_verbosity > 5) {
57 pout() << m_name + "::addParticles" << endl;
58 }
59
61
63 if (a_destructive) {
64 my_particles.addItemsDestructive(a_inputParticles.listItems());
65 }
66 else {
67 my_particles.addItems(a_inputParticles.listItems());
68 }
69}
70
71template <class P, class Ret, Ret (P ::*MemberFunc)() const>
72void
74{
75 CH_TIME("ItoSolver::depositParticles");
76 if (m_verbosity > 5) {
77 pout() << m_name + "::depositParticles" << endl;
78 }
79
81}
82
83template <class P, class Ret, Ret (P ::*MemberFunc)() const>
84void
87 const int a_level) const noexcept
88{
89 CH_TIME("ItoSolver::depositParticlesNGP");
90 if (m_verbosity > 5) {
91 pout() << m_name + "::depositParticlesNGP" << 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
116
118 const List<P>& particles = a_particles[a_level][din].listItems();
119
120 particleMesh.deposit<P, Ret, MemberFunc>(output, particles, DepositionType::NGP, 1.0, true);
121 }
122}
123
124template <class P, class Ret, Ret (P ::*MemberFunc)() const>
125void
130{
131 CH_TIME("ItoSolver::depositParticles");
132 if (m_verbosity > 5) {
133 pout() << m_name + "::depositParticles" << endl;
134 }
135
136 CH_assert(a_phi[0]->nComp() == 1);
137 CH_assert(!a_particles.isOrganizedByCell());
138
139 // 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
140 // conserve total mass (if that is important). But the corresponding scheme will be O(1) accurate.
142
143 // Redistribution magic.
144 this->redistributeAMR(a_phi);
145
146 // Average down and interpolate
147 m_amr->conservativeAverage(a_phi, m_realm, m_phase);
148 m_amr->interpGhost(a_phi, m_realm, m_phase);
149}
150
151template <class P, class Ret, Ret (P ::*MemberFunc)() const>
152void
157{
158 CH_TIME("ItoSolver::depositKappaConservative");
159 if (m_verbosity > 5) {
160 pout() << m_name + "::depositKappaConservative" << endl;
161 }
162
163 CH_assert(a_phi[0]->nComp() == 1);
164
166 m_realm,
167 m_phase,
172}
173
174#include <CD_NamespaceFooter.H>
175
176#endif
CoarseFineDeposition
Coarse-fine deposition types (see CD_EBAMRParticleMesh for how these are handled).
Definition CD_CoarseFineDeposition.H:26
Agglomeration of useful data operations.
DepositionType
Deposition types.
Definition CD_DepositionType.H:23
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:34
CoarseFineDeposition m_coarseFineDeposition
Coarse-fine deposition strategy.
Definition CD_ItoSolver.H:1236
virtual void depositParticles()
Deposit particles onto mesh.
Definition CD_ItoSolver.cpp:1825
bool m_forceIrregDepositionNGP
NGP deposition in cut cells or not.
Definition CD_ItoSolver.H:1146
std::string m_realm
Realm where this solve lives.
Definition CD_ItoSolver.H:1079
DepositionType m_deposition
Deposition method when depositing particles to the mesh.
Definition CD_ItoSolver.H:1231
std::string m_name
Solver name.
Definition CD_ItoSolver.H:1104
RealVect randomGaussian() const
Draw a random N-dimensional Gaussian number from a normal distribution with zero with and unit standa...
Definition CD_ItoSolverImplem.H:30
std::map< WhichContainer, ParticleContainer< ItoParticle > > m_particleContainers
Various particle containers with identifiers.
Definition CD_ItoSolver.H:1276
int m_verbosity
Verbosity level for this solver.
Definition CD_ItoSolver.H:1126
void addParticles(ListBox< ItoParticle > &a_inputParticles, const int a_lvl, const DataIndex a_dit, const 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:50
void depositKappaConservative(EBAMRCellData &a_phi, ParticleContainer< P > &a_particles, const DepositionType a_deposition, const CoarseFineDeposition a_coarseFineDeposition) const
Compute the cell-centered deposition – this is the main deposition function.
Definition CD_ItoSolverImplem.H:153
Real m_normalDistributionTruncation
Truncation value for normal distribution.
Definition CD_ItoSolver.H:1116
RefCountedPtr< AmrMesh > m_amr
AMR; needed for grid stuff.
Definition CD_ItoSolver.H:1089
virtual void redistributeAMR(EBAMRCellData &a_phi) const
Redistribute mass in an AMR context.
Definition CD_ItoSolver.cpp:1850
phase::which_phase m_phase
Phase where this solver lives.
Definition CD_ItoSolver.H:1099
void depositParticlesNGP(LevelData< EBCellFAB > &a_output, const ParticleContainer< P > &a_particles, const int a_level) const noexcept
Do an NGP deposit on a specific grid level. Used for IO.
Definition CD_ItoSolverImplem.H:85
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:37
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:735
TracerParticleSolver()
Default constructor.
Definition CD_TracerParticleSolverImplem.H:25
virtual void deposit(EBAMRCellData &a_phi) const noexcept
Deposit particle weight on mesh.
Definition CD_TracerParticleSolverImplem.H:362