13#ifndef CD_AMRMESHIMPLEM_H
14#define CD_AMRMESHIMPLEM_H
19#include <CD_NamespaceHeader.H>
28 CH_TIME(
"AmrMesh::copyData(EBAMRData, simple)");
29 if (m_verbosity > 5) {
30 pout() <<
"AmrMesh::copyData(EBAMRData, simple)" << endl;
33 const int nComp = a_dst[0]->nComp();
34 const Interval dstComps = Interval(0, nComp - 1);
35 const Interval srcComps = Interval(0, nComp - 1);
37 const std::string toRealm = a_dst.getRealm();
38 const std::string fromRealm = a_src.getRealm();
40 for (
int lvl = 0; lvl <= m_finestLevel; lvl++) {
41 CH_assert(!(a_dst[lvl].isNull()));
42 CH_assert(!(a_src[lvl].isNull()));
44 this->copyData(*a_dst[lvl], *a_src[lvl], lvl, toRealm, fromRealm, dstComps, srcComps, a_toRegion, a_fromRegion);
52 const Interval& a_dstComps,
53 const Interval& a_srcComps,
57 CH_TIME(
"AmrMesh::copyData(EBAMRData, full)");
58 if (m_verbosity > 5) {
59 pout() <<
"AmrMesh::copyData(EBAMRData, full)" << endl;
62 const std::string toRealm = a_dst.getRealm();
63 const std::string fromRealm = a_src.getRealm();
65 for (
int lvl = 0; lvl <= m_finestLevel; lvl++) {
66 CH_assert(!(a_dst[lvl].isNull()));
67 CH_assert(!(a_src[lvl].isNull()));
69 this->copyData(*a_dst[lvl], *a_src[lvl], lvl, toRealm, fromRealm, a_dstComps, a_srcComps, a_toRegion, a_fromRegion);
76 const LevelData<T>& a_src,
78 const std::string a_toRealm,
79 const std::string a_fromRealm,
83 CH_TIME(
"AmrMesh::copyData(LD<T>_full)");
84 if (m_verbosity > 5) {
85 pout() <<
"AmrMesh::copyData(LD<T>_full)" << endl;
88 const Interval dstComps = Interval(0, a_dst.nComp() - 1);
89 const Interval srcComps = Interval(0, a_src.nComp() - 1);
91 this->copyData(a_dst, a_src, a_level, a_toRealm, a_fromRealm, dstComps, srcComps, a_toRegion, a_fromRegion);
97 const LevelData<T>& a_src,
99 const std::string a_toRealm,
100 const std::string a_fromRealm,
101 const Interval& a_dstComps,
102 const Interval& a_srcComps,
106 CH_TIME(
"AmrMesh::copyData(LD<T>_full)");
107 if (m_verbosity > 5) {
108 pout() <<
"AmrMesh::copyData(LD<T>_full)" << endl;
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());
115 if (a_toRealm != a_fromRealm) {
116 const auto id = std::make_pair(a_fromRealm, a_toRealm);
118 if (a_toRegion == CopyStrategy::ValidGhost) {
119 CH_assert(a_dst.ghostVect() == m_numGhostCells * IntVect::Unit);
121 if (a_fromRegion == CopyStrategy::ValidGhost) {
122 CH_assert(a_src.ghostVect() == m_numGhostCells * IntVect::Unit);
128 const Copier* copier =
nullptr;
130 if (a_fromRegion == CopyStrategy::Valid) {
131 if (a_toRegion == CopyStrategy::Valid) {
132 copier = &m_validToValidRealmCopiers.at(
id)[a_level];
134 else if (a_toRegion == CopyStrategy::ValidGhost) {
135 copier = &m_validToValidGhostRealmCopiers.at(
id)[a_level];
138 MayDay::Abort(
"AmrMesh::copyData - logic bust 1");
141 else if (a_fromRegion == CopyStrategy::ValidGhost) {
142 if (a_toRegion == CopyStrategy::Valid) {
143 copier = &m_validGhostToValidRealmCopiers.at(
id)[a_level];
145 else if (a_toRegion == CopyStrategy::ValidGhost) {
146 copier = &m_validGhostToValidGhostRealmCopiers.at(
id)[a_level];
149 MayDay::Abort(
"AmrMesh::copyData - logic bust 2");
153 MayDay::Abort(
"AmrMesh::copyData - logic bust 3");
156 a_src.copyTo(a_srcComps, a_dst, a_dstComps, *copier);
159 a_src.localCopyTo(a_srcComps, a_dst, a_dstComps);
167 CH_TIME(
"AmrMesh::deallocate(Vector<T*>)");
169 pout() <<
"AmrMesh::deallocate(Vector<T*>)" << endl;
181 CH_TIME(
"AmrMesh::deallocate(Vector<RefCountedPtr<T>)");
183 pout() <<
"AmrMesh::deallocate(Vector<RefCountedPtr<T>)" << endl;
186 for (
int lvl = 0; lvl < a_data.size(); lvl++) {
188 a_data[lvl] = RefCountedPtr<T>(0);
190 if(!a_data[lvl].isNull()){
191 delete &(*a_data[lvl]);
192 a_data[lvl] = RefCountedPtr<T> (NULL);
203 CH_TIME(
"AmrMesh::deallocate(EBAMRData<T>)");
205 pout() <<
"AmrMesh::deallocate(EBAMRData<T>)" << endl;
215 CH_TIME(
"AmrMesh::alias(Vector<T*>, Vector<RefCountedPtr<T>)");
217 pout() <<
"AmrMesh::alias(Vector<T*>, Vector<RefCountedPtr<T>)" << endl;
220 a_alias.resize(a_data.size());
222 for (
int lvl = 0; lvl < a_data.size(); lvl++) {
223 a_alias[lvl] = &(*a_data[lvl]);
227template <
typename T,
typename S>
231 CH_TIME(
"AmrMesh::alias(Vector<T*>, EBAMRData<S>)");
233 pout() <<
"AmrMesh::alias(Vector<T*>, EBAMRData<S>" << endl;
239template <
typename P,
typename Traits>
243 CH_TIME(
"AmrMesh::allocate(ParticleContainer<P, Traits>, string)");
245 pout() <<
"AmrMesh::allocate(ParticleContainer<P, Traits>, string)" << endl;
249 const std::string str =
"AmrMesh::allocate(ParticleContainer<P, Traits>, string) - could not find Realm '" +
251 MayDay::Abort(str.c_str());
270 CH_TIME(
"AmrMesh::allocatePointer(Vector<RefCountedPtr<T> >)");
272 pout() <<
"AmrMesh::allocatePointer(Vector<RefCountedPtr<T> >)" << endl;
277 a_data[lvl] = RefCountedPtr<T>(
new T());
285 CH_TIME(
"AmrMesh::allocatePointer(Vector<RefCountedPtr<T> >, int)");
287 pout() <<
"AmrMesh::allocatePointer(Vector<RefCountedPtr<T> >, int)" << endl;
290 a_data.resize(1 + a_finestLevel);
292 for (
int lvl = 0; lvl <= a_finestLevel; lvl++) {
293 a_data[lvl] = RefCountedPtr<T>(
new T());
301 CH_TIME(
"AmrMesh::allocatePointer(EBAMRData<T>, std::string)");
303 pout() <<
"AmrMesh::allocatePointer(EBAMRData<T>, std::string)" << endl;
315 CH_TIME(
"AmrMesh::allocatePointer(EBAMRData<T>, std::string, int)");
317 pout() <<
"AmrMesh::allocatePointer(EBAMRData<T>, std::string, int)" << endl;
325template <
typename P,
typename Traits>
329 const int a_newFinestLevel)
const noexcept
331 CH_TIME(
"AmrMesh::remapToNewGrids(ParticleContainer)");
332 if (m_verbosity > 5) {
333 pout() <<
"AmrMesh::remapToNewGrids(ParticleContainer)" << endl;
338 const std::string realm = a_particles.getRealm();
340 a_particles.regrid(this->getGrids(realm),
343 this->getRefinementRatios(),
345 m_realms[realm]->getLevelTiles(),
349template <
typename P,
typename Traits>
352 const std::string& a_realm,
356 CH_TIME(
"AmrMesh::depositParticles(surface, SoA)");
357 if (m_verbosity > 5) {
358 pout() <<
"AmrMesh::depositParticles(surface, SoA)" << endl;
361 CH_assert(a_meshData[0]->nComp() == 1);
362 CH_assert(a_meshData.getRealm() == a_particles.getRealm());
366 surfaceDeposition.
deposit<P, Traits>(a_meshData, a_particles);
369template <
typename P,
typename Traits>
372 const std::string& a_realm,
379 CH_TIME(
"AmrMesh::depositWeight(ParticleContainer)");
381 pout() <<
"AmrMesh::depositWeight(ParticleContainer)" << endl;
386 particleMesh.
depositWeight(a_meshData, a_particles, a_depositionType, a_coarseFineDeposition, a_irregularDeposition);
389template <
typename P,
typename Traits,
typename CellGather>
392 const std::string& a_realm,
398 CellGather a_cellGather)
400 CH_TIME(
"AmrMesh::depositGathered(ParticleContainer)");
402 pout() <<
"AmrMesh::depositGathered(ParticleContainer)" << endl;
410 a_coarseFineDeposition,
411 a_irregularDeposition,
415template <
auto... Members,
typename P,
typename Traits>
418 const std::string& a_realm,
425 CH_TIME(
"AmrMesh::depositParticles(ParticleContainer)");
427 pout() <<
"AmrMesh::depositParticles(ParticleContainer)" << endl;
432 particleMesh.template deposit<Members...>(a_meshData,
435 a_coarseFineDeposition,
436 a_irregularDeposition);
439template <
typename P,
typename Traits>
442 const std::string& a_realm,
444 const EBAMRCellData& a_meshScalarField,
446 const bool a_forceIrregNGP)
const
448 CH_TIME(
"AmrMesh::interpolateWeight(ParticleContainer)");
450 pout() <<
"AmrMesh::interpolateWeight(ParticleContainer)" << endl;
455 particleMesh.
interpolateWeight(a_particles, a_meshScalarField, a_interpType, a_forceIrregNGP);
458template <
auto... Members,
typename P,
typename Traits>
461 const std::string& a_realm,
463 const EBAMRCellData& a_meshField,
465 const bool a_forceIrregNGP)
const
467 CH_TIME(
"AmrMesh::interpolateParticles(ParticleContainer)");
469 pout() <<
"AmrMesh::interpolateParticles(ParticleContainer)" << endl;
474 particleMesh.template interpolate<Members...>(a_particles, a_meshField, a_interpType, a_forceIrregNGP);
477template <
typename P,
typename Traits>
481 const Real a_tolerance)
const
483 CH_TIME(
"AmrMesh::removeCoveredParticlesIF(ParticleContainer)");
485 pout() <<
"AmrMesh::removeCoveredParticlesIF(ParticleContainer)" << endl;
489 RefCountedPtr<BaseIF> implicitFunction;
503 MayDay::Error(
"AmrMesh::removeCoveredParticlesIF(ParticleContainer) - logic bust");
507 const std::string whichRealm = a_particles.
getRealm();
510 const DisjointBoxLayout& dbl = this->
getGrids(whichRealm)[lvl];
511 const DataIterator& dit = dbl.dataIterator();
512 const Real dx = this->
getDx()[lvl];
513 const Real tol = a_tolerance * dx;
515 const int nbox = dit.size();
516#pragma omp parallel for schedule(runtime)
517 for (
int mybox = 0; mybox < nbox; mybox++) {
518 const DataIndex& din = dit[mybox];
524 while (i < leaf.
size()) {
525 if (implicitFunction->value(leaf.
position(i)) > tol) {
536template <
typename P,
typename Traits>
540 const Real a_tolerance)
const
542 CH_TIME(
"AmrMesh::removeCoveredParticlesDiscrete(ParticleContainer)");
544 pout() <<
"AmrMesh::removeCoveredParticlesDiscrete(ParticleContainer)" << endl;
547 const std::string whichRealm = a_particles.
getRealm();
550 const DisjointBoxLayout& dbl = this->
getGrids(whichRealm)[lvl];
551 const DataIterator& dit = dbl.dataIterator();
552 const EBISLayout& ebisl = this->
getEBISLayout(whichRealm, a_phase)[lvl];
553 const Real dx = this->
getDx()[lvl];
554 const Real tol = a_tolerance * dx;
556 const int nbox = dit.size();
557#pragma omp parallel for schedule(runtime)
558 for (
int mybox = 0; mybox < nbox; mybox++) {
559 const DataIndex& din = dit[mybox];
560 const EBISBox& ebisBox = ebisl[din];
561 const Box region = ebisBox.getRegion();
563 const bool isRegular = ebisBox.isAllRegular();
564 const bool isCovered = ebisBox.isAllCovered();
565 const bool isIrregular = !isRegular && !isCovered;
572 else if (isIrregular) {
575 while (i < leaf.
size()) {
576 const RealVect pos = leaf.
position(i);
579 CH_assert(region.contains(iv));
581 if (ebisBox.isCovered(iv)) {
584 else if (ebisBox.isIrregular(iv)) {
586 bool insideAtLeastOneVoF =
false;
588 const std::vector<VolIndex> vofs = ebisBox.getVoFs(iv).stdVector();
589 for (
const auto& vof : vofs) {
590 const RealVect ebNormal = ebisBox.normal(vof);
592 const Real faceProjection = ebNormal.dotProduct(pos - ebCentroid);
594 if (faceProjection >= -tol) {
595 insideAtLeastOneVoF =
true;
600 if (!insideAtLeastOneVoF) {
616template <
typename P,
typename Traits>
621 CH_TIME(
"AmrMesh::removeCoveredParticlesVoxels(ParticleContainer)");
623 pout() <<
"AmrMesh::removeCoveredParticlesVoxels(ParticleContainer)" << endl;
626 const std::string whichRealm = a_particles.
getRealm();
629 const DisjointBoxLayout& dbl = this->
getGrids(whichRealm)[lvl];
630 const DataIterator& dit = dbl.dataIterator();
631 const EBISLayout& ebisl = this->
getEBISLayout(whichRealm, a_phase)[lvl];
632 const Real dx = this->
getDx()[lvl];
634 const int nbox = dit.size();
635#pragma omp parallel for schedule(runtime)
636 for (
int mybox = 0; mybox < nbox; mybox++) {
637 const DataIndex& din = dit[mybox];
638 const EBISBox& ebisBox = ebisl[din];
639 const Box region = ebisBox.getRegion();
641 const bool isRegular = ebisBox.isAllRegular();
642 const bool isCovered = ebisBox.isAllCovered();
643 const bool isIrregular = !isRegular && !isCovered;
650 else if (isIrregular) {
652 while (i < leaf.
size()) {
653 const RealVect pos = leaf.
position(i);
654 const RealVect rv = (pos -
m_probLo) / dx;
655 const IntVect iv = IntVect(D_DECL(floor(rv[0]), floor(rv[1]), floor(rv[2])));
657 CH_assert(region.contains(iv));
659 if (ebisBox.isCovered(iv)) {
671template <
typename P,
typename Traits>
676 const Real a_tolerance)
const
678 CH_TIME(
"AmrMesh::transferCoveredParticlesIF(ParticleContainer)");
680 pout() <<
"AmrMesh::transferCoveredParticlesIF(ParticleContainer)" << endl;
684 RefCountedPtr<BaseIF> implicitFunction;
698 MayDay::Error(
"AmrMesh::transferCoveredParticlesIF(ParticleContainer) - logic bust");
702 const std::string realmFrom = a_particlesFrom.
getRealm();
703 const std::string realmTo = a_particlesTo.
getRealm();
705 CH_assert(realmFrom == realmTo);
708 const DisjointBoxLayout& dbl = this->
getGrids(realmFrom)[lvl];
709 const DataIterator& dit = dbl.dataIterator();
710 const Real dx = this->
getDx()[lvl];
711 const Real tol = a_tolerance * dx;
713 const int nbox = dit.size();
714#pragma omp parallel for schedule(runtime)
715 for (
int mybox = 0; mybox < nbox; mybox++) {
716 const DataIndex& din = dit[mybox];
723 while (i < from.
size()) {
724 if (implicitFunction->value(from.
position(i)) > tol) {
736template <
typename P,
typename Traits>
741 const Real a_tolerance)
const
743 CH_TIME(
"AmrMesh::transferCoveredParticlesDiscrete(ParticleContainer)");
745 pout() <<
"AmrMesh::transferCoveredParticlesDiscrete(ParticleContainer)" << endl;
748 const std::string realmFrom = a_particlesFrom.
getRealm();
749 const std::string realmTo = a_particlesTo.
getRealm();
751 CH_assert(realmFrom == realmTo);
754 const DisjointBoxLayout& dbl = this->
getGrids(realmFrom)[lvl];
755 const DataIterator& dit = dbl.dataIterator();
756 const EBISLayout& ebisl = this->
getEBISLayout(realmFrom, a_phase)[lvl];
757 const Real dx = this->
getDx()[lvl];
758 const Real tol = a_tolerance * dx;
760 const int nbox = dit.size();
761#pragma omp parallel for schedule(runtime)
762 for (
int mybox = 0; mybox < nbox; mybox++) {
763 const DataIndex& din = dit[mybox];
764 const EBISBox& ebisBox = ebisl[din];
765 const Box region = ebisBox.getRegion();
767 const bool isRegular = ebisBox.isAllRegular();
768 const bool isCovered = ebisBox.isAllCovered();
769 const bool isIrregular = !isRegular && !isCovered;
777 else if (isIrregular) {
780 while (i < from.
size()) {
781 const RealVect pos = from.
position(i);
784 CH_assert(region.contains(iv));
786 if (ebisBox.isCovered(iv)) {
790 else if (ebisBox.isIrregular(iv)) {
792 bool insideAtLeastOneVoF =
false;
794 const std::vector<VolIndex> vofs = ebisBox.getVoFs(iv).stdVector();
795 for (
const auto& vof : vofs) {
797 const RealVect ebNormal = ebisBox.normal(vof);
798 const Real faceProjection = ebNormal.dotProduct(pos - ebCentroid);
800 if (faceProjection >= -tol) {
801 insideAtLeastOneVoF =
true;
806 if (!insideAtLeastOneVoF) {
823template <
typename P,
typename Traits>
829 CH_TIME(
"AmrMesh::transferCoveredParticlesVoxels(ParticleContainer)");
831 pout() <<
"AmrMesh::transferCoveredParticlesVoxels(ParticleContainer)" << endl;
834 const std::string realmFrom = a_particlesFrom.
getRealm();
835 const std::string realmTo = a_particlesTo.
getRealm();
837 CH_assert(realmFrom == realmTo);
840 const DisjointBoxLayout& dbl = this->
getGrids(realmFrom)[lvl];
841 const DataIterator& dit = dbl.dataIterator();
842 const EBISLayout& ebisl = this->
getEBISLayout(realmFrom, a_phase)[lvl];
843 const Real dx = this->
getDx()[lvl];
845 const int nbox = dit.size();
846#pragma omp parallel for schedule(runtime)
847 for (
int mybox = 0; mybox < nbox; mybox++) {
848 const DataIndex& din = dit[mybox];
849 const EBISBox& ebisBox = ebisl[din];
850 const Box region = ebisBox.getRegion();
852 const bool isRegular = ebisBox.isAllRegular();
853 const bool isCovered = ebisBox.isAllCovered();
854 const bool isIrregular = !isRegular && !isCovered;
862 else if (isIrregular) {
864 while (i < from.
size()) {
865 const RealVect pos = from.
position(i);
868 CH_assert(region.contains(iv));
870 if (ebisBox.isCovered(iv)) {
883template <
auto... OldPosition,
typename P,
typename Traits>
890 const Real a_tolerance,
891 const bool a_deleteParticles,
894 CH_TIME(
"AmrMesh::intersectParticlesRaycastIF(ParticleContainer)");
895 if (m_verbosity > 5) {
896 pout() <<
"AmrMesh::intersectParticlesRaycastIF(ParticleContainer)" << endl;
899 static_assert(
sizeof...(OldPosition) == SpaceDim,
900 "AmrMesh::intersectParticlesRaycastIF(ParticleContainer) - need exactly SpaceDim oldPosition members");
908 const std::string whichRealm = a_activeParticles.
getRealm();
911 RefCountedPtr<BaseIF> implicitFunction;
925 MayDay::Error(
"AmrMesh::intersectParticlesRaycastIF(ParticleContainer) - logic bust");
932 constexpr Real safety = 1.E-12;
935 for (
int lvl = 0; lvl <= m_finestLevel; lvl++) {
938 const DisjointBoxLayout& dbl = this->getGrids(whichRealm)[lvl];
939 const DataIterator& dit = dbl.dataIterator();
944 const Real tolerance = a_tolerance * m_dx[lvl];
946 const int nbox = dit.size();
947#pragma omp parallel for schedule(runtime)
948 for (
int mybox = 0; mybox < nbox; mybox++) {
949 const DataIndex& din = dit[mybox];
957 while (i < active.
size()) {
958 const RealVect newPos = active.
position(i);
963 ((oldPos[odir++] = active.template get<OldPosition>(i)), ...);
965 const RealVect path = newPos - oldPos;
968 bool checkEB =
false;
969 bool checkDomain =
false;
971 if (!implicitFunction.isNull()) {
974 for (
int dir = 0; dir < SpaceDim; dir++) {
975 const bool outsideLo = newPos[dir] < m_probLo[dir];
976 const bool outsideHi = newPos[dir] > m_probHi[dir];
978 if (outsideLo || outsideHi) {
984 if (checkEB || checkDomain) {
987 Real sDomain = std::numeric_limits<Real>::max();
988 Real sEB = std::numeric_limits<Real>::max();
990 bool contactDomain =
false;
991 bool contactEB =
false;
1002 if (contactDomain || contactEB) {
1003 if (sEB <= sDomain) {
1004 const RealVect intersectionPos = oldPos + sEB * path;
1009 if (a_deleteParticles) {
1014 a_nonDeletionModifier(active, i);
1019 const Real sSafety = std::max((Real)0.0, sDomain - safety);
1020 const RealVect intersectionPos = oldPos + sSafety * path;
1025 if (a_deleteParticles) {
1030 a_nonDeletionModifier(active, i);
1047 a_ebParticles.
remap();
1048 a_domainParticles.
remap();
1051template <
auto... OldPosition,
typename P,
typename Traits>
1058 const Real a_bisectionStep,
1059 const bool a_deleteParticles,
1062 CH_TIME(
"AmrMesh::intersectParticlesBisectIF(ParticleContainer)");
1063 if (m_verbosity > 5) {
1064 pout() <<
"AmrMesh::intersectParticlesBisectIF(ParticleContainer)" << endl;
1067 static_assert(
sizeof...(OldPosition) == SpaceDim,
1068 "AmrMesh::intersectParticlesBisectIF(ParticleContainer) - need exactly SpaceDim oldPosition members");
1079 const std::string whichRealm = a_activeParticles.
getRealm();
1082 RefCountedPtr<BaseIF> implicitFunction;
1096 MayDay::Error(
"AmrMesh::intersectParticlesBisectIF(ParticleContainer) - logic bust");
1103 constexpr Real safety = 1.E-12;
1106 for (
int lvl = 0; lvl <= m_finestLevel; lvl++) {
1109 const DisjointBoxLayout& dbl = this->getGrids(whichRealm)[lvl];
1110 const DataIterator& dit = dbl.dataIterator();
1112 const int nbox = dit.size();
1113#pragma omp parallel for schedule(runtime)
1114 for (
int mybox = 0; mybox < nbox; mybox++) {
1115 const DataIndex& din = dit[mybox];
1123 while (i < active.
size()) {
1124 const RealVect newPos = active.
position(i);
1129 ((oldPos[odir++] = active.template get<OldPosition>(i)), ...);
1131 const RealVect path = newPos - oldPos;
1134 bool checkEB =
false;
1135 bool checkDomain =
false;
1137 if (!implicitFunction.isNull()) {
1140 for (
int dir = 0; dir < SpaceDim; dir++) {
1141 const bool outsideLo = newPos[dir] < m_probLo[dir];
1142 const bool outsideHi = newPos[dir] > m_probHi[dir];
1144 if (outsideLo || outsideHi) {
1150 if (checkEB || checkDomain) {
1153 Real sDomain = std::numeric_limits<Real>::max();
1154 Real sEB = std::numeric_limits<Real>::max();
1156 bool contactDomain =
false;
1157 bool contactEB =
false;
1168 if (contactDomain || contactEB) {
1169 if (sEB <= sDomain) {
1170 const RealVect intersectionPos = oldPos + sEB * path;
1175 if (a_deleteParticles) {
1180 a_nonDeletionModifier(active, i);
1185 const Real sSafety = std::max((Real)0.0, sDomain - safety);
1186 const RealVect intersectionPos = oldPos + sSafety * path;
1191 if (a_deleteParticles) {
1196 a_nonDeletionModifier(active, i);
1213 a_ebParticles.
remap();
1214 a_domainParticles.
remap();
1217template <
typename P,
typename Traits>
1223 CH_TIME(
"AmrMesh::transferIrregularParticles(ParticleContainer)");
1224 if (m_verbosity > 5) {
1225 pout() <<
"AmrMesh::transferIrregularParticles(ParticleContainer)" << endl;
1228 CH_assert(a_dstParticles.getRealm() == a_srcParticles.getRealm());
1230 const std::string realm = a_dstParticles.getRealm();
1232 for (
int lvl = 0; lvl <= m_finestLevel; lvl++) {
1233 const DisjointBoxLayout& dbl = this->getGrids(realm)[lvl];
1234 const DataIterator& dit = dbl.dataIterator();
1235 const EBISLayout& ebisl = this->getEBISLayout(realm, a_phase)[lvl];
1236 const Real dx = m_dx[lvl];
1238 const int nbox = dit.size();
1239#pragma omp parallel for schedule(runtime)
1240 for (
int mybox = 0; mybox < nbox; mybox++) {
1241 const DataIndex& din = dit[mybox];
1242 const Box cellBox = dbl[din];
1243 const EBISBox& ebisbox = ebisl[din];
1250 while (i < src.
size()) {
1251 const RealVect pos = src.
position(i);
1256 if (cellBox.contains(iv) && ebisbox.isIrregular(iv)) {
1257 bool insideAnyVoF =
false;
1259 const Vector<VolIndex> allVoFs = ebisbox.getVoFs(iv);
1260 for (
int k = 0; k < allVoFs.size(); k++) {
1261 const RealVect normal = ebisbox.normal(allVoFs[k]);
1262 const RealVect ebPos = m_probLo +
Location::position(Location::Cell::Boundary, allVoFs[k], ebisbox, dx);
1264 if ((pos - ebPos).dotProduct(normal) >= 0.0) {
1265 insideAnyVoF =
true;
1269 if (!insideAnyVoF) {
1270 const VolIndex& vof = allVoFs[0];
1271 const RealVect ebPos = m_probLo +
Location::position(Location::Cell::Boundary, vof, ebisbox, dx);
1289#include <CD_NamespaceFooter.H>
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:391
void allocatePointer(Vector< RefCountedPtr< T > > &a_data) const
Allocate pointer but not any memory blocks.
Definition CD_AmrMeshImplem.H:268
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:673
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:241
const Vector< RefCountedPtr< LevelTiles > > & getLevelTiles(const std::string &a_realm) const
Get the tiled space representation.
Definition CD_AmrMesh.cpp:3568
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:371
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
const AMRMask & getValidCells(const std::string &a_realm) const
Get a map of all valid cells on a specified realm.
Definition CD_AmrMesh.cpp:3552
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:441
RealVect m_probLo
Domain simulation corner.
Definition CD_AmrMesh.H:2310
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:1053
const Vector< DisjointBoxLayout > & getGrids(const std::string &a_realm) const
Get the grids.
Definition CD_AmrMesh.cpp:3400
int m_verbosity
Verbosity.
Definition CD_AmrMesh.H:2325
int m_minBlockSize
Blocking factor.
Definition CD_AmrMesh.H:2365
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:738
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:618
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:1219
int m_finestLevel
Finest level.
Definition CD_AmrMesh.H:2330
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:479
std::map< phase::which_phase, RefCountedPtr< BaseIF > > m_baseif
Implicit functions.
Definition CD_AmrMesh.H:2229
bool queryRealm(const std::string &a_realm) const
Query if a realm exists.
Definition CD_AmrMesh.cpp:4036
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:885
const Vector< Real > & getDx() const
Get spatial resolutions.
Definition CD_AmrMesh.cpp:3344
EBAMRParticleMesh & getParticleMesh(const std::string &a_realm, const phase::which_phase a_phase) const
Get EBAMRParticleMesh operator.
Definition CD_AmrMesh.cpp:3860
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:3416
std::map< std::string, RefCountedPtr< Realm > > m_realms
These are all the Realms.
Definition CD_AmrMesh.H:2224
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:460
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:351
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:327
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:213
void deallocate(Vector< T * > &a_data) const
Deallocate data.
Definition CD_AmrMeshImplem.H:165
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:825
const Vector< int > & getRefinementRatios() const
Get refinement ratios.
Definition CD_AmrMesh.cpp:3355
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:538
const Vector< ProblemDomain > & getDomains() const
Get domains.
Definition CD_AmrMesh.cpp:3378
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:442
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:193
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 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