Skip to content

Commit 5db724c

Browse files
authored
origin made global (#1093)
1 parent ffccf14 commit 5db724c

36 files changed

+583
-1096
lines changed

pyphare/pyphare/core/gridlayout.py

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -271,24 +271,6 @@ def physicalEndIndex(self, interpOrder, centering, nbrCells):
271271
)
272272
return index
273273

274-
def physicalStartIndices(self, qty):
275-
assert qty in self.hybridQuantities
276-
indices = np.zeros(self.box.ndim)
277-
for i, direction in enumerate(directions[: self.box.ndim]):
278-
centering = yee_centering[direction][qty]
279-
indices[i] = self.physicalStartIndex(self.interp_order, centering)
280-
return indices
281-
282-
def physicalEndIndices(self, qty):
283-
assert qty in self.hybridQuantities
284-
indices = np.zeros(self.box.ndim)
285-
for i, direction in enumerate(directions[: self.box.ndim]):
286-
centering = yee_centering[direction][qty]
287-
indices[i] = self.physicalEndIndex(
288-
self.interp_order, centering, self.box.shape[i]
289-
)
290-
return indices
291-
292274
def nbrGhostFor(self, qty):
293275
assert qty in self.hybridQuantities
294276
nGhosts = np.zeros(self.box.ndim, dtype=np.int32)
@@ -329,6 +311,11 @@ def allocSizeDerived(self, interpOrder, centering, nbrCells):
329311
)
330312
return size
331313

314+
def localPointToAMR(self, point):
315+
return (
316+
point + self.box.lower - self.physicalStartIndex(self.interp_order, "dual")
317+
)
318+
332319
def AMRPointToLocal(self, point):
333320
return (
334321
point - self.box.lower + self.physicalStartIndex(self.interp_order, "dual")

pyphare/pyphare/pharein/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,19 +166,16 @@ def add_vector_int(path, val):
166166
add_string("simulation/grid/layout_type", simulation.layout)
167167
add_int("simulation/grid/nbr_cells/x", simulation.cells[0])
168168
add_double("simulation/grid/meshsize/x", simulation.dl[0])
169-
add_double("simulation/grid/origin/x", simulation.origin[0])
170169
add_string("simulation/grid/boundary_type/x", simulation.boundary_types[0])
171170

172171
if simulation.ndim > 1:
173172
add_int("simulation/grid/nbr_cells/y", simulation.cells[1])
174173
add_double("simulation/grid/meshsize/y", simulation.dl[1])
175-
add_double("simulation/grid/origin/y", simulation.origin[1])
176174
add_string("simulation/grid/boundary_type/y", simulation.boundary_types[1])
177175

178176
if simulation.ndim > 2:
179177
add_int("simulation/grid/nbr_cells/z", simulation.cells[2])
180178
add_double("simulation/grid/meshsize/z", simulation.dl[2])
181-
add_double("simulation/grid/origin/z", simulation.origin[2])
182179
add_string("simulation/grid/boundary_type/z", simulation.boundary_types[2])
183180

184181
add_int("simulation/interp_order", simulation.interp_order)

pyphare/pyphare/pharein/maxwellian_fluid_model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def validate(self, sim, atol=1e-15):
196196

197197
def validate1d(self, sim, atol):
198198
domain_box = Box([0] * sim.ndim, sim.cells)
199-
layout = GridLayout(domain_box, sim.origin, sim.dl, sim.interp_order)
199+
layout = GridLayout(domain_box, domain_box.lower, sim.dl, sim.interp_order)
200200
nbrDualGhosts = layout.nbrGhostsPrimal(sim.interp_order)
201201
nbrPrimalGhosts = layout.nbrGhostsPrimal(sim.interp_order)
202202
directions = ["X"]
@@ -236,7 +236,7 @@ def validate1d(self, sim, atol):
236236

237237
def validate2d(self, sim, atol):
238238
domain_box = Box([0] * sim.ndim, sim.cells)
239-
layout = GridLayout(domain_box, sim.origin, sim.dl, sim.interp_order)
239+
layout = GridLayout(domain_box, domain_box.lower, sim.dl, sim.interp_order)
240240
nbrDualGhosts = layout.nbrGhostsPrimal(sim.interp_order)
241241
nbrPrimalGhosts = layout.nbrGhostsPrimal(sim.interp_order)
242242
directions = ["X", "Y"]

pyphare/pyphare/pharein/simulation.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -295,14 +295,6 @@ def check_refined_particle_nbr(ndim, **kwargs):
295295
# ------------------------------------------------------------------------------
296296

297297

298-
def check_origin(ndim, **kwargs):
299-
origin = kwargs.get("origin", [0.0] * ndim)
300-
return origin
301-
302-
303-
# ------------------------------------------------------------------------------
304-
305-
306298
def as_list_per_level(refinement_boxes):
307299
"""
308300
accepts various formats of boxes.
@@ -636,7 +628,6 @@ def wrapper(simulation_object, **kwargs):
636628
"time_step_nbr",
637629
"layout",
638630
"interp_order",
639-
"origin",
640631
"boundary_types",
641632
"refined_particle_nbr",
642633
"path",
@@ -695,7 +686,6 @@ def wrapper(simulation_object, **kwargs):
695686
kwargs["restart_options"] = check_restart_options(**kwargs)
696687

697688
kwargs["boundary_types"] = check_boundaries(ndim, **kwargs)
698-
kwargs["origin"] = check_origin(ndim, **kwargs)
699689

700690
kwargs["refined_particle_nbr"] = check_refined_particle_nbr(ndim, **kwargs)
701691
kwargs["diag_export_format"] = kwargs.get("diag_export_format", "hdf5")
@@ -850,7 +840,6 @@ class Simulation(object):
850840
These parameters are more advanced, modify them at your own risk
851841
852842
* **layout** (``str``), layout of the physical quantities on the mesh (default = "yee")
853-
* **origin** (``int`` or ``tuple``), origin of the physical domain, (default (0,0,0) in 3D)
854843
855844
856845
For instance:
@@ -976,7 +965,7 @@ def __init__(self, **kwargs):
976965
validate_restart_options(self)
977966

978967
def simulation_domain(self):
979-
return [dl * n + ori for dl, n, ori in zip(self.dl, self.cells, self.origin)]
968+
return [dl * n for dl, n in zip(self.dl, self.cells)]
980969

981970
def within_simulation_duration(self, time_period):
982971
return time_period[0] >= 0 and time_period[1] < self.time_step_nbr

src/amr/resources_manager/amr_utils.hpp

Lines changed: 25 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
#ifndef PHARE_AMR_UTILS_HPP
22
#define PHARE_AMR_UTILS_HPP
33

4-
#include "core/def/phare_mpi.hpp" // IWYU pragma: keep
5-
64

75
#include "core/def.hpp"
6+
#include "core/def/phare_mpi.hpp" // IWYU pragma: keep
87
#include "core/utilities/constants.hpp"
9-
#include "core/utilities/point/point.hpp"
108

119
#include "amr/types/amr_types.hpp"
1210
#include "amr/utilities/box/amr_box.hpp"
@@ -158,54 +156,43 @@ namespace amr
158156
{
159157
auto constexpr dimension = GridLayoutT::dimension;
160158

161-
SAMRAI::tbox::Dimension const dim{dimension};
162-
163159
// We get geometry information from the patch, such as meshSize, and physical origin
164160
auto patchGeom = std::dynamic_pointer_cast<SAMRAI::geom::CartesianPatchGeometry>(
165161
patch.getPatchGeometry());
166-
core::Point<double, dimension> origin;
167162

168-
std::array<double, dimension> dl;
169-
170-
if (patchGeom != nullptr)
171-
{
172-
auto pOrigin = patchGeom->getXLower();
173-
auto pDl = patchGeom->getDx();
174-
175-
for (std::size_t iDim = 0; iDim < dimension; ++iDim)
176-
{
177-
origin[iDim] = pOrigin[iDim];
178-
dl[iDim] = pDl[iDim];
179-
}
180-
}
181-
else
182163
/*
164+
if(patchGeom == nullptr)
165+
183166
We assume that this is a temporary patch used by SAMRAI for data transfers
184167
Temporary patches are not given a Geometry at this moment so we can't use it.
185168
This happens in:
186169
SAMRAI::xfer::RefineTimeTransaction::packStream(tbox::MessageStream&stream)
187170
188171
SEE: https://github.com/LLNL/SAMRAI/issues/147
189172
*/
190-
{
191-
for (std::size_t iDim = 0; iDim < dimension; ++iDim)
192-
{
193-
origin[iDim] = 0;
194-
dl[iDim] = 1;
195-
}
196-
}
197-
198-
SAMRAI::hier::Box domain = patch.getBox();
199-
200-
std::array<std::uint32_t, dimension> nbrCell;
201-
202-
for (std::size_t iDim = 0; iDim < dimension; ++iDim)
203-
{
204-
nbrCell[iDim] = static_cast<std::uint32_t>(domain.numberCells(iDim));
205-
}
206173

207-
auto lvlNbr = patch.getPatchLevelNumber();
208-
return GridLayoutT{dl, nbrCell, origin, amr::Box<int, dimension>{domain}, lvlNbr};
174+
auto const dl = core::for_N_make_array<dimension>([&](auto i) {
175+
if (patchGeom != nullptr)
176+
return patchGeom->getDx()[i];
177+
return 1.0;
178+
});
179+
180+
auto const origin = core::for_N_make_array<dimension>([&](auto i) {
181+
if (patchGeom != nullptr)
182+
return patchGeom->getXLower()[i];
183+
return 0.0;
184+
});
185+
186+
auto const nbrCell = core::for_N_make_array<dimension>(
187+
[&](auto i) { return static_cast<std::uint32_t>(patch.getBox().numberCells(i)); });
188+
189+
return {
190+
dl,
191+
nbrCell,
192+
origin, //
193+
amr::Box<int, dimension>{patch.getBox()},
194+
patch.getPatchLevelNumber(), //
195+
};
209196
}
210197

211198

src/amr/wrappers/hierarchy.hpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class Hierarchy : public HierarchyRestarter, public SAMRAI::hier::PatchHierarchy
9494
NO_DISCARD auto const& boundaryConditions() const { return boundaryConditions_; }
9595
NO_DISCARD auto const& cellWidth() const { return cellWidth_; }
9696
NO_DISCARD auto const& domainBox() const { return domainBox_; }
97-
NO_DISCARD auto const& origin() const { return origin_; }
97+
9898

9999

100100
auto writeRestartFile(std::string directory) const;
@@ -113,14 +113,12 @@ class Hierarchy : public HierarchyRestarter, public SAMRAI::hier::PatchHierarchy
113113
std::shared_ptr<SAMRAI::geom::CartesianGridGeometry>&& geo,
114114
std::shared_ptr<SAMRAI::tbox::MemoryDatabase>&& db,
115115
std::array<int, dimension> const domainBox,
116-
std::array<double, dimension> const origin,
117116
std::array<double, dimension> const cellWidth,
118117
std::array<std::string, dimension> const boundaryConditions);
119118

120119
private:
121120
std::vector<double> const cellWidth_;
122121
std::vector<int> const domainBox_;
123-
std::vector<double> const origin_;
124122
std::vector<std::string> boundaryConditions_;
125123
};
126124

@@ -204,15 +202,13 @@ Hierarchy::Hierarchy(initializer::PHAREDict const& dict,
204202
std::shared_ptr<SAMRAI::geom::CartesianGridGeometry>&& geo,
205203
std::shared_ptr<SAMRAI::tbox::MemoryDatabase>&& db,
206204
std::array<int, dimension> const domainBox,
207-
std::array<double, dimension> const origin,
208205
std::array<double, dimension> const cellWidth,
209206
std::array<std::string, dimension> const boundaryConditions)
210207
// needs to open restart database before SAMRAI::PatchHierarcy constructor
211208
: HierarchyRestarter{dict}
212209
, SAMRAI::hier::PatchHierarchy{"PHARE_hierarchy", geo, db}
213210
, cellWidth_(cellWidth.data(), cellWidth.data() + dimension)
214211
, domainBox_(domainBox.data(), domainBox.data() + dimension)
215-
, origin_(origin.data(), origin.data() + dimension)
216212
, boundaryConditions_(boundaryConditions.data(), boundaryConditions.data() + dimension)
217213
{
218214
}
@@ -264,11 +260,10 @@ void getDomainCoords(PHARE::initializer::PHAREDict const& grid, double lower[dim
264260

265261
auto nbr_cells = parseDimXYZType<int, dimension>(grid, "nbr_cells");
266262
auto mesh_size = parseDimXYZType<double, dimension>(grid, "meshsize");
267-
auto origin = parseDimXYZType<double, dimension>(grid, "origin");
268263

269264
for (std::size_t i = 0; i < dimension; i++)
270265
{
271-
lower[i] = origin[i];
266+
lower[i] = 0;
272267
upper[i] = lower[i] + nbr_cells[i] * mesh_size[i];
273268
}
274269
}
@@ -400,7 +395,6 @@ DimHierarchy<_dimension>::DimHierarchy(PHARE::initializer::PHAREDict const& dict
400395
griddingAlgorithmDatabase<dimension>(dict["simulation"]["grid"])),
401396
patchHierarchyDatabase<dimension>(dict["simulation"]["AMR"]),
402397
shapeToBox(parseDimXYZType<int, dimension>(dict["simulation"]["grid"], "nbr_cells")),
403-
parseDimXYZType<double, dimension>(dict["simulation"]["grid"], "origin"),
404398
parseDimXYZType<double, dimension>(dict["simulation"]["grid"], "meshsize"),
405399
parseDimXYZType<std::string, dimension>(dict["simulation"]["grid"], "boundary_type")}
406400
{

src/core/data/field/initializers/field_user_initializer.hpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33

44
#include "core/utilities/span.hpp"
55
#include "initializer/data_provider.hpp"
6+
#include "core/utilities/point/point.hpp"
67

78
#include <tuple>
89
#include <memory>
10+
#include <cassert>
911

1012
namespace PHARE::core
1113
{
@@ -16,18 +18,20 @@ class FieldUserFunctionInitializer
1618
void static initialize(Field& field, GridLayout const& layout,
1719
initializer::InitFunction<GridLayout::dimension> const& init)
1820
{
19-
auto const indices = layout.ghostStartToEndIndices(field, /*includeEnd=*/true);
21+
auto const indices = layout.indices(layout.AMRGhostBoxFor(field));
2022
auto const coords = layout.template indexesToCoordVectors</*WithField=*/true>(
2123
indices, field, [](auto& gridLayout, auto& field_, auto const&... args) {
22-
return gridLayout.fieldNodeCoordinates(field_, gridLayout.origin(), args...);
24+
return gridLayout.fieldNodeCoordinates(field_, args...);
2325
});
2426

2527
std::shared_ptr<Span<double>> gridPtr // keep grid data alive
2628
= std::apply([&](auto&... args) { return init(args...); }, coords);
2729
Span<double>& grid = *gridPtr;
2830

2931
for (std::size_t cell_idx = 0; cell_idx < indices.size(); cell_idx++)
30-
std::apply([&](auto&... args) { field(args...) = grid[cell_idx]; }, indices[cell_idx]);
32+
std::apply(
33+
[&](auto&... args) { field(layout.AMRToLocal(Point{args...})) = grid[cell_idx]; },
34+
indices[cell_idx]);
3135
}
3236
};
3337

0 commit comments

Comments
 (0)