Skip to content

Commit 69bc76b

Browse files
committed
++
1 parent 175c459 commit 69bc76b

File tree

4 files changed

+170
-18
lines changed

4 files changed

+170
-18
lines changed

tests/functional/harris/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ if(HighFive AND testMPI)
1414
if(testMPI)
1515

1616
phare_mpi_python3_exec(11 4 harris_2d_100_x_100 harris_2d_100_x_100.py ${CMAKE_CURRENT_BINARY_DIR})
17+
phare_mpi_python3_exec(11 4 harris_2d_100_x_100_slow harris_2d_100_x_100_slow.py ${CMAKE_CURRENT_BINARY_DIR})
1718

1819
endif(testMPI)
1920

tests/functional/harris/harris_2d.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python3
2-
import os
2+
33
import numpy as np
44

55
import pyphare.pharein as ph
@@ -8,21 +8,26 @@
88
from pyphare.simulator.simulator import startMPI
99

1010

11-
def default_setup():
11+
ph.NO_GUI()
12+
cpp = cpp_lib()
1213

13-
ph.NO_GUI()
14-
cpp = cpp_lib()
15-
startMPI()
1614

1715

18-
diag_outputs = "phare_outputs/test/harris/2d"
19-
time_step_nbr = 1000
20-
time_step = 0.001
21-
final_time = time_step * time_step_nbr
16+
diag_outputs = "phare_outputs/test/harris/2d"
17+
time_step_nbr = 1000
18+
time_step = 0.001
19+
final_time = time_step * time_step_nbr
20+
21+
22+
def default_timestamps():
2223
dt = 10 * time_step
2324
nt = final_time / dt + 1
2425
timestamps = dt * np.arange(nt)
2526

27+
28+
def default_setup():
29+
startMPI()
30+
2631
return ph.Simulation(
2732
smallest_patch_size=15,
2833
largest_patch_size=25,
@@ -43,9 +48,11 @@ def default_setup():
4348
)
4449

4550

46-
def config(sim = None, seed = 12334):
47-
if not sim:
51+
def config(sim = None, timestamps = None, seed = 12334):
52+
if sim is None:
4853
sim = default_setup()
54+
if timestamps is None:
55+
timestamps = default_timestamps()
4956

5057
def density(x, y):
5158
L = sim.simulation_domain()[1]

tests/functional/harris/harris_2d_100_x_100.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,10 @@
3535
startMPI()
3636

3737
cells = (100, 100)
38-
time_steps = 1000
38+
final_time = 50
3939
time_step = 0.005
40-
final_time = time_step * time_steps
4140
timestamps = np.arange(0, final_time + time_step, final_time / 5)
4241

43-
if cpp.mpi_rank() == 0:
44-
print(LOAD_BALANCE, "diag timestamps:", timestamps)
45-
4642
diag_dir = "phare_outputs/harris_2d_100_x_100"
4743
plot_dir = Path(f"{diag_dir}_plots")
4844
plot_dir.mkdir(parents=True, exist_ok=True)
@@ -55,7 +51,7 @@ def config():
5551
cells=cells,
5652
dl=(0.40, 0.40),
5753
# refinement="tagging",
58-
max_nbr_levels=1,
54+
# max_nbr_levels=1,
5955
nesting_buffer=1,
6056
clustering="tile",
6157
tag_buffer="1",
@@ -67,7 +63,14 @@ def config():
6763
},
6864
)
6965

70-
sim = base.config(sim)
66+
sim = base.config(sim, timestamps)
67+
68+
for quantity in ["density", "bulkVelocity"]:
69+
ph.FluidDiagnostics(quantity=quantity, write_timestamps=timestamps)
70+
71+
ph.FluidDiagnostics(
72+
quantity="density", write_timestamps=timestamps, population_name="protons"
73+
)
7174

7275
if LOAD_BALANCE:
7376
ph.LoadBalancer(active=True, auto=True, mode="nppc", tol=0.05)
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
import numpy as np
5+
import matplotlib as mpl
6+
from pathlib import Path
7+
8+
import pyphare.pharein as ph
9+
from pyphare.cpp import cpp_lib
10+
from pyphare.pharesee.run import Run
11+
from pyphare.simulator.simulator import Simulator, startMPI
12+
13+
from tests.simulator import SimulatorTest
14+
from tools.python3 import plotting as m_plotting
15+
16+
import harris_2d as base
17+
18+
mpl.use("Agg")
19+
20+
SCOPE_TIMING = os.getenv("PHARE_SCOPE_TIMING", "False").lower() in ("true", "1", "t")
21+
"""
22+
For scope timings to work
23+
The env var PHARE_SCOPE_TIMING must be == "1" (or "true")
24+
See src/phare/phare.hpp
25+
CMake must be configured with: -DwithPhlop=ON
26+
And a LOG_LEVEL must be defined via compile args: -DPHARE_LOG_LEVEL=1
27+
Or change the default value in src/core/logger.hpp
28+
And phlop must be available on PYTHONPATH either from subprojects
29+
or install phlop via pip
30+
"""
31+
32+
LOAD_BALANCE = os.getenv("LOAD_BALANCE", "True").lower() in ("true", "1", "t")
33+
34+
cpp = cpp_lib()
35+
startMPI()
36+
37+
cells = (100, 100)
38+
final_time = 50
39+
time_step = 0.001
40+
timestamps = np.arange(0, final_time + time_step, final_time / 5)
41+
42+
diag_dir = "phare_outputs/harris_2d_100_x_100_slow"
43+
plot_dir = Path(f"{diag_dir}_plots")
44+
plot_dir.mkdir(parents=True, exist_ok=True)
45+
46+
47+
def config():
48+
sim = ph.Simulation(
49+
time_step=time_step,
50+
final_time=final_time,
51+
cells=cells,
52+
dl=(0.40, 0.40),
53+
# refinement="tagging",
54+
# max_nbr_levels=1,
55+
nesting_buffer=1,
56+
clustering="tile",
57+
tag_buffer="1",
58+
hyper_resistivity=0.002,
59+
resistivity=0.001,
60+
diag_options={
61+
"format": "phareh5",
62+
"options": {"dir": diag_dir, "mode": "overwrite"},
63+
},
64+
)
65+
66+
sim = base.config(sim, timestamps)
67+
68+
for quantity in ["density", "bulkVelocity"]:
69+
ph.FluidDiagnostics(quantity=quantity, write_timestamps=timestamps)
70+
71+
ph.FluidDiagnostics(
72+
quantity="density", write_timestamps=timestamps, population_name="protons"
73+
)
74+
75+
if LOAD_BALANCE:
76+
ph.LoadBalancer(active=True, auto=True, mode="nppc", tol=0.05)
77+
78+
return sim
79+
80+
81+
def plot_file_for_qty(qty, time):
82+
return f"{plot_dir}/harris_{qty}_t{time}.png"
83+
84+
85+
def plot(diag_dir):
86+
run = Run(diag_dir)
87+
for time in timestamps:
88+
run.GetDivB(time).plot(
89+
filename=plot_file_for_qty("divb", time),
90+
plot_patches=True,
91+
vmin=1e-11,
92+
vmax=2e-10,
93+
)
94+
run.GetRanks(time).plot(
95+
filename=plot_file_for_qty("Ranks", time),
96+
plot_patches=True,
97+
)
98+
run.GetN(time, pop_name="protons").plot(
99+
filename=plot_file_for_qty("N", time),
100+
plot_patches=True,
101+
)
102+
for c in ["x", "y", "z"]:
103+
run.GetB(time).plot(
104+
filename=plot_file_for_qty(f"b{c}", time),
105+
qty=f"{c}",
106+
plot_patches=True,
107+
)
108+
run.GetJ(time).plot(
109+
filename=plot_file_for_qty("jz", time),
110+
qty="z",
111+
plot_patches=True,
112+
vmin=-2,
113+
vmax=2,
114+
)
115+
116+
117+
class HarrisTest(SimulatorTest):
118+
def __init__(self, *args, **kwargs):
119+
super(HarrisTest, self).__init__(*args, **kwargs)
120+
self.simulator = None
121+
122+
def tearDown(self):
123+
super(HarrisTest, self).tearDown()
124+
if self.simulator is not None:
125+
self.simulator.reset()
126+
self.simulator = None
127+
ph.global_vars.sim = None
128+
129+
def test_run(self):
130+
self.register_diag_dir_for_cleanup(diag_dir)
131+
Simulator(config()).run().reset()
132+
if cpp.mpi_rank() == 0:
133+
plot(diag_dir)
134+
if SCOPE_TIMING:
135+
m_plotting.plot_run_timer_data(diag_dir, cpp.mpi_rank())
136+
cpp.mpi_barrier()
137+
return self
138+
139+
140+
if __name__ == "__main__":
141+
HarrisTest().test_run().tearDown()

0 commit comments

Comments
 (0)