Skip to content
Closed
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
5 changes: 5 additions & 0 deletions src/amr/data/field/field_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,11 @@ namespace amr
SAMRAI::hier::Box const intersectionBox{box * transformedSource
* destinationBox};

std::cout << "copy_ debug all boxes: "
<< "sourceBox: " << sourceBox
<< ", destinationBox: " << destinationBox
<< ", transformedSource: " << transformedSource
<< ", intersectionBox: " << intersectionBox << std::endl;
Comment on lines +401 to +405
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Remove or properly implement debug output

Debug print statements should not be committed to production code. This file already uses the PHARE logging framework (e.g., PHARE_LOG_SCOPE at line 115).

-                        std::cout << "copy_ debug all boxes: "
-                                  << "sourceBox: " << sourceBox
-                                  << ", destinationBox: " << destinationBox
-                                  << ", transformedSource: " << transformedSource
-                                  << ", intersectionBox: " << intersectionBox << std::endl;
+                        // If debug output is needed, use PHARE logging:
+                        // PHARE_LOG_SCOPE(4, "FieldData::copy_::debug_boxes");
+                        // PHARE_LOG_LINE_STR("sourceBox: " << sourceBox
+                        //                   << ", destinationBox: " << destinationBox
+                        //                   << ", transformedSource: " << transformedSource
+                        //                   << ", intersectionBox: " << intersectionBox);
🤖 Prompt for AI Agents
In src/amr/data/field/field_data.hpp around lines 401 to 405, remove the
std::cout debug print statements or replace them with appropriate PHARE logging
calls consistent with the existing logging framework used in the file. This
ensures debug output is managed uniformly and not left as raw console prints in
production code.

if (!intersectionBox.empty())
copy_<Operator>(intersectionBox, transformedSource, destinationBox,
source, dst);
Expand Down
21 changes: 1 addition & 20 deletions src/amr/data/field/field_geometry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ namespace amr
// generic BoxGeometry into the specific geometry but cannot cast into
// the FieldGeometry below because it does not have the GridLayoutT and
// PhysicalQuantity for template arguments.
// this class is thus used instead and provide the method pureInteriorFieldBox()
// used in FieldFillPattern::calculateOverlap()
template<std::size_t dimension>
class FieldGeometryBase : public SAMRAI::hier::BoxGeometry
{
Expand All @@ -43,34 +41,17 @@ namespace amr
, ghostFieldBox_{ghostFieldBox}
, interiorFieldBox_{interiorFieldBox}
, centerings_{centerings}
, pureInteriorFieldBox_{pureInteriorBox_(interiorFieldBox, centerings)}
{
}

auto const& pureInteriorFieldBox() const { return pureInteriorFieldBox_; }
auto const& interiorFieldBox() const { return interiorFieldBox_; }

SAMRAI::hier::Box const patchBox;

protected:
SAMRAI::hier::Box const ghostFieldBox_;
SAMRAI::hier::Box const interiorFieldBox_;
std::array<core::QtyCentering, dimension> const centerings_;
SAMRAI::hier::Box const pureInteriorFieldBox_;

private:
static SAMRAI::hier::Box
pureInteriorBox_(SAMRAI::hier::Box const& interiorFieldBox,
std::array<core::QtyCentering, dimension> const& centerings)
{
auto noSharedNodeBox{interiorFieldBox};
SAMRAI::hier::IntVector growth(SAMRAI::tbox::Dimension{dimension});
for (auto dir = 0u; dir < dimension; ++dir)
{
growth[dir] = (centerings[dir] == core::QtyCentering::primal) ? -1 : 0;
}
noSharedNodeBox.grow(growth);
return noSharedNodeBox;
}
};

template<typename GridLayoutT, typename PhysicalQuantity>
Expand Down
15 changes: 10 additions & 5 deletions src/amr/data/field/field_variable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,18 @@ namespace amr
*
* FieldVariable represent a data on a patch, it does not contain the data itself,
* after creation, one need to register it with a context : see registerVariableAndContext.
*
*
* Note that `fineBoundaryRepresentsVariable` is set to false so that
* coarse-fine interfaces are handled such that copy happens **before**
* refining. See https://github.com/LLNL/SAMRAI/issues/292
*/
FieldVariable(std::string const& name, PhysicalQuantity qty,
bool fineBoundaryRepresentsVariable = true)
: SAMRAI::hier::Variable(
name,
std::make_shared<FieldDataFactory<GridLayoutT, FieldImpl>>(
fineBoundaryRepresentsVariable, computeDataLivesOnPatchBorder_(qty), name, qty))
bool fineBoundaryRepresentsVariable = false)
: SAMRAI::hier::Variable(name,
std::make_shared<FieldDataFactory<GridLayoutT, FieldImpl>>(
fineBoundaryRepresentsVariable,
computeDataLivesOnPatchBorder_(qty), name, qty))
, fineBoundaryRepresentsVariable_{fineBoundaryRepresentsVariable}
, dataLivesOnPatchBorder_{computeDataLivesOnPatchBorder_(qty)}
{
Expand Down
17 changes: 16 additions & 1 deletion src/amr/data/field/field_variable_fill_pattern.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class FieldFillPattern : public SAMRAI::xfer::VariableFillPattern
{
NULL_USE(node_fill_boxes);


/*
* For this (default) case, the overlap is simply the intersection of
* fill_boxes and data_box.
Expand All @@ -104,7 +105,21 @@ class FieldFillPattern : public SAMRAI::xfer::VariableFillPattern

SAMRAI::hier::BoxContainer overlap_boxes(fill_boxes);
overlap_boxes.intersectBoxes(data_box);
return pdf.getBoxGeometry(patch_box)->setUpOverlap(overlap_boxes, transformation);

auto geom = pdf.getBoxGeometry(patch_box);
auto basic_overlap
= pdf.getBoxGeometry(patch_box)->setUpOverlap(overlap_boxes, transformation);

if (overwrite_interior_)
// if (true)
return basic_overlap;

auto& overlap = dynamic_cast<FieldOverlap const&>(*basic_overlap);
auto destinationBoxes = overlap.getDestinationBoxContainer();
auto& casted = dynamic_cast<FieldGeometryBase<dimension> const&>(*geom);
destinationBoxes.removeIntersections(casted.interiorFieldBox());

return std::make_shared<FieldOverlap>(destinationBoxes, overlap.getTransformation());
}

bool overwrite_interior_;
Expand Down
119 changes: 73 additions & 46 deletions src/amr/data/field/refine/electric_field_refiner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ class ElectricFieldRefiner
//
// therefore in all cases in 1D we just copy the coarse value
//
fineField(locFineIdx[dirX]) = coarseField(locCoarseIdx[dirX]);
if (std::isnan(fineField(locFineIdx[dirX])))
fineField(locFineIdx[dirX]) = coarseField(locCoarseIdx[dirX]);
}

template<typename FieldT>
Expand All @@ -119,14 +120,16 @@ class ElectricFieldRefiner
{
// we're on a fine edge shared with coarse mesh
// take the coarse face value
fineField(ilfx, ilfy) = coarseField(ilcx, ilcy);
if (std::isnan(fineField(ilfx, ilfy)))
fineField(ilfx, ilfy) = coarseField(ilcx, ilcy);
}
else
{
// we're on a fine edge in between two coarse edges
// we take the average
fineField(ilfx, ilfy)
= 0.5 * (coarseField(ilcx, ilcy) + coarseField(ilcx, ilcy + 1));
if (std::isnan(fineField(ilfx, ilfy)))
fineField(ilfx, ilfy)
= 0.5 * (coarseField(ilcx, ilcy) + coarseField(ilcx, ilcy + 1));
}
}
// Ey
Expand All @@ -140,14 +143,16 @@ class ElectricFieldRefiner
// both fine Ey e.g. at j=100 and 101 will take j=50 on coarse
// so no need to look at whether jfine is even or odd
// just take the value at the local coarse index
fineField(ilfx, ilfy) = coarseField(ilcx, ilcy);
if (std::isnan(fineField(ilfx, ilfy)))
fineField(ilfx, ilfy) = coarseField(ilcx, ilcy);
}
else
{
// we're on a fine edge in between two coarse ones
// we take the average
fineField(ilfx, ilfy)
= 0.5 * (coarseField(ilcx, ilcy) + coarseField(ilcx + 1, ilcy));
if (std::isnan(fineField(ilfx, ilfy)))
fineField(ilfx, ilfy)
= 0.5 * (coarseField(ilcx, ilcy) + coarseField(ilcx + 1, ilcy));
}
}
// and this is now Ez
Expand All @@ -156,19 +161,29 @@ class ElectricFieldRefiner
{
if (onCoarseXFace_(fineIndex) and onCoarseYFace_(fineIndex))
{
fineField(ilfx, ilfy) = coarseField(ilcx, ilcy);
if (std::isnan(fineField(ilfx, ilfy)))
fineField(ilfx, ilfy) = coarseField(ilcx, ilcy);
}
else if (onCoarseXFace_(fineIndex))
fineField(ilfx, ilfy)
= 0.5 * (coarseField(ilcx, ilcy) + coarseField(ilcx, ilcy + 1));
{
if (std::isnan(fineField(ilfx, ilfy)))
fineField(ilfx, ilfy)
= 0.5 * (coarseField(ilcx, ilcy) + coarseField(ilcx, ilcy + 1));
}
else if (onCoarseYFace_(fineIndex))
fineField(ilfx, ilfy)
= 0.5 * (coarseField(ilcx, ilcy) + coarseField(ilcx + 1, ilcy));
{
if (std::isnan(fineField(ilfx, ilfy)))
fineField(ilfx, ilfy)
= 0.5 * (coarseField(ilcx, ilcy) + coarseField(ilcx + 1, ilcy));
}
else
fineField(ilfx, ilfy)
= 0.25
* (coarseField(ilcx, ilcy) + coarseField(ilcx + 1, ilcy)
+ coarseField(ilcx, ilcy + 1) + coarseField(ilcx + 1, ilcy + 1));
{
if (std::isnan(fineField(ilfx, ilfy)))
fineField(ilfx, ilfy)
= 0.25
* (coarseField(ilcx, ilcy) + coarseField(ilcx + 1, ilcy)
+ coarseField(ilcx, ilcy + 1) + coarseField(ilcx + 1, ilcy + 1));
}
}
}

Expand Down Expand Up @@ -197,33 +212,37 @@ class ElectricFieldRefiner
// just copy the coarse value
if (onCoarseYFace_(fineIndex) and onCoarseZFace_(fineIndex))
{
fineField(ilfx, ilfy, ilfz) = coarseField(ilcx, ilcy, ilcz);
if (std::isnan(fineField(ilfx, ilfy, ilfz)))
fineField(ilfx, ilfy, ilfz) = coarseField(ilcx, ilcy, ilcz);
}
// we share the Y face but not the Z face
// we must be one of the 2 X fine edges on a Y face
// thus we take the average of the two surrounding edges at Z and Z+DZ
else if (onCoarseYFace_(fineIndex))
{
fineField(ilfx, ilfy, ilfz)
= 0.5 * (coarseField(ilcx, ilcy, ilcz) + coarseField(ilcx, ilcy, ilcz + 1));
if (std::isnan(fineField(ilfx, ilfy, ilfz)))
fineField(ilfx, ilfy, ilfz)
= 0.5 * (coarseField(ilcx, ilcy, ilcz) + coarseField(ilcx, ilcy, ilcz + 1));
}
// we share a Z face but not the Y face
// we must be one of the 2 X fine edges on a Z face
// we thus take the average of the two X edges at y and y+dy
else if (onCoarseZFace_(fineIndex))
{
fineField(ilfx, ilfy, ilfz)
= 0.5 * (coarseField(ilcx, ilcy, ilcz) + coarseField(ilcx, ilcy + 1, ilcz));
if (std::isnan(fineField(ilfx, ilfy, ilfz)))
fineField(ilfx, ilfy, ilfz)
= 0.5 * (coarseField(ilcx, ilcy, ilcz) + coarseField(ilcx, ilcy + 1, ilcz));
}
else
{
// we don't share any face thus we're on one of the 2 middle X edges
// we take the average of the 4 surrounding X averages
fineField(ilfx, ilfy, ilfz)
= 0.25 * (coarseField(ilcx, ilcy, ilcz) + coarseField(ilcx, ilcy + 1, ilcz))
+ 0.25
* (coarseField(ilcx, ilcy, ilcz + 1)
+ coarseField(ilcx, ilcy + 1, ilcz + 1));
if (std::isnan(fineField(ilfx, ilfy, ilfz)))
fineField(ilfx, ilfy, ilfz)
= 0.25 * (coarseField(ilcx, ilcy, ilcz) + coarseField(ilcx, ilcy + 1, ilcz))
+ 0.25
* (coarseField(ilcx, ilcy, ilcz + 1)
+ coarseField(ilcx, ilcy + 1, ilcz + 1));
}
}
// now this is Ey
Expand All @@ -235,7 +254,8 @@ class ElectricFieldRefiner
if (onCoarseXFace_(fineIndex) and onCoarseZFace_(fineIndex))
{
// we thus just copy the coarse value
fineField(ilfx, ilfy, ilfz) = coarseField(ilcx, ilcy, ilcz);
if (std::isnan(fineField(ilfx, ilfy, ilfz)))
fineField(ilfx, ilfy, ilfz) = coarseField(ilcx, ilcy, ilcz);
}
// now we only have same X face, but not (else) the Z face
// so we're a new fine Y edge in between two coarse Y edges
Expand All @@ -247,27 +267,30 @@ class ElectricFieldRefiner
// this means we are on a Y edge that lies in between 2 coarse edges
// at z and z+dz
// take the average of these 2 coarse value
fineField(ilfx, ilfy, ilfz)
= 0.5 * (coarseField(ilcx, ilcy, ilcz) + coarseField(ilcx, ilcy, ilcz + 1));
if (std::isnan(fineField(ilfx, ilfy, ilfz)))
fineField(ilfx, ilfy, ilfz)
= 0.5 * (coarseField(ilcx, ilcy, ilcz) + coarseField(ilcx, ilcy, ilcz + 1));
}
// we're on a Z coarse face, but not on a X coarse face
// we thus must be one of the 2 Y edges on a Z face
// and thus we take the average of the 2 Y edges at X and X+dX
else if (onCoarseZFace_(fineIndex))
{
fineField(ilfx, ilfy, ilfz)
= 0.5 * (coarseField(ilcx, ilcy, ilcz) + coarseField(ilcx + 1, ilcy, ilcz));
if (std::isnan(fineField(ilfx, ilfy, ilfz)))
fineField(ilfx, ilfy, ilfz)
= 0.5 * (coarseField(ilcx, ilcy, ilcz) + coarseField(ilcx + 1, ilcy, ilcz));
}
// now we're not on any of the coarse faces
// so we must be one of the two Y edge in the middle of the cell
// we thus average over the 4 Y edges of the coarse cell
else
{
fineField(ilfx, ilfy, ilfz)
= 0.25
* (coarseField(ilcx, ilcy, ilcz) + coarseField(ilcx + 1, ilcy, ilcz)
+ coarseField(ilcx, ilcy, ilcz + 1)
+ coarseField(ilcx + 1, ilcy, ilcz + 1));
if (std::isnan(fineField(ilfx, ilfy, ilfz)))
fineField(ilfx, ilfy, ilfz)
= 0.25
* (coarseField(ilcx, ilcy, ilcz) + coarseField(ilcx + 1, ilcy, ilcz)
+ coarseField(ilcx, ilcy, ilcz + 1)
+ coarseField(ilcx + 1, ilcy, ilcz + 1));
}
}
// now let's do Ez
Expand All @@ -279,34 +302,38 @@ class ElectricFieldRefiner
// we thus copy the coarse value
if (onCoarseXFace_(fineIndex) and onCoarseYFace_(fineIndex))
{
fineField(ilfx, ilfy, ilfz) = coarseField(ilcx, ilcy, ilcz);
if (std::isnan(fineField(ilfx, ilfy, ilfz)))
fineField(ilfx, ilfy, ilfz) = coarseField(ilcx, ilcy, ilcz);
}
// here we're on a coarse X face, but not a Y face
// we must be 1 of the 2 Z edges on a X face
// thus we average the 2 surrounding Z coarse edges at Y and Y+dY
else if (onCoarseXFace_(fineIndex))
{
fineField(locFineIdx[dirX], locFineIdx[dirY], locFineIdx[dirZ])
= 0.5 * (coarseField(ilcx, ilcy, ilcz) + coarseField(ilcx, ilcy + 1, ilcz));
if (std::isnan(fineField(ilfx, ilfy, ilfz)))
fineField(locFineIdx[dirX], locFineIdx[dirY], locFineIdx[dirZ])
= 0.5 * (coarseField(ilcx, ilcy, ilcz) + coarseField(ilcx, ilcy + 1, ilcz));
}
// here we're on a coarse Y face, but not a X face
// we must be 1 of the 2 Z edges on a Y face
// thus we average the 2 surrounding Z coarse edges at X and X+dX
else if (onCoarseYFace_(fineIndex))
{
fineField(ilfx, ilfy, ilfz)
= 0.5 * (coarseField(ilcx, ilcy, ilcz) + coarseField(ilcx + 1, ilcy, ilcz));
if (std::isnan(fineField(ilfx, ilfy, ilfz)))
fineField(ilfx, ilfy, ilfz)
= 0.5 * (coarseField(ilcx, ilcy, ilcz) + coarseField(ilcx + 1, ilcy, ilcz));
}
// we're not on any coarse face thus must be one of the 2 Z edges
// in the middle of the coarse cell
// we therefore take the average of the 4 surrounding Z edges
else
{
fineField(ilfx, ilfy, ilfz)
= 0.25
* (coarseField(ilcx, ilcy, ilcz) + coarseField(ilcx + 1, ilcy, ilcz)
+ coarseField(ilcx, ilcy + 1, ilcz + 1)
+ coarseField(ilcx + 1, ilcy + 1, ilcz));
if (std::isnan(fineField(ilfx, ilfy, ilfz)))
fineField(ilfx, ilfy, ilfz)
= 0.25
* (coarseField(ilcx, ilcy, ilcz) + coarseField(ilcx + 1, ilcy, ilcz)
+ coarseField(ilcx, ilcy + 1, ilcz + 1)
+ coarseField(ilcx + 1, ilcy + 1, ilcz));
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/amr/data/field/refine/field_refine_operator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ class FieldRefineOperator : public SAMRAI::hier::RefineOperator
auto intersectionBox = destFieldBox * box;


std::cout << "debug refine operator: "
<< "destinationFieldBox: " << destFieldBox
<< ", sourceFieldBox: " << sourceFieldBox << ", box: " << box
<< ", intersectionBox: " << intersectionBox << std::endl;
Comment on lines +111 to +114
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Remove or properly implement debug output

Debug print statements should not be committed to production code. Consider either:

  1. Removing this debug output entirely, or
  2. Using the PHARE logging framework with appropriate log levels
-            std::cout << "debug refine operator: "
-                      << "destinationFieldBox: " << destFieldBox
-                      << ", sourceFieldBox: " << sourceFieldBox << ", box: " << box
-                      << ", intersectionBox: " << intersectionBox << std::endl;
+            // If debug output is needed, use PHARE logging:
+            // PHARE_LOG_SCOPE(4, "refine_operator_debug");
+            // PHARE_LOG_LINE_STR("destinationFieldBox: " << destFieldBox
+            //                   << ", sourceFieldBox: " << sourceFieldBox 
+            //                   << ", box: " << box
+            //                   << ", intersectionBox: " << intersectionBox);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
std::cout << "debug refine operator: "
<< "destinationFieldBox: " << destFieldBox
<< ", sourceFieldBox: " << sourceFieldBox << ", box: " << box
<< ", intersectionBox: " << intersectionBox << std::endl;
// If debug output is needed, use PHARE logging:
// PHARE_LOG_SCOPE(4, "refine_operator_debug");
// PHARE_LOG_LINE_STR("destinationFieldBox: " << destFieldBox
// << ", sourceFieldBox: " << sourceFieldBox
// << ", box: " << box
// << ", intersectionBox: " << intersectionBox);
🤖 Prompt for AI Agents
In src/amr/data/field/refine/field_refine_operator.hpp around lines 111 to 114,
the code contains a std::cout debug print statement that should not be in
production code. Remove this debug output entirely or replace it with a call to
the PHARE logging framework using an appropriate log level to ensure proper
logging without cluttering standard output.



if constexpr (dimension == 1)
Expand Down
10 changes: 7 additions & 3 deletions src/amr/data/field/refine/field_refiner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ namespace amr
{
fieldValue += sourceField(xStartIndex + iShiftX) * leftRightWeights[iShiftX];
}
destinationField(fineIndex[dirX]) = fieldValue;
if (std::isnan(destinationField(fineIndex[dirX])))
destinationField(fineIndex[dirX]) = fieldValue;
}


Expand Down Expand Up @@ -119,7 +120,8 @@ namespace amr
fieldValue += Yinterp * xLeftRightWeights[iShiftX];
}

destinationField(fineIndex[dirX], fineIndex[dirY]) = fieldValue;
if (std::isnan(destinationField(fineIndex[dirX], fineIndex[dirY])))
destinationField(fineIndex[dirX], fineIndex[dirY]) = fieldValue;
}


Expand Down Expand Up @@ -157,7 +159,9 @@ namespace amr
fieldValue += Yinterp * xLeftRightWeights[iShiftX];
}

destinationField(fineIndex[dirX], fineIndex[dirY], fineIndex[dirZ]) = fieldValue;
if (std::isnan(destinationField(fineIndex[dirX], fineIndex[dirY], fineIndex[dirZ])))
destinationField(fineIndex[dirX], fineIndex[dirY], fineIndex[dirZ])
= fieldValue;
}
}

Expand Down
Loading
Loading