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);
127 if (a_fromRegion == CopyStrategy::Valid) {
128 if (a_toRegion == CopyStrategy::Valid) {
129 copier = m_validToValidRealmCopiers.at(
id)[a_level];
131 else if (a_toRegion == CopyStrategy::ValidGhost) {
132 copier = m_validToValidGhostRealmCopiers.at(
id)[a_level];
135 MayDay::Abort(
"AmrMesh::copyData - logic bust 1");
138 else if (a_fromRegion == CopyStrategy::ValidGhost) {
139 if (a_toRegion == CopyStrategy::Valid) {
140 copier = m_validGhostToValidRealmCopiers.at(
id)[a_level];
142 else if (a_toRegion == CopyStrategy::ValidGhost) {
143 copier = m_validGhostToValidGhostRealmCopiers.at(
id)[a_level];
146 MayDay::Abort(
"AmrMesh::copyData - logic bust 2");
150 MayDay::Abort(
"AmrMesh::copyData - logic bust 3");
153 a_src.copyTo(a_srcComps, a_dst, a_dstComps, copier);
156 a_src.localCopyTo(a_srcComps, a_dst, a_dstComps);
164 CH_TIME(
"AmrMesh::deallocate(Vector<T*>)");
166 pout() <<
"AmrMesh::deallocate(Vector<T*>)" << endl;
178 CH_TIME(
"AmrMesh::deallocate(Vector<RefCountedPtr<T>)");
180 pout() <<
"AmrMesh::deallocate(Vector<RefCountedPtr<T>)" << endl;
183 for (
int lvl = 0; lvl < a_data.size(); lvl++) {
185 a_data[lvl] = RefCountedPtr<T>(0);
187 if(!a_data[lvl].isNull()){
188 delete &(*a_data[lvl]);
189 a_data[lvl] = RefCountedPtr<T> (NULL);
200 CH_TIME(
"AmrMesh::deallocate(EBAMRData<T>)");
202 pout() <<
"AmrMesh::deallocate(EBAMRData<T>)" << endl;
212 CH_TIME(
"AmrMesh::alias(Vector<T*>, Vector<RefCountedPtr<T>)");
214 pout() <<
"AmrMesh::alias(Vector<T*>, Vector<RefCountedPtr<T>)" << endl;
217 a_alias.resize(a_data.size());
219 for (
int lvl = 0; lvl < a_data.size(); lvl++) {
220 a_alias[lvl] = &(*a_data[lvl]);
224template <
typename T,
typename S>
228 CH_TIME(
"AmrMesh::alias(Vector<T*>, EBAMRData<S>)");
230 pout() <<
"AmrMesh::alias(Vector<T*>, EBAMRData<S>" << endl;
236template <
typename P,
typename Traits>
240 CH_TIME(
"AmrMesh::allocate(ParticleContainer<P, Traits>, string)");
242 pout() <<
"AmrMesh::allocate(ParticleContainer<P, Traits>, string)" << endl;
246 const std::string str =
"AmrMesh::allocate(ParticleContainer<P, Traits>, string) - could not find Realm '" +
248 MayDay::Abort(str.c_str());
267 CH_TIME(
"AmrMesh::allocatePointer(Vector<RefCountedPtr<T> >)");
269 pout() <<
"AmrMesh::allocatePointer(Vector<RefCountedPtr<T> >)" << endl;
274 a_data[lvl] = RefCountedPtr<T>(
new T());
282 CH_TIME(
"AmrMesh::allocatePointer(Vector<RefCountedPtr<T> >, int)");
284 pout() <<
"AmrMesh::allocatePointer(Vector<RefCountedPtr<T> >, int)" << endl;
287 a_data.resize(1 + a_finestLevel);
289 for (
int lvl = 0; lvl <= a_finestLevel; lvl++) {
290 a_data[lvl] = RefCountedPtr<T>(
new T());
298 CH_TIME(
"AmrMesh::allocatePointer(EBAMRData<T>, std::string)");
300 pout() <<
"AmrMesh::allocatePointer(EBAMRData<T>, std::string)" << endl;
312 CH_TIME(
"AmrMesh::allocatePointer(EBAMRData<T>, std::string, int)");
314 pout() <<
"AmrMesh::allocatePointer(EBAMRData<T>, std::string, int)" << endl;
322template <
typename P,
typename Traits>
326 const int a_newFinestLevel)
const noexcept
328 CH_TIME(
"AmrMesh::remapToNewGrids(ParticleContainer)");
329 if (m_verbosity > 5) {
330 pout() <<
"AmrMesh::remapToNewGrids(ParticleContainer)" << endl;
335 const std::string realm = a_particles.getRealm();
337 a_particles.regrid(this->getGrids(realm),
340 this->getRefinementRatios(),
342 m_realms[realm]->getLevelTiles(),
346template <
typename P,
typename Traits>
349 const std::string& a_realm,
353 CH_TIME(
"AmrMesh::depositParticles(surface, SoA)");
354 if (m_verbosity > 5) {
355 pout() <<
"AmrMesh::depositParticles(surface, SoA)" << endl;
358 CH_assert(a_meshData[0]->nComp() == 1);
359 CH_assert(a_meshData.getRealm() == a_particles.getRealm());
363 surfaceDeposition.
deposit<P, Traits>(a_meshData, a_particles);
366template <
typename P,
typename Traits>
369 const std::string& a_realm,
374 const bool a_forceIrregNGP)
376 CH_TIME(
"AmrMesh::depositWeight(ParticleContainer)");
378 pout() <<
"AmrMesh::depositWeight(ParticleContainer)" << endl;
383 particleMesh.
depositWeight(a_meshData, a_particles, a_depositionType, a_coarseFineDeposition, a_forceIrregNGP);
386template <
typename P,
typename Traits,
typename CellGather>
389 const std::string& a_realm,
394 const bool a_forceIrregNGP,
395 CellGather a_cellGather)
397 CH_TIME(
"AmrMesh::depositGathered(ParticleContainer)");
399 pout() <<
"AmrMesh::depositGathered(ParticleContainer)" << endl;
405 .
depositGathered(a_meshData, a_particles, a_depositionType, a_coarseFineDeposition, a_forceIrregNGP, a_cellGather);
408template <
auto... Members,
typename P,
typename Traits>
411 const std::string& a_realm,
416 const bool a_forceIrregNGP)
418 CH_TIME(
"AmrMesh::depositParticles(ParticleContainer)");
420 pout() <<
"AmrMesh::depositParticles(ParticleContainer)" << endl;
425 particleMesh.template deposit<Members...>(a_meshData,
428 a_coarseFineDeposition,
432template <
typename P,
typename Traits>
435 const std::string& a_realm,
437 const EBAMRCellData& a_meshScalarField,
439 const bool a_forceIrregNGP)
const
441 CH_TIME(
"AmrMesh::interpolateWeight(ParticleContainer)");
443 pout() <<
"AmrMesh::interpolateWeight(ParticleContainer)" << endl;
448 particleMesh.
interpolateWeight(a_particles, a_meshScalarField, a_interpType, a_forceIrregNGP);
451template <
auto... Members,
typename P,
typename Traits>
454 const std::string& a_realm,
456 const EBAMRCellData& a_meshField,
458 const bool a_forceIrregNGP)
const
460 CH_TIME(
"AmrMesh::interpolateParticles(ParticleContainer)");
462 pout() <<
"AmrMesh::interpolateParticles(ParticleContainer)" << endl;
467 particleMesh.template interpolate<Members...>(a_particles, a_meshField, a_interpType, a_forceIrregNGP);
470template <
typename P,
typename Traits>
474 const Real a_tolerance)
const
476 CH_TIME(
"AmrMesh::removeCoveredParticlesIF(ParticleContainer)");
478 pout() <<
"AmrMesh::removeCoveredParticlesIF(ParticleContainer)" << endl;
482 RefCountedPtr<BaseIF> implicitFunction;
496 MayDay::Error(
"AmrMesh::removeCoveredParticlesIF(ParticleContainer) - logic bust");
500 const std::string whichRealm = a_particles.
getRealm();
503 const DisjointBoxLayout& dbl = this->
getGrids(whichRealm)[lvl];
504 const DataIterator& dit = dbl.dataIterator();
505 const Real dx = this->
getDx()[lvl];
506 const Real tol = a_tolerance * dx;
508 const int nbox = dit.size();
509#pragma omp parallel for schedule(runtime)
510 for (
int mybox = 0; mybox < nbox; mybox++) {
511 const DataIndex& din = dit[mybox];
517 while (i < leaf.
size()) {
518 if (implicitFunction->value(leaf.
position(i)) > tol) {
529template <
typename P,
typename Traits>
533 const Real a_tolerance)
const
535 CH_TIME(
"AmrMesh::removeCoveredParticlesDiscrete(ParticleContainer)");
537 pout() <<
"AmrMesh::removeCoveredParticlesDiscrete(ParticleContainer)" << endl;
540 const std::string whichRealm = a_particles.
getRealm();
543 const DisjointBoxLayout& dbl = this->
getGrids(whichRealm)[lvl];
544 const DataIterator& dit = dbl.dataIterator();
545 const EBISLayout& ebisl = this->
getEBISLayout(whichRealm, a_phase)[lvl];
546 const Real dx = this->
getDx()[lvl];
547 const Real tol = a_tolerance * dx;
549 const int nbox = dit.size();
550#pragma omp parallel for schedule(runtime)
551 for (
int mybox = 0; mybox < nbox; mybox++) {
552 const DataIndex& din = dit[mybox];
553 const EBISBox& ebisBox = ebisl[din];
554 const Box region = ebisBox.getRegion();
556 const bool isRegular = ebisBox.isAllRegular();
557 const bool isCovered = ebisBox.isAllCovered();
558 const bool isIrregular = !isRegular && !isCovered;
565 else if (isIrregular) {
568 while (i < leaf.
size()) {
569 const RealVect pos = leaf.
position(i);
572 CH_assert(region.contains(iv));
574 if (ebisBox.isCovered(iv)) {
577 else if (ebisBox.isIrregular(iv)) {
579 bool insideAtLeastOneVoF =
false;
581 const std::vector<VolIndex> vofs = ebisBox.getVoFs(iv).stdVector();
582 for (
const auto& vof : vofs) {
583 const RealVect ebNormal = ebisBox.normal(vof);
585 const Real faceProjection = ebNormal.dotProduct(pos - ebCentroid);
587 if (faceProjection >= -tol) {
588 insideAtLeastOneVoF =
true;
593 if (!insideAtLeastOneVoF) {
609template <
typename P,
typename Traits>
614 CH_TIME(
"AmrMesh::removeCoveredParticlesVoxels(ParticleContainer)");
616 pout() <<
"AmrMesh::removeCoveredParticlesVoxels(ParticleContainer)" << endl;
619 const std::string whichRealm = a_particles.
getRealm();
622 const DisjointBoxLayout& dbl = this->
getGrids(whichRealm)[lvl];
623 const DataIterator& dit = dbl.dataIterator();
624 const EBISLayout& ebisl = this->
getEBISLayout(whichRealm, a_phase)[lvl];
625 const Real dx = this->
getDx()[lvl];
627 const int nbox = dit.size();
628#pragma omp parallel for schedule(runtime)
629 for (
int mybox = 0; mybox < nbox; mybox++) {
630 const DataIndex& din = dit[mybox];
631 const EBISBox& ebisBox = ebisl[din];
632 const Box region = ebisBox.getRegion();
634 const bool isRegular = ebisBox.isAllRegular();
635 const bool isCovered = ebisBox.isAllCovered();
636 const bool isIrregular = !isRegular && !isCovered;
643 else if (isIrregular) {
645 while (i < leaf.
size()) {
646 const RealVect pos = leaf.
position(i);
647 const RealVect rv = (pos -
m_probLo) / dx;
648 const IntVect iv = IntVect(D_DECL(floor(rv[0]), floor(rv[1]), floor(rv[2])));
650 CH_assert(region.contains(iv));
652 if (ebisBox.isCovered(iv)) {
664template <
typename P,
typename Traits>
669 const Real a_tolerance)
const
671 CH_TIME(
"AmrMesh::transferCoveredParticlesIF(ParticleContainer)");
673 pout() <<
"AmrMesh::transferCoveredParticlesIF(ParticleContainer)" << endl;
677 RefCountedPtr<BaseIF> implicitFunction;
691 MayDay::Error(
"AmrMesh::transferCoveredParticlesIF(ParticleContainer) - logic bust");
695 const std::string realmFrom = a_particlesFrom.
getRealm();
696 const std::string realmTo = a_particlesTo.
getRealm();
698 CH_assert(realmFrom == realmTo);
701 const DisjointBoxLayout& dbl = this->
getGrids(realmFrom)[lvl];
702 const DataIterator& dit = dbl.dataIterator();
703 const Real dx = this->
getDx()[lvl];
704 const Real tol = a_tolerance * dx;
706 const int nbox = dit.size();
707#pragma omp parallel for schedule(runtime)
708 for (
int mybox = 0; mybox < nbox; mybox++) {
709 const DataIndex& din = dit[mybox];
716 while (i < from.
size()) {
717 if (implicitFunction->value(from.
position(i)) > tol) {
729template <
typename P,
typename Traits>
734 const Real a_tolerance)
const
736 CH_TIME(
"AmrMesh::transferCoveredParticlesDiscrete(ParticleContainer)");
738 pout() <<
"AmrMesh::transferCoveredParticlesDiscrete(ParticleContainer)" << endl;
741 const std::string realmFrom = a_particlesFrom.
getRealm();
742 const std::string realmTo = a_particlesTo.
getRealm();
744 CH_assert(realmFrom == realmTo);
747 const DisjointBoxLayout& dbl = this->
getGrids(realmFrom)[lvl];
748 const DataIterator& dit = dbl.dataIterator();
749 const EBISLayout& ebisl = this->
getEBISLayout(realmFrom, a_phase)[lvl];
750 const Real dx = this->
getDx()[lvl];
751 const Real tol = a_tolerance * dx;
753 const int nbox = dit.size();
754#pragma omp parallel for schedule(runtime)
755 for (
int mybox = 0; mybox < nbox; mybox++) {
756 const DataIndex& din = dit[mybox];
757 const EBISBox& ebisBox = ebisl[din];
758 const Box region = ebisBox.getRegion();
760 const bool isRegular = ebisBox.isAllRegular();
761 const bool isCovered = ebisBox.isAllCovered();
762 const bool isIrregular = !isRegular && !isCovered;
770 else if (isIrregular) {
773 while (i < from.
size()) {
774 const RealVect pos = from.
position(i);
777 CH_assert(region.contains(iv));
779 if (ebisBox.isCovered(iv)) {
783 else if (ebisBox.isIrregular(iv)) {
785 bool insideAtLeastOneVoF =
false;
787 const std::vector<VolIndex> vofs = ebisBox.getVoFs(iv).stdVector();
788 for (
const auto& vof : vofs) {
790 const RealVect ebNormal = ebisBox.normal(vof);
791 const Real faceProjection = ebNormal.dotProduct(pos - ebCentroid);
793 if (faceProjection >= -tol) {
794 insideAtLeastOneVoF =
true;
799 if (!insideAtLeastOneVoF) {
816template <
typename P,
typename Traits>
822 CH_TIME(
"AmrMesh::transferCoveredParticlesVoxels(ParticleContainer)");
824 pout() <<
"AmrMesh::transferCoveredParticlesVoxels(ParticleContainer)" << endl;
827 const std::string realmFrom = a_particlesFrom.
getRealm();
828 const std::string realmTo = a_particlesTo.
getRealm();
830 CH_assert(realmFrom == realmTo);
833 const DisjointBoxLayout& dbl = this->
getGrids(realmFrom)[lvl];
834 const DataIterator& dit = dbl.dataIterator();
835 const EBISLayout& ebisl = this->
getEBISLayout(realmFrom, a_phase)[lvl];
836 const Real dx = this->
getDx()[lvl];
838 const int nbox = dit.size();
839#pragma omp parallel for schedule(runtime)
840 for (
int mybox = 0; mybox < nbox; mybox++) {
841 const DataIndex& din = dit[mybox];
842 const EBISBox& ebisBox = ebisl[din];
843 const Box region = ebisBox.getRegion();
845 const bool isRegular = ebisBox.isAllRegular();
846 const bool isCovered = ebisBox.isAllCovered();
847 const bool isIrregular = !isRegular && !isCovered;
855 else if (isIrregular) {
857 while (i < from.
size()) {
858 const RealVect pos = from.
position(i);
861 CH_assert(region.contains(iv));
863 if (ebisBox.isCovered(iv)) {
876template <
auto... OldPosition,
typename P,
typename Traits>
883 const Real a_tolerance,
884 const bool a_deleteParticles,
887 CH_TIME(
"AmrMesh::intersectParticlesRaycastIF(ParticleContainer)");
888 if (m_verbosity > 5) {
889 pout() <<
"AmrMesh::intersectParticlesRaycastIF(ParticleContainer)" << endl;
892 static_assert(
sizeof...(OldPosition) == SpaceDim,
893 "AmrMesh::intersectParticlesRaycastIF(ParticleContainer) - need exactly SpaceDim oldPosition members");
901 const std::string whichRealm = a_activeParticles.
getRealm();
904 RefCountedPtr<BaseIF> implicitFunction;
918 MayDay::Error(
"AmrMesh::intersectParticlesRaycastIF(ParticleContainer) - logic bust");
925 constexpr Real safety = 1.E-12;
928 for (
int lvl = 0; lvl <= m_finestLevel; lvl++) {
931 const DisjointBoxLayout& dbl = this->getGrids(whichRealm)[lvl];
932 const DataIterator& dit = dbl.dataIterator();
934 const int nbox = dit.size();
935#pragma omp parallel for schedule(runtime)
936 for (
int mybox = 0; mybox < nbox; mybox++) {
937 const DataIndex& din = dit[mybox];
945 while (i < active.
size()) {
946 const RealVect newPos = active.
position(i);
951 ((oldPos[odir++] = active.template get<OldPosition>(i)), ...);
953 const RealVect path = newPos - oldPos;
956 bool checkEB =
false;
957 bool checkDomain =
false;
959 if (!implicitFunction.isNull()) {
962 for (
int dir = 0; dir < SpaceDim; dir++) {
963 const bool outsideLo = newPos[dir] < m_probLo[dir];
964 const bool outsideHi = newPos[dir] > m_probHi[dir];
966 if (outsideLo || outsideHi) {
972 if (checkEB || checkDomain) {
975 Real sDomain = std::numeric_limits<Real>::max();
976 Real sEB = std::numeric_limits<Real>::max();
978 bool contactDomain =
false;
979 bool contactEB =
false;
990 if (contactDomain || contactEB) {
991 if (sEB <= sDomain) {
992 const RealVect intersectionPos = oldPos + sEB * path;
997 if (a_deleteParticles) {
1002 a_nonDeletionModifier(active, i);
1007 const Real sSafety = std::max((Real)0.0, sDomain - safety);
1008 const RealVect intersectionPos = oldPos + sSafety * path;
1013 if (a_deleteParticles) {
1018 a_nonDeletionModifier(active, i);
1035 a_ebParticles.
remap();
1036 a_domainParticles.
remap();
1039template <
auto... OldPosition,
typename P,
typename Traits>
1046 const Real a_bisectionStep,
1047 const bool a_deleteParticles,
1050 CH_TIME(
"AmrMesh::intersectParticlesBisectIF(ParticleContainer)");
1051 if (m_verbosity > 5) {
1052 pout() <<
"AmrMesh::intersectParticlesBisectIF(ParticleContainer)" << endl;
1055 static_assert(
sizeof...(OldPosition) == SpaceDim,
1056 "AmrMesh::intersectParticlesBisectIF(ParticleContainer) - need exactly SpaceDim oldPosition members");
1067 const std::string whichRealm = a_activeParticles.
getRealm();
1070 RefCountedPtr<BaseIF> implicitFunction;
1084 MayDay::Error(
"AmrMesh::intersectParticlesBisectIF(ParticleContainer) - logic bust");
1091 constexpr Real safety = 1.E-12;
1094 for (
int lvl = 0; lvl <= m_finestLevel; lvl++) {
1097 const DisjointBoxLayout& dbl = this->getGrids(whichRealm)[lvl];
1098 const DataIterator& dit = dbl.dataIterator();
1100 const int nbox = dit.size();
1101#pragma omp parallel for schedule(runtime)
1102 for (
int mybox = 0; mybox < nbox; mybox++) {
1103 const DataIndex& din = dit[mybox];
1111 while (i < active.
size()) {
1112 const RealVect newPos = active.
position(i);
1117 ((oldPos[odir++] = active.template get<OldPosition>(i)), ...);
1119 const RealVect path = newPos - oldPos;
1122 bool checkEB =
false;
1123 bool checkDomain =
false;
1125 if (!implicitFunction.isNull()) {
1128 for (
int dir = 0; dir < SpaceDim; dir++) {
1129 const bool outsideLo = newPos[dir] < m_probLo[dir];
1130 const bool outsideHi = newPos[dir] > m_probHi[dir];
1132 if (outsideLo || outsideHi) {
1138 if (checkEB || checkDomain) {
1141 Real sDomain = std::numeric_limits<Real>::max();
1142 Real sEB = std::numeric_limits<Real>::max();
1144 bool contactDomain =
false;
1145 bool contactEB =
false;
1156 if (contactDomain || contactEB) {
1157 if (sEB <= sDomain) {
1158 const RealVect intersectionPos = oldPos + sEB * path;
1163 if (a_deleteParticles) {
1168 a_nonDeletionModifier(active, i);
1173 const Real sSafety = std::max((Real)0.0, sDomain - safety);
1174 const RealVect intersectionPos = oldPos + sSafety * path;
1179 if (a_deleteParticles) {
1184 a_nonDeletionModifier(active, i);
1201 a_ebParticles.
remap();
1202 a_domainParticles.
remap();
1205template <
typename P,
typename Traits>
1211 CH_TIME(
"AmrMesh::transferIrregularParticles(ParticleContainer)");
1212 if (m_verbosity > 5) {
1213 pout() <<
"AmrMesh::transferIrregularParticles(ParticleContainer)" << endl;
1216 CH_assert(a_dstParticles.getRealm() == a_srcParticles.getRealm());
1218 const std::string realm = a_dstParticles.getRealm();
1220 for (
int lvl = 0; lvl <= m_finestLevel; lvl++) {
1221 const DisjointBoxLayout& dbl = this->getGrids(realm)[lvl];
1222 const DataIterator& dit = dbl.dataIterator();
1223 const EBISLayout& ebisl = this->getEBISLayout(realm, a_phase)[lvl];
1224 const Real dx = m_dx[lvl];
1226 const int nbox = dit.size();
1227#pragma omp parallel for schedule(runtime)
1228 for (
int mybox = 0; mybox < nbox; mybox++) {
1229 const DataIndex& din = dit[mybox];
1230 const Box cellBox = dbl[din];
1231 const EBISBox& ebisbox = ebisl[din];
1238 while (i < src.
size()) {
1239 const RealVect pos = src.
position(i);
1244 if (cellBox.contains(iv) && ebisbox.isIrregular(iv)) {
1245 bool insideAnyVoF =
false;
1247 const Vector<VolIndex> allVoFs = ebisbox.getVoFs(iv);
1248 for (
int k = 0; k < allVoFs.size(); k++) {
1249 const RealVect normal = ebisbox.normal(allVoFs[k]);
1250 const RealVect ebPos = m_probLo +
Location::position(Location::Cell::Boundary, allVoFs[k], ebisbox, dx);
1252 if ((pos - ebPos).dotProduct(normal) >= 0.0) {
1253 insideAnyVoF =
true;
1257 if (!insideAnyVoF) {
1258 const VolIndex& vof = allVoFs[0];
1259 const RealVect ebPos = m_probLo +
Location::position(Location::Cell::Boundary, vof, ebisbox, dx);
1277#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
Declaration of a static class containing some common useful particle routines that would otherwise be...
void allocatePointer(Vector< RefCountedPtr< T > > &a_data) const
Allocate pointer but not any memory blocks.
Definition CD_AmrMeshImplem.H:265
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:666
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:238
const Vector< RefCountedPtr< LevelTiles > > & getLevelTiles(const std::string &a_realm) const
Get the tiled space representation.
Definition CD_AmrMesh.cpp:3439
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:3423
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:434
RealVect m_probLo
Domain simulation corner.
Definition CD_AmrMesh.H:2241
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:1041
const Vector< DisjointBoxLayout > & getGrids(const std::string &a_realm) const
Get the grids.
Definition CD_AmrMesh.cpp:3271
int m_verbosity
Verbosity.
Definition CD_AmrMesh.H:2256
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 bool a_forceIrregNGP, CellGather a_cellGather)
Deposit a custom per-particle scalar (a_cellGather) of an SoA container on the mesh.
Definition CD_AmrMeshImplem.H:388
int m_minBlockSize
Blocking factor.
Definition CD_AmrMesh.H:2296
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 bool a_forceIrregNGP)
Deposit the SoA container's weight column on the mesh (all coarse-fine strategies).
Definition CD_AmrMeshImplem.H:368
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:731
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:611
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:1207
int m_finestLevel
Finest level.
Definition CD_AmrMesh.H:2261
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:472
std::map< phase::which_phase, RefCountedPtr< BaseIF > > m_baseif
Implicit functions.
Definition CD_AmrMesh.H:2160
bool queryRealm(const std::string &a_realm) const
Query if a realm exists.
Definition CD_AmrMesh.cpp:3861
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:878
const Vector< Real > & getDx() const
Get spatial resolutions.
Definition CD_AmrMesh.cpp:3215
EBAMRParticleMesh & getParticleMesh(const std::string &a_realm, const phase::which_phase a_phase) const
Get EBAMRParticleMesh operator.
Definition CD_AmrMesh.cpp:3685
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:3287
std::map< std::string, RefCountedPtr< Realm > > m_realms
These are all the Realms.
Definition CD_AmrMesh.H:2155
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:453
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:348
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:324
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:210
void deallocate(Vector< T * > &a_data) const
Deallocate data.
Definition CD_AmrMeshImplem.H:162
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:818
const Vector< int > & getRefinementRatios() const
Get refinement ratios.
Definition CD_AmrMesh.cpp:3226
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:531
const Vector< ProblemDomain > & getDomains() const
Get domains.
Definition CD_AmrMesh.cpp:3249
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:115
void setRealm(const std::string &a_realm) noexcept
Sets the realm for this object.
Definition CD_EBAMRDataImplem.H:143
AMR driver that deposits/interpolates ParticleContainer particles across the hierarchy.
Definition CD_EBAMRParticleMesh.H:74
void depositWeight(EBAMRCellData &a_meshData, const ParticleContainer< P, Traits > &a_particles, const DepositionType a_depositionType, const CoarseFineDeposition a_coarseFineDeposition, const bool a_forceIrregNGP)
Deposit the container-owned weight onto the AMR mesh.
Definition CD_EBAMRParticleMesh.H:251
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:204
void depositGathered(EBAMRCellData &a_meshData, const ParticleContainer< P, Traits > &a_particles, const DepositionType a_depositionType, const CoarseFineDeposition a_coarseFineDeposition, const bool a_forceIrregNGP, CellGather a_cellGather)
Deposit a custom per-particle scalar (computed by a_cellGather) onto the AMR mesh.
Definition CD_EBAMRParticleMesh.H:316
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:1188
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:1206
void catenate(ParticleSoA &a_other)
Move every particle of another container into this one, leaving a_other empty (catenate).
Definition CD_ParticleSoA.H:1002
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:1033
void clear() noexcept
Drop all particles (keeps the arena; invalidates the cell sort).
Definition CD_ParticleSoA.H:911
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