Skip to content

Commit

Permalink
some more
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipDeegan committed Jun 6, 2024
1 parent 9405a34 commit fe6973b
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 30 deletions.
13 changes: 8 additions & 5 deletions tests/diagnostic/test-diagnostics_1d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,29 @@
#include "test_diagnostics.ipp"

static std::string const job_file = "job_1d";
static std::string const out_dir = "phare_outputs/diags_1d/";
void static out_dir()
{
return std::string{"phare_outputs/diags_2d/" + std::to_string() PHARE::core::mpi::rank()};
}

TYPED_TEST(Simulator1dTest, fluid)
{
fluid_test(TypeParam{job_file}, out_dir);
fluid_test(TypeParam{job_file}, out_dir());
}

TYPED_TEST(Simulator1dTest, particles)
{
particles_test(TypeParam{job_file}, out_dir);
particles_test(TypeParam{job_file}, out_dir());
}

TYPED_TEST(Simulator1dTest, electromag)
{
electromag_test(TypeParam{job_file}, out_dir);
electromag_test(TypeParam{job_file}, out_dir());
}

TYPED_TEST(Simulator1dTest, allFromPython)
{
allFromPython_test(TypeParam{job_file}, out_dir);
allFromPython_test(TypeParam{job_file}, out_dir());
}


Expand Down
15 changes: 10 additions & 5 deletions tests/diagnostic/test-diagnostics_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,31 @@
#include "test_diagnostics.ipp"

static std::string const job_file = "job_2d";
static std::string const out_dir = "phare_outputs/diags_2d/";

void static out_dir()
{
return std::string{"phare_outputs/diags_2d/" + std::to_string() PHARE::core::mpi::rank()};
}


TYPED_TEST(Simulator2dTest, fluid)
{
fluid_test(TypeParam{job_file}, out_dir);
fluid_test(TypeParam{job_file}, out_dir());
}

TYPED_TEST(Simulator2dTest, particles)
{
particles_test(TypeParam{job_file}, out_dir);
particles_test(TypeParam{job_file}, out_dir());
}

TYPED_TEST(Simulator2dTest, electromag)
{
electromag_test(TypeParam{job_file}, out_dir);
electromag_test(TypeParam{job_file}, out_dir());
}

TYPED_TEST(Simulator2dTest, allFromPython)
{
allFromPython_test(TypeParam{job_file}, out_dir);
allFromPython_test(TypeParam{job_file}, out_dir());
}


Expand Down
2 changes: 1 addition & 1 deletion tests/simulator/refinement/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ if(HighFive)
## These test use dump diagnostics so require HighFive!
if(testMPI)
phare_mpi_python3_exec(9 2 simple_2d_refinement test_2d_2_core.py ${CMAKE_CURRENT_BINARY_DIR})
phare_mpi_python3_exec(11 10 complex_2d_refinement test_2d_10_core.py ${CMAKE_CURRENT_BINARY_DIR})
#phare_mpi_python3_exec(11 10 complex_2d_refinement test_2d_10_core.py ${CMAKE_CURRENT_BINARY_DIR})
endif(testMPI)
endif()
4 changes: 2 additions & 2 deletions tests/simulator/refinement/test_2d_10_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def config(diag_outputs, model_init={}, refinement_boxes=None):
ph.global_vars.sim = None

sim = ph.Simulation(
smallest_patch_size=10,
largest_patch_size=20,
# smallest_patch_size=10,
# largest_patch_size=20,
time_step_nbr=1,
final_time=0.001,
# boundary_types="periodic",
Expand Down
10 changes: 7 additions & 3 deletions tests/simulator/test_diagnostic_timestamps.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def test_dump_diags_timestamps(self):

simInput = simArgs.copy()
diag_outputs = self.unique_diag_dir_for_test_case(out, 1, 1)
self.register_diag_dir_for_cleanup(diag_outputs)
simInput["diag_options"]["options"]["dir"] = diag_outputs

simulation = ph.Simulation(**simArgs.copy())
Expand All @@ -130,7 +131,7 @@ def make_time(stamp):
return "{:.10f}".format(stamp)

for diagname, diagInfo in ph.global_vars.sim.diagnostics.items():
h5_filename = os.path.join(out, h5_filename_from(diagInfo))
h5_filename = os.path.join(diag_outputs, h5_filename_from(diagInfo))
self.assertTrue(os.path.exists(h5_filename))

h5_file = h5py.File(h5_filename, "r")
Expand All @@ -143,7 +144,7 @@ def make_time(stamp):
)
def test_hierarchy_timestamp_cadence(self, refinement_boxes):
dim = refinement_boxes["L0"]["B0"].ndim

interp = 1
time_step = 0.001
# time_step_nbr chosen to force diagnostics dumping double imprecision cadence calculations accuracy testing
time_step_nbr = 101
Expand All @@ -152,8 +153,11 @@ def test_hierarchy_timestamp_cadence(self, refinement_boxes):
for trailing in [0, 1]: # 1 = skip init dumps
for i in [2, 3]:
simInput = simArgs.copy()
diag_outputs = self.unique_diag_dir_for_test_case(out, dim, 1)
diag_outputs = self.unique_diag_dir_for_test_case(
f"{out}/{i}", dim, interp
)
simInput["diag_options"]["options"]["dir"] = diag_outputs
self.register_diag_dir_for_cleanup(diag_outputs)
simInput["time_step_nbr"] = time_step_nbr

ph.global_vars.sim = None
Expand Down
34 changes: 21 additions & 13 deletions tests/simulator/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@
startMPI()

time_step = 0.005
final_time = .1
final_time = 0.1
time_step_nbr = int(final_time / time_step)
timestamps = np.arange(0, final_time+.01, 0.05)
timestamps = np.arange(0, final_time + 0.01, 0.05)
diag_dir = "phare_outputs/test_run"
plot_dir = Path(f"{diag_dir}_plots")
plot_dir.mkdir(parents=True, exist_ok=True)

def config():

def config(diag_outputs):
L = 0.5

sim = ph.Simulation(
Expand All @@ -44,8 +45,8 @@ def config():
resistivity=0.001,
diag_options={
"format": "phareh5",
"options": {"dir": diag_dir, "mode": "overwrite"},
}
"options": {"dir": diag_outputs, "mode": "overwrite"},
},
)

def density(x, y):
Expand Down Expand Up @@ -154,7 +155,9 @@ def vthz(x, y):
write_timestamps=timestamps,
population_name=pop,
)
ph.FluidDiagnostics(quantity="density", write_timestamps=timestamps, population_name=pop)
ph.FluidDiagnostics(
quantity="density", write_timestamps=timestamps, population_name=pop
)

return sim

Expand All @@ -180,7 +183,7 @@ def plot(diag_dir):
filename=plot_file_for_qty("N", time),
plot_patches=True,
)
for c in ["x","y","z"]:
for c in ["x", "y", "z"]:
run.GetB(time).plot(
filename=plot_file_for_qty(f"b{c}", time),
qty=f"B{c}",
Expand All @@ -200,7 +203,10 @@ def assert_file_exists_with_size_at_least(file, size=10000):
if not path.exists():
raise FileNotFoundError("file not found: " + file)
if path.stat().st_size < size:
raise ValueError("file has unexpected size, possibly corrupt or not written properly: " + file)
raise ValueError(
"file has unexpected size, possibly corrupt or not written properly: "
+ file
)


class RunTest(SimulatorTest):
Expand All @@ -216,22 +222,24 @@ def tearDown(self):
ph.global_vars.sim = None

def test_run(self):
sim = config()
self.register_diag_dir_for_cleanup(diag_dir)
diag_outputs = self.unique_diag_dir_for_test_case(diag_dir, ndim=2, interp=1)
sim = config(diag_outputs)
self.register_diag_dir_for_cleanup(diag_outputs)
Simulator(sim).run()
if cpp.mpi_rank() == 0:
plot(diag_dir)
plot(diag_outputs)

for time in timestamps:
for q in ["divb","Ranks","N","jz"]:
for q in ["divb", "Ranks", "N", "jz"]:
assert_file_exists_with_size_at_least(plot_file_for_qty(q, time))

for c in ["x","y","z"]:
for c in ["x", "y", "z"]:
assert_file_exists_with_size_at_least(plot_file_for_qty(f"b{c}", time))

cpp.mpi_barrier()


if __name__ == "__main__":
import unittest

unittest.main()
2 changes: 1 addition & 1 deletion tools/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def write_local_cmake_file(mpi_results):
if mpi_type == "OMPI":
# work around for https://github.com/open-mpi/ompi/issues/10761#issuecomment-1236909802
file.write(
"""set (PHARE_MPIRUN_POSTFIX "${PHARE_MPIRUN_POSTFIX} --bind-to none")
"""set (PHARE_MPIRUN_POSTFIX "${PHARE_MPIRUN_POSTFIX} --bind-to none -quiet")
"""
)

Expand Down

0 comments on commit fe6973b

Please sign in to comment.