Skip to content

Commit 05caf2f

Browse files
jcitrinTorax team
authored andcommitted
Avoid NaNs.
NaNs were found in solution in detached regime with qcc calculation and T_e_target calculations in extended Lengyel solver hybrid + fixed-point solver modes. Exposed when doing more integration testing with different configs. PiperOrigin-RevId: 839343474
1 parent 4611bd6 commit 05caf2f

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

torax/_src/edge/extended_lengyel_solvers.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,13 @@ def body_fun(i, carry):
164164
new_q_cc, physics_outcome = _solve_for_qcc(sol_model=current_sol_model)
165165

166166
# Calculate new target electron temperature with forward two-point model.
167-
current_sol_model.state.T_e_target = divertor_sol_1d_lib.calc_T_e_target(
168-
sol_model=current_sol_model,
169-
parallel_heat_flux_at_cc_interface=new_q_cc,
167+
# Clip to small positive value to avoid NaNs.
168+
current_sol_model.state.T_e_target = jnp.maximum(
169+
divertor_sol_1d_lib.calc_T_e_target(
170+
sol_model=current_sol_model,
171+
parallel_heat_flux_at_cc_interface=new_q_cc,
172+
),
173+
constants.CONSTANTS.eps,
170174
)
171175

172176
# Update kappa_e and alpha_t for the next iteration.
@@ -708,11 +712,17 @@ def _solve_for_qcc(
708712

709713
# Check for unphysical result.
710714
status = jnp.where(
711-
qcc_squared < 0.0,
715+
qcc_squared <= constants.CONSTANTS.eps,
712716
PhysicsOutcome.Q_CC_SQUARED_NEGATIVE,
713717
PhysicsOutcome.SUCCESS,
714718
)
715719

716-
qcc = jnp.where(status == PhysicsOutcome.SUCCESS, jnp.sqrt(qcc_squared), 0.0)
720+
# Clip qcc to a low but positive value to avoid NaNs. Still corresponds to
721+
# near total detachment.
722+
qcc = jnp.where(
723+
status == PhysicsOutcome.SUCCESS,
724+
jnp.sqrt(qcc_squared),
725+
constants.CONSTANTS.eps,
726+
)
717727

718728
return qcc, status

0 commit comments

Comments
 (0)