Skip to content

Commit be3f8c4

Browse files
committed
add post_processed_outputs as input for geometry_to_IMAS
1 parent b0eb90f commit be3f8c4

1 file changed

Lines changed: 16 additions & 12 deletions

File tree

torax/torax_imastools/equilibrium.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,13 @@ def geometry_from_IMAS(
177177
"z_magnetic_axis": z_magnetic_axis,
178178
}
179179

180+
180181
@requires_module("imas")
181-
def geometry_to_IMAS(SimState: state.ToraxSimState, equilibrium_in: IDSToplevel | None=None) -> IDSToplevel:
182+
def geometry_to_IMAS(
183+
SimState: state.ToraxSimState,
184+
post_processed_outputs: state.PostProcessedOutputs,
185+
equilibrium_in: IDSToplevel | None = None,
186+
) -> IDSToplevel:
182187
"""Constructs an IMAS equilibrium IDS from a StandardGeometry object.
183188
Takes the cell grid as a basis and converts values on face grid to cell.
184189
Args:
@@ -194,13 +199,12 @@ def geometry_to_IMAS(SimState: state.ToraxSimState, equilibrium_in: IDSToplevel
194199

195200
geometry = SimState.geometry
196201
core_profiles = SimState.core_profiles
197-
post_processed_outputs = SimState.post_processed_outputs
198-
#Rebuilding the equilibrium from the geometry object (Which should remain unchanged by the transport code), is it needed or do we only need coupling variables ?
202+
# Rebuilding the equilibrium from the geometry object (Which should remain unchanged by the transport code), is it needed or do we only need coupling variables ?
199203
equilibrium = imas.IDSFactory().equilibrium()
200-
equilibrium.ids_properties.homogeneous_time = 1 #Should be 0 or 1 ?
204+
equilibrium.ids_properties.homogeneous_time = 1 # Should be 0 or 1 ?
201205
equilibrium.ids_properties.comment = "equilibrium IDS built from ToraxSimState object."
202206
equilibrium.time.resize(1)
203-
equilibrium.time = [SimState.t] #What time should be set ? Needed for B0
207+
equilibrium.time = [SimState.t] # What time should be set ? Needed for B0
204208
equilibrium.vacuum_toroidal_field.r0 = geometry.Rmaj
205209
equilibrium.vacuum_toroidal_field.b0.resize(1)
206210
equilibrium.vacuum_toroidal_field.b0[0] = -1 * geometry.B0
@@ -230,7 +234,7 @@ def geometry_to_IMAS(SimState: state.ToraxSimState, equilibrium_in: IDSToplevel
230234
1
231235
* np.gradient(eq.profiles_1d.volume)
232236
/ np.gradient(eq.profiles_1d.psi)
233-
)
237+
)
234238
dpsidrhotor = (
235239
1
236240
* np.gradient(eq.profiles_1d.psi)
@@ -243,19 +247,19 @@ def geometry_to_IMAS(SimState: state.ToraxSimState, equilibrium_in: IDSToplevel
243247
eq.profiles_1d.gm3 = geometry.g1 / (dpsidrhotor ** 2 * dvoldpsi**2)
244248
eq.profiles_1d.gm2 = geometry.g2 / (dpsidrhotor ** 2 * dvoldpsi**2)
245249

246-
#Quantities computed by the transport code useful for coupling with equilibrium code
250+
# Quantities computed by the transport code useful for coupling with equilibrium code
247251
eq.profiles_1d.pressure = face_to_cell(post_processed_outputs.pressure_thermal_tot_face)
248252
eq.profiles_1d.dpressure_dpsi = face_to_cell(post_processed_outputs.pprime_face)
249253

250-
#<j.B>/B0, could be useful to calculate and use instead of FF'
254+
# <j.B>/B0, could be useful to calculate and use instead of FF'
251255
# determine sign how?
252-
eq.profiles_1d.f = -1 * geometry.F #Is probably not self-consistent due to the evolution of the state by the solver.
256+
eq.profiles_1d.f = -1 * geometry.F # Is probably not self-consistent due to the evolution of the state by the solver.
253257
eq.profiles_1d.f_df_dpsi = face_to_cell(post_processed_outputs.FFprime_face)
254258
eq.profiles_1d.q = face_to_cell(core_profiles.q_face)
255259

256-
#Optionally maps fixed quantities not evolved by TORAX and read directly from input equilibrium. Needed to couple with NICE inverse
260+
# Optionally maps fixed quantities not evolved by TORAX and read directly from input equilibrium. Needed to couple with NICE inverse
257261
if equilibrium_in is not None:
258-
eq.boundary.outline.r = equilibrium_in.time_slice[0].boundary.outline.r
259-
eq.boundary.outline.z = equilibrium_in.time_slice[0].boundary.outline.z
262+
eq.boundary.outline.r = equilibrium_in.time_slice[0].boundary.outline.r
263+
eq.boundary.outline.z = equilibrium_in.time_slice[0].boundary.outline.z
260264

261265
return equilibrium

0 commit comments

Comments
 (0)