Skip to content
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ PHARE_REPORT.zip
.cache
.gdbinit
.phlop
pyrightconfig.json

8 changes: 8 additions & 0 deletions pyphare/pyphare/pharein/initialize/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ def populateDict(sim):
add_double("simulation/grid/meshsize/z", sim.dl[2])
add_string("simulation/grid/boundary_type/z", sim.boundary_types[2])

directions = "x", "y", "z"
sides = "lower", "upper"
for direction in directions[:sim.ndim]:
for side in sides:
location = f"{direction}{side}"
add_string(f"simulation/grid/boundary_conditions/{location}/type",
sim.boundary_conditions[f"{location}"]["type"])

add_int("simulation/interp_order", sim.interp_order)
add_int("simulation/refined_particle_nbr", sim.refined_particle_nbr)
add_double("simulation/time_step", sim.time_step)
Expand Down
55 changes: 54 additions & 1 deletion pyphare/pyphare/pharein/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def check_path(**kwargs):


def check_boundaries(ndim, **kwargs):
valid_boundary_types = ("periodic",)
valid_boundary_types = ("periodic","physical")
boundary_types = kwargs.get("boundary_types", ["periodic"] * ndim)
phare_utilities.check_iterables(boundary_types)

Expand All @@ -267,6 +267,57 @@ def check_boundaries(ndim, **kwargs):
return boundary_types


# ------------------------------------------------------------------------------

def check_boundary_conditions(ndim, **kwargs):
valid_bc_types = ("open", "reflective", "none")
all_directions = ["x", "y", "z"][:ndim]
sides = "lower", "upper"
boundary_types = kwargs["boundary_types"]
physical_directions = []
periodic_directions = []
for dir, type in zip(all_directions, boundary_types):
if type == "physical":
physical_directions.append(dir)
elif type == "periodic":
periodic_directions.append(dir)
physical_boundary_locations = [f"{dir}{side}" for dir in physical_directions for side in sides]
all_boundary_locations = [f"{dir}{side}" for side in sides for dir in all_directions]
default_boundary_conditions = {location: {"type": "none"} for location in all_boundary_locations}
boundary_conditions = kwargs.get("boundary_conditions", {})

if not isinstance(boundary_conditions, dict):
raise TypeError(f"A dict should be passed to argument 'boundary_conditions'")

# check first that all provided locations are valid
for location in boundary_conditions:
if not location in all_boundary_locations:
raise ValueError(f"Wrong boundary name {location}: should belong to {all_boundary_locations}")

# attribute a default 'none' type to all unspecified boundaries
for location in all_boundary_locations:
if location not in boundary_conditions:
boundary_conditions[location] = {'type': 'none'}

# check that all boundaries have a dict, which contain a 'type' key in their dict associated to a valid value
for location in all_boundary_locations:
boundary_condition = boundary_conditions[location]
if not isinstance(boundary_condition, dict):
raise TypeError(f"A dict should be passed to the boundary {location} for specifying a boundary condition")
if 'type' not in boundary_condition:
raise KeyError(f"No key 'type' found in the boundary_condition dict passed to {location}")
boundary_type = boundary_condition['type']
if boundary_type not in valid_bc_types:
raise ValueError(f"Boundary type {boundary_type} is not valid: it should belong to {valid_bc_types}")

# now check that all physical boundary have a boundary type other than 'none'
for location in physical_boundary_locations:
if boundary_conditions[location]['type'] == 'none':
raise KeyError(f"{location} is a physical boundary and should be provided with a valid type other than 'none'.")

return boundary_conditions


# ------------------------------------------------------------------------------


Expand Down Expand Up @@ -716,6 +767,7 @@ def wrapper(simulation_object, **kwargs_in):
"layout",
"interp_order",
"boundary_types",
"boundary_conditions",
"refined_particle_nbr",
"path",
"nesting_buffer",
Expand Down Expand Up @@ -786,6 +838,7 @@ def wrapper(simulation_object, **kwargs_in):
ndim = compute_dimension(cells)
kwargs["diag_options"] = check_diag_options(**kwargs)
kwargs["boundary_types"] = check_boundaries(ndim, **kwargs)
kwargs["boundary_conditions"] = check_boundary_conditions(ndim, **kwargs)

kwargs["refined_particle_nbr"] = check_refined_particle_nbr(ndim, **kwargs)
kwargs["diag_export_format"] = kwargs.get("diag_export_format", "hdf5")
Expand Down
6 changes: 0 additions & 6 deletions pyphare/pyphare/pharesee/run/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@
from pyphare.core.gridlayout import yee_centering


from pyphare.core.gridlayout import yee_centering


from pyphare.core.gridlayout import yee_centering


def _current1d(by, bz, xby, xbz):
# jx = 0
# jy = -dxBz
Expand Down
5 changes: 4 additions & 1 deletion res/cmake/test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ if (test AND ${PHARE_EXEC_LEVEL_MIN} GREATER 0) # 0 = no tests

configure_file(${CMAKE_SOURCE_DIR}/tests/__init__.py ${CMAKE_BINARY_DIR}/tests/__init__.py @ONLY)


add_subdirectory(tests/core/boundary/boundary_manager)
add_subdirectory(tests/core/data/ndarray)
add_subdirectory(tests/core/data/grid)
add_subdirectory(tests/core/data/gridlayout)
add_subdirectory(tests/core/data/vecfield)
add_subdirectory(tests/core/data/tensorfield)
add_subdirectory(tests/core/data/particles)
add_subdirectory(tests/core/data/ions)
add_subdirectory(tests/core/data/electrons)
Expand All @@ -19,6 +20,7 @@ if (test AND ${PHARE_EXEC_LEVEL_MIN} GREATER 0) # 0 = no tests
add_subdirectory(tests/core/data/particle_initializer)
add_subdirectory(tests/core/data/mhd_state)
add_subdirectory(tests/core/utilities/box)
add_subdirectory(tests/core/utilities/point)
add_subdirectory(tests/core/utilities/range)
add_subdirectory(tests/core/utilities/index)
add_subdirectory(tests/core/utilities/indexer)
Expand Down Expand Up @@ -48,6 +50,7 @@ if (test AND ${PHARE_EXEC_LEVEL_MIN} GREATER 0) # 0 = no tests
add_subdirectory(tests/amr/models)
add_subdirectory(tests/amr/multiphysics_integrator)
add_subdirectory(tests/amr/tagging)
add_subdirectory(tests/amr/data/tensorfield/tensor_field_data)

add_subdirectory(tests/diagnostic)

Expand Down
2 changes: 2 additions & 0 deletions res/sim/all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@
3,3,6
3,3,12
3,3,27
2,2,4,TVDRK2,Linear,VanLeer,HLLD,false,false,false
2,2,4,TVDRK3,WENOZ,None,HLLD,false,false,false
4 changes: 4 additions & 0 deletions src/amr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ set( SOURCES_INC
data/field/coarsening/mhd_flux_coarsener.hpp
data/field/field_data.hpp
data/field/field_data_factory.hpp
data/field/field_data_traits.hpp
data/field/field_geometry.hpp
data/field/field_overlap.hpp
data/field/field_variable.hpp
Expand All @@ -25,10 +26,13 @@ set( SOURCES_INC
data/field/refine/magnetic_field_regrider.hpp
data/field/refine/electric_field_refiner.hpp
data/field/refine/mhd_field_refiner.hpp
data/field/refine/field_refine_patch_strategy.hpp
data/field/refine/mhd_flux_refiner.hpp
data/field/refine/linear_weighter.hpp
data/field/refine/field_refine_operator.hpp
data/field/time_interpolate/field_linear_time_interpolate.hpp
data/tensorfield/tensor_field_data.hpp
data/tensorfield/tensor_field_data_traits.hpp
resources_manager/field_resource.hpp
resources_manager/particle_resource.hpp
resources_manager/amr_utils.hpp
Expand Down
4 changes: 3 additions & 1 deletion src/amr/data/field/field_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ namespace amr
static constexpr std::size_t interp_order = GridLayoutT::interp_order;
using Geometry = FieldGeometry<GridLayoutT, PhysicalQuantity>;
using gridlayout_type = GridLayoutT;
using grid_type = Grid_t;
using physical_quantity_type = PhysicalQuantity;
static constexpr auto NO_ROTATE = SAMRAI::hier::Transformation::NO_ROTATE;


Expand Down Expand Up @@ -300,7 +302,7 @@ namespace amr
return patchData->gridLayout;
}


/// @warning this name is weird, as we are return a Grid and not a Field
static Grid_t& getField(SAMRAI::hier::Patch const& patch, int id)
{
auto const& patchData = patch.getPatchData(id);
Expand Down
39 changes: 39 additions & 0 deletions src/amr/data/field/field_data_traits.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#ifndef PHARE_SRC_AMR_FIELD_FIELD_DATA_TRAITS_HPP
#define PHARE_SRC_AMR_FIELD_FIELD_DATA_TRAITS_HPP

#include <SAMRAI/hier/Patch.h>
#include <SAMRAI/hier/PatchData.h>

#include <concepts>

namespace PHARE::amr
{
/**
* @brief Concept ensuring a type satisfies the PHARE FieldData interface.
*/
template<typename T>
concept IsFieldData
= std::derived_from<T, SAMRAI::hier::PatchData>
&& requires(T a, T const ca, SAMRAI::hier::Patch const& patch) {
// Type aliases
typename T::gridlayout_type;
typename T::grid_type;
typename T::physical_quantity_type;

// Static constexpr variables
requires std::same_as<decltype(T::dimension), std::size_t const>;
requires std::same_as<decltype(T::interp_order), std::size_t const>;

// Public member variables
requires std::same_as<decltype(a.gridLayout), typename T::gridlayout_type>;
requires std::same_as<decltype(a.field), typename T::grid_type>;

// API requirements
{ a.getPointer() } -> std::same_as<typename T::grid_type::field_type*>;
{ T::getLayout(patch, 0) } -> std::same_as<typename T::gridlayout_type const&>;
{ T::getField(patch, 0) } -> std::same_as<typename T::grid_type&>;
};

} // namespace PHARE::amr

#endif // PHARE_SRC_AMR_FIELD_FIELD_DATA_TRAITS_HPP
Loading