Skip to content

Commit

Permalink
Cleaned RFOF implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
miekkasarki committed Jul 23, 2024
1 parent 04d7afe commit 021f273
Show file tree
Hide file tree
Showing 7 changed files with 349 additions and 709 deletions.
5 changes: 2 additions & 3 deletions src/ascot5_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
#include "diag.h"
#include "B_field.h"
#include "plasma.h"
#include "rfof.h"
#include "print.h"
#include "simulate.h"
#include "particle.h"
Expand Down Expand Up @@ -233,9 +234,7 @@ int main(int argc, char** argv) {
offload_free_offload(&offload_data, &offload_array, &int_offload_array);

if(sim.enable_icrh) {
rfof_interface_deallocate_rfof_input_param(
&(sim.rfof_data.cptr_rfof_input_params));
rfof_interface_deallocate_rfglobal(&(sim.rfof_data.cptr_rfglobal));
rfof_free_offload(&sim.rfof_data);
}

/* Write output and clean */
Expand Down
68 changes: 34 additions & 34 deletions src/libascot.c
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,7 @@ void libascot_eval_ratecoeff(
* @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].
* [dimensionless].
*/
void libascot_eval_rfof(
sim_offload_data* sim_offload_data, real* B_offload_array, int Neval,
Expand All @@ -1027,40 +1027,40 @@ void libascot_eval_rfof(
B_field_init(&sim.B_data, &sim_offload_data->B_offload_data,
B_offload_array);
rfof_init(&sim.rfof_data, &sim_offload_data->rfof_data);
#pragma omp parallel for
for(int k = 0; k < Neval; k++) {
real B[3];
if( B_field_eval_B(B, R[k], phi[k], z[k], t[k], &sim.B_data) ) {
continue;
}
real B_magn = sqrt(B[0]*B[0] + B[1]*B[1] + B[2]*B[2]);
real gyrofreq = q * B_magn / mass;

#pragma omp parallel
{
/* The function that evaluates resonance condition takes an RFOF marker
* as an input. However, only the R and vpar values are actually used.
* Therefore, we initialize a dummy marker and adjust only the values of
* R and vpar. */
void* marker_pointer;
* as an input. However, only the R and vpar values are actually used.
* Therefore, we initialize a dummy marker and adjust only the values of
* R and vpar. */
rfof_marker rfof_mrk;
int dummy_int = 1;
real dummy_real = -999.0;
rfof_interface_allocate_rfof_marker(&marker_pointer);
rfof_interface_set_marker_pointers(&marker_pointer, &dummy_int,
&dummy_real, &(R[k]), &dummy_real, &dummy_real, &dummy_real,
&dummy_real, &dummy_real, &dummy_real, &dummy_real, &dummy_real,
&dummy_real, &vpar, &dummy_real, &gyrofreq, &dummy_real,
&dummy_real, &dummy_int, &dummy_int);

int nharm; /* For storing return value which is not used */
rfof_interface_eval_resonance_function(
&marker_pointer, &(sim.rfof_data.cptr_rfglobal),
&(res_cond[k]), &nharm);

// 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_real[k]), &(Eminus_real[k]),
&(Eplus_imag[k]), &(Eminus_imag[k]));
rfof_interface_deallocate_marker(&marker_pointer);
continue;
real dummy_real = 0.0;
rfof_set_up(&rfof_mrk, &sim.rfof_data);

#pragma omp for
for(int k = 0; k < Neval; k++) {
real B[3];
if( B_field_eval_B(B, R[k], phi[k], z[k], t[k], &sim.B_data) ) {
continue;
}
real B_magn = sqrt(B[0]*B[0] + B[1]*B[1] + B[2]*B[2]);
real gyrofreq = q * B_magn / mass;
rfof_set_marker_manually(&rfof_mrk, &dummy_int,
&dummy_real, &(R[k]), &dummy_real, &dummy_real, &dummy_real,
&dummy_real, &dummy_real, &dummy_real, &dummy_real, &dummy_real,
&dummy_real, &vpar, &dummy_real, &gyrofreq, &dummy_real,
&dummy_real, &dummy_int, &dummy_int);

int nharm; /* For storing return value which is not used */
rfof_eval_resonance_function(
&(res_cond[k]), &nharm, &rfof_mrk, &(sim.rfof_data.rfglobal));

// TODO: this should return a non-zero value for failed evaluations
rfof_eval_rf_wave(
&(Eplus_real[k]), &(Eminus_real[k]), &(Eplus_imag[k]),
&(Eminus_imag[k]), R[k], z[k], &sim.rfof_data);
}
rfof_tear_down(&rfof_mrk);
}
}
Loading

0 comments on commit 021f273

Please sign in to comment.