12 #ifndef CD_AmrMeshImplem_H
13 #define CD_AmrMeshImplem_H
18 #include <CD_NamespaceHeader.H>
27 CH_TIME(
"AmrMesh::copyData(EBAMRData, simple)");
28 if (m_verbosity > 5) {
29 pout() <<
"AmrMesh::copyData(EBAMRData, simple)" << endl;
32 const int nComp = a_dst[0]->nComp();
33 const Interval dstComps = Interval(0, nComp - 1);
34 const Interval srcComps = Interval(0, nComp - 1);
36 const std::string toRealm = a_dst.getRealm();
37 const std::string fromRealm = a_src.getRealm();
39 for (
int lvl = 0; lvl <= m_finestLevel; lvl++) {
40 CH_assert(!(a_dst[lvl].isNull()));
41 CH_assert(!(a_src[lvl].isNull()));
43 this->copyData(*a_dst[lvl], *a_src[lvl], lvl, toRealm, fromRealm, dstComps, srcComps, a_toRegion, a_fromRegion);
51 const Interval& a_dstComps,
52 const Interval& a_srcComps,
56 CH_TIME(
"AmrMesh::copyData(EBAMRData, full)");
57 if (m_verbosity > 5) {
58 pout() <<
"AmrMesh::copyData(EBAMRData, full)" << endl;
61 const std::string toRealm = a_dst.getRealm();
62 const std::string fromRealm = a_src.getRealm();
64 for (
int lvl = 0; lvl <= m_finestLevel; lvl++) {
65 CH_assert(!(a_dst[lvl].isNull()));
66 CH_assert(!(a_src[lvl].isNull()));
68 this->copyData(*a_dst[lvl], *a_src[lvl], lvl, toRealm, fromRealm, a_dstComps, a_srcComps, a_toRegion, a_fromRegion);
75 const LevelData<T>& a_src,
77 const std::string a_toRealm,
78 const std::string a_fromRealm,
82 CH_TIME(
"AmrMesh::copyData(LD<T>_full)");
83 if (m_verbosity > 5) {
84 pout() <<
"AmrMesh::copyData(LD<T>_full)" << endl;
87 const Interval dstComps = Interval(0, a_dst.nComp() - 1);
88 const Interval srcComps = Interval(0, a_src.nComp() - 1);
90 this->copyData(a_dst, a_src, a_level, a_toRealm, a_fromRealm, dstComps, srcComps, a_toRegion, a_fromRegion);
96 const LevelData<T>& a_src,
98 const std::string a_toRealm,
99 const std::string a_fromRealm,
100 const Interval& a_dstComps,
101 const Interval& a_srcComps,
105 CH_TIME(
"AmrMesh::copyData(LD<T>_full)");
106 if (m_verbosity > 5) {
107 pout() <<
"AmrMesh::copyData(LD<T>_full)" << endl;
110 CH_assert(a_dstComps.size() == a_srcComps.size());
111 CH_assert(a_dst.nComp() > a_dstComps.end());
112 CH_assert(a_src.nComp() > a_srcComps.end());
114 if (a_toRealm != a_fromRealm) {
115 const auto id = std::make_pair(a_fromRealm, a_toRealm);
117 if (a_toRegion == CopyStrategy::ValidGhost) {
118 CH_assert(a_dst.ghostVect() == m_numGhostCells * IntVect::Unit);
120 if (a_fromRegion == CopyStrategy::ValidGhost) {
121 CH_assert(a_src.ghostVect() == m_numGhostCells * IntVect::Unit);
126 if (a_fromRegion == CopyStrategy::Valid) {
127 if (a_toRegion == CopyStrategy::Valid) {
128 copier = m_validToValidRealmCopiers.at(
id)[a_level];
130 else if (a_toRegion == CopyStrategy::ValidGhost) {
131 copier = m_validToValidGhostRealmCopiers.at(
id)[a_level];
134 MayDay::Abort(
"AmrMesh::copyData - logic bust 1");
137 else if (a_fromRegion == CopyStrategy::ValidGhost) {
138 if (a_toRegion == CopyStrategy::Valid) {
139 copier = m_validGhostToValidRealmCopiers.at(
id)[a_level];
141 else if (a_toRegion == CopyStrategy::ValidGhost) {
142 copier = m_validGhostToValidGhostRealmCopiers.at(
id)[a_level];
145 MayDay::Abort(
"AmrMesh::copyData - logic bust 2");
149 MayDay::Abort(
"AmrMesh::copyData - logic bust 3");
152 a_src.copyTo(a_srcComps, a_dst, a_dstComps, copier);
155 a_src.localCopyTo(a_srcComps, a_dst, a_dstComps);
159 template <
typename T>
163 CH_TIME(
"AmrMesh::deallocate(Vector<T*>)");
165 pout() <<
"AmrMesh::deallocate(Vector<T*>)" << endl;
173 template <
typename T>
177 CH_TIME(
"AmrMesh::deallocate(Vector<RefCountedPtr<T>)");
179 pout() <<
"AmrMesh::deallocate(Vector<RefCountedPtr<T>)" << endl;
182 for (
int lvl = 0; lvl < a_data.size(); lvl++) {
184 a_data[lvl] = RefCountedPtr<T>(0);
186 if(!a_data[lvl].isNull()){
187 delete &(*a_data[lvl]);
188 a_data[lvl] = RefCountedPtr<T> (NULL);
195 template <
typename T>
199 CH_TIME(
"AmrMesh::deallocate(EBAMRData<T>)");
201 pout() <<
"AmrMesh::deallocate(EBAMRData<T>)" << endl;
207 template <
typename T>
209 AmrMesh::alias(Vector<T*>& a_alias,
const Vector<RefCountedPtr<T>>& a_data)
const
211 CH_TIME(
"AmrMesh::alias(Vector<T*>, Vector<RefCountedPtr<T>)");
213 pout() <<
"AmrMesh::alias(Vector<T*>, Vector<RefCountedPtr<T>)" << endl;
216 a_alias.resize(a_data.size());
218 for (
int lvl = 0; lvl < a_data.size(); lvl++) {
219 a_alias[lvl] = &(*a_data[lvl]);
223 template <
typename T,
typename S>
227 CH_TIME(
"AmrMesh::alias(Vector<T*>, EBAMRData<S>)");
229 pout() <<
"AmrMesh::alias(Vector<T*>, EBAMRData<S>" << endl;
235 template <
typename T>
237 AmrMesh::allocate(Vector<RefCountedPtr<ParticleData<T>>>& a_particles,
const std::string a_realm)
const
239 CH_TIME(
"AmrMesh::allocate(Vector<RefCountedPtr<ParticleData<T> > >, string)");
241 pout() <<
"AmrMesh::allocate(Vector<RefCountedPtr<ParticleData<T> > >, string)" << endl;
246 str =
"AmrMesh::allocate(Vector<RefCountedPtr<ParticleData<T> > >, string) - could not find Realm '" + a_realm +
248 MayDay::Abort(str.c_str());
253 "AmrMesh::allocate(Vector<RefCountedPtr<ParticleData<T> > >, string) - only constant box sizes supported for particle methods");
259 const DisjointBoxLayout& dbl =
m_realms[a_realm]->getGrids()[lvl];
260 const ProblemDomain& domain =
m_realms[a_realm]->getDomains()[lvl];
262 const Real dx =
m_dx[lvl];
264 a_particles[lvl] = RefCountedPtr<ParticleData<T>>(
269 template <
typename T>
273 CH_TIME(
"AmrMesh::allocate(ParticleContainer<T>, int, string)");
275 pout() <<
"AmrMesh::allocate(ParticleContainer<T>, int, string)" << endl;
279 const std::string str =
"AmrMesh::allocate(ParticleContainer<T>, int, string) - could not find Realm '" + a_realm +
281 MayDay::Abort(str.c_str());
286 "AmrMesh::allocate(ParticleContainer<T>, int, string) - only constant box sizes are supported for particle methods");
301 template <
typename T>
305 CH_TIME(
"AmrMesh::allocatePointer(Vector<RefCountedPtr<T> >)");
307 pout() <<
"AmrMesh::allocatePointer(Vector<RefCountedPtr<T> >)" << endl;
312 a_data[lvl] = RefCountedPtr<T>(
new T());
316 template <
typename T>
320 CH_TIME(
"AmrMesh::allocatePointer(Vector<RefCountedPtr<T> >, int)");
322 pout() <<
"AmrMesh::allocatePointer(Vector<RefCountedPtr<T> >, int)" << endl;
325 a_data.resize(1 + a_finestLevel);
327 for (
int lvl = 0; lvl <= a_finestLevel; lvl++) {
328 a_data[lvl] = RefCountedPtr<T>(
new T());
332 template <
typename T>
336 CH_TIME(
"AmrMesh::allocatePointer(EBAMRData<T>, std::string)");
338 pout() <<
"AmrMesh::allocatePointer(EBAMRData<T>, std::string)" << endl;
346 template <
typename T>
350 CH_TIME(
"AmrMesh::allocatePointer(EBAMRData<T>, std::string, int)");
352 pout() <<
"AmrMesh::allocatePointer(EBAMRData<T>, std::string, int)" << endl;
364 CH_TIME(
"AmrMesh::remapToNewGrids");
365 if (m_verbosity > 5) {
366 pout() <<
"AmrMesh::remapToNewGrids" << endl;
369 const std::string realm = a_particles.getRealm();
371 a_particles.regrid(this->getGrids(realm),
374 this->getRefinementRatios(),
375 this->getValidCells(realm),
376 this->getLevelTiles(realm),
381 template <
class P, const Real& (P::*particleScalarField)() const>
384 const std::string& a_realm,
385 const phase::which_phase& a_phase,
389 const bool a_forceIrregNGP)
391 CH_TIME(
"AmrMesh::depositParticles");
393 pout() <<
"AmrMesh::depositParticles" << endl;
398 particleMesh.
deposit<P, particleScalarField>(a_meshData,
401 a_coarseFineDeposition,
405 template <
class P, Real (P::*particleScalarField)() const>
408 const std::string& a_realm,
409 const phase::which_phase& a_phase,
413 const bool a_forceIrregNGP)
415 CH_TIME(
"AmrMesh::depositParticles");
417 pout() <<
"AmrMesh::depositParticles" << endl;
422 particleMesh.
deposit<P, particleScalarField>(a_meshData,
425 a_coarseFineDeposition,
429 template <
class P, const RealVect& (P::*particleVectorField)() const>
432 const std::string& a_realm,
433 const phase::which_phase& a_phase,
437 const bool a_forceIrregNGP)
439 CH_TIME(
"AmrMesh::depositParticles");
441 pout() <<
"AmrMesh::depositParticles" << endl;
446 particleMesh.
deposit<P, particleVectorField>(a_meshData,
449 a_coarseFineDeposition,
453 template <
class P, const Real& (P::*particleScalarField)() const>
456 const std::string& a_realm,
457 const phase::which_phase& a_phase,
460 CH_TIME(
"AmrMesh::depositParticles(surface)");
461 if (m_verbosity > 5) {
462 pout() <<
"AmrMesh::depositParticles(surface)" << endl;
465 CH_assert(a_meshData[0]->nComp() == 1);
470 surfaceDeposition.
deposit<P, particleScalarField>(a_meshData, a_particles);
473 template <
class P, Real (P::*particleScalarField)() const>
476 const std::string& a_realm,
477 const phase::which_phase& a_phase,
480 CH_TIME(
"AmrMesh::depositParticles(surface)");
481 if (m_verbosity > 5) {
482 pout() <<
"AmrMesh::depositParticles(surface)" << endl;
485 CH_assert(a_meshData[0]->nComp() == 1);
490 surfaceDeposition.
deposit<P, particleScalarField>(a_meshData, a_particles);
493 template <
class P, Real& (P::*particleScalarField)()>
496 const std::string& a_realm,
497 const phase::which_phase& a_phase,
500 const bool a_forceIrregNGP)
const
502 CH_TIME(
"AmrMesh::interpolateParticles(scalar)");
504 pout() <<
"AmrMesh::interpolateParticles(scalar)" << endl;
507 CH_assert(a_realm == a_particles.
getRealm());
508 CH_assert(a_realm == a_meshScalarField.
getRealm());
512 particleMesh.
interpolate<P, particleScalarField>(a_particles, a_meshScalarField, a_interpType, a_forceIrregNGP);
515 template <
class P, RealVect& (P::*particleVectorField)()>
518 const std::string& a_realm,
519 const phase::which_phase& a_phase,
522 const bool a_forceIrregNGP)
const
524 CH_TIME(
"AmrMesh::interpolateParticles(vector)");
526 pout() <<
"AmrMesh::interpolateParticles(vector)" << endl;
529 CH_assert(a_realm == a_particles.
getRealm());
530 CH_assert(a_realm == a_meshVectorField.
getRealm());
534 particleMesh.
interpolate<P, particleVectorField>(a_particles, a_meshVectorField, a_interpType, a_forceIrregNGP);
540 const phase::which_phase& a_phase,
541 const Real a_tolerance)
const
543 CH_TIME(
"AmrMesh::removeCoveredParticlesIF");
545 pout() <<
"AmrMesh::removeCoveredParticlesIF" << endl;
551 RefCountedPtr<BaseIF> implicitFunction;
555 implicitFunction =
m_baseif.at(phase::gas);
560 implicitFunction =
m_baseif.at(phase::solid);
565 MayDay::Error(
"AmrMesh::removeCoveredParticlesIF - logic bust");
570 const std::string whichRealm = a_particles.
getRealm();
574 const DisjointBoxLayout& dbl = this->
getGrids(whichRealm)[lvl];
575 const DataIterator& dit = dbl.dataIterator();
576 const Real dx = this->
getDx()[lvl];
577 const Real tol = a_tolerance * dx;
579 const int nbox = dit.size();
580 #pragma omp parallel for schedule(runtime)
581 for (
int mybox = 0; mybox < nbox; mybox++) {
582 const DataIndex& din = dit[mybox];
584 List<P>& particles = a_particles[lvl][din].listItems();
587 for (ListIterator<P> lit(particles); lit.ok();) {
588 const RealVect& pos = lit().position();
590 const Real f = implicitFunction->value(pos);
593 particles.remove(lit);
606 const phase::which_phase& a_phase,
607 const Real a_tolerance)
const
609 CH_TIME(
"AmrMesh::removeCoveredParticlesDiscrete");
611 pout() <<
"AmrMesh::removeCoveredParticlesDiscrete" << endl;
617 const std::string whichRealm = a_particles.
getRealm();
620 const DisjointBoxLayout& dbl = this->
getGrids(whichRealm)[lvl];
621 const DataIterator& dit = dbl.dataIterator();
622 const EBISLayout& ebisl = this->
getEBISLayout(whichRealm, a_phase)[lvl];
623 const Real dx = this->
getDx()[lvl];
624 const Real tol = a_tolerance * dx;
626 const int nbox = dit.size();
627 #pragma omp parallel for schedule(runtime)
628 for (
int mybox = 0; mybox < nbox; mybox++) {
629 const DataIndex& din = dit[mybox];
630 const EBISBox& ebisBox = ebisl[din];
631 const Box region = ebisBox.getRegion();
633 const bool isRegular = ebisBox.isAllRegular();
634 const bool isCovered = ebisBox.isAllCovered();
635 const bool isIrregular = !isRegular && !isCovered;
637 List<P>& particles = a_particles[lvl][din].listItems();
642 else if (isIrregular) {
643 for (ListIterator<P> lit(particles); lit.ok();) {
644 const P& particle = lit();
645 const RealVect& pos = particle.position();
650 CH_assert(region.contains(iv));
652 if (ebisBox.isCovered(iv)) {
653 particles.remove(lit);
655 else if (ebisBox.isIrregular(iv)) {
660 bool insideAtLeastOneVoF =
false;
664 const std::vector<VolIndex> vofs = ebisBox.getVoFs(iv).stdVector();
665 for (
const auto& vof : vofs) {
666 const RealVect ebNormal = ebisBox.normal(vof);
668 const Real faceProjection = ebNormal.dotProduct(pos - ebCentroid);
670 if (faceProjection >= -tol) {
671 insideAtLeastOneVoF =
true;
677 if (!insideAtLeastOneVoF) {
678 particles.remove(lit);
697 CH_TIME(
"AmrMesh::removeCoveredParticlesVoxels");
699 pout() <<
"AmrMesh::removeCoveredParticlesVoxels" << endl;
705 const std::string whichRealm = a_particles.
getRealm();
708 const DisjointBoxLayout& dbl = this->
getGrids(whichRealm)[lvl];
709 const DataIterator& dit = dbl.dataIterator();
710 const EBISLayout& ebisl = this->
getEBISLayout(whichRealm, a_phase)[lvl];
711 const Real dx = this->
getDx()[lvl];
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];
717 const EBISBox& ebisBox = ebisl[din];
718 const Box region = ebisBox.getRegion();
720 const bool isRegular = ebisBox.isAllRegular();
721 const bool isCovered = ebisBox.isAllCovered();
722 const bool isIrregular = !isRegular && !isCovered;
724 List<P>& particles = a_particles[lvl][din].listItems();
729 else if (isIrregular) {
730 for (ListIterator<P> lit(particles); lit.ok();) {
731 const P& particle = lit();
732 const RealVect& pos = particle.position();
735 const RealVect rv = (pos -
m_probLo) / dx;
736 const IntVect iv = IntVect(D_DECL(floor(rv[0]), floor(rv[1]), floor(rv[2])));
738 CH_assert(region.contains(iv));
740 if (ebisBox.isCovered(iv)) {
741 particles.remove(lit);
756 const phase::which_phase& a_phase,
757 const Real a_tolerance)
const
759 CH_TIME(
"AmrMesh::transferCoveredParticlesIF");
761 pout() <<
"AmrMesh::transferCoveredParticlesIF" << endl;
768 RefCountedPtr<BaseIF> implicitFunction;
772 implicitFunction =
m_baseif.at(phase::gas);
777 implicitFunction =
m_baseif.at(phase::solid);
782 MayDay::Error(
"AmrMesh::removeCoveredParticlesIF - logic bust");
789 const std::string realmFrom = a_particlesFrom.
getRealm();
790 const std::string realmTo = a_particlesTo.
getRealm();
792 CH_assert(realmFrom == realmTo);
796 const DisjointBoxLayout& dbl = this->
getGrids(realmFrom)[lvl];
797 const DataIterator& dit = dbl.dataIterator();
798 const Real dx = this->
getDx()[lvl];
799 const Real tol = a_tolerance * dx;
801 const int nbox = dit.size();
802 #pragma omp parallel for schedule(runtime)
803 for (
int mybox = 0; mybox < nbox; mybox++) {
804 const DataIndex& din = dit[mybox];
806 List<P>& particlesFrom = a_particlesFrom[lvl][din].listItems();
807 List<P>& particlesTo = a_particlesTo[lvl][din].listItems();
810 for (ListIterator<P> lit(particlesFrom); lit.ok();) {
811 const RealVect& pos = lit().position();
813 const Real f = implicitFunction->value(pos);
816 particlesTo.transfer(lit);
830 const phase::which_phase& a_phase,
831 const Real a_tolerance)
const
833 CH_TIME(
"AmrMesh::transferCoveredParticlesDiscrete");
835 pout() <<
"AmrMesh::transferCoveredParticlesDiscrete" << endl;
842 const std::string realmFrom = a_particlesFrom.
getRealm();
843 const std::string realmTo = a_particlesTo.
getRealm();
845 CH_assert(realmFrom == realmTo);
848 const DisjointBoxLayout& dbl = this->
getGrids(realmFrom)[lvl];
849 const DataIterator& dit = dbl.dataIterator();
850 const EBISLayout& ebisl = this->
getEBISLayout(realmFrom, a_phase)[lvl];
851 const Real dx = this->
getDx()[lvl];
852 const Real tol = a_tolerance * dx;
854 const int nbox = dit.size();
855 #pragma omp parallel for schedule(runtime)
856 for (
int mybox = 0; mybox < nbox; mybox++) {
857 const DataIndex& din = dit[mybox];
858 const EBISBox& ebisBox = ebisl[din];
859 const Box region = ebisBox.getRegion();
861 const bool isRegular = ebisBox.isAllRegular();
862 const bool isCovered = ebisBox.isAllCovered();
863 const bool isIrregular = !isRegular && !isCovered;
865 List<P>& particlesFrom = a_particlesFrom[lvl][din].listItems();
866 List<P>& particlesTo = a_particlesTo[lvl][din].listItems();
869 particlesTo.catenate(particlesFrom);
871 else if (isIrregular) {
872 for (ListIterator<P> lit(particlesFrom); lit.ok();) {
873 const P& particle = lit();
874 const RealVect& pos = particle.position();
879 CH_assert(region.contains(iv));
881 if (ebisBox.isCovered(iv)) {
882 particlesTo.transfer(lit);
884 else if (ebisBox.isIrregular(iv)) {
887 bool insideAtLeastOneVoF =
false;
891 const std::vector<VolIndex> vofs = ebisBox.getVoFs(iv).stdVector();
892 for (
const auto& vof : vofs) {
894 const RealVect ebNormal = ebisBox.normal(vof);
895 const Real faceProjection = ebNormal.dotProduct(pos - ebCentroid);
897 if (faceProjection >= -tol) {
898 insideAtLeastOneVoF =
true;
904 if (!insideAtLeastOneVoF) {
905 particlesTo.transfer(lit);
924 const phase::which_phase& a_phase)
const
926 CH_TIME(
"AmrMesh::transferCoveredParticlesVoxels");
928 pout() <<
"AmrMesh::transferCoveredParticlesVoxels" << endl;
935 const std::string realmFrom = a_particlesFrom.
getRealm();
936 const std::string realmTo = a_particlesTo.
getRealm();
938 CH_assert(realmFrom == realmTo);
941 const DisjointBoxLayout& dbl = this->
getGrids(realmFrom)[lvl];
942 const DataIterator dit = dbl.dataIterator();
943 const EBISLayout& ebisl = this->
getEBISLayout(realmFrom, a_phase)[lvl];
944 const Real dx = this->
getDx()[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];
950 const EBISBox& ebisBox = ebisl[din];
951 const Box region = ebisBox.getRegion();
953 const bool isRegular = ebisBox.isAllRegular();
954 const bool isCovered = ebisBox.isAllCovered();
955 const bool isIrregular = !isRegular && !isCovered;
957 List<P>& particlesFrom = a_particlesFrom[lvl][din].listItems();
958 List<P>& particlesTo = a_particlesTo[lvl][din].listItems();
961 particlesTo.catenate(particlesFrom);
963 else if (isIrregular) {
964 for (ListIterator<P> lit(particlesFrom); lit.ok();) {
965 const P& particle = lit();
966 const RealVect& pos = particle.position();
971 CH_assert(region.contains(iv));
973 if (ebisBox.isCovered(iv)) {
974 particlesTo.transfer(lit);
989 const phase::which_phase a_phase,
990 const std::function<
void(P&)> a_transferModifier)
const noexcept
992 CH_TIME(
"AmrMesh::transferIrregularParticles");
993 if (m_verbosity > 5) {
994 pout() <<
"AmrMesh::transferIrregularParticles" << endl;
999 const std::string realm = a_dstParticles.
getRealm();
1001 for (
int lvl = 0; lvl <= m_finestLevel; lvl++) {
1002 const DisjointBoxLayout& dbl = this->getGrids(realm)[lvl];
1003 const DataIterator& dit = dbl.dataIterator();
1004 const EBISLayout& ebisl = this->getEBISLayout(realm, a_phase)[lvl];
1005 const ProblemDomain& domain = this->getDomains()[lvl];
1006 const RealVect probLo = this->getProbLo();
1007 const Real dx = this->getDx()[lvl];
1009 const int nbox = dit.size();
1010 #pragma omp parallel for schedule(runtime)
1011 for (
int mybox = 0; mybox < nbox; mybox++) {
1012 const DataIndex& din = dit[mybox];
1014 const Box cellBox = dbl[din];
1015 const EBISBox& ebisbox = ebisl[din];
1017 List<P>& dstParticles = a_dstParticles[lvl][din].listItems();
1018 List<P>& srcParticles = a_srcParticles[lvl][din].listItems();
1020 for (ListIterator<P> lit(srcParticles); lit.ok();) {
1025 if (!(cellBox.contains(iv))) {
1026 MayDay::Warning(
"CD_AmrMeshImplem.H in routine 'transferIrregularParticles' - particle not in box!");
1031 if (ebisbox.isIrregular(iv)) {
1032 bool insideAnyVoF =
false;
1034 const Vector<VolIndex> allVoFs = ebisbox.getVoFs(iv);
1036 for (
int i = 0; i < allVoFs.size(); i++) {
1037 const VolIndex& vof = allVoFs[i];
1038 const RealVect normal = ebisbox.normal(vof);
1039 const RealVect ebPos = probLo +
Location::position(Location::Cell::Boundary, vof, ebisbox, dx);
1042 if ((p.position() - ebPos).dotProduct(normal) >= 0.0) {
1043 insideAnyVoF =
true;
1047 if (!insideAnyVoF) {
1048 const VolIndex& vof = allVoFs[0];
1049 const RealVect ebPos = probLo +
Location::position(Location::Cell::Boundary, vof, ebisbox, dx);
1051 p.position() = ebPos;
1053 a_transferModifier(p);
1055 dstParticles.transfer(lit);
1074 const phase::which_phase a_phase,
1075 const Real a_tolerance,
1076 const bool a_deleteParticles,
1077 const std::function<
void(P&)> a_nonDeletionModifier)
const noexcept
1079 CH_TIME(
"AmrMesh::intersectParticlesRaycastIF");
1080 if (m_verbosity > 5) {
1081 pout() <<
"AmrMesh::intersectParticlesRaycastIF" << endl;
1090 const std::string whichRealm = a_activeParticles.
getRealm();
1093 RefCountedPtr<BaseIF> implicitFunction;
1097 implicitFunction = m_baseif.at(phase::gas);
1101 case phase::solid: {
1102 implicitFunction = m_baseif.at(phase::solid);
1107 MayDay::Error(
"AmrMesh::intersectParticlesRaycastIF - logic bust");
1114 constexpr Real safety = 1.E-12;
1117 for (
int lvl = 0; lvl <= m_finestLevel; lvl++) {
1120 const DisjointBoxLayout& dbl = this->getGrids(whichRealm)[lvl];
1121 const DataIterator& dit = dbl.dataIterator();
1123 const int nbox = dit.size();
1124 #pragma omp parallel for schedule(runtime)
1125 for (
int mybox = 0; mybox < nbox; mybox++) {
1126 const DataIndex& din = dit[mybox];
1128 List<P>& activeParticles = a_activeParticles[lvl][din].listItems();
1129 List<P>& ebParticles = a_ebParticles[lvl][din].listItems();
1130 List<P>& domainParticles = a_domainParticles[lvl][din].listItems();
1132 for (ListIterator<P> lit(activeParticles); lit.ok();) {
1133 P& particle = lit();
1135 const RealVect newPos = particle.position();
1136 const RealVect oldPos = particle.oldPosition();
1137 const RealVect path = newPos - oldPos;
1140 bool checkEB =
false;
1141 bool checkDomain =
false;
1143 if (!implicitFunction.isNull()) {
1146 for (
int dir = 0; dir < SpaceDim; dir++) {
1147 const bool outsideLo = newPos[dir] < m_probLo[dir];
1148 const bool outsideHi = newPos[dir] > m_probHi[dir];
1150 if (outsideLo || outsideHi) {
1156 if (checkEB || checkDomain) {
1162 bool contactDomain =
false;
1163 bool contactEB =
false;
1178 if (contactDomain || contactEB) {
1179 if (sEB <= sDomain) {
1180 const RealVect intersectionPos = oldPos + sEB * path;
1184 if (a_deleteParticles) {
1185 particle.position() = intersectionPos;
1187 ebParticles.transfer(lit);
1192 p.position() = intersectionPos;
1196 a_nonDeletionModifier(particle);
1203 const Real sSafety =
std::max((Real)0.0, sDomain - safety);
1205 const RealVect intersectionPos = oldPos + sSafety * path;
1207 if (a_deleteParticles) {
1208 particle.position() = intersectionPos;
1210 domainParticles.transfer(lit);
1215 p.position() = intersectionPos;
1217 domainParticles.add(p);
1219 a_nonDeletionModifier(particle);
1237 a_ebParticles.
remap();
1238 a_domainParticles.
remap();
1246 const phase::which_phase a_phase,
1247 const Real a_bisectionStep,
1248 const bool a_deleteParticles,
1249 const std::function<
void(P&)> a_nonDeletionModifier)
const noexcept
1251 CH_TIME(
"AmrMesh::intersectParticlesBisectIF");
1252 if (m_verbosity > 5) {
1253 pout() <<
"AmrMesh::intersectParticlesBisectIF" << endl;
1265 const std::string whichRealm = a_activeParticles.
getRealm();
1268 RefCountedPtr<BaseIF> implicitFunction;
1272 implicitFunction = m_baseif.at(phase::gas);
1276 case phase::solid: {
1277 implicitFunction = m_baseif.at(phase::solid);
1282 MayDay::Error(
"AmrMesh::intersectParticlesBisectIF - logic bust");
1289 constexpr Real safety = 1.E-12;
1292 for (
int lvl = 0; lvl <= m_finestLevel; lvl++) {
1295 const DisjointBoxLayout& dbl = this->getGrids(whichRealm)[lvl];
1296 const DataIterator& dit = dbl.dataIterator();
1298 const int nbox = dit.size();
1299 #pragma omp parallel for schedule(runtime)
1300 for (
int mybox = 0; mybox < nbox; mybox++) {
1301 const DataIndex& din = dit[mybox];
1303 List<P>& activeParticles = a_activeParticles[lvl][din].listItems();
1304 List<P>& ebParticles = a_ebParticles[lvl][din].listItems();
1305 List<P>& domainParticles = a_domainParticles[lvl][din].listItems();
1307 for (ListIterator<P> lit(activeParticles); lit.ok();) {
1308 P& particle = lit();
1310 const RealVect newPos = particle.position();
1311 const RealVect oldPos = particle.oldPosition();
1312 const RealVect path = newPos - oldPos;
1315 bool checkEB =
false;
1316 bool checkDomain =
false;
1318 if (!implicitFunction.isNull()) {
1321 for (
int dir = 0; dir < SpaceDim; dir++) {
1322 const bool outsideLo = newPos[dir] < m_probLo[dir];
1323 const bool outsideHi = newPos[dir] > m_probHi[dir];
1325 if (outsideLo || outsideHi) {
1331 if (checkEB || checkDomain) {
1337 bool contactDomain =
false;
1338 bool contactEB =
false;
1353 if (contactDomain || contactEB) {
1354 if (sEB <= sDomain) {
1356 const RealVect intersectionPos = oldPos + sEB * path;
1358 if (a_deleteParticles) {
1359 particle.position() = intersectionPos;
1361 ebParticles.transfer(lit);
1366 p.position() = intersectionPos;
1372 a_nonDeletionModifier(particle);
1377 const Real sSafety =
std::max((Real)0.0, sDomain - safety);
1379 const RealVect intersectionPos = oldPos + sSafety * path;
1381 if (a_deleteParticles) {
1382 particle.position() = intersectionPos;
1384 domainParticles.transfer(lit);
1389 p.position() = intersectionPos;
1391 domainParticles.add(p);
1395 a_nonDeletionModifier(particle);
1411 a_ebParticles.
remap();
1412 a_domainParticles.
remap();
1415 #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:26
CopyStrategy
Enum for distinguishing how we copy data Valid => valid region ValidGhost => valid+ghost region.
Definition: CD_CopyStrategy.H:23
DepositionType
Deposition types.
Definition: CD_DepositionType.H:23
Declaration of a static class containing some common useful particle routines that would otherwise be...
void removeCoveredParticlesVoxels(ParticleContainer< P > &a_particles, const phase::which_phase &a_phase) const
Function which removes particles from the domain if they fall inside the EB.
Definition: CD_AmrMeshImplem.H:695
void transferCoveredParticlesDiscrete(ParticleContainer< P > &a_particlesFrom, ParticleContainer< P > &a_particlesTo, const phase::which_phase &a_phase, const Real a_tolerance=0.0) const
Function which transferse particles from one particle container to another if they fall inside the EB...
Definition: CD_AmrMeshImplem.H:828
const AMRMask & getValidCells(const std::string a_realm) const
Get a map of all valid cells on a specified realm.
Definition: CD_AmrMesh.cpp:3038
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:22
void transferCoveredParticlesIF(ParticleContainer< P > &a_particlesFrom, ParticleContainer< P > &a_particlesTo, const phase::which_phase &a_phase, const Real a_tolerance=0.0) const
Function which transferse particles from one particle container to another if they fall inside the EB...
Definition: CD_AmrMeshImplem.H:754
int m_maxBoxSize
Max box size.
Definition: CD_AmrMesh.H:2001
RealVect m_probLo
Domain simulation corner.
Definition: CD_AmrMesh.H:1961
void remapToNewGrids(ParticleContainer< P > &a_particles, const int a_lmin, const int a_newFinestLevel) const noexcept
Regrid particle to new grids.
Definition: CD_AmrMeshImplem.H:362
void transferIrregularParticles(ParticleContainer< P > &a_dstParticles, ParticleContainer< P > &a_srcParticles, const phase::which_phase a_phase, const std::function< void(P &)> a_transferModifier=[](P &) -> void { return;}) const noexcept
Transfer particles that are on the wrong side of the EB to a different container.
Definition: CD_AmrMeshImplem.H:987
bool queryRealm(const std::string a_realm) const
Query if a realm exists.
Definition: CD_AmrMesh.cpp:3310
void removeCoveredParticlesIF(ParticleContainer< P > &a_particles, const phase::which_phase &a_phase, const Real a_tolerance=0.0) const
Function which removes particles from the domain if they fall inside the EB.
Definition: CD_AmrMeshImplem.H:539
void depositParticles(EBAMRCellData &a_meshData, const std::string &a_realm, const phase::which_phase &a_phase, const ParticleContainer< P > &a_particles, const DepositionType a_depositionType, const CoarseFineDeposition a_coarseFineDeposition, const bool a_forceIrregNGP=false)
Deposit scalar particle quantities on the mesh.
Definition: CD_AmrMeshImplem.H:383
int m_verbosity
Verbosity.
Definition: CD_AmrMesh.H:1976
void intersectParticlesRaycastIF(ParticleContainer< P > &a_activeParticles, ParticleContainer< P > &a_ebParticles, ParticleContainer< P > &a_domainParticles, const phase::which_phase a_phase, const Real a_tolerance, const bool a_deleteParticles, const std::function< void(P &)> a_nonDeletionModifier=[](P &) -> void { return;}) const noexcept
Particle intersection algorithm based on ray-casting.
Definition: CD_AmrMeshImplem.H:1071
void removeCoveredParticlesDiscrete(ParticleContainer< P > &a_particles, const phase::which_phase &a_phase, const Real a_tolerance=0.0) const
Function which removes particles from the domain if they fall inside the EB.
Definition: CD_AmrMeshImplem.H:605
Vector< Real > m_dx
Level resolutions.
Definition: CD_AmrMesh.H:2111
const Vector< DisjointBoxLayout > & getGrids(const std::string a_realm) const
Get the grids.
Definition: CD_AmrMesh.cpp:2972
void intersectParticlesBisectIF(ParticleContainer< P > &a_activeParticles, ParticleContainer< P > &a_ebParticles, ParticleContainer< P > &a_domainParticles, const phase::which_phase a_phase, const Real a_bisectionStep, const bool a_deleteParticles, const std::function< void(P &)> a_nonDeletionModifier=[](P &) -> void { return;}) const noexcept
Particle intersection algorithm based on bisection.
Definition: CD_AmrMeshImplem.H:1243
int m_finestLevel
Finest level.
Definition: CD_AmrMesh.H:1981
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:2988
std::map< phase::which_phase, RefCountedPtr< BaseIF > > m_baseif
Implicit functions.
Definition: CD_AmrMesh.H:1875
void interpolateParticles(ParticleContainer< P > &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=false) const
Interpolate a scalar field onto the particle position.
Definition: CD_AmrMeshImplem.H:495
const Vector< Real > & getDx() const
Get spatial resolutions.
Definition: CD_AmrMesh.cpp:2917
std::map< std::string, RefCountedPtr< Realm > > m_realms
These are all the Realms.
Definition: CD_AmrMesh.H:1870
int m_blockingFactor
Blocking factor.
Definition: CD_AmrMesh.H:2016
void allocatePointer(Vector< RefCountedPtr< T >> &a_data) const
Allocate pointer but not any memory blocks.
Definition: CD_AmrMeshImplem.H:303
void allocate(Vector< RefCountedPtr< ParticleData< T >>> &a_particles, const std::string a_realm) const
Template class for generic allocation of particle data.
Definition: CD_AmrMeshImplem.H:237
void transferCoveredParticlesVoxels(ParticleContainer< P > &a_particlesFrom, ParticleContainer< P > &a_particlesTo, const phase::which_phase &a_phase) const
Function which transferse particles from one particle container to another if they fall inside the EB...
Definition: CD_AmrMeshImplem.H:922
EBAMRParticleMesh & getParticleMesh(const std::string a_realm, const phase::which_phase a_phase) const
Get EBAMRParticleMesh operator.
Definition: CD_AmrMesh.cpp:3137
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:209
void deallocate(Vector< T * > &a_data) const
Deallocate data.
Definition: CD_AmrMeshImplem.H:161
const Vector< int > & getRefinementRatios() const
Get refinement ratios.
Definition: CD_AmrMesh.cpp:2928
const Vector< RefCountedPtr< LevelTiles > > & getLevelTiles(const std::string a_realm) const
Get the tiled space representation.
Definition: CD_AmrMesh.cpp:3054
const Vector< ProblemDomain > & getDomains() const
Get domains.
Definition: CD_AmrMesh.cpp:2950
Default class for holding LevelData<T> data across an EBAMR realm.
Definition: CD_EBAMRData.H:40
void setRealm(const std::string a_realm) noexcept
Sets the realm for this object.
Definition: CD_EBAMRDataImplem.H:142
Vector< RefCountedPtr< LevelData< T > > > & getData() noexcept
Get underlying data. Returns m_data.
Definition: CD_EBAMRDataImplem.H:114
const std::string getRealm() const noexcept
Returns the string identifier for whatever realm this data is supposed to be allocated over.
Definition: CD_EBAMRDataImplem.H:135
Class for handling particle-mesh operations with AMR.
Definition: CD_EBAMRParticleMesh.H:47
void interpolate(ParticleContainer< P > &a_particles, const EBAMRCellData &a_meshVectorField, const DepositionType a_interpType, const bool a_forceIrregNGP=false) const
Interpolate a scalar field onto the particle position.
Definition: CD_EBAMRParticleMeshImplem.H:612
void deposit(EBAMRCellData &a_meshData, const ParticleContainer< P > &a_particles, const DepositionType a_depositionType, const CoarseFineDeposition a_coarseFineDeposition, const bool a_forceIrregNGP=false)
Class for deposition of particles of a type P to the mesh. This does scalar quantities.
Definition: CD_EBAMRParticleMeshImplem.H:29
class for handling surface deposition of particles with EB and AMR.
Definition: CD_EBAMRSurfaceDeposition.H:29
void deposit(EBAMRIVData &a_meshData, const ParticleContainer< P > &a_particles) const noexcept
Deposit function. Deposits particle on surface.
Definition: CD_EBAMRSurfaceDepositionImplem.H:28
Templated class for holding particles on an AMR hierarchy with particle remapping.
Definition: CD_ParticleContainer.H:50
void define(const Vector< DisjointBoxLayout > &a_grids, const Vector< ProblemDomain > &a_domains, const Vector< Real > &a_dx, const Vector< int > &a_refRat, const Vector< ValidMask > &a_validMask, const Vector< RefCountedPtr< LevelTiles >> &a_levelTiles, const RealVect &a_probLo, const int a_blockingFactor, const int a_finestLevel, const std::string a_realm)
Define the container. This will do a clear-out of all particles.
Definition: CD_ParticleContainerImplem.H:77
void clear(AMRParticles< P > &a_particles) const
Clear particles on input data holder.
Definition: CD_ParticleContainerImplem.H:1712
void remap()
Remap over the entire AMR hierarchy.
Definition: CD_ParticleContainerImplem.H:973
void clearParticles()
Clear all particles.
Definition: CD_ParticleContainerImplem.H:1670
const std::string getRealm() const
Get the realm where this ParticleContainer lives.
Definition: CD_ParticleContainerImplem.H:240
bool isOrganizedByCell() const
Is cell-sorted or not.
Definition: CD_ParticleContainerImplem.H:224
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:217
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:173
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:26
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:127
RealVect position(const 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:20
Real max(const Real &a_input) noexcept
Get the maximum of the input, reduced over MPI ranks (in the Chombo communicator)
Definition: CD_ParallelOpsImplem.H:176