@@ -76,6 +76,7 @@ def moments_3d(data_in, sc_pot=0, no_unit_conversion=False):
7676 'density'
7777 'flux'
7878 'eflux'
79+ 'qflux'
7980 'mftens'
8081 'velocity'
8182 'ptens'
@@ -159,6 +160,56 @@ def moments_3d(data_in, sc_pot=0, no_unit_conversion=False):
159160
160161 velocity = flux / density / 1e5 # km/s
161162
163+ # Heat flux moments -- derived from code contributed by Terry Liu
164+ #
165+ # Terry's code has been modified to work with the units, scaling, and spacecraft potential handling in moments_3d, rather than the older
166+ # n_3d, j_3d, and v_3d routines.
167+ # JWL 2025-07-10
168+
169+ eV_J = 1.602176634e-19 # conversion from eV to J
170+
171+ mp = data ['mass' ] # mass units are eV/(km/sec)^2, for working with eflux units. In these units, proton mass = 0.010453500
172+ q = eV_J
173+
174+ v = np .sqrt (2.0 * energy / mp ) # convert energy array to velocity (km/sec)
175+
176+ vx = v * np .cos (data ['theta' ]/ 180. * np .pi )* np .cos (data ['phi' ]/ 180. * np .pi )
177+ vy = v * np .cos (data ['theta' ]/ 180. * np .pi )* np .sin (data ['phi' ]/ 180. * np .pi )
178+ vz = v * np .sin (data ['theta' ]/ 180. * np .pi )
179+
180+ # Subtract bulk velocity to get thermal velocity, km/sec
181+
182+ wx = vx - velocity [0 ]
183+ wy = vy - velocity [1 ]
184+ wz = vz - velocity [2 ]
185+
186+ # thermal energy, eV
187+ Eth = 0.5 * mp * (wx ** 2 + wy ** 2 + wz ** 2 )
188+
189+ # Repurposed density calculation for integrating heat flux, original code made several calls to n_3d()
190+
191+ data_dvx = Eth * wx * data ['data' ] * de_e * weight * domega_weight [0 ,:,:]
192+ data_dvy = Eth * wy * data ['data' ] * de_e * weight * domega_weight [0 ,:,:]
193+ data_dvz = Eth * wz * data ['data' ] * de_e * weight * domega_weight [0 ,:,:]
194+
195+
196+ dweight = np .sqrt (e_inf )/ energy
197+ parqx = np .sqrt (mass / 2. )* 1e-5 * data_dvx * dweight
198+ parqy = np .sqrt (mass / 2. )* 1e-5 * data_dvy * dweight
199+ parqz = np .sqrt (mass / 2. )* 1e-5 * data_dvz * dweight
200+
201+ # Conversion to output units
202+ conv_mw = eV_J * 1.0e12 # output in mW/m^2
203+ conv_ev = 1.0e05 # output in eV/(cm^2-sec)
204+
205+
206+ heat_x = conv_ev * nansum (parqx )
207+ heat_y = conv_ev * nansum (parqy )
208+ heat_z = conv_ev * nansum (parqz )
209+
210+ qflux = [heat_x , heat_y , heat_z ]
211+
212+
162213 mf3x3 = np .array ([[mftens [0 ], mftens [3 ], mftens [4 ]], [mftens [3 ], mftens [1 ], mftens [5 ]], [mftens [4 ], mftens [5 ], mftens [2 ]]])
163214 pt3x3 = mf3x3 - np .outer (velocity , flux )* mass / 1e5
164215 ptens = np .array ([pt3x3 [0 , 0 ], pt3x3 [1 , 1 ], pt3x3 [2 , 2 ], pt3x3 [0 , 1 ], pt3x3 [0 , 2 ], pt3x3 [1 , 2 ]])
@@ -259,6 +310,7 @@ def moments_3d(data_in, sc_pot=0, no_unit_conversion=False):
259310 output = {'density' : density ,
260311 'flux' : flux ,
261312 'eflux' : eflux ,
313+ 'qflux' : qflux ,
262314 'mftens' : mftens ,
263315 'velocity' : velocity ,
264316 'ptens' : ptens ,
0 commit comments