chombo-discharge
Loading...
Searching...
No Matches
CD_AmrMeshImplem.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
12
13#ifndef CD_AMRMESHIMPLEM_H
14#define CD_AMRMESHIMPLEM_H
15
16// Our includes
17#include <CD_AmrMesh.H>
18#include <CD_ParticleOps.H>
19#include <CD_NamespaceHeader.H>
20
21template <typename T>
22void
24 const EBAMRData<T>& a_src,
25 const CopyStrategy& a_toRegion,
26 const CopyStrategy& a_fromRegion) const noexcept
27{
28 CH_TIME("AmrMesh::copyData(EBAMRData, simple)");
29 if (m_verbosity > 5) {
30 pout() << "AmrMesh::copyData(EBAMRData, simple)" << endl;
31 }
32
33 const int nComp = a_dst[0]->nComp();
34 const Interval dstComps = Interval(0, nComp - 1);
35 const Interval srcComps = Interval(0, nComp - 1);
36
37 const std::string toRealm = a_dst.getRealm();
38 const std::string fromRealm = a_src.getRealm();
39
40 for (int lvl = 0; lvl <= m_finestLevel; lvl++) {
41 CH_assert(!(a_dst[lvl].isNull()));
42 CH_assert(!(a_src[lvl].isNull()));
43
44 this->copyData(*a_dst[lvl], *a_src[lvl], lvl, toRealm, fromRealm, dstComps, srcComps, a_toRegion, a_fromRegion);
45 }
46}
47
48template <typename T>
49void
51 const EBAMRData<T>& a_src,
52 const Interval& a_dstComps,
53 const Interval& a_srcComps,
54 const CopyStrategy& a_toRegion,
55 const CopyStrategy& a_fromRegion) const noexcept
56{
57 CH_TIME("AmrMesh::copyData(EBAMRData, full)");
58 if (m_verbosity > 5) {
59 pout() << "AmrMesh::copyData(EBAMRData, full)" << endl;
60 }
61
62 const std::string toRealm = a_dst.getRealm();
63 const std::string fromRealm = a_src.getRealm();
64
65 for (int lvl = 0; lvl <= m_finestLevel; lvl++) {
66 CH_assert(!(a_dst[lvl].isNull()));
67 CH_assert(!(a_src[lvl].isNull()));
68
69 this->copyData(*a_dst[lvl], *a_src[lvl], lvl, toRealm, fromRealm, a_dstComps, a_srcComps, a_toRegion, a_fromRegion);
70 }
71}
72
73template <typename T>
74void
75AmrMesh::copyData(LevelData<T>& a_dst,
76 const LevelData<T>& a_src,
77 const int a_level,
78 const std::string a_toRealm,
79 const std::string a_fromRealm,
80 const CopyStrategy& a_toRegion,
81 const CopyStrategy& a_fromRegion) const noexcept
82{
83 CH_TIME("AmrMesh::copyData(LD<T>_full)");
84 if (m_verbosity > 5) {
85 pout() << "AmrMesh::copyData(LD<T>_full)" << endl;
86 }
87
88 const Interval dstComps = Interval(0, a_dst.nComp() - 1);
89 const Interval srcComps = Interval(0, a_src.nComp() - 1);
90
91 this->copyData(a_dst, a_src, a_level, a_toRealm, a_fromRealm, dstComps, srcComps, a_toRegion, a_fromRegion);
92}
93
94template <typename T>
95void
96AmrMesh::copyData(LevelData<T>& a_dst,
97 const LevelData<T>& a_src,
98 const int a_level,
99 const std::string a_toRealm,
100 const std::string a_fromRealm,
101 const Interval& a_dstComps,
102 const Interval& a_srcComps,
103 const CopyStrategy& a_toRegion,
104 const CopyStrategy& a_fromRegion) const noexcept
105{
106 CH_TIME("AmrMesh::copyData(LD<T>_full)");
107 if (m_verbosity > 5) {
108 pout() << "AmrMesh::copyData(LD<T>_full)" << endl;
109 }
110
111 CH_assert(a_dstComps.size() == a_srcComps.size());
112 CH_assert(a_dst.nComp() > a_dstComps.end());
113 CH_assert(a_src.nComp() > a_srcComps.end());
114
115 if (a_toRealm != a_fromRealm) {
116 const auto id = std::make_pair(a_fromRealm, a_toRealm);
117
118 if (a_toRegion == CopyStrategy::ValidGhost) {
119 CH_assert(a_dst.ghostVect() == m_numGhostCells * IntVect::Unit);
120 }
121 if (a_fromRegion == CopyStrategy::ValidGhost) {
122 CH_assert(a_src.ghostVect() == m_numGhostCells * IntVect::Unit);
123 }
124
125 // Copy the cached Copier rather than using it in place. copyTo() stores the size of every message in the
126 // Copier's buffers and reuses them on the next call with the same number of components, but these Copiers
127 // serve every data type and phase copied between the two realms, and the message sizes of EB data depend on
128 // both. A copy starts with empty buffers, so copyTo() computes the sizes for the data actually being copied.
129 Copier copier;
130
131 if (a_fromRegion == CopyStrategy::Valid) {
132 if (a_toRegion == CopyStrategy::Valid) {
133 copier = m_validToValidRealmCopiers.at(id)[a_level];
134 }
135 else if (a_toRegion == CopyStrategy::ValidGhost) {
136 copier = m_validToValidGhostRealmCopiers.at(id)[a_level];
137 }
138 else {
139 MayDay::Abort("AmrMesh::copyData - logic bust 1");
140 }
141 }
142 else if (a_fromRegion == CopyStrategy::ValidGhost) {
143 if (a_toRegion == CopyStrategy::Valid) {
144 copier = m_validGhostToValidRealmCopiers.at(id)[a_level];
145 }
146 else if (a_toRegion == CopyStrategy::ValidGhost) {
147 copier = m_validGhostToValidGhostRealmCopiers.at(id)[a_level];
148 }
149 else {
150 MayDay::Abort("AmrMesh::copyData - logic bust 2");
151 }
152 }
153 else {
154 MayDay::Abort("AmrMesh::copyData - logic bust 3");
155 }
156
157 a_src.copyTo(a_srcComps, a_dst, a_dstComps, copier);
158 }
159 else {
160 a_src.localCopyTo(a_srcComps, a_dst, a_dstComps);
161 }
162}
163
164template <typename T>
165void
166AmrMesh::deallocate(Vector<T*>& a_data) const
167{
168 CH_TIME("AmrMesh::deallocate(Vector<T*>)");
169 if (m_verbosity > 5) {
170 pout() << "AmrMesh::deallocate(Vector<T*>)" << endl;
171 }
172
173 for (int lvl = 0; lvl <= m_finestLevel; lvl++) {
174 delete a_data[lvl];
175 }
176}
177
178template <typename T>
179void
180AmrMesh::deallocate(Vector<RefCountedPtr<T>>& a_data) const
181{
182 CH_TIME("AmrMesh::deallocate(Vector<RefCountedPtr<T>)");
183 if (m_verbosity > 5) {
184 pout() << "AmrMesh::deallocate(Vector<RefCountedPtr<T>)" << endl;
185 }
186
187 for (int lvl = 0; lvl < a_data.size(); lvl++) {
188 // delete &a_data[lvl];
189 a_data[lvl] = RefCountedPtr<T>(0);
190#if 0
191 if(!a_data[lvl].isNull()){
192 delete &(*a_data[lvl]);
193 a_data[lvl] = RefCountedPtr<T> (NULL);
194 }
195
196#endif
197 }
198}
199
200template <typename T>
201void
203{
204 CH_TIME("AmrMesh::deallocate(EBAMRData<T>)");
205 if (m_verbosity > 5) {
206 pout() << "AmrMesh::deallocate(EBAMRData<T>)" << endl;
207 }
208
209 return this->deallocate(a_data.getData());
210}
211
212template <typename T>
213void
214AmrMesh::alias(Vector<T*>& a_alias, const Vector<RefCountedPtr<T>>& a_data) const
215{
216 CH_TIME("AmrMesh::alias(Vector<T*>, Vector<RefCountedPtr<T>)");
217 if (m_verbosity > 5) {
218 pout() << "AmrMesh::alias(Vector<T*>, Vector<RefCountedPtr<T>)" << endl;
219 }
220
221 a_alias.resize(a_data.size());
222
223 for (int lvl = 0; lvl < a_data.size(); lvl++) {
224 a_alias[lvl] = &(*a_data[lvl]);
225 }
226}
227
228template <typename T, typename S>
229void
230AmrMesh::alias(Vector<T*>& a_alias, const EBAMRData<S>& a_data) const
231{
232 CH_TIME("AmrMesh::alias(Vector<T*>, EBAMRData<S>)");
233 if (m_verbosity > 5) {
234 pout() << "AmrMesh::alias(Vector<T*>, EBAMRData<S>" << endl;
235 }
236
237 return this->alias(a_alias, a_data.getData());
238}
239
240template <typename P, typename Traits>
241void
242AmrMesh::allocate(ParticleContainer<P, Traits>& a_container, const std::string& a_realm) const
243{
244 CH_TIME("AmrMesh::allocate(ParticleContainer<P, Traits>, string)");
245 if (m_verbosity > 5) {
246 pout() << "AmrMesh::allocate(ParticleContainer<P, Traits>, string)" << endl;
247 }
248
249 if (!this->queryRealm(a_realm)) {
250 const std::string str = "AmrMesh::allocate(ParticleContainer<P, Traits>, string) - could not find Realm '" +
251 a_realm + "'";
252 MayDay::Abort(str.c_str());
253 }
254
255 a_container.define(m_realms[a_realm]->getGrids(),
256 m_realms[a_realm]->getDomains(),
257 m_realms[a_realm]->getDx(),
258 m_realms[a_realm]->getRefinementRatios(),
259 m_probLo,
261 m_realms[a_realm]->getLevelTiles(), // alias the Realm's tile->box maps (single source)
263 a_realm,
264 &m_realms[a_realm]->getValidCells()); // alias for remap()'s stayer fast path
265}
266
267template <typename T>
268void
269AmrMesh::allocatePointer(Vector<RefCountedPtr<T>>& a_data) const
270{
271 CH_TIME("AmrMesh::allocatePointer(Vector<RefCountedPtr<T> >)");
272 if (m_verbosity > 5) {
273 pout() << "AmrMesh::allocatePointer(Vector<RefCountedPtr<T> >)" << endl;
274 }
275
276 a_data.resize(1 + m_finestLevel);
277 for (int lvl = 0; lvl <= m_finestLevel; lvl++) {
278 a_data[lvl] = RefCountedPtr<T>(new T());
279 }
280}
281
282template <typename T>
283void
284AmrMesh::allocatePointer(Vector<RefCountedPtr<T>>& a_data, const int a_finestLevel) const
285{
286 CH_TIME("AmrMesh::allocatePointer(Vector<RefCountedPtr<T> >, int)");
287 if (m_verbosity > 5) {
288 pout() << "AmrMesh::allocatePointer(Vector<RefCountedPtr<T> >, int)" << endl;
289 }
290
291 a_data.resize(1 + a_finestLevel);
292
293 for (int lvl = 0; lvl <= a_finestLevel; lvl++) {
294 a_data[lvl] = RefCountedPtr<T>(new T());
295 }
296}
297
298template <typename T>
299void
300AmrMesh::allocatePointer(EBAMRData<T>& a_data, const std::string& a_realm) const
301{
302 CH_TIME("AmrMesh::allocatePointer(EBAMRData<T>, std::string)");
303 if (m_verbosity > 5) {
304 pout() << "AmrMesh::allocatePointer(EBAMRData<T>, std::string)" << endl;
305 }
306
307 this->allocatePointer(a_data.getData());
308
309 a_data.setRealm(a_realm);
310}
311
312template <typename T>
313void
314AmrMesh::allocatePointer(EBAMRData<T>& a_data, const std::string& a_realm, const int a_finestLevel) const
315{
316 CH_TIME("AmrMesh::allocatePointer(EBAMRData<T>, std::string, int)");
317 if (m_verbosity > 5) {
318 pout() << "AmrMesh::allocatePointer(EBAMRData<T>, std::string, int)" << endl;
319 }
320
321 this->allocatePointer(a_data.getData(), a_finestLevel);
322
323 a_data.setRealm(a_realm);
324}
325
326template <typename P, typename Traits>
327void
329 const int a_lmin,
330 const int a_newFinestLevel) const noexcept
331{
332 CH_TIME("AmrMesh::remapToNewGrids(ParticleContainer)");
333 if (m_verbosity > 5) {
334 pout() << "AmrMesh::remapToNewGrids(ParticleContainer)" << endl;
335 }
336
337 (void)a_lmin; // ParticleContainer::regrid redistributes from the preRegrid cache; no lmin needed.
338
339 const std::string realm = a_particles.getRealm();
340
341 a_particles.regrid(this->getGrids(realm),
342 this->getDomains(),
343 this->getDx(),
344 this->getRefinementRatios(),
346 m_realms[realm]->getLevelTiles(), // alias the Realm's tile->box maps (single source)
347 a_newFinestLevel);
348}
349
350template <typename P, typename Traits>
351void
352AmrMesh::depositParticles(EBAMRIVData& a_meshData,
353 const std::string& a_realm,
354 const phase::which_phase& a_phase,
355 const ParticleContainer<P, Traits>& a_particles) const noexcept
356{
357 CH_TIME("AmrMesh::depositParticles(surface, SoA)");
358 if (m_verbosity > 5) {
359 pout() << "AmrMesh::depositParticles(surface, SoA)" << endl;
360 }
361
362 CH_assert(a_meshData[0]->nComp() == 1);
363 CH_assert(a_meshData.getRealm() == a_particles.getRealm());
364
365 EBAMRSurfaceDeposition& surfaceDeposition = this->getSurfaceDeposition(a_realm, a_phase);
366
367 surfaceDeposition.deposit<P, Traits>(a_meshData, a_particles);
368}
369
370template <typename P, typename Traits>
371void
372AmrMesh::depositWeight(EBAMRCellData& a_meshData,
373 const std::string& a_realm,
374 const phase::which_phase& a_phase,
375 const ParticleContainer<P, Traits>& a_particles,
376 const DepositionType a_depositionType,
377 const CoarseFineDeposition a_coarseFineDeposition,
378 const IrregularDeposition a_irregularDeposition)
379{
380 CH_TIME("AmrMesh::depositWeight(ParticleContainer)");
381 if (m_verbosity > 5) {
382 pout() << "AmrMesh::depositWeight(ParticleContainer)" << endl;
383 }
384
385 EBAMRParticleMesh& particleMesh = this->getParticleMesh(a_realm, a_phase);
386
387 particleMesh.depositWeight(a_meshData, a_particles, a_depositionType, a_coarseFineDeposition, a_irregularDeposition);
388}
389
390template <typename P, typename Traits, typename CellGather>
391void
392AmrMesh::depositGathered(EBAMRCellData& a_meshData,
393 const std::string& a_realm,
394 const phase::which_phase& a_phase,
395 const ParticleContainer<P, Traits>& a_particles,
396 const DepositionType a_depositionType,
397 const CoarseFineDeposition a_coarseFineDeposition,
398 const IrregularDeposition a_irregularDeposition,
399 CellGather a_cellGather)
400{
401 CH_TIME("AmrMesh::depositGathered(ParticleContainer)");
402 if (m_verbosity > 5) {
403 pout() << "AmrMesh::depositGathered(ParticleContainer)" << endl;
404 }
405
406 EBAMRParticleMesh& particleMesh = this->getParticleMesh(a_realm, a_phase);
407
408 particleMesh.depositGathered(a_meshData,
409 a_particles,
410 a_depositionType,
411 a_coarseFineDeposition,
412 a_irregularDeposition,
413 a_cellGather);
414}
415
416template <auto... Members, typename P, typename Traits>
417void
418AmrMesh::depositParticles(EBAMRCellData& a_meshData,
419 const std::string& a_realm,
420 const phase::which_phase& a_phase,
421 const ParticleContainer<P, Traits>& a_particles,
422 const DepositionType a_depositionType,
423 const CoarseFineDeposition a_coarseFineDeposition,
424 const IrregularDeposition a_irregularDeposition)
425{
426 CH_TIME("AmrMesh::depositParticles(ParticleContainer)");
427 if (m_verbosity > 5) {
428 pout() << "AmrMesh::depositParticles(ParticleContainer)" << endl;
429 }
430
431 EBAMRParticleMesh& particleMesh = this->getParticleMesh(a_realm, a_phase);
432
433 particleMesh.template deposit<Members...>(a_meshData,
434 a_particles,
435 a_depositionType,
436 a_coarseFineDeposition,
437 a_irregularDeposition);
438}
439
440template <typename P, typename Traits>
441void
443 const std::string& a_realm,
444 const phase::which_phase& a_phase,
445 const EBAMRCellData& a_meshScalarField,
446 const DepositionType a_interpType,
447 const bool a_forceIrregNGP) const
448{
449 CH_TIME("AmrMesh::interpolateWeight(ParticleContainer)");
450 if (m_verbosity > 5) {
451 pout() << "AmrMesh::interpolateWeight(ParticleContainer)" << endl;
452 }
453
454 EBAMRParticleMesh& particleMesh = this->getParticleMesh(a_realm, a_phase);
455
456 particleMesh.interpolateWeight(a_particles, a_meshScalarField, a_interpType, a_forceIrregNGP);
457}
458
459template <auto... Members, typename P, typename Traits>
460void
462 const std::string& a_realm,
463 const phase::which_phase& a_phase,
464 const EBAMRCellData& a_meshField,
465 const DepositionType a_interpType,
466 const bool a_forceIrregNGP) const
467{
468 CH_TIME("AmrMesh::interpolateParticles(ParticleContainer)");
469 if (m_verbosity > 5) {
470 pout() << "AmrMesh::interpolateParticles(ParticleContainer)" << endl;
471 }
472
473 EBAMRParticleMesh& particleMesh = this->getParticleMesh(a_realm, a_phase);
474
475 particleMesh.template interpolate<Members...>(a_particles, a_meshField, a_interpType, a_forceIrregNGP);
476}
477
478template <typename P, typename Traits>
479void
481 const phase::which_phase& a_phase,
482 const Real a_tolerance) const
483{
484 CH_TIME("AmrMesh::removeCoveredParticlesIF(ParticleContainer)");
485 if (m_verbosity > 5) {
486 pout() << "AmrMesh::removeCoveredParticlesIF(ParticleContainer)" << endl;
487 }
488
489 // Figure out the implicit function
490 RefCountedPtr<BaseIF> implicitFunction;
491
492 switch (a_phase) {
493 case phase::gas: {
494 implicitFunction = m_baseif.at(phase::gas);
495
496 break;
497 }
498 case phase::solid: {
499 implicitFunction = m_baseif.at(phase::solid);
500
501 break;
502 }
503 default: {
504 MayDay::Error("AmrMesh::removeCoveredParticlesIF(ParticleContainer) - logic bust");
505 }
506 }
507
508 const std::string whichRealm = a_particles.getRealm();
509
510 for (int lvl = 0; lvl <= m_finestLevel; lvl++) {
511 const DisjointBoxLayout& dbl = this->getGrids(whichRealm)[lvl];
512 const DataIterator& dit = dbl.dataIterator();
513 const Real dx = this->getDx()[lvl];
514 const Real tol = a_tolerance * dx;
515
516 const int nbox = dit.size();
517#pragma omp parallel for schedule(runtime)
518 for (int mybox = 0; mybox < nbox; mybox++) {
519 const DataIndex& din = dit[mybox];
520
521 ParticleSoA<P, Traits>& leaf = a_particles[lvl][din];
522
523 // swap-and-pop removal: do NOT advance i after a removal (a new particle now sits in slot i).
524 std::size_t i = 0;
525 while (i < leaf.size()) {
526 if (implicitFunction->value(leaf.position(i)) > tol) {
527 leaf.remove(i);
528 }
529 else {
530 i++;
531 }
532 }
533 }
534 }
535}
536
537template <typename P, typename Traits>
538void
540 const phase::which_phase& a_phase,
541 const Real a_tolerance) const
542{
543 CH_TIME("AmrMesh::removeCoveredParticlesDiscrete(ParticleContainer)");
544 if (m_verbosity > 5) {
545 pout() << "AmrMesh::removeCoveredParticlesDiscrete(ParticleContainer)" << endl;
546 }
547
548 const std::string whichRealm = a_particles.getRealm();
549
550 for (int lvl = 0; lvl <= m_finestLevel; lvl++) {
551 const DisjointBoxLayout& dbl = this->getGrids(whichRealm)[lvl];
552 const DataIterator& dit = dbl.dataIterator();
553 const EBISLayout& ebisl = this->getEBISLayout(whichRealm, a_phase)[lvl];
554 const Real dx = this->getDx()[lvl];
555 const Real tol = a_tolerance * dx;
556
557 const int nbox = dit.size();
558#pragma omp parallel for schedule(runtime)
559 for (int mybox = 0; mybox < nbox; mybox++) {
560 const DataIndex& din = dit[mybox];
561 const EBISBox& ebisBox = ebisl[din];
562 const Box region = ebisBox.getRegion();
563
564 const bool isRegular = ebisBox.isAllRegular();
565 const bool isCovered = ebisBox.isAllCovered();
566 const bool isIrregular = !isRegular && !isCovered;
567
568 ParticleSoA<P, Traits>& leaf = a_particles[lvl][din];
569
570 if (isCovered) {
571 leaf.clear();
572 }
573 else if (isIrregular) {
574 // swap-and-pop removal: do NOT advance i after a removal.
575 std::size_t i = 0;
576 while (i < leaf.size()) {
577 const RealVect pos = leaf.position(i);
578 const IntVect iv = ParticleOps::getParticleCellIndex(pos, m_probLo, dx);
579
580 CH_assert(region.contains(iv));
581
582 if (ebisBox.isCovered(iv)) {
583 leaf.remove(i);
584 }
585 else if (ebisBox.isIrregular(iv)) {
586 // Inside the valid region if it is on the valid side of at least one of the cell's VoF faces.
587 bool insideAtLeastOneVoF = false;
588
589 const std::vector<VolIndex> vofs = ebisBox.getVoFs(iv).stdVector();
590 for (const auto& vof : vofs) {
591 const RealVect ebNormal = ebisBox.normal(vof);
592 const RealVect ebCentroid = m_probLo + Location::position(Location::Cell::Boundary, vof, ebisBox, dx);
593 const Real faceProjection = ebNormal.dotProduct(pos - ebCentroid);
594
595 if (faceProjection >= -tol) {
596 insideAtLeastOneVoF = true;
597 break;
598 }
599 }
600
601 if (!insideAtLeastOneVoF) {
602 leaf.remove(i);
603 }
604 else {
605 i++;
606 }
607 }
608 else {
609 i++;
610 }
611 }
612 }
613 }
614 }
615}
616
617template <typename P, typename Traits>
618void
620 const phase::which_phase& a_phase) const
621{
622 CH_TIME("AmrMesh::removeCoveredParticlesVoxels(ParticleContainer)");
623 if (m_verbosity > 5) {
624 pout() << "AmrMesh::removeCoveredParticlesVoxels(ParticleContainer)" << endl;
625 }
626
627 const std::string whichRealm = a_particles.getRealm();
628
629 for (int lvl = 0; lvl <= m_finestLevel; lvl++) {
630 const DisjointBoxLayout& dbl = this->getGrids(whichRealm)[lvl];
631 const DataIterator& dit = dbl.dataIterator();
632 const EBISLayout& ebisl = this->getEBISLayout(whichRealm, a_phase)[lvl];
633 const Real dx = this->getDx()[lvl];
634
635 const int nbox = dit.size();
636#pragma omp parallel for schedule(runtime)
637 for (int mybox = 0; mybox < nbox; mybox++) {
638 const DataIndex& din = dit[mybox];
639 const EBISBox& ebisBox = ebisl[din];
640 const Box region = ebisBox.getRegion();
641
642 const bool isRegular = ebisBox.isAllRegular();
643 const bool isCovered = ebisBox.isAllCovered();
644 const bool isIrregular = !isRegular && !isCovered;
645
646 ParticleSoA<P, Traits>& leaf = a_particles[lvl][din];
647
648 if (isCovered) {
649 leaf.clear();
650 }
651 else if (isIrregular) {
652 std::size_t i = 0;
653 while (i < leaf.size()) {
654 const RealVect pos = leaf.position(i);
655 const RealVect rv = (pos - m_probLo) / dx;
656 const IntVect iv = IntVect(D_DECL(floor(rv[0]), floor(rv[1]), floor(rv[2])));
657
658 CH_assert(region.contains(iv));
659
660 if (ebisBox.isCovered(iv)) {
661 leaf.remove(i);
662 }
663 else {
664 i++;
665 }
666 }
667 }
668 }
669 }
670}
671
672template <typename P, typename Traits>
673void
675 ParticleContainer<P, Traits>& a_particlesTo,
676 const phase::which_phase& a_phase,
677 const Real a_tolerance) const
678{
679 CH_TIME("AmrMesh::transferCoveredParticlesIF(ParticleContainer)");
680 if (m_verbosity > 5) {
681 pout() << "AmrMesh::transferCoveredParticlesIF(ParticleContainer)" << endl;
682 }
683
684 // Figure out the implicit function
685 RefCountedPtr<BaseIF> implicitFunction;
686
687 switch (a_phase) {
688 case phase::gas: {
689 implicitFunction = m_baseif.at(phase::gas);
690
691 break;
692 }
693 case phase::solid: {
694 implicitFunction = m_baseif.at(phase::solid);
695
696 break;
697 }
698 default: {
699 MayDay::Error("AmrMesh::transferCoveredParticlesIF(ParticleContainer) - logic bust");
700 }
701 }
702
703 const std::string realmFrom = a_particlesFrom.getRealm();
704 const std::string realmTo = a_particlesTo.getRealm();
705
706 CH_assert(realmFrom == realmTo);
707
708 for (int lvl = 0; lvl <= m_finestLevel; lvl++) {
709 const DisjointBoxLayout& dbl = this->getGrids(realmFrom)[lvl];
710 const DataIterator& dit = dbl.dataIterator();
711 const Real dx = this->getDx()[lvl];
712 const Real tol = a_tolerance * dx;
713
714 const int nbox = dit.size();
715#pragma omp parallel for schedule(runtime)
716 for (int mybox = 0; mybox < nbox; mybox++) {
717 const DataIndex& din = dit[mybox];
718
719 ParticleSoA<P, Traits>& from = a_particlesFrom[lvl][din];
720 ParticleSoA<P, Traits>& to = a_particlesTo[lvl][din];
721
722 // swap-and-pop transfer: do NOT advance i after a transfer (a new particle now sits in slot i).
723 std::size_t i = 0;
724 while (i < from.size()) {
725 if (implicitFunction->value(from.position(i)) > tol) {
726 to.appendParticle(from, i);
727 from.remove(i);
728 }
729 else {
730 i++;
731 }
732 }
733 }
734 }
735}
736
737template <typename P, typename Traits>
738void
740 ParticleContainer<P, Traits>& a_particlesTo,
741 const phase::which_phase& a_phase,
742 const Real a_tolerance) const
743{
744 CH_TIME("AmrMesh::transferCoveredParticlesDiscrete(ParticleContainer)");
745 if (m_verbosity > 5) {
746 pout() << "AmrMesh::transferCoveredParticlesDiscrete(ParticleContainer)" << endl;
747 }
748
749 const std::string realmFrom = a_particlesFrom.getRealm();
750 const std::string realmTo = a_particlesTo.getRealm();
751
752 CH_assert(realmFrom == realmTo);
753
754 for (int lvl = 0; lvl <= m_finestLevel; lvl++) {
755 const DisjointBoxLayout& dbl = this->getGrids(realmFrom)[lvl];
756 const DataIterator& dit = dbl.dataIterator();
757 const EBISLayout& ebisl = this->getEBISLayout(realmFrom, a_phase)[lvl];
758 const Real dx = this->getDx()[lvl];
759 const Real tol = a_tolerance * dx;
760
761 const int nbox = dit.size();
762#pragma omp parallel for schedule(runtime)
763 for (int mybox = 0; mybox < nbox; mybox++) {
764 const DataIndex& din = dit[mybox];
765 const EBISBox& ebisBox = ebisl[din];
766 const Box region = ebisBox.getRegion();
767
768 const bool isRegular = ebisBox.isAllRegular();
769 const bool isCovered = ebisBox.isAllCovered();
770 const bool isIrregular = !isRegular && !isCovered;
771
772 ParticleSoA<P, Traits>& from = a_particlesFrom[lvl][din];
773 ParticleSoA<P, Traits>& to = a_particlesTo[lvl][din];
774
775 if (isCovered) {
776 to.catenate(from);
777 }
778 else if (isIrregular) {
779 // swap-and-pop transfer: do NOT advance i after a transfer.
780 std::size_t i = 0;
781 while (i < from.size()) {
782 const RealVect pos = from.position(i);
783 const IntVect iv = ParticleOps::getParticleCellIndex(pos, m_probLo, dx);
784
785 CH_assert(region.contains(iv));
786
787 if (ebisBox.isCovered(iv)) {
788 to.appendParticle(from, i);
789 from.remove(i);
790 }
791 else if (ebisBox.isIrregular(iv)) {
792 // Inside the valid region if it is on the valid side of at least one of the cell's VoF faces.
793 bool insideAtLeastOneVoF = false;
794
795 const std::vector<VolIndex> vofs = ebisBox.getVoFs(iv).stdVector();
796 for (const auto& vof : vofs) {
797 const RealVect ebCentroid = m_probLo + Location::position(Location::Cell::Boundary, vof, ebisBox, dx);
798 const RealVect ebNormal = ebisBox.normal(vof);
799 const Real faceProjection = ebNormal.dotProduct(pos - ebCentroid);
800
801 if (faceProjection >= -tol) {
802 insideAtLeastOneVoF = true;
803 break;
804 }
805 }
806
807 if (!insideAtLeastOneVoF) {
808 to.appendParticle(from, i);
809 from.remove(i);
810 }
811 else {
812 i++;
813 }
814 }
815 else {
816 i++;
817 }
818 }
819 }
820 }
821 }
822}
823
824template <typename P, typename Traits>
825void
827 ParticleContainer<P, Traits>& a_particlesTo,
828 const phase::which_phase& a_phase) const
829{
830 CH_TIME("AmrMesh::transferCoveredParticlesVoxels(ParticleContainer)");
831 if (m_verbosity > 5) {
832 pout() << "AmrMesh::transferCoveredParticlesVoxels(ParticleContainer)" << endl;
833 }
834
835 const std::string realmFrom = a_particlesFrom.getRealm();
836 const std::string realmTo = a_particlesTo.getRealm();
837
838 CH_assert(realmFrom == realmTo);
839
840 for (int lvl = 0; lvl <= m_finestLevel; lvl++) {
841 const DisjointBoxLayout& dbl = this->getGrids(realmFrom)[lvl];
842 const DataIterator& dit = dbl.dataIterator();
843 const EBISLayout& ebisl = this->getEBISLayout(realmFrom, a_phase)[lvl];
844 const Real dx = this->getDx()[lvl];
845
846 const int nbox = dit.size();
847#pragma omp parallel for schedule(runtime)
848 for (int mybox = 0; mybox < nbox; mybox++) {
849 const DataIndex& din = dit[mybox];
850 const EBISBox& ebisBox = ebisl[din];
851 const Box region = ebisBox.getRegion();
852
853 const bool isRegular = ebisBox.isAllRegular();
854 const bool isCovered = ebisBox.isAllCovered();
855 const bool isIrregular = !isRegular && !isCovered;
856
857 ParticleSoA<P, Traits>& from = a_particlesFrom[lvl][din];
858 ParticleSoA<P, Traits>& to = a_particlesTo[lvl][din];
859
860 if (isCovered) {
861 to.catenate(from);
862 }
863 else if (isIrregular) {
864 std::size_t i = 0;
865 while (i < from.size()) {
866 const RealVect pos = from.position(i);
867 const IntVect iv = ParticleOps::getParticleCellIndex(pos, m_probLo, dx);
868
869 CH_assert(region.contains(iv));
870
871 if (ebisBox.isCovered(iv)) {
872 to.appendParticle(from, i);
873 from.remove(i);
874 }
875 else {
876 i++;
877 }
878 }
879 }
880 }
881 }
882}
883
884template <auto... OldPosition, typename P, typename Traits>
885void
887 ParticleContainer<P, Traits>& a_activeParticles,
888 ParticleContainer<P, Traits>& a_ebParticles,
889 ParticleContainer<P, Traits>& a_domainParticles,
890 const phase::which_phase a_phase,
891 const Real a_tolerance,
892 const bool a_deleteParticles,
893 const std::function<void(ParticleSoA<P, Traits>&, std::size_t)>& a_nonDeletionModifier) const noexcept
894{
895 CH_TIME("AmrMesh::intersectParticlesRaycastIF(ParticleContainer)");
896 if (m_verbosity > 5) {
897 pout() << "AmrMesh::intersectParticlesRaycastIF(ParticleContainer)" << endl;
898 }
899
900 static_assert(sizeof...(OldPosition) == SpaceDim,
901 "AmrMesh::intersectParticlesRaycastIF(ParticleContainer) - need exactly SpaceDim oldPosition members");
902
903 CH_assert(a_activeParticles.getRealm() == a_ebParticles.getRealm());
904 CH_assert(a_activeParticles.getRealm() == a_domainParticles.getRealm());
905
906 a_ebParticles.clearParticles();
907 a_domainParticles.clearParticles();
908
909 const std::string whichRealm = a_activeParticles.getRealm();
910
911 // Figure out the implicit function
912 RefCountedPtr<BaseIF> implicitFunction;
913
914 switch (a_phase) {
915 case phase::gas: {
916 implicitFunction = m_baseif.at(phase::gas);
917
918 break;
919 }
920 case phase::solid: {
921 implicitFunction = m_baseif.at(phase::solid);
922
923 break;
924 }
925 default: {
926 MayDay::Error("AmrMesh::intersectParticlesRaycastIF(ParticleContainer) - logic bust");
927
928 break;
929 }
930 }
931
932 // A particle on or past a domain face lies in no grid cell, and a margin along the path does not keep it off the face
933 // once it is below the floating-point resolution of the position. The intersection point is therefore put a fixed
934 // fraction of a cell inside the domain.
935 constexpr Real safety = 1.E-6;
936
937 // Level loop -- go through each AMR level
938 for (int lvl = 0; lvl <= m_finestLevel; lvl++) {
939
940 // Handle to various grid stuff.
941 const DisjointBoxLayout& dbl = this->getGrids(whichRealm)[lvl];
942 const DataIterator& dit = dbl.dataIterator();
943
944 // The ray march converges on the surface geometrically and never reaches it, so the hit has to be declared
945 // within some distance of the surface rather than on it. That distance is a resolution and not a length, which
946 // is why the tolerance is taken relative to dx -- the same scaling McPhoto applies at its own call sites.
947 const Real tolerance = a_tolerance * m_dx[lvl];
948
949 const int nbox = dit.size();
950#pragma omp parallel for schedule(runtime)
951 for (int mybox = 0; mybox < nbox; mybox++) {
952 const DataIndex& din = dit[mybox];
953
954 ParticleSoA<P, Traits>& active = a_activeParticles[lvl][din];
955 ParticleSoA<P, Traits>& eb = a_ebParticles[lvl][din];
956 ParticleSoA<P, Traits>& domain = a_domainParticles[lvl][din];
957
958 // swap-and-pop transfer: do NOT advance i after a deletion (a new particle now sits in slot i).
959 std::size_t i = 0;
960 while (i < active.size()) {
961 const RealVect newPos = active.position(i);
962
963 // Assemble the previous position from the payload columns (left-to-right pack expansion).
964 RealVect oldPos;
965 int odir = 0;
966 ((oldPos[odir++] = active.template get<OldPosition>(i)), ...);
967
968 const RealVect path = newPos - oldPos;
969
970 // Cheap initial tests that allow us to skip some intersections tests.
971 bool checkEB = false;
972 bool checkDomain = false;
973
974 if (!implicitFunction.isNull()) {
975 checkEB = true;
976 }
977 for (int dir = 0; dir < SpaceDim; dir++) {
978 const bool outsideLo = newPos[dir] < m_probLo[dir];
979 const bool outsideHi = newPos[dir] > m_probHi[dir];
980
981 if (outsideLo || outsideHi) {
982 checkDomain = true;
983 }
984 }
985
986 // Do the intersection tests.
987 if (checkEB || checkDomain) {
988
989 // These are the solution
990 Real sDomain = std::numeric_limits<Real>::max();
991 Real sEB = std::numeric_limits<Real>::max();
992
993 bool contactDomain = false;
994 bool contactEB = false;
995
996 if (checkDomain) {
997 contactDomain = ParticleOps::domainIntersection(oldPos, newPos, m_probLo, m_probHi, sDomain);
998 }
999 if (checkEB) {
1000 contactEB = ParticleOps::ebIntersectionRaycast(implicitFunction, oldPos, newPos, tolerance, sEB);
1001 }
1002
1003 // Particle bumped into something. Move it onto the intersection point and transfer it to the EB/domain
1004 // container. When the original is kept we restore its end position after copying the intersection point.
1005 if (contactDomain || contactEB) {
1006 if (sEB <= sDomain) { // Crashed with EB "first".
1007 const RealVect intersectionPos = oldPos + sEB * path;
1008
1009 active.setPosition(i, intersectionPos);
1010 eb.appendParticle(active, i);
1011
1012 if (a_deleteParticles) {
1013 active.remove(i);
1014 }
1015 else {
1016 active.setPosition(i, newPos);
1017 a_nonDeletionModifier(active, i);
1018 i++;
1019 }
1020 }
1021 else { // Crashed with domain "first".
1022 RealVect intersectionPos = oldPos + sDomain * path;
1023
1024 for (int dir = 0; dir < SpaceDim; dir++) {
1025 intersectionPos[dir] = std::max(intersectionPos[dir], m_probLo[dir] + safety * m_dx[lvl]);
1026 intersectionPos[dir] = std::min(intersectionPos[dir], m_probHi[dir] - safety * m_dx[lvl]);
1027 }
1028
1029 active.setPosition(i, intersectionPos);
1030 domain.appendParticle(active, i);
1031
1032 if (a_deleteParticles) {
1033 active.remove(i);
1034 }
1035 else {
1036 active.setPosition(i, newPos);
1037 a_nonDeletionModifier(active, i);
1038 i++;
1039 }
1040 }
1041 }
1042 else {
1043 i++;
1044 }
1045 }
1046 else {
1047 i++;
1048 }
1049 }
1050 }
1051 }
1052
1053 // These need to be remapped.
1054 a_ebParticles.remap();
1055 a_domainParticles.remap();
1056}
1057
1058template <auto... OldPosition, typename P, typename Traits>
1059void
1061 ParticleContainer<P, Traits>& a_activeParticles,
1062 ParticleContainer<P, Traits>& a_ebParticles,
1063 ParticleContainer<P, Traits>& a_domainParticles,
1064 const phase::which_phase a_phase,
1065 const Real a_bisectionStep,
1066 const bool a_deleteParticles,
1067 const std::function<void(ParticleSoA<P, Traits>&, std::size_t)>& a_nonDeletionModifier) const noexcept
1068{
1069 CH_TIME("AmrMesh::intersectParticlesBisectIF(ParticleContainer)");
1070 if (m_verbosity > 5) {
1071 pout() << "AmrMesh::intersectParticlesBisectIF(ParticleContainer)" << endl;
1072 }
1073
1074 static_assert(sizeof...(OldPosition) == SpaceDim,
1075 "AmrMesh::intersectParticlesBisectIF(ParticleContainer) - need exactly SpaceDim oldPosition members");
1076
1077 CH_assert(a_activeParticles.getRealm() == a_ebParticles.getRealm());
1078 CH_assert(a_activeParticles.getRealm() == a_domainParticles.getRealm());
1079
1080 // TLDR: This is pretty much a hard-copy of intersectParticlesRaycastIF(ParticleContainer), with the exception
1081 // that the EB intersection test is replaced by a bisection test.
1082
1083 a_ebParticles.clearParticles();
1084 a_domainParticles.clearParticles();
1085
1086 const std::string whichRealm = a_activeParticles.getRealm();
1087
1088 // Figure out the implicit function
1089 RefCountedPtr<BaseIF> implicitFunction;
1090
1091 switch (a_phase) {
1092 case phase::gas: {
1093 implicitFunction = m_baseif.at(phase::gas);
1094
1095 break;
1096 }
1097 case phase::solid: {
1098 implicitFunction = m_baseif.at(phase::solid);
1099
1100 break;
1101 }
1102 default: {
1103 MayDay::Error("AmrMesh::intersectParticlesBisectIF(ParticleContainer) - logic bust");
1104
1105 break;
1106 }
1107 }
1108
1109 // A particle on or past a domain face lies in no grid cell, and a margin along the path does not keep it off the face
1110 // once it is below the floating-point resolution of the position. The intersection point is therefore put a fixed
1111 // fraction of a cell inside the domain.
1112 constexpr Real safety = 1.E-6;
1113
1114 // Level loop -- go through each AMR level
1115 for (int lvl = 0; lvl <= m_finestLevel; lvl++) {
1116
1117 // Handle to various grid stuff.
1118 const DisjointBoxLayout& dbl = this->getGrids(whichRealm)[lvl];
1119 const DataIterator& dit = dbl.dataIterator();
1120
1121 const int nbox = dit.size();
1122#pragma omp parallel for schedule(runtime)
1123 for (int mybox = 0; mybox < nbox; mybox++) {
1124 const DataIndex& din = dit[mybox];
1125
1126 ParticleSoA<P, Traits>& active = a_activeParticles[lvl][din];
1127 ParticleSoA<P, Traits>& eb = a_ebParticles[lvl][din];
1128 ParticleSoA<P, Traits>& domain = a_domainParticles[lvl][din];
1129
1130 // swap-and-pop transfer: do NOT advance i after a deletion (a new particle now sits in slot i).
1131 std::size_t i = 0;
1132 while (i < active.size()) {
1133 const RealVect newPos = active.position(i);
1134
1135 // Assemble the previous position from the payload columns (left-to-right pack expansion).
1136 RealVect oldPos;
1137 int odir = 0;
1138 ((oldPos[odir++] = active.template get<OldPosition>(i)), ...);
1139
1140 const RealVect path = newPos - oldPos;
1141
1142 // Cheap initial tests that allow us to skip some intersections tests.
1143 bool checkEB = false;
1144 bool checkDomain = false;
1145
1146 if (!implicitFunction.isNull()) {
1147 checkEB = true;
1148 }
1149 for (int dir = 0; dir < SpaceDim; dir++) {
1150 const bool outsideLo = newPos[dir] < m_probLo[dir];
1151 const bool outsideHi = newPos[dir] > m_probHi[dir];
1152
1153 if (outsideLo || outsideHi) {
1154 checkDomain = true;
1155 }
1156 }
1157
1158 // Do the intersection tests.
1159 if (checkEB || checkDomain) {
1160
1161 // These are the solution
1162 Real sDomain = std::numeric_limits<Real>::max();
1163 Real sEB = std::numeric_limits<Real>::max();
1164
1165 bool contactDomain = false;
1166 bool contactEB = false;
1167
1168 if (checkDomain) {
1169 contactDomain = ParticleOps::domainIntersection(oldPos, newPos, m_probLo, m_probHi, sDomain);
1170 }
1171 if (checkEB) {
1172 contactEB = ParticleOps::ebIntersectionBisect(implicitFunction, oldPos, newPos, a_bisectionStep, sEB);
1173 }
1174
1175 // Particle bumped into something. Move it onto the intersection point and transfer it to the EB/domain
1176 // container. When the original is kept we restore its end position after copying the intersection point.
1177 if (contactDomain || contactEB) {
1178 if (sEB <= sDomain) { // Crashed with EB "first".
1179 const RealVect intersectionPos = oldPos + sEB * path;
1180
1181 active.setPosition(i, intersectionPos);
1182 eb.appendParticle(active, i);
1183
1184 if (a_deleteParticles) {
1185 active.remove(i);
1186 }
1187 else {
1188 active.setPosition(i, newPos);
1189 a_nonDeletionModifier(active, i);
1190 i++;
1191 }
1192 }
1193 else { // Crashed with domain "first".
1194 RealVect intersectionPos = oldPos + sDomain * path;
1195
1196 for (int dir = 0; dir < SpaceDim; dir++) {
1197 intersectionPos[dir] = std::max(intersectionPos[dir], m_probLo[dir] + safety * m_dx[lvl]);
1198 intersectionPos[dir] = std::min(intersectionPos[dir], m_probHi[dir] - safety * m_dx[lvl]);
1199 }
1200
1201 active.setPosition(i, intersectionPos);
1202 domain.appendParticle(active, i);
1203
1204 if (a_deleteParticles) {
1205 active.remove(i);
1206 }
1207 else {
1208 active.setPosition(i, newPos);
1209 a_nonDeletionModifier(active, i);
1210 i++;
1211 }
1212 }
1213 }
1214 else {
1215 i++;
1216 }
1217 }
1218 else {
1219 i++;
1220 }
1221 }
1222 }
1223 }
1224
1225 // These need to be remapped.
1226 a_ebParticles.remap();
1227 a_domainParticles.remap();
1228}
1229
1230template <typename P, typename Traits>
1231void
1233 ParticleContainer<P, Traits>& a_srcParticles,
1234 const phase::which_phase a_phase) const noexcept
1235{
1236 CH_TIME("AmrMesh::transferIrregularParticles(ParticleContainer)");
1237 if (m_verbosity > 5) {
1238 pout() << "AmrMesh::transferIrregularParticles(ParticleContainer)" << endl;
1239 }
1240
1241 CH_assert(a_dstParticles.getRealm() == a_srcParticles.getRealm());
1242
1243 const std::string realm = a_dstParticles.getRealm();
1244
1245 for (int lvl = 0; lvl <= m_finestLevel; lvl++) {
1246 const DisjointBoxLayout& dbl = this->getGrids(realm)[lvl];
1247 const DataIterator& dit = dbl.dataIterator();
1248 const EBISLayout& ebisl = this->getEBISLayout(realm, a_phase)[lvl];
1249 const Real dx = m_dx[lvl];
1250
1251 const int nbox = dit.size();
1252#pragma omp parallel for schedule(runtime)
1253 for (int mybox = 0; mybox < nbox; mybox++) {
1254 const DataIndex& din = dit[mybox];
1255 const Box cellBox = dbl[din];
1256 const EBISBox& ebisbox = ebisl[din];
1257
1258 ParticleSoA<P, Traits>& dst = a_dstParticles[lvl][din];
1259 ParticleSoA<P, Traits>& src = a_srcParticles[lvl][din];
1260
1261 // swap-and-pop transfer: do NOT advance i after a transfer (a new particle now sits in slot i).
1262 std::size_t i = 0;
1263 while (i < src.size()) {
1264 const RealVect pos = src.position(i);
1265 const IntVect iv = ParticleOps::getParticleCellIndex(pos, m_probLo, dx);
1266
1267 bool moved = false;
1268
1269 if (cellBox.contains(iv) && ebisbox.isIrregular(iv)) {
1270 bool insideAnyVoF = false;
1271
1272 const Vector<VolIndex> allVoFs = ebisbox.getVoFs(iv);
1273 for (int k = 0; k < allVoFs.size(); k++) {
1274 const RealVect normal = ebisbox.normal(allVoFs[k]);
1275 const RealVect ebPos = m_probLo + Location::position(Location::Cell::Boundary, allVoFs[k], ebisbox, dx);
1276
1277 if ((pos - ebPos).dotProduct(normal) >= 0.0) {
1278 insideAnyVoF = true;
1279 }
1280 }
1281
1282 if (!insideAnyVoF) {
1283 const VolIndex& vof = allVoFs[0];
1284 const RealVect ebPos = m_probLo + Location::position(Location::Cell::Boundary, vof, ebisbox, dx);
1285
1286 src.setPosition(i, ebPos);
1287 dst.appendParticle(src, i);
1288 src.remove(i);
1289
1290 moved = true;
1291 }
1292 }
1293
1294 if (!moved) {
1295 i++;
1296 }
1297 }
1298 }
1299 }
1300}
1301
1302#include <CD_NamespaceFooter.H>
1303
1304#endif
Declaration of core class for handling AMR-related operations (with embedded boundaries).
CoarseFineDeposition
Coarse-fine deposition types (see CD_EBAMRParticleMesh for how these are handled).
Definition CD_CoarseFineDeposition.H:28
CopyStrategy
Enum for distinguishing how we copy data Valid => valid region ValidGhost => valid+ghost region.
Definition CD_CopyStrategy.H:24
DepositionType
Deposition types.
Definition CD_DepositionType.H:24
IrregularDeposition
How a deposition scheme treats the cut cells.
Definition CD_IrregularDeposition.H:36
Declaration of a static class containing some common useful particle routines that would otherwise be...
void depositGathered(EBAMRCellData &a_meshData, const std::string &a_realm, const phase::which_phase &a_phase, const ParticleContainer< P, Traits > &a_particles, const DepositionType a_depositionType, const CoarseFineDeposition a_coarseFineDeposition, const IrregularDeposition a_irregularDeposition, CellGather a_cellGather)
Deposit a custom per-particle scalar (a_cellGather) of an SoA container on the mesh.
Definition CD_AmrMeshImplem.H:392
void allocatePointer(Vector< RefCountedPtr< T > > &a_data) const
Allocate pointer but not any memory blocks.
Definition CD_AmrMeshImplem.H:269
EBAMRSurfaceDeposition & getSurfaceDeposition(const std::string &a_realm, const phase::which_phase a_phase) const
Get EBAMRSurfaceDeposition surface deposition operator.
Definition CD_AmrMesh.cpp:3969
void transferCoveredParticlesIF(ParticleContainer< P, Traits > &a_particlesFrom, ParticleContainer< P, Traits > &a_particlesTo, const phase::which_phase &a_phase, const Real a_tolerance) const
Transfer SoA particles inside the EB (implicit-function test) from one container to another: f(x) > a...
Definition CD_AmrMeshImplem.H:674
void allocate(ParticleContainer< P, Traits > &a_container, const std::string &a_realm) const
Allocate a struct-of-arrays particle container on the given realm.
Definition CD_AmrMeshImplem.H:242
const Vector< RefCountedPtr< LevelTiles > > & getLevelTiles(const std::string &a_realm) const
Get the tiled space representation.
Definition CD_AmrMesh.cpp:3561
void depositWeight(EBAMRCellData &a_meshData, const std::string &a_realm, const phase::which_phase &a_phase, const ParticleContainer< P, Traits > &a_particles, const DepositionType a_depositionType, const CoarseFineDeposition a_coarseFineDeposition, const IrregularDeposition a_irregularDeposition)
Deposit the SoA container's weight column on the mesh (all coarse-fine strategies).
Definition CD_AmrMeshImplem.H:372
void copyData(EBAMRData< T > &a_dst, const EBAMRData< T > &a_src, const CopyStrategy &a_toRegion=CopyStrategy::Valid, const CopyStrategy &a_fromRegion=CopyStrategy::Valid) const noexcept
Method for copying from a source container to a destination container. User supplies information abou...
Definition CD_AmrMeshImplem.H:23
RealVect m_probHi
Domain simulation corner.
Definition CD_AmrMesh.H:2403
const AMRMask & getValidCells(const std::string &a_realm) const
Get a map of all valid cells on a specified realm.
Definition CD_AmrMesh.cpp:3545
void interpolateWeight(ParticleContainer< P, Traits > &a_particles, const std::string &a_realm, const phase::which_phase &a_phase, const EBAMRCellData &a_meshScalarField, const DepositionType a_interpType, const bool a_forceIrregNGP) const
Interpolate a mesh scalar field onto the SoA container's weight column.
Definition CD_AmrMeshImplem.H:442
RealVect m_probLo
Domain simulation corner.
Definition CD_AmrMesh.H:2398
void intersectParticlesBisectIF(ParticleContainer< P, Traits > &a_activeParticles, ParticleContainer< P, Traits > &a_ebParticles, ParticleContainer< P, Traits > &a_domainParticles, const phase::which_phase a_phase, const Real a_bisectionStep, const bool a_deleteParticles, const std::function< void(ParticleSoA< P, Traits > &, std::size_t)> &a_nonDeletionModifier) const noexcept
SoA bisection-based particle intersection algorithm.
Definition CD_AmrMeshImplem.H:1060
const Vector< DisjointBoxLayout > & getGrids(const std::string &a_realm) const
Get the grids.
Definition CD_AmrMesh.cpp:3393
int m_verbosity
Verbosity.
Definition CD_AmrMesh.H:2413
int m_minBlockSize
Blocking factor.
Definition CD_AmrMesh.H:2453
std::map< std::pair< std::string, std::string >, Vector< Copier > > m_validToValidRealmCopiers
Map for copying between various Realms. First index is the "from" realm and second index is the "to" ...
Definition CD_AmrMesh.H:2340
std::map< std::pair< std::string, std::string >, Vector< Copier > > m_validGhostToValidRealmCopiers
Map for copying between various Realms. First index is the "from" realm and second index is the "to" ...
Definition CD_AmrMesh.H:2352
int m_numGhostCells
Number of ghost cells.
Definition CD_AmrMesh.H:2473
std::map< std::pair< std::string, std::string >, Vector< Copier > > m_validGhostToValidGhostRealmCopiers
Map for copying between various Realms. First index is the "from" realm and second index is the "to" ...
Definition CD_AmrMesh.H:2358
void transferCoveredParticlesDiscrete(ParticleContainer< P, Traits > &a_particlesFrom, ParticleContainer< P, Traits > &a_particlesTo, const phase::which_phase &a_phase, const Real a_tolerance) const
Transfer SoA particles inside the EB using discrete (EBISBox) information from one container to anoth...
Definition CD_AmrMeshImplem.H:739
void removeCoveredParticlesVoxels(ParticleContainer< P, Traits > &a_particles, const phase::which_phase &a_phase) const
Remove SoA particles that live in covered cells (voxel test).
Definition CD_AmrMeshImplem.H:619
Vector< Real > m_dx
Level resolutions.
Definition CD_AmrMesh.H:2569
void transferIrregularParticles(ParticleContainer< P, Traits > &a_dstParticles, ParticleContainer< P, Traits > &a_srcParticles, const phase::which_phase a_phase) const noexcept
Transfer SoA particles that are on the covered side of the EB to a different container.
Definition CD_AmrMeshImplem.H:1232
int m_finestLevel
Finest level.
Definition CD_AmrMesh.H:2418
void removeCoveredParticlesIF(ParticleContainer< P, Traits > &a_particles, const phase::which_phase &a_phase, const Real a_tolerance) const
Remove SoA particles that fall inside the EB (implicit-function test): f(x) > a_tolerance*dx.
Definition CD_AmrMeshImplem.H:480
std::map< phase::which_phase, RefCountedPtr< BaseIF > > m_baseif
Implicit functions.
Definition CD_AmrMesh.H:2317
bool queryRealm(const std::string &a_realm) const
Query if a realm exists.
Definition CD_AmrMesh.cpp:4184
void intersectParticlesRaycastIF(ParticleContainer< P, Traits > &a_activeParticles, ParticleContainer< P, Traits > &a_ebParticles, ParticleContainer< P, Traits > &a_domainParticles, const phase::which_phase a_phase, const Real a_tolerance, const bool a_deleteParticles, const std::function< void(ParticleSoA< P, Traits > &, std::size_t)> &a_nonDeletionModifier) const noexcept
SoA ray-casting particle intersection algorithm.
Definition CD_AmrMeshImplem.H:886
std::map< std::pair< std::string, std::string >, Vector< Copier > > m_validToValidGhostRealmCopiers
Map for copying between various Realms. First index is the "from" realm and second index is the "to" ...
Definition CD_AmrMesh.H:2346
const Vector< Real > & getDx() const
Get spatial resolutions.
Definition CD_AmrMesh.cpp:3337
EBAMRParticleMesh & getParticleMesh(const std::string &a_realm, const phase::which_phase a_phase) const
Get EBAMRParticleMesh operator.
Definition CD_AmrMesh.cpp:3952
const Vector< EBISLayout > & getEBISLayout(const std::string &a_realm, const phase::which_phase a_phase) const
Get EBISLayouts for a Realm and phase.
Definition CD_AmrMesh.cpp:3409
std::map< std::string, RefCountedPtr< Realm > > m_realms
These are all the Realms.
Definition CD_AmrMesh.H:2312
void interpolateParticles(ParticleContainer< P, Traits > &a_particles, const std::string &a_realm, const phase::which_phase &a_phase, const EBAMRCellData &a_meshField, const DepositionType a_interpType, const bool a_forceIrregNGP) const
Interpolate a mesh field onto one or more SoA payload columns.
Definition CD_AmrMeshImplem.H:461
void depositParticles(EBAMRIVData &a_meshData, const std::string &a_realm, const phase::which_phase &a_phase, const ParticleContainer< P, Traits > &a_particles) const noexcept
Deposit the weight column of an SoA particle container onto the surface (EB).
Definition CD_AmrMeshImplem.H:352
void remapToNewGrids(ParticleContainer< P, Traits > &a_particles, const int a_lmin, const int a_newFinestLevel) const noexcept
Regrid a struct-of-arrays particle container to new grids.
Definition CD_AmrMeshImplem.H:328
void alias(Vector< T * > &a_alias, const Vector< RefCountedPtr< T > > &a_data) const
Turn smart-pointer data structure into regular-pointer data structure.
Definition CD_AmrMeshImplem.H:214
void deallocate(Vector< T * > &a_data) const
Deallocate data.
Definition CD_AmrMeshImplem.H:166
void transferCoveredParticlesVoxels(ParticleContainer< P, Traits > &a_particlesFrom, ParticleContainer< P, Traits > &a_particlesTo, const phase::which_phase &a_phase) const
Transfer SoA particles that live in covered cells (voxel test) from one container to another.
Definition CD_AmrMeshImplem.H:826
const Vector< int > & getRefinementRatios() const
Get refinement ratios.
Definition CD_AmrMesh.cpp:3348
void removeCoveredParticlesDiscrete(ParticleContainer< P, Traits > &a_particles, const phase::which_phase &a_phase, const Real a_tolerance) const
Remove SoA particles inside the EB using discrete (EBISBox) information: covered cells,...
Definition CD_AmrMeshImplem.H:539
const Vector< ProblemDomain > & getDomains() const
Get domains.
Definition CD_AmrMesh.cpp:3371
Default class for holding LevelData<T> data across an EBAMR realm.
Definition CD_EBAMRData.H:41
Vector< RefCountedPtr< LevelData< T > > > & getData() noexcept
Get underlying data. Returns m_data.
Definition CD_EBAMRDataImplem.H:154
void setRealm(const std::string &a_realm) noexcept
Sets the realm for this object.
Definition CD_EBAMRDataImplem.H:182
AMR driver that deposits/interpolates ParticleContainer particles across the hierarchy.
Definition CD_EBAMRParticleMesh.H:95
void interpolateWeight(ParticleContainer< P, Traits > &a_particles, const EBAMRCellData &a_meshData, const DepositionType a_interpType, const bool a_forceIrregNGP) const
Interpolate a mesh field onto the container-owned weight column, across all levels.
Definition CD_EBAMRParticleMesh.H:225
void depositWeight(EBAMRCellData &a_meshData, const ParticleContainer< P, Traits > &a_particles, const DepositionType a_depositionType, const CoarseFineDeposition a_coarseFineDeposition, const IrregularDeposition a_irregularDeposition)
Deposit the container-owned weight onto the AMR mesh.
Definition CD_EBAMRParticleMesh.H:272
void depositGathered(EBAMRCellData &a_meshData, const ParticleContainer< P, Traits > &a_particles, const DepositionType a_depositionType, const CoarseFineDeposition a_coarseFineDeposition, const IrregularDeposition a_irregularDeposition, CellGather a_cellGather)
Deposit a custom per-particle scalar (computed by a_cellGather) onto the AMR mesh.
Definition CD_EBAMRParticleMesh.H:342
class for handling surface deposition of particles with EB and AMR.
Definition CD_EBAMRSurfaceDeposition.H:30
void deposit(EBAMRIVData &a_meshData, const ParticleContainer< P, Traits > &a_particles) const noexcept
Deposit the container-owned weight column of an SoA particle container onto the surface.
Definition CD_EBAMRSurfaceDepositionImplem.H:32
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:447
void define(const Vector< DisjointBoxLayout > &a_grids, const Vector< ProblemDomain > &a_domains, const Vector< Real > &a_dx, const Vector< int > &a_refRat, const RealVect &a_probLo, const int a_minBlockSize, const Vector< RefCountedPtr< LevelTiles > > &a_levelTiles, const int a_finestLevel, const std::string &a_realm, const Vector< RefCountedPtr< LevelData< BaseFab< bool > > > > *a_validCells)
Allocate the per-level holders and the per-level tile-ownership maps over the AMR grids.
Definition CD_ParticleContainer.H:194
std::string getRealm() const
Realm label.
Definition CD_ParticleContainer.H:305
void remap()
Redistribute every valid particle to the patch/level/rank that owns its cell.
Definition CD_ParticleContainerImplem.H:502
static bool ebIntersectionRaycast(const RefCountedPtr< BaseIF > &a_impFunc, const RealVect &a_oldPos, const RealVect &a_newPos, const Real &a_tolerance, Real &a_s)
Compute the intersection point between a particle path and an implicit function using a ray-casting a...
Definition CD_ParticleOpsImplem.H:224
static bool ebIntersectionBisect(const RefCountedPtr< BaseIF > &a_impFunc, const RealVect &a_oldPos, const RealVect &a_newPos, const Real &a_bisectStep, Real &a_s)
Compute the intersection point between a particle path and an implicit function using a bisection alg...
Definition CD_ParticleOpsImplem.H:175
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
static bool domainIntersection(const RealVect &a_oldPos, const RealVect &a_newPos, const RealVect &a_probLo, const RealVect &a_probHi, Real &a_s)
Compute the intersection point between a particle path and a domain side.
Definition CD_ParticleOpsImplem.H:126
Arena-backed Struct-of-Arrays particle container for a single grid patch.
Definition CD_ParticleSoA.H:655
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
std::size_t size() const noexcept
Number of particles currently stored.
Definition CD_ParticleSoA.H:882
void setPosition(const std::size_t a_index, const RealVect &a_position) noexcept
Set the position of particle i.
Definition CD_ParticleSoA.H:1213
void catenate(ParticleSoA &a_other)
Move every particle of another container into this one, leaving a_other empty (catenate).
Definition CD_ParticleSoA.H:1009
void remove(const std::size_t a_index) noexcept
Remove particle i using swap-and-pop (O(1), does NOT preserve order).
Definition CD_ParticleSoA.H:1040
void clear() noexcept
Drop all particles (keeps the arena; invalidates the cell sort unless there was nothing to drop).
Definition CD_ParticleSoA.H:915
void appendParticle(const ParticleSoA &a_src, const std::size_t a_index)
Append a single particle (all columns, incl. id/rank) copied from another container.
Definition CD_ParticleSoAImplem.H:172
RealVect position(Location::Cell a_location, const VolIndex &a_vof, const EBISBox &a_ebisbox, const Real &a_dx)
Compute the position (ignoring the "origin) of a Vof.
Definition CD_LocationImplem.H:21
which_phase
Enumeration of supported phases.
Definition CD_MultiFluidIndexSpace.H:38
@ solid
Solid (dielectric) phase.
Definition CD_MultiFluidIndexSpace.H:40
@ gas
Gas phase.
Definition CD_MultiFluidIndexSpace.H:39