Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 13 additions & 20 deletions src/amr/data/field/coarsening/field_coarsen_operator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,42 +95,35 @@ 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<GridLayoutT, PhysicalQuantity>;

// we assume that quantity are the same
// note that an assertion will be raised
// in coarseIt operator
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<GridLayoutT, PhysicalQuantity>::toFieldBox(
destinationPatch.getBox(), qty, destinationLayout, withGhost);
auto destPData = destinationPatch.getPatchData(destinationId);
auto srcPData = sourcePatch.getPatchData(sourceId);

auto sourceBox = FieldGeometry<GridLayoutT, PhysicalQuantity>::toFieldBox(
sourcePatch.getBox(), qty, sourceLayout, withGhost);

auto coarseLayout = FieldGeometry<GridLayoutT, PhysicalQuantity>::layoutFromBox(
coarseBox, destinationLayout);

auto coarseFieldBox = FieldGeometry<GridLayoutT, PhysicalQuantity>::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

Expand Down
22 changes: 10 additions & 12 deletions src/amr/data/field/field_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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};

Expand Down Expand Up @@ -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};
Expand Down Expand Up @@ -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};
Expand Down
105 changes: 24 additions & 81 deletions src/amr/data/field/field_geometry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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}
{
Expand Down Expand Up @@ -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<FieldOverlap>(destinationBox, offset);
return std::make_shared<FieldOverlap>(destinationBoxes, offset);
}


Expand All @@ -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;
Expand Down Expand Up @@ -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<dimension>( //
[&](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;
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
28 changes: 12 additions & 16 deletions src/amr/data/field/refine/field_refine_operator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,40 +90,36 @@ 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.
// Note that an assertion will be raised
// 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)
{
// 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;



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,17 @@ class FieldLinearTimeInterpolate : public SAMRAI::hier::TimeInterpolateOperator
auto const whereLayout
= FieldGeometry<GridLayoutT, PhysicalQuantity>::layoutFromBox(where, layout);

bool const withGhost{true};
auto qty = fieldDest.physicalQuantity();
auto const interpolateBox = FieldGeometry<GridLayoutT, PhysicalQuantity>::toFieldBox(
where, qty, whereLayout, !withGhost);
auto qty = fieldDest.physicalQuantity();
auto const interpolateBox
= FieldGeometry<GridLayoutT, PhysicalQuantity>::toFieldBox(where, qty, whereLayout);

auto const ghostBox = FieldGeometry<GridLayoutT, PhysicalQuantity>::toFieldBox(
fieldDataDest.getBox(), qty, layout, withGhost);
fieldDataDest.getGhostBox(), qty, layout);

auto const finalBox = interpolateBox * ghostBox;

auto srcGhostBox = FieldGeometry<GridLayoutT, PhysicalQuantity>::toFieldBox(
fieldDataSrcNew.getBox(), qty, fieldDataSrcNew.gridLayout, withGhost);
fieldDataSrcNew.getGhostBox(), qty, fieldDataSrcNew.gridLayout);

auto const localDestBox = AMRToLocal(finalBox, ghostBox);
auto const localSrcBox = AMRToLocal(finalBox, srcGhostBox);
Expand Down
1 change: 0 additions & 1 deletion src/core/data/grid/gridlayout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ namespace core
NO_DISCARD auto const& AMRBox() const { return AMRBox_; }



NO_DISCARD static std::size_t constexpr nbrParticleGhosts()
{
return ghostWidthForParticles<interp_order>();
Expand Down
Loading