diff --git a/src/amr/data/field/coarsening/field_coarsen_operator.hpp b/src/amr/data/field/coarsening/field_coarsen_operator.hpp index c75a8e95d..02ff02029 100644 --- a/src/amr/data/field/coarsening/field_coarsen_operator.hpp +++ b/src/amr/data/field/coarsening/field_coarsen_operator.hpp @@ -95,10 +95,11 @@ namespace amr SAMRAI::hier::Box const& coarseBox, SAMRAI::hier::IntVector const& ratio) const override { - auto& destinationField = FieldDataT::getField(destinationPatch, destinationId); - auto const& sourceField = FieldDataT::getField(sourcePatch, sourceId); - auto const& sourceLayout = FieldDataT::getLayout(sourcePatch, sourceId); - auto const& destinationLayout = FieldDataT::getLayout(destinationPatch, destinationId); + auto& destinationField = FieldDataT::getField(destinationPatch, destinationId); + auto const& sourceField = FieldDataT::getField(sourcePatch, sourceId); + auto const& sourceLayout = FieldDataT::getLayout(sourcePatch, sourceId); + auto const& destLayout = FieldDataT::getLayout(destinationPatch, destinationId); + using FieldGeometryT = FieldGeometry; // we assume that quantity are the same // note that an assertion will be raised @@ -106,31 +107,23 @@ namespace amr auto const& qty = destinationField.physicalQuantity(); - bool const withGhost{true}; // We get different boxes : destination , source, restrictBoxes // and transform them in the correct indexing. - auto destinationBox = FieldGeometry::toFieldBox( - destinationPatch.getBox(), qty, destinationLayout, withGhost); + auto destPData = destinationPatch.getPatchData(destinationId); + auto srcPData = sourcePatch.getPatchData(sourceId); - auto sourceBox = FieldGeometry::toFieldBox( - sourcePatch.getBox(), qty, sourceLayout, withGhost); - - auto coarseLayout = FieldGeometry::layoutFromBox( - coarseBox, destinationLayout); - - auto coarseFieldBox = FieldGeometry::toFieldBox( - coarseBox, qty, coarseLayout, !withGhost); - - // finnaly we compute the intersection - auto intersectionBox = destinationBox * coarseFieldBox; + auto destGBox = FieldGeometryT::toFieldBox(destPData->getGhostBox(), qty, destLayout); + auto srcGBox = FieldGeometryT::toFieldBox(srcPData->getGhostBox(), qty, sourceLayout); + auto coarseLayout = FieldGeometryT::layoutFromBox(coarseBox, destLayout); + auto coarseFieldBox = FieldGeometryT::toFieldBox(coarseBox, qty, coarseLayout); + auto const intersectionBox = destGBox * coarseFieldBox; // We can now create the coarsening operator - FieldCoarsenerPolicy coarsener{destinationLayout.centering(qty), sourceBox, - destinationBox, ratio}; + FieldCoarsenerPolicy coarsener{destLayout.centering(qty), srcGBox, destGBox, ratio}; // now we can loop over the intersection box diff --git a/src/amr/data/field/field_data.hpp b/src/amr/data/field/field_data.hpp index 385393be7..6a57411f6 100644 --- a/src/amr/data/field/field_data.hpp +++ b/src/amr/data/field/field_data.hpp @@ -123,16 +123,14 @@ namespace amr TBOX_ASSERT(quantity_ == fieldSource.quantity_); // First step is to translate the AMR box into proper index space of the given // quantity_ using the source gridlayout to accomplish that we get the interior box, - // from the FieldData. and we call toFieldBox (with the default parameter withGhost - // = true). note that we could have stored the ghost box of the field data at - // creation + // from the FieldData. - SAMRAI::hier::Box sourceBox - = Geometry::toFieldBox(fieldSource.getBox(), quantity_, fieldSource.gridLayout); + SAMRAI::hier::Box sourceBox = Geometry::toFieldBox(fieldSource.getGhostBox(), quantity_, + fieldSource.gridLayout); SAMRAI::hier::Box destinationBox - = Geometry::toFieldBox(this->getBox(), quantity_, this->gridLayout); + = Geometry::toFieldBox(this->getGhostBox(), quantity_, this->gridLayout); // Given the two boxes in correct space we just have to intersect them SAMRAI::hier::Box intersectionBox = sourceBox * destinationBox; @@ -240,7 +238,7 @@ namespace amr { auto const& source = field; SAMRAI::hier::Box sourceBox - = Geometry::toFieldBox(getBox(), quantity_, gridLayout); + = Geometry::toFieldBox(getGhostBox(), quantity_, gridLayout); SAMRAI::hier::Box packBox{box}; @@ -298,7 +296,7 @@ namespace amr auto& source = field; SAMRAI::hier::Box destination - = Geometry::toFieldBox(getBox(), quantity_, gridLayout); + = Geometry::toFieldBox(getGhostBox(), quantity_, gridLayout); SAMRAI::hier::Box packBox{box * destination}; @@ -396,12 +394,12 @@ namespace amr { for (auto const& box : boxList) { - SAMRAI::hier::Box sourceBox - = Geometry::toFieldBox(source.getBox(), quantity_, source.gridLayout); + SAMRAI::hier::Box sourceBox = Geometry::toFieldBox( + source.getGhostBox(), quantity_, source.gridLayout); - SAMRAI::hier::Box destinationBox - = Geometry::toFieldBox(this->getBox(), quantity_, this->gridLayout); + SAMRAI::hier::Box destinationBox = Geometry::toFieldBox( + this->getGhostBox(), quantity_, this->gridLayout); SAMRAI::hier::Box transformedSource{sourceBox}; diff --git a/src/amr/data/field/field_geometry.hpp b/src/amr/data/field/field_geometry.hpp index 8db1383b4..fc424915c 100644 --- a/src/amr/data/field/field_geometry.hpp +++ b/src/amr/data/field/field_geometry.hpp @@ -10,6 +10,7 @@ #include "SAMRAI/hier/IntVector.h" #include "core/data/grid/gridlayoutdefs.hpp" #include "core/data/grid/gridlayout.hpp" +#include "core/utilities/types.hpp" #include "field_overlap.hpp" @@ -88,8 +89,12 @@ namespace amr */ FieldGeometry(SAMRAI::hier::Box const& box, GridLayoutT const& layout, PhysicalQuantity const qty) - : Super(box, toFieldBox(box, qty, layout), - toFieldBox(box, qty, layout, /*withGhost=*/false), GridLayoutT::centering(qty)) + : Super(box, + toFieldBox(SAMRAI::hier::Box::grow( + box, SAMRAI::hier::IntVector{SAMRAI::tbox::Dimension{dimension}, + GridLayoutT::nbrGhosts()}), + qty, layout), + toFieldBox(box, qty, layout), GridLayoutT::centering(qty)) , layout_{layout} , quantity_{qty} { @@ -128,16 +133,15 @@ namespace amr setUpOverlap(SAMRAI::hier::BoxContainer const& boxes, SAMRAI::hier::Transformation const& offset) const final { - SAMRAI::hier::BoxContainer destinationBox; + SAMRAI::hier::BoxContainer destinationBoxes; for (auto& box : boxes) { - core::GridLayout layout = layoutFromBox(box, layout_); - SAMRAI::hier::Box fieldBox(toFieldBox(box, quantity_, layout, false)); - destinationBox.push_back(fieldBox); + core::GridLayout const layout = layoutFromBox(box, layout_); + destinationBoxes.push_back(toFieldBox(box, quantity_, layout)); } - return std::make_shared(destinationBox, offset); + return std::make_shared(destinationBoxes, offset); } @@ -153,9 +157,10 @@ namespace amr * to the nbr of cells of the box. */ static SAMRAI::hier::Box toFieldBox(SAMRAI::hier::Box box, PhysicalQuantity qty, - GridLayoutT const& layout, bool withGhost = true) + GridLayoutT const& layout) { SAMRAI::hier::IntVector lower = box.lower(); + SAMRAI::hier::IntVector upper = box.upper(); using PHARE::core::dirX; using PHARE::core::dirY; using PHARE::core::dirZ; @@ -183,76 +188,15 @@ namespace amr // box.lower must be shifted left to move to the first ghost node // box.upper is still box.lower + end-start, end &start of ghosts + auto const centerings = layout.centering(qty); + core::for_N( // + [&](auto i) { + box.setLower(i, lower[i]); + auto const is_primal = (centerings[i] == core::QtyCentering::primal) ? 1 : 0; + box.setUpper(i, upper[i] + is_primal); + } // + ); - if (!withGhost) - { - std::int32_t xStart = layout.physicalStartIndex(qty, core::Direction::X); - std::int32_t xEnd = layout.physicalEndIndex(qty, core::Direction::X); - - box.setLower(dirX, lower[dirX]); - box.setUpper(dirX, xEnd - xStart + lower[dirX]); - - if (dimension > 1) - { - std::int32_t yStart = layout.physicalStartIndex(qty, core::Direction::Y); - std::int32_t yEnd = layout.physicalEndIndex(qty, core::Direction::Y); - - box.setLower(dirY, lower[dirY]); - box.setUpper(dirY, yEnd - yStart + lower[dirY]); - } - if (dimension > 2) - { - std::int32_t zStart = layout.physicalStartIndex(qty, core::Direction::Z); - std::int32_t zEnd = layout.physicalEndIndex(qty, core::Direction::Z); - - box.setLower(dirZ, lower[dirZ]); - box.setUpper(dirZ, zEnd - zStart + lower[dirZ]); - } - } // end withoutGhosts - - - - else - { - auto const& centering = GridLayoutT::centering(qty); - - SAMRAI::hier::IntVector shift(box.getDim()); - shift[dirX] = layout.nbrGhosts(centering[dirX]); - - if (dimension > 1) - { - shift[dirY] = layout.nbrGhosts(centering[dirY]); - } - if (dimension > 2) - { - shift[dirZ] = layout.nbrGhosts(centering[dirZ]); - } - - lower = lower - shift; - - std::int32_t xStart = layout.ghostStartIndex(qty, core::Direction::X); - std::int32_t xEnd = layout.ghostEndIndex(qty, core::Direction::X); - - box.setLower(dirX, lower[dirX]); - box.setUpper(dirX, xEnd - xStart + lower[dirX]); - - if (dimension > 1) - { - std::int32_t yStart = layout.ghostStartIndex(qty, core::Direction::Y); - std::int32_t yEnd = layout.ghostEndIndex(qty, core::Direction::Y); - - box.setLower(dirY, lower[dirY]); - box.setUpper(dirY, yEnd - yStart + lower[dirY]); - } - if (dimension > 2) - { - std::int32_t zStart = layout.ghostStartIndex(qty, core::Direction::Z); - std::int32_t zEnd = layout.ghostEndIndex(qty, core::Direction::Z); - - box.setLower(dirZ, lower[dirZ]); - box.setUpper(dirZ, zEnd - zStart + lower[dirZ]); - } - } return box; } @@ -333,10 +277,9 @@ namespace amr auto const& destinationBox = this->ghostFieldBox_; SAMRAI::hier::Box const sourceBox{ - toFieldBox(sourceShift, quantity_, sourceShiftLayout, !withGhosts)}; + toFieldBox(sourceShift, quantity_, sourceShiftLayout)}; - SAMRAI::hier::Box const fillField{ - toFieldBox(fillBox, quantity_, fillBoxLayout, !withGhosts)}; + SAMRAI::hier::Box const fillField{toFieldBox(fillBox, quantity_, fillBoxLayout)}; // now we have all boxes shifted and translated to field boxes @@ -367,7 +310,7 @@ namespace amr box != destinationRestrictBoxes.end(); ++box) { restrictBoxes.push_back( - toFieldBox(*box, quantity_, layoutFromBox(*box, layout_), !withGhosts)); + toFieldBox(*box, quantity_, layoutFromBox(*box, layout_))); } // will only keep of together the boxes that interesect the restrictions diff --git a/src/amr/data/field/refine/field_refine_operator.hpp b/src/amr/data/field/refine/field_refine_operator.hpp index 436195b2d..7ba73cf41 100644 --- a/src/amr/data/field/refine/field_refine_operator.hpp +++ b/src/amr/data/field/refine/field_refine_operator.hpp @@ -90,10 +90,10 @@ class FieldRefineOperator : public SAMRAI::hier::RefineOperator, public AFieldRe auto const& overlapBoxes = destinationFieldOverlap.getDestinationBoxContainer(); - auto& destinationField = FieldDataT::getField(destination, destinationId); - auto const& destinationLayout = FieldDataT::getLayout(destination, destinationId); - auto const& sourceField = FieldDataT::getField(source, sourceId); - auto const& sourceLayout = FieldDataT::getLayout(source, sourceId); + auto& destinationField = FieldDataT::getField(destination, destinationId); + auto const& destLayout = FieldDataT::getLayout(destination, destinationId); + auto const& sourceField = FieldDataT::getField(source, sourceId); + auto const& srcLayout = FieldDataT::getLayout(source, sourceId); // We assume that quantity are all the same. @@ -101,21 +101,17 @@ class FieldRefineOperator : public SAMRAI::hier::RefineOperator, public AFieldRe // in refineIt operator auto const& qty = destinationField.physicalQuantity(); - bool const withGhost{true}; - auto destinationFieldBox - = FieldGeometry::toFieldBox(destination.getBox(), qty, destinationLayout, withGhost); + auto const destData = destination.getPatchData(destinationId); + auto const srcData = source.getPatchData(sourceId); + auto const destFieldBox + = FieldGeometry::toFieldBox(destData->getGhostBox(), qty, destLayout); + auto const sourceFieldBox + = FieldGeometry::toFieldBox(srcData->getGhostBox(), qty, srcLayout); - auto sourceFieldBox - = FieldGeometry::toFieldBox(source.getBox(), qty, sourceLayout, withGhost); - - - - - FieldRefinerPolicy refiner{destinationLayout.centering(qty), destinationFieldBox, - sourceFieldBox, ratio}; + FieldRefinerPolicy refiner{destLayout.centering(qty), destFieldBox, sourceFieldBox, ratio}; for (auto const& box : overlapBoxes) @@ -123,7 +119,7 @@ class FieldRefineOperator : public SAMRAI::hier::RefineOperator, public AFieldRe // we compute the intersection with the destination, // and then we apply the refine operation on each fine // index. - auto intersectionBox = destinationFieldBox * box; + auto intersectionBox = destFieldBox * box; diff --git a/src/amr/data/field/time_interpolate/field_linear_time_interpolate.hpp b/src/amr/data/field/time_interpolate/field_linear_time_interpolate.hpp index 3ec28b75d..ab857fa62 100644 --- a/src/amr/data/field/time_interpolate/field_linear_time_interpolate.hpp +++ b/src/amr/data/field/time_interpolate/field_linear_time_interpolate.hpp @@ -65,18 +65,17 @@ class FieldLinearTimeInterpolate : public SAMRAI::hier::TimeInterpolateOperator auto const whereLayout = FieldGeometry::layoutFromBox(where, layout); - bool const withGhost{true}; - auto qty = fieldDest.physicalQuantity(); - auto const interpolateBox = FieldGeometry::toFieldBox( - where, qty, whereLayout, !withGhost); + auto qty = fieldDest.physicalQuantity(); + auto const interpolateBox + = FieldGeometry::toFieldBox(where, qty, whereLayout); auto const ghostBox = FieldGeometry::toFieldBox( - fieldDataDest.getBox(), qty, layout, withGhost); + fieldDataDest.getGhostBox(), qty, layout); auto const finalBox = interpolateBox * ghostBox; auto srcGhostBox = FieldGeometry::toFieldBox( - fieldDataSrcNew.getBox(), qty, fieldDataSrcNew.gridLayout, withGhost); + fieldDataSrcNew.getGhostBox(), qty, fieldDataSrcNew.gridLayout); auto const localDestBox = AMRToLocal(finalBox, ghostBox); auto const localSrcBox = AMRToLocal(finalBox, srcGhostBox); diff --git a/src/core/data/grid/gridlayout.hpp b/src/core/data/grid/gridlayout.hpp index 1b087a999..786b99500 100644 --- a/src/core/data/grid/gridlayout.hpp +++ b/src/core/data/grid/gridlayout.hpp @@ -193,7 +193,6 @@ namespace core NO_DISCARD auto const& AMRBox() const { return AMRBox_; } - NO_DISCARD static std::size_t constexpr nbrParticleGhosts() { return ghostWidthForParticles(); diff --git a/src/core/data/grid/gridlayoutimplyee.hpp b/src/core/data/grid/gridlayoutimplyee.hpp index 76926ce93..d60537315 100644 --- a/src/core/data/grid/gridlayoutimplyee.hpp +++ b/src/core/data/grid/gridlayoutimplyee.hpp @@ -67,47 +67,47 @@ namespace core */ constexpr auto static initLayoutCentering_() { - const gridDataT data{}; - const std::array Bx = {{data.primal, data.dual, data.dual}}; - const std::array By = {{data.dual, data.primal, data.dual}}; - const std::array Bz = {{data.dual, data.dual, data.primal}}; + gridDataT const data{}; + std::array const Bx = {{data.primal, data.dual, data.dual}}; + std::array const By = {{data.dual, data.primal, data.dual}}; + std::array const Bz = {{data.dual, data.dual, data.primal}}; - const std::array Ex = {{data.dual, data.primal, data.primal}}; - const std::array Ey = {{data.primal, data.dual, data.primal}}; - const std::array Ez = {{data.primal, data.primal, data.dual}}; + std::array const Ex = {{data.dual, data.primal, data.primal}}; + std::array const Ey = {{data.primal, data.dual, data.primal}}; + std::array const Ez = {{data.primal, data.primal, data.dual}}; - const std::array Jx = {{data.dual, data.primal, data.primal}}; - const std::array Jy = {{data.primal, data.dual, data.primal}}; - const std::array Jz = {{data.primal, data.primal, data.dual}}; + std::array const Jx = {{data.dual, data.primal, data.primal}}; + std::array const Jy = {{data.primal, data.dual, data.primal}}; + std::array const Jz = {{data.primal, data.primal, data.dual}}; - const std::array Rho + std::array const Rho = {{data.primal, data.primal, data.primal}}; - const std::array Vx + std::array const Vx = {{data.primal, data.primal, data.primal}}; - const std::array Vy + std::array const Vy = {{data.primal, data.primal, data.primal}}; - const std::array Vz + std::array const Vz = {{data.primal, data.primal, data.primal}}; - const std::array Mxx + std::array const Mxx = {{data.primal, data.primal, data.primal}}; - const std::array Mxy + std::array const Mxy = {{data.primal, data.primal, data.primal}}; - const std::array Mxz + std::array const Mxz = {{data.primal, data.primal, data.primal}}; - const std::array Myy + std::array const Myy = {{data.primal, data.primal, data.primal}}; - const std::array Myz + std::array const Myz = {{data.primal, data.primal, data.primal}}; - const std::array Mzz + std::array const Mzz = {{data.primal, data.primal, data.primal}}; - const std::array P = {{data.primal, data.primal, data.primal}}; + std::array const P = {{data.primal, data.primal, data.primal}}; - const std::array, - static_cast(HybridQuantity::Scalar::count)> + std::array, + static_cast(HybridQuantity::Scalar::count)> const hybridQtyCentering{Bx, By, Bz, Ex, Ey, Ez, Jx, Jy, Jz, Rho, Vx, Vy, Vz, P, Mxx, Mxy, Mxz, Myy, Myz, Mzz}; @@ -118,11 +118,11 @@ namespace core //! says for each HybridQuantity::Quantity whether it is primal or dual, in each direction - constexpr const static std::array, - static_cast(HybridQuantity::Scalar::count)> + constexpr static std::array, + static_cast(HybridQuantity::Scalar::count)> const hybridQtyCentering_{initLayoutCentering_()}; - static const std::size_t dim_{dim}; + static std::size_t const dim_{dim}; // ------------------------------------------------------------------------ // PUBLIC INTERFACE @@ -339,7 +339,6 @@ namespace core - NO_DISCARD constexpr static std::array, 3> centering(HybridQuantity::Vector hybridQuantity) { diff --git a/tests/amr/data/field/time_interpolate/test_field_data_time_interpolate.cpp b/tests/amr/data/field/time_interpolate/test_field_data_time_interpolate.cpp index 80861eb61..79e6824ea 100644 --- a/tests/amr/data/field/time_interpolate/test_field_data_time_interpolate.cpp +++ b/tests/amr/data/field/time_interpolate/test_field_data_time_interpolate.cpp @@ -1,4 +1,3 @@ - #include #include "core/def/phare_mpi.hpp" @@ -65,7 +64,7 @@ struct aFieldLinearTimeInterpolate : public ::testing::Test SAMRAI::tbox::SAMRAI_MPI::getSAMRAIWorld().getRank()}; std::string const fieldName{"Bx"}; - SAMRAI::hier::IntVector ghost{dimension, 5}; + SAMRAI::hier::IntVector ghost{dimension, GridYee::nbrGhosts()}; static auto constexpr dl = ConstArray(0.01); static constexpr auto nbrCells = ConstArray(upper - lower + 1); @@ -192,7 +191,6 @@ TYPED_TEST(aFieldLinearTimeInterpolate, giveOldSrcForAlphaZero) this->timeOp.timeInterpolate(*(this->destNew), this->domain, overlap, *(this->srcOld), *(this->srcNew)); - bool const withGhost{true}; static constexpr auto dim = typename TypeParam::first_type{}(); static constexpr auto interp = typename TypeParam::second_type{}(); @@ -200,10 +198,13 @@ TYPED_TEST(aFieldLinearTimeInterpolate, giveOldSrcForAlphaZero) using GridYee = GridLayout>; auto box = FieldGeometry::toFieldBox(this->domain, this->qty, - layout, !withGhost); + layout); - auto ghostBox = FieldGeometry::toFieldBox( - this->domain, this->qty, layout, withGhost); + auto ghostBox_{this->domain}; + ghostBox_.grow(SAMRAI::hier::IntVector{SAMRAI::tbox::Dimension{dim}, + static_cast(GridYee::nbrGhosts())}); + auto ghostBox + = FieldGeometry::toFieldBox(ghostBox_, this->qty, layout); auto localBox = AMRToLocal(static_cast>(box), ghostBox); @@ -273,7 +274,6 @@ TYPED_TEST(aFieldLinearTimeInterpolate, giveNewSrcForAlphaOne) this->timeOp.timeInterpolate(*(this->destNew), this->domain, overlap, *(this->srcOld), *(this->srcNew)); - bool const withGhost{true}; static constexpr auto dim = typename TypeParam::first_type{}(); static constexpr auto interp = typename TypeParam::second_type{}(); @@ -281,10 +281,13 @@ TYPED_TEST(aFieldLinearTimeInterpolate, giveNewSrcForAlphaOne) using GridYee = GridLayout>; auto box = FieldGeometry::toFieldBox(this->domain, this->qty, - layout, !withGhost); + layout); - auto ghostBox = FieldGeometry::toFieldBox( - this->domain, this->qty, layout, withGhost); + auto ghostBox_{this->domain}; + ghostBox_.grow(SAMRAI::hier::IntVector{SAMRAI::tbox::Dimension{dim}, + static_cast(GridYee::nbrGhosts())}); + auto ghostBox + = FieldGeometry::toFieldBox(ghostBox_, this->qty, layout); auto localBox = AMRToLocal(static_cast>(box), ghostBox); @@ -352,7 +355,6 @@ TYPED_TEST(aFieldLinearTimeInterpolate, giveEvaluationOnTheInterpolateTimeForLin this->timeOp.timeInterpolate(*(this->destNew), this->domain, overlap, *(this->srcOld), *(this->srcNew)); - bool const withGhost{true}; static constexpr auto dim = typename TypeParam::first_type{}(); static constexpr auto interp = typename TypeParam::second_type{}(); @@ -360,10 +362,13 @@ TYPED_TEST(aFieldLinearTimeInterpolate, giveEvaluationOnTheInterpolateTimeForLin using GridYee = GridLayout>; auto box = FieldGeometry::toFieldBox(this->domain, this->qty, - layout, !withGhost); + layout); - auto ghostBox = FieldGeometry::toFieldBox( - this->domain, this->qty, layout, withGhost); + auto ghostBox_{this->domain}; + ghostBox_.grow(SAMRAI::hier::IntVector{SAMRAI::tbox::Dimension{dim}, + static_cast(GridYee::nbrGhosts())}); + auto ghostBox + = FieldGeometry::toFieldBox(ghostBox_, this->qty, layout); auto localBox = AMRToLocal(static_cast>(box), ghostBox);