10
10
from pyphare .pharesee .run import Run
11
11
from pyphare .simulator .simulator import Simulator , startMPI
12
12
13
-
14
13
from tests .simulator import SimulatorTest
14
+ from tools .python3 import plotting as m_plotting
15
+
16
+ import harris_2d as base
15
17
16
18
mpl .use ("Agg" )
17
19
18
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
+
19
32
LOAD_BALANCE = os .getenv ("LOAD_BALANCE" , "True" ).lower () in ("true" , "1" , "t" )
20
33
21
34
cpp = cpp_lib ()
22
35
startMPI ()
23
36
24
- cells = (800 , 800 )
37
+ cells = (100 , 100 )
38
+ time_steps = 1000
25
39
time_step = 0.005
26
- final_time = 50
40
+ final_time = time_step * time_steps
27
41
timestamps = np .arange (0 , final_time + time_step , final_time / 5 )
28
42
29
43
if cpp .mpi_rank () == 0 :
30
44
print (LOAD_BALANCE , "diag timestamps:" , timestamps )
31
45
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"
36
47
plot_dir = Path (f"{ diag_dir } _plots" )
37
48
plot_dir .mkdir (parents = True , exist_ok = True )
38
49
39
50
40
51
def config ():
41
- L = 0.5
42
-
43
52
sim = ph .Simulation (
44
53
time_step = time_step ,
45
54
final_time = final_time ,
46
55
cells = cells ,
47
56
dl = (0.40 , 0.40 ),
48
- refinement = "tagging" ,
49
- max_nbr_levels = 2 ,
57
+ # refinement="tagging",
58
+ max_nbr_levels = 1 ,
50
59
nesting_buffer = 1 ,
51
60
clustering = "tile" ,
52
61
tag_buffer = "1" ,
@@ -56,91 +65,9 @@ def config():
56
65
"format" : "phareh5" ,
57
66
"options" : {"dir" : diag_dir , "mode" : "overwrite" },
58
67
},
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 }
132
68
)
133
- ph .ElectronModel (closure = "isothermal" , Te = 0.0 )
134
69
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 )
144
71
145
72
if LOAD_BALANCE :
146
73
ph .LoadBalancer (active = True , auto = True , mode = "nppc" , tol = 0.05 )
@@ -184,15 +111,6 @@ def plot(diag_dir):
184
111
)
185
112
186
113
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
-
196
114
class HarrisTest (SimulatorTest ):
197
115
def __init__ (self , * args , ** kwargs ):
198
116
super (HarrisTest , self ).__init__ (* args , ** kwargs )
@@ -211,7 +129,7 @@ def test_run(self):
211
129
if cpp .mpi_rank () == 0 :
212
130
plot (diag_dir )
213
131
if SCOPE_TIMING :
214
- plot_runtimer (diag_dir , cpp .mpi_rank ())
132
+ m_plotting . plot_run_timer_data (diag_dir , cpp .mpi_rank ())
215
133
cpp .mpi_barrier ()
216
134
return self
217
135
0 commit comments