Skip to content

Commit 175c459

Browse files
committed
smaller harris 1 level
1 parent 45db18b commit 175c459

File tree

3 files changed

+51
-134
lines changed

3 files changed

+51
-134
lines changed

tests/functional/harris/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ if(HighFive AND testMPI)
1212
## These test use dump diagnostics so require HighFive!
1313

1414
if(testMPI)
15-
phare_mpi_python3_exec(11 10 harris_2d harris_2d_lb.py ${CMAKE_CURRENT_BINARY_DIR})
15+
16+
phare_mpi_python3_exec(11 4 harris_2d_100_x_100 harris_2d_100_x_100.py ${CMAKE_CURRENT_BINARY_DIR})
17+
1618
endif(testMPI)
1719

1820
endif()

tests/functional/harris/harris_2d.py

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,25 @@
77
from pyphare.simulator.simulator import Simulator
88
from pyphare.simulator.simulator import startMPI
99

10-
os.environ["PHARE_SCOPE_TIMING"] = "1" # turn on scope timing
11-
"""
12-
For scope timings to work
13-
The env var PHARE_SCOPE_TIMING must be == "1" (or "true")
14-
See src/phare/phare.hpp
15-
CMake must be configured with: -DwithPhlop=ON
16-
And a LOG_LEVEL must be defined via compile args: -DPHARE_LOG_LEVEL=1
17-
Or change the default value in src/core/logger.hpp
18-
And phlop must be available on PYTHONPATH either from subprojects
19-
or install phlop via pip
20-
"""
21-
22-
23-
ph.NO_GUI()
24-
cpp = cpp_lib()
25-
startMPI()
26-
27-
diag_outputs = "phare_outputs/test/harris/2d"
28-
time_step_nbr = 1000
29-
time_step = 0.001
30-
final_time = time_step * time_step_nbr
31-
dt = 10 * time_step
32-
nt = final_time / dt + 1
33-
timestamps = dt * np.arange(nt)
34-
35-
36-
def config():
37-
sim = ph.Simulation(
10+
11+
def default_setup():
12+
13+
ph.NO_GUI()
14+
cpp = cpp_lib()
15+
startMPI()
16+
17+
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
22+
dt = 10 * time_step
23+
nt = final_time / dt + 1
24+
timestamps = dt * np.arange(nt)
25+
26+
return ph.Simulation(
27+
smallest_patch_size=15,
28+
largest_patch_size=25,
3829
time_step_nbr=time_step_nbr,
3930
time_step=time_step,
4031
# boundary_types="periodic",
@@ -51,6 +42,11 @@ def config():
5142
strict=True,
5243
)
5344

45+
46+
def config(sim = None, seed = 12334):
47+
if not sim:
48+
sim = default_setup()
49+
5450
def density(x, y):
5551
L = sim.simulation_domain()[1]
5652
return (
@@ -139,7 +135,7 @@ def vthz(x, y):
139135
bx=bx,
140136
by=by,
141137
bz=bz,
142-
protons={"charge": 1, "density": density, **vvv, "init": {"seed": 12334}},
138+
protons={"charge": 1, "density": density, **vvv, "init": {"seed": seed}},
143139
)
144140

145141
ph.ElectronModel(closure="isothermal", Te=0.0)
@@ -155,5 +151,6 @@ def main():
155151
Simulator(config()).run()
156152

157153

154+
158155
if __name__ == "__main__":
159156
main()

tests/functional/harris/harris_2d_lb.py renamed to tests/functional/harris/harris_2d_100_x_100.py

Lines changed: 22 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -10,43 +10,52 @@
1010
from pyphare.pharesee.run import Run
1111
from pyphare.simulator.simulator import Simulator, startMPI
1212

13-
1413
from tests.simulator import SimulatorTest
14+
from tools.python3 import plotting as m_plotting
15+
16+
import harris_2d as base
1517

1618
mpl.use("Agg")
1719

1820
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+
1932
LOAD_BALANCE = os.getenv("LOAD_BALANCE", "True").lower() in ("true", "1", "t")
2033

2134
cpp = cpp_lib()
2235
startMPI()
2336

24-
cells = (800, 800)
37+
cells = (100, 100)
38+
time_steps = 1000
2539
time_step = 0.005
26-
final_time = 50
40+
final_time = time_step * time_steps
2741
timestamps = np.arange(0, final_time + time_step, final_time / 5)
2842

2943
if cpp.mpi_rank() == 0:
3044
print(LOAD_BALANCE, "diag timestamps:", timestamps)
3145

32-
diag_dir = "phare_outputs/harris_lb"
33-
if not LOAD_BALANCE:
34-
diag_dir = "phare_outputs/harris"
35-
46+
diag_dir = "phare_outputs/harris_2d_100_x_100"
3647
plot_dir = Path(f"{diag_dir}_plots")
3748
plot_dir.mkdir(parents=True, exist_ok=True)
3849

3950

4051
def config():
41-
L = 0.5
42-
4352
sim = ph.Simulation(
4453
time_step=time_step,
4554
final_time=final_time,
4655
cells=cells,
4756
dl=(0.40, 0.40),
48-
refinement="tagging",
49-
max_nbr_levels=2,
57+
# refinement="tagging",
58+
max_nbr_levels=1,
5059
nesting_buffer=1,
5160
clustering="tile",
5261
tag_buffer="1",
@@ -56,91 +65,9 @@ def config():
5665
"format": "phareh5",
5766
"options": {"dir": diag_dir, "mode": "overwrite"},
5867
},
59-
restart_options={
60-
"dir": "checkpoints",
61-
"mode": "overwrite",
62-
"timestamps": timestamps,
63-
# "restart_time": 0.0,
64-
},
65-
)
66-
67-
def density(x, y):
68-
Ly = sim.simulation_domain()[1]
69-
return (
70-
0.4
71-
+ 1.0 / np.cosh((y - Ly * 0.3) / L) ** 2
72-
+ 1.0 / np.cosh((y - Ly * 0.7) / L) ** 2
73-
)
74-
75-
def S(y, y0, l):
76-
return 0.5 * (1.0 + np.tanh((y - y0) / l))
77-
78-
def by(x, y):
79-
Lx = sim.simulation_domain()[0]
80-
Ly = sim.simulation_domain()[1]
81-
sigma = 1.0
82-
dB = 0.1
83-
84-
x0 = x - 0.5 * Lx
85-
y1 = y - 0.3 * Ly
86-
y2 = y - 0.7 * Ly
87-
88-
dBy1 = 2 * dB * x0 * np.exp(-(x0**2 + y1**2) / (sigma) ** 2)
89-
dBy2 = -2 * dB * x0 * np.exp(-(x0**2 + y2**2) / (sigma) ** 2)
90-
91-
return dBy1 + dBy2
92-
93-
def bx(x, y):
94-
Lx = sim.simulation_domain()[0]
95-
Ly = sim.simulation_domain()[1]
96-
sigma = 1.0
97-
dB = 0.1
98-
99-
x0 = x - 0.5 * Lx
100-
y1 = y - 0.3 * Ly
101-
y2 = y - 0.7 * Ly
102-
103-
dBx1 = -2 * dB * y1 * np.exp(-(x0**2 + y1**2) / (sigma) ** 2)
104-
dBx2 = 2 * dB * y2 * np.exp(-(x0**2 + y2**2) / (sigma) ** 2)
105-
106-
v1 = -1
107-
v2 = 1.0
108-
return v1 + (v2 - v1) * (S(y, Ly * 0.3, L) - S(y, Ly * 0.7, L)) + dBx1 + dBx2
109-
110-
def bz(x, y):
111-
return 0.0
112-
113-
def b2(x, y):
114-
return bx(x, y) ** 2 + by(x, y) ** 2 + bz(x, y) ** 2
115-
116-
def T(x, y):
117-
K = 0.7
118-
temp = 1.0 / density(x, y) * (K - b2(x, y) * 0.5)
119-
assert np.all(temp > 0)
120-
return temp
121-
122-
def vxyz(x, y):
123-
return 0.0
124-
125-
def vthxyz(x, y):
126-
return np.sqrt(T(x, y))
127-
128-
vvv = {**{f"vbulk{c}": vxyz for c in "xyz"}, **{f"vth{c}": vthxyz for c in "xyz"}}
129-
130-
ph.MaxwellianFluidModel(
131-
bx=bx, by=by, bz=bz, protons={"charge": 1, "density": density, **vvv}
13268
)
133-
ph.ElectronModel(closure="isothermal", Te=0.0)
13469

135-
for quantity in ["E", "B"]:
136-
ph.ElectromagDiagnostics(quantity=quantity, write_timestamps=timestamps)
137-
for quantity in ["density", "bulkVelocity"]:
138-
ph.FluidDiagnostics(quantity=quantity, write_timestamps=timestamps)
139-
140-
ph.FluidDiagnostics(
141-
quantity="density", write_timestamps=timestamps, population_name="protons"
142-
)
143-
ph.InfoDiagnostics(quantity="particle_count")
70+
sim = base.config(sim)
14471

14572
if LOAD_BALANCE:
14673
ph.LoadBalancer(active=True, auto=True, mode="nppc", tol=0.05)
@@ -184,15 +111,6 @@ def plot(diag_dir):
184111
)
185112

186113

187-
def plot_runtimer(diag_dir, rank):
188-
try:
189-
from tools.python3 import plotting as m_plotting
190-
191-
m_plotting.plot_run_timer_data(diag_dir, cpp.mpi_rank())
192-
except ImportError:
193-
print("phlop not found - or phare src dir not in pythonpath")
194-
195-
196114
class HarrisTest(SimulatorTest):
197115
def __init__(self, *args, **kwargs):
198116
super(HarrisTest, self).__init__(*args, **kwargs)
@@ -211,7 +129,7 @@ def test_run(self):
211129
if cpp.mpi_rank() == 0:
212130
plot(diag_dir)
213131
if SCOPE_TIMING:
214-
plot_runtimer(diag_dir, cpp.mpi_rank())
132+
m_plotting.plot_run_timer_data(diag_dir, cpp.mpi_rank())
215133
cpp.mpi_barrier()
216134
return self
217135

0 commit comments

Comments
 (0)