Skip to content

Commit

Permalink
Fixed ICRH wave field plotting (Im(E+) and Im(E-)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsjoona committed Jul 22, 2024
1 parent 4c292aa commit e46e959
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 20 deletions.
2 changes: 1 addition & 1 deletion a5py/ascotpy/ascot2py.py
Original file line number Diff line number Diff line change
Expand Up @@ -2845,7 +2845,7 @@ class struct_c__SA_rfof_data(Structure):
rfof_interface_deallocate_marker.argtypes = [ctypes.POINTER(ctypes.POINTER(None))]
rfof_interface_get_rf_wave_local = _libraries['libascot.so'].rfof_interface_get_rf_wave_local
rfof_interface_get_rf_wave_local.restype = None
rfof_interface_get_rf_wave_local.argtypes = [ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.POINTER(None)), ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double)]
rfof_interface_get_rf_wave_local.argtypes = [ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.POINTER(None)), ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double)]
rfof_interface_eval_resonance_function = _libraries['libascot.so'].rfof_interface_eval_resonance_function
rfof_interface_eval_resonance_function.restype = None
rfof_interface_eval_resonance_function.argtypes = [ctypes.POINTER(ctypes.POINTER(None)), ctypes.POINTER(ctypes.POINTER(None)), ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_int32)]
Expand Down
20 changes: 12 additions & 8 deletions a5py/ascotpy/libascot.py
Original file line number Diff line number Diff line change
Expand Up @@ -911,9 +911,10 @@ def input_eval_rfof(self, m, q, vpar, r, phi, z, t):
Returns
-------
eplus : array_like, (n,)
Reaction cross-section.
eminus : array_like, (n,)
eplus_real : array_like, (n,)
eminus_real : array_like, (n,)
eplus_imag : array_like, (n,)
eminus_imag : array_like, (n,)
rescond : array_like, (n,)
Raises
Expand All @@ -926,17 +927,20 @@ def input_eval_rfof(self, m, q, vpar, r, phi, z, t):
raise RuntimeError("RFOF data not initialized.")

Neval = r.size
eplus = np.NaN * np.zeros((Neval,), dtype="f8") * unyt.V/unyt.m
eminus = np.NaN * np.zeros((Neval,), dtype="f8") * unyt.V/unyt.m
eplus_real = np.NaN * np.zeros((Neval,), dtype="f8") * unyt.V/unyt.m
eminus_real = np.NaN * np.zeros((Neval,), dtype="f8") * unyt.V/unyt.m
eplus_imag = np.NaN * np.zeros((Neval,), dtype="f8") * unyt.V/unyt.m
eminus_imag = np.NaN * np.zeros((Neval,), dtype="f8") * unyt.V/unyt.m
res_cond = np.NaN * np.zeros((Neval,), dtype="f8") * unyt.dimensionless

fun = _LIBASCOT.libascot_eval_rfof
fun.restype = None
fun.argtypes = [PTR_SIM, PTR_ARR,
ctypes.c_int, PTR_REAL, PTR_REAL, PTR_REAL, PTR_REAL,
ctypes.c_double, ctypes.c_double, ctypes.c_double,
PTR_REAL, PTR_REAL, PTR_REAL]
PTR_REAL, PTR_REAL, PTR_REAL, PTR_REAL, PTR_REAL]
fun(ctypes.byref(self._sim), self._bfield_offload_array,
Neval, r, phi, z, t, m, q, vpar, eplus, eminus, res_cond)
Neval, r, phi, z, t, m, q, vpar, eplus_real, eminus_real,
eplus_imag, eminus_imag, res_cond)

return eplus, eminus, res_cond
return eplus_real, eminus_real, eplus_imag, eminus_imag, res_cond
16 changes: 12 additions & 4 deletions src/libascot.c
Original file line number Diff line number Diff line change
Expand Up @@ -1006,15 +1006,22 @@ void libascot_eval_ratecoeff(
* @param mass test particle mass (for computing resonance) [kg].
* @param q test particle charge (for computing resonance) [C].
* @param vpar test particle parallel velocity (for computing resonance) [m/s].
* @param Eplus left-handed electric field component of the wave [V/m].
* @param Eminus right-handed electric field component of the wave [V/m].
* @param Eplus_real Real part of the left-handed electric field component of
* the wave [V/m].
* @param Eminus_real Real part of the right-handed electric field component of
* the wave [V/m].
* @param Eplus_imag Imaginary part of the left-handed electric field component
* of the wave [V/m].
* @param Eminus_imag Imaginary part of the right-handed electric field
* component of the wave [V/m].
* @param res_cond value of the resonance condition where zero is the resonance
* [unitless].
*/
void libascot_eval_rfof(
sim_offload_data* sim_offload_data, real* B_offload_array, int Neval,
real* R, real* phi, real* z, real* t, real mass, real q, real vpar,
real* Eplus, real* Eminus, real* res_cond) {
real* Eplus_real, real* Eminus_real, real* Eplus_imag, real* Eminus_imag,
real* res_cond) {

sim_data sim;
B_field_init(&sim.B_data, &sim_offload_data->B_offload_data,
Expand Down Expand Up @@ -1051,7 +1058,8 @@ void libascot_eval_rfof(
// TODO: this should return a non-zero value if the evaluation failed.
rfof_interface_get_rf_wave_local(
&(R[k]), &(z[k]), &dummy_real, &dummy_real,
&(sim.rfof_data.cptr_rfglobal), &(Eplus[k]), &(Eminus[k]));
&(sim.rfof_data.cptr_rfglobal), &(Eplus_real[k]), &(Eminus_real[k]),
&(Eplus_imag[k]), &(Eminus_imag[k]));
rfof_interface_deallocate_marker(&marker_pointer);
continue;
}
Expand Down
15 changes: 9 additions & 6 deletions src/rfof_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ void __ascot5_icrh_routines_MOD_deallocate_marker(void** cptr_rfof_marker);
/* FOR VISUALISING ICRH WAVE FIELD */

void __ascot5_icrh_routines_MOD_get_rf_wave_local_v2(real* R, real* z,
real* rho_tor, real* theta, void** cptr_wi, real* e_plus_out,
real* e_minus_out);
real* rho_tor, real* theta, void** cptr_wi, real* e_plus_real,
real* e_minus_real, real* e_plus_imag, real* e_minus_imag);

void __ascot5_icrh_routines_MOD_eval_resonance_function(void** cptr_marker,
void** cptr_rfglobal, real* omega_res, int* nharm);
Expand Down Expand Up @@ -659,14 +659,17 @@ void rfof_interface_deallocate_marker(void** cptr_rfof_marker) {
* @param theta
* @param cptr_rfglobal Void pointer to the RFglobal global wave field in
* fortran
* @param e_plus E+ component of the local wave field
* @param e_minus E- component of the local wave field
* @param e_plus_real Re(E+) component of the local wave field
* @param e_minus_real Re(E-) component of the local wave field
* @param e_plus_imag Im(E+) component of the local wave field
* @param e_minus_imag Im(E-) component of the local wave field
*/
void rfof_interface_get_rf_wave_local(real* R, real* z, real* rho_tor,
real* theta, void** cptr_wi, real* e_plus_out, real* e_minus_out) {
real* theta, void** cptr_wi, real* e_plus_real, real* e_minus_real,
real* e_plus_imag, real* e_minus_imag) {
#ifdef RFOF
__ascot5_icrh_routines_MOD_get_rf_wave_local_v2(R, z, rho_tor, theta,
cptr_wi, e_plus_out, e_minus_out);
cptr_wi, e_plus_real, e_minus_real, e_plus_imag, e_minus_imag);
#endif
};

Expand Down
3 changes: 2 additions & 1 deletion src/rfof_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ void rfof_interface_deallocate_marker(void** cptr_rfof_marker);
/* FOR VISUALISING ICRH WAVE FIELD AND RESONANCE */

void rfof_interface_get_rf_wave_local(real* R, real* z, real* rho_tor,
real* theta, void** cptr_wi, real* e_plus_out, real* e_minus_out);
real* theta, void** cptr_wi, real* e_plus_real, real* e_minus_real,
real* e_plus_imag, real* e_minus_imag);

void rfof_interface_eval_resonance_function(void** cptr_marker,
void** cptr_rfglobal, real* omega_res, int* nharm);
Expand Down

0 comments on commit e46e959

Please sign in to comment.