15import sys, io, subprocess, traceback
32BIN_KW = dict(i_discrete=i_mobile, v_discrete=v_mobile, I_bin=15, V_bin=15)
36 sys.path.insert(0, str(REPO_ROOT))
37 sys.path.insert(0, str(MODULE_ROOT))
39 from radcluster_code.py_utils.simulation
import RadClusterSimulation
41 po = (
'full_CD_' if eq ==
'discrete' else 'bin_moment_CD_') + cas
42 _saved = sys.stdout, sys.stderr
43 sys.stdout = sys.stderr = io.StringIO()
45 sim = RadClusterSimulation(I=I, V=V, solver_mode=
'full_system',
46 physics_option=po, C_floor=1e-25,
48 i_mobile=i_mobile, v_mobile=v_mobile)
50 if eq ==
'bin_moment':
51 for k, v
in BIN_KW.items():
53 inp.reactions[
'shape_function'] =
'linear'
54 inp._calculate_derived()
56 results = sim.run_adaptive(
57 solver_config=SOLVER_CONFIG, save_output=
False,
58 boundary_threshold=0.1, max_doublings=0, points_per_segment=10)
60 sys.stdout, sys.stderr = _saved
63 print(
'RESULT FAILED solver-returned-None')
65 dHe = np.asarray(results[
'delta_He'])
66 dFP = np.asarray(results[
'delta_FP'])
67 He_tot = np.asarray(results[
'C_He_tot'])
70 mask = He_tot > (He_tot[-1] * 1e-6
if He_tot[-1] > 0
else 0.0)
71 dHe_max = float(np.max(dHe[mask]))
if mask.any()
else float(np.max(dHe))
72 print(f
'RESULT OK {dHe_max:.3e} {dHe[-1]:.3e} {dFP[-1]:.3e}')
77 configs = [(eq, cas, hk)
78 for eq
in (
'discrete',
'bin_moment')
79 for cas
in (
'fission',
'fusion')
80 for hk
in (
'quasi_steady_state',
'dynamic')]
82 for eq, cas, hk
in configs:
83 label = f
'{eq:>10s}/{cas:<7s}/{hk}'
84 proc = subprocess.run([sys.executable, __file__, eq, cas, hk],
85 capture_output=
True, text=
True, timeout=1800)
86 line = next((l
for l
in proc.stdout.splitlines()
87 if l.startswith(
'RESULT')),
None)
88 if line
is None or 'FAILED' in line
or proc.returncode != 0:
89 rows.append((label,
None))
90 print(f
'{label}: FAILED', flush=
True)
91 tail = (proc.stderr
or proc.stdout).strip().splitlines()
93 print(f
' {l}', flush=
True)
95 _, _, dmax, dlast, dfp = line.split()
96 rows.append((label, float(dmax)))
97 print(f
'{label}: max delta_He = {dmax} final delta_He = {dlast}'
98 f
' final delta_FP = {dfp}', flush=
True)
100 print(
'\n' +
'=' * 78, flush=
True)
101 bad = [r
for r
in rows
if r[1]
is None or r[1] > 1e-6]
103 print(f
'ALL {len(rows)} CONFIGS PASS: max delta_He <= 1e-6.', flush=
True)
105 print(f
'{len(bad)} of {len(rows)} configs exceed delta_He = 1e-6:', flush=
True)
107 print(f
' {r[0]}: {r[1]}', flush=
True)