@@ -147,6 +147,53 @@ function flux_gacode_to_imas(
147147 end
148148end
149149
150+ """
151+ sources_to_gyrobohm(dd::IMAS.dd, rho_transport::AbstractVector{<:Real})
152+
153+ Compute total source fluxes in gyro-Bohm units at the transport grid locations.
154+
155+ Returns a NamedTuple `(Qe, Qi, Ge, Pi)` — electron heat flux, ion heat flux,
156+ electron particle flux, and toroidal momentum flux — each normalized by the
157+ local gyro-Bohm scale factor and the Miller volume correction.
158+
159+ This is the inverse of `flux_gacode_to_imas`: it takes IMAS physical source
160+ fluxes and converts them to the dimensionless gyro-Bohm units used by GA codes.
161+ """
162+ function sources_to_gyrobohm (dd:: IMAS.dd , rho_transport:: AbstractVector{<:Real} )
163+ cp1d = dd. core_profiles. profiles_1d[]
164+ eqt = dd. equilibrium. time_slice[]
165+
166+ total_source = resize! (dd. core_sources. source, :total ; wipe= false )
167+ total_source1d = resize! (total_source. profiles_1d; wipe= false )
168+ IMAS. total_sources! (total_source1d, dd. core_sources, cp1d;
169+ time0= dd. global_time,
170+ fields= [:total_ion_power_inside , :power_inside , :particles_inside , :torque_tor_inside ])
171+
172+ cs_gridpoints = [argmin_abs (total_source1d. grid. rho_tor_norm, rho_x) for rho_x in rho_transport]
173+ rho_cp_idxs = [argmin_abs (cp1d. grid. rho_tor_norm, rho_x) for rho_x in rho_transport]
174+ rho_eq_idxs = [argmin_abs (eqt. profiles_1d. rho_tor_norm, rho_x) for rho_x in rho_transport]
175+
176+ ne = cp1d. electrons. density_thermal[rho_cp_idxs]
177+ Te = cp1d. electrons. temperature[rho_cp_idxs]
178+ bu_itp = IMAS. interp1d (eqt. profiles_1d. rho_tor_norm, bunit (eqt. profiles_1d))
179+ rhos = rho_s .(cp1d. grid. rho_tor_norm[rho_cp_idxs], Te, Ref (bu_itp))
180+ a = eqt. boundary. minor_radius
181+ vprime_miller = volume_prime_miller_correction (eqt)[rho_eq_idxs]
182+
183+ gB_energy = gyrobohm_energy_flux .(ne, Te, rhos, a)
184+ gB_particle = gyrobohm_particle_flux .(ne, Te, rhos, a)
185+ gB_momentum = gyrobohm_momentum_flux .(ne, Te, rhos, a)
186+
187+ surface = total_source1d. grid. surface[cs_gridpoints]
188+
189+ Qe = (total_source1d. electrons. power_inside[cs_gridpoints] ./ surface) ./ (gB_energy .* vprime_miller)
190+ Qi = (total_source1d. total_ion_power_inside[cs_gridpoints] ./ surface) ./ (gB_energy .* vprime_miller)
191+ Ge = (total_source1d. electrons. particles_inside[cs_gridpoints] ./ surface) ./ (gB_particle .* vprime_miller)
192+ Pi = (total_source1d. torque_tor_inside[cs_gridpoints] ./ surface) ./ (gB_momentum .* vprime_miller)
193+
194+ return (; Qe, Qi, Ge, Pi)
195+ end
196+
150197"""
151198 pick_ion_flux(ion_fluxes::AbstractVector{T}, kk::Int) where {T<:Real}
152199
0 commit comments