ASCOT5
Loading...
Searching...
No Matches
libascot.c
Go to the documentation of this file.
1
8#include <stdlib.h>
9#include <stdio.h>
10#include <string.h>
11#include <hdf5.h>
12#include <math.h>
13
14#include "ascot5.h"
15#include "gitver.h"
16#include "math.h"
17#include "simulate.h"
18#include "B_field.h"
19#include "E_field.h"
20#include "plasma.h"
21#include "wall.h"
22#include "neutral.h"
23#include "boozer.h"
24#include "mhd.h"
25#include "asigma.h"
26#include "consts.h"
27#include "physlib.h"
28
30
31#include "hdf5_interface.h"
32#include "hdf5io/hdf5_helpers.h"
33#include "hdf5io/hdf5_bfield.h"
34#include "hdf5io/hdf5_efield.h"
35#include "hdf5io/hdf5_plasma.h"
36#include "hdf5io/hdf5_wall.h"
37#include "hdf5io/hdf5_neutral.h"
38#include "hdf5io/hdf5_boozer.h"
39#include "hdf5io/hdf5_mhd.h"
40
41
66 sim_offload_data* sim_offload_data, real* B_offload_array, int Neval,
67 real* R, real* phi, real* z, real* t, real* BR, real* Bphi, real* Bz,
68 real* BR_dR, real* BR_dphi, real* BR_dz, real* Bphi_dR, real* Bphi_dphi,
69 real* Bphi_dz, real* Bz_dR, real* Bz_dphi, real* Bz_dz) {
70
71 sim_data sim;
73 B_offload_array);
74
75 #pragma omp parallel for
76 for(int k = 0; k < Neval; k++) {
77 real B[15];
78 if( B_field_eval_B_dB(B, R[k], phi[k], z[k], t[k], &sim.B_data) ) {
79 continue;
80 }
81 BR[k] = B[0];
82 Bphi[k] = B[4];
83 Bz[k] = B[8];
84 BR_dR[k] = B[1];
85 BR_dphi[k] = B[2];
86 BR_dz[k] = B[3];
87 Bphi_dR[k] = B[5];
88 Bphi_dphi[k] = B[6];
89 Bphi_dz[k] = B[7];
90 Bz_dR[k] = B[9];
91 Bz_dphi[k] = B[10];
92 Bz_dz[k] = B[11];
93 }
94}
95
114 sim_offload_data* sim_offload_data, real* B_offload_array, int Neval,
115 real* R, real* phi, real* z, real* t, real* rho, real* drhodpsi, real* psi,
116 real* dpsidr, real* dpsidphi, real* dpsidz) {
117
118 sim_data sim;
120 B_offload_array);
121
122 #pragma omp parallel for
123 for(int k = 0; k < Neval; k++) {
124 real rhoval[2], psival[4];
125 if( B_field_eval_psi_dpsi(psival, R[k], phi[k], z[k], t[k],
126 &sim.B_data) ) {
127 continue;
128 }
129 psi[k] = psival[0];
130 dpsidr[k] = psival[1];
131 dpsidphi[k] = psival[2];
132 dpsidz[k] = psival[3];
133 if( B_field_eval_rho(rhoval, psival[0], &sim.B_data) ) {
134 continue;
135 }
136 rho[k] = rhoval[0];
137 drhodpsi[k] = rhoval[1];
138 }
139}
140
152 sim_offload_data* sim_offload_data, real* B_offload_array, int Neval,
153 real* phi, real* Raxis, real* zaxis) {
154
155 sim_data sim;
157 B_offload_array);
158 #pragma omp parallel for
159 for(int k = 0; k < Neval; k++) {
160 real axisrz[2];
161 if( B_field_get_axis_rz(axisrz, &sim.B_data, phi[k]) ) {
162 continue;
163 }
164 Raxis[k] = axisrz[0];
165 zaxis[k] = axisrz[1];
166 }
167}
168
189 sim_offload_data* sim_offload_data, real* B_offload_array, int Neval,
190 real* rho, real* theta, real* phi, real t, int maxiter, real tol,
191 real* r, real* z) {
192
193 sim_data sim;
195 B_offload_array);
196
197 #pragma omp parallel for
198 for(int j=0; j<Neval; j++) {
199 real axisrz[2];
200 real rhodrho[4];
201 if( B_field_get_axis_rz(axisrz, &sim.B_data, phi[j]) ) {
202 continue;
203 }
204 if( B_field_eval_rho_drho(rhodrho, axisrz[0], phi[j], axisrz[1],
205 &sim.B_data)) {
206 continue;
207 }
208 if( rhodrho[0] > rho[j] ) {
209 /* Due to padding, rho might not be exactly zero on the axis so we
210 * return the axis position for small values of queried rho */
211 r[j] = axisrz[0];
212 z[j] = axisrz[1];
213 continue;
214 }
215
216 real x = 1e-1;
217 real rj, zj;
218 real costh = cos(theta[j]);
219 real sinth = sin(theta[j]);
220 for(int i=0; i<maxiter; i++) {
221 rj = axisrz[0] + x * costh;
222 zj = axisrz[1] + x * sinth;
223 if( B_field_eval_rho_drho(rhodrho, rj, phi[j], zj, &sim.B_data) ) {
224 break;
225 }
226 if( fabs(rho[j] - rhodrho[0]) < tol ) {
227 r[j] = rj;
228 z[j] = zj;
229 break;
230 }
231
232 real drhodx = costh * rhodrho[1] + sinth * rhodrho[3];
233 x = x - (rhodrho[0] - rho[j]) / drhodx;
234 if( x < 0 ) {
235 /* Try again starting closer from the axis */
236 x = (x + (rhodrho[0] - rho[j]) / drhodx) / 2;
237 }
238 }
239 }
240}
241
258 sim_offload_data* sim_offload_data, real* B_offload_array, real psi[1],
259 real rz[2], real step, real tol, int maxiter, int ascent) {
260 sim_data sim;
262 B_offload_array);
263
264 if(ascent) {
265 step = -1 * step;
266 }
267
268 real phi = 0.0, time = 0.0;
269 real psidpsi[4], nextrz[2];
270 B_field_eval_psi_dpsi(psidpsi, rz[0], phi, rz[1], time, &sim.B_data);
271
272 int iter = 0;
273 while(1) {
274 if( B_field_eval_psi_dpsi(psidpsi, rz[0], phi, rz[1], time,
275 &sim.B_data) ) {
276 break;
277 }
278 nextrz[0] = rz[0] - step * psidpsi[1];
279 nextrz[1] = rz[1] - step * psidpsi[3];
280
281 // Check convergence
282 if(sqrt( (nextrz[0] - rz[0]) * (nextrz[0] - rz[0])
283 + (nextrz[1] - rz[1]) * (nextrz[1] - rz[1]) ) < tol) {
284 psi[0] = psidpsi[0];
285 rz[0] = nextrz[0];
286 rz[1] = nextrz[1];
287
288 // Add a bit of padding
290 psidpsi, rz[0], phi, rz[1], time, &sim.B_data);
291 psi[0] = psi[0] + (tol * psidpsi[1] + tol * psidpsi[3]);
292 break;
293 }
294
295 rz[0] = nextrz[0];
296 rz[1] = nextrz[1];
297 iter++;
298
299 if(iter == maxiter) {
300 break;
301 }
302 }
303}
304
321 sim_offload_data* sim_offload_data, real* B_offload_array,
322 real* E_offload_array, int Neval, real* R, real* phi, real* z, real* t,
323 real* ER, real* Ephi, real* Ez) {
324
325 sim_data sim;
327 B_offload_array);
329 E_offload_array);
330
331 #pragma omp parallel for
332 for(int k = 0; k < Neval; k++) {
333 real E[3];
334 if( E_field_eval_E(E, R[k], phi[k], z[k], t[k],
335 &sim.E_data, &sim.B_data) ) {
336 continue;
337 }
338 ER[k] = E[0];
339 Ephi[k] = E[1];
340 Ez[k] = E[2];
341 }
342}
343
353 sim_offload_data* sim_offload_data, real* plasma_offload_array) {
354
355 sim_data sim;
357 plasma_offload_array);
359}
360
372 sim_offload_data* sim_offload_data, real* plasma_offload_array, real* mass,
373 real* charge, int* anum, int* znum) {
374
375 sim_data sim;
377 plasma_offload_array);
378 int n_species = plasma_get_n_species(&sim.plasma_data);
381 const int* a = plasma_get_species_anum(&sim.plasma_data);
382 const int* z = plasma_get_species_znum(&sim.plasma_data);
383 mass[0] = CONST_M_E;
384 charge[0] = -CONST_E;
385 anum[0] = 0;
386 znum[0] = 0;
387 for(int i=1; i<n_species; i++) {
388 mass[i] = m[i];
389 charge[i] = q[i];
390 anum[i] = a[i-1];
391 znum[i] = z[i-1];
392 }
393}
394
410 sim_offload_data* sim_offload_data, real* B_offload_array,
411 real* plasma_offload_array, int Neval, real* R, real* phi, real* z, real* t,
412 real* dens, real* temp) {
413
414 sim_data sim;
416 B_offload_array);
418 plasma_offload_array);
419 int n_species = plasma_get_n_species(&sim.plasma_data);
420
421 #pragma omp parallel for
422 for(int k = 0; k < Neval; k++) {
423 real psi[1], rho[2], n[MAX_SPECIES], T[MAX_SPECIES];
424 if( B_field_eval_psi(psi, R[k], phi[k], z[k], t[k], &sim.B_data) ) {
425 continue;
426 }
427 if( B_field_eval_rho(rho, psi[0], &sim.B_data) ) {
428 continue;
429 }
430 if( plasma_eval_densandtemp(n, T, rho[0], R[k], phi[k], z[k], t[k],
431 &sim.plasma_data) ) {
432 continue;
433 }
434 for(int i=0; i<n_species; i++) {
435 dens[k + i*Neval] = n[i];
436 temp[k + i*Neval] = T[i]/CONST_E;
437 }
438 }
439}
440
455 sim_offload_data* sim_offload_data, real* B_offload_array,
456 real* neutral_offload_array, int Neval,
457 real* R, real* phi, real* z, real* t, real* dens) {
458
459 sim_data sim;
461 B_offload_array);
463 neutral_offload_array);
464
465 #pragma omp parallel for
466 for(int k = 0; k < Neval; k++) {
467 real psi[1], rho[2], n0[1];
468 if( B_field_eval_psi(psi, R[k], phi[k], z[k], t[k], &sim.B_data) ) {
469 continue;
470 }
471 if( B_field_eval_rho(rho, psi[0], &sim.B_data) ) {
472 continue;
473 }
474 if( neutral_eval_n0(n0, rho[0], R[k], phi[k], z[k], t[k],
475 &sim.neutral_data) ) {
476 continue;
477 }
478 dens[k] = n0[0];
479 }
480}
481
508 sim_offload_data* sim_offload_data, real* B_offload_array,
509 real* boozer_offload_array, int Neval,
510 real* R, real* phi, real* z, real* t, real* psi, real* theta, real* zeta,
511 real* dpsidr, real* dpsidphi, real* dpsidz, real* dthetadr,
512 real* dthetadphi, real* dthetadz, real* dzetadr, real* dzetadphi,
513 real* dzetadz, real* rho) {
514
515 sim_data sim;
517 B_offload_array);
519 boozer_offload_array);
520
521 #pragma omp parallel for
522 for(int k = 0; k < Neval; k++) {
523 int isinside;
524 real psithetazeta[12], rhoval[2];
525 if( boozer_eval_psithetazeta(psithetazeta, &isinside, R[k], phi[k],
526 z[k], &sim.B_data, &sim.boozer_data) ) {
527 continue;
528 }
529 if(!isinside) {
530 continue;
531 }
532 if( B_field_eval_rho(rhoval, psithetazeta[0], &sim.B_data) ) {
533 continue;
534 }
535 psi[k] = psithetazeta[0];
536 theta[k] = psithetazeta[4];
537 zeta[k] = psithetazeta[8];
538 dpsidr[k] = psithetazeta[1];
539 dpsidphi[k] = psithetazeta[2];
540 dpsidz[k] = psithetazeta[3];
541 dthetadr[k] = psithetazeta[5];
542 dthetadphi[k] = psithetazeta[6];
543 dthetadz[k] = psithetazeta[7];
544 dzetadr[k] = psithetazeta[9];
545 dzetadphi[k] = psithetazeta[10];
546 dzetadz[k] = psithetazeta[11];
547 rho[k] = rhoval[0];
548 }
549}
550
567 sim_offload_data* sim_offload_data, real* B_offload_array,
568 real* boozer_offload_array, int Neval, real* R, real* phi, real* z, real* t,
569 real* qprof, real* jac, real* jacB2) {
570
571 sim_data sim;
573 B_offload_array);
575 boozer_offload_array);
576
577 #pragma omp parallel for
578 for(int k = 0; k < Neval; k++) {
579 int isinside;
580 real psithetazeta[12], B[15];
581 if( boozer_eval_psithetazeta(psithetazeta, &isinside, R[k], phi[k],
582 z[k], &sim.B_data, &sim.boozer_data) ) {
583 continue;
584 }
585 if(!isinside) {
586 continue;
587 }
588 if( B_field_eval_B_dB(B, R[k], phi[k], z[k], t[k], &sim.B_data) ) {
589 continue;
590 }
591
592 real bvec[] = {B[0], B[4], B[8]};
593 real gradpsi[] = {psithetazeta[1],
594 psithetazeta[2]/R[k],
595 psithetazeta[3]};
596 real gradtheta[] = {psithetazeta[5],
597 psithetazeta[6]/R[k],
598 psithetazeta[7]};
599 real gradzeta[] = {psithetazeta[9],
600 psithetazeta[10]/R[k],
601 psithetazeta[11]};
602
603 real veca[3], vecb[3];
604
605 math_cross(gradpsi, gradzeta, veca);
606 math_cross(gradpsi, gradtheta, vecb);
607 qprof[k] = (veca[1] - bvec[1]) / vecb[1];
608
609 math_cross(gradtheta, gradzeta, veca);
610 jac[k] = -1.0 / math_dot(veca, gradpsi);
611 jacB2[k] = jac[k]*math_norm(bvec)*math_norm(bvec);
612 }
613}
614
624 sim_offload_data* sim_offload_data, real* mhd_offload_array) {
625
626 sim_data sim;
628 mhd_offload_array);
629 return mhd_get_n_modes(&sim.mhd_data);
630}
631
644 sim_offload_data* sim_offload_data, real* mhd_offload_array, int* nmode,
645 int* mmode, real* amplitude, real* omega, real* phase) {
646
647 sim_data sim;
649 mhd_offload_array);
650 int n_modes = mhd_get_n_modes(&sim.mhd_data);
651 const int* n = mhd_get_nmode(&sim.mhd_data);
652 const int* m = mhd_get_mmode(&sim.mhd_data);
653 const real* a = mhd_get_amplitude(&sim.mhd_data);
654 const real* o = mhd_get_frequency(&sim.mhd_data);
655 const real* p = mhd_get_phase(&sim.mhd_data);
656 for(int i=0; i<n_modes; i++) {
657 nmode[i] = n[i];
658 mmode[i] = m[i];
659 amplitude[i] = a[i];
660 omega[i] = o[i];
661 phase[i] = p[i];
662 }
663}
664
690 sim_offload_data* sim_offload_data, real* B_offload_array,
691 real* boozer_offload_array, real* mhd_offload_array, int Neval,
692 real* R, real* phi, real* z, real* t, int includemode,
693 real* alpha, real* dadr, real* dadphi, real* dadz, real* dadt, real* Phi,
694 real* dPhidr, real* dPhidphi, real* dPhidz, real* dPhidt) {
695
696 sim_data sim;
698 B_offload_array);
700 boozer_offload_array);
702 mhd_offload_array);
703
704 #pragma omp parallel for
705 for(int k = 0; k < Neval; k++) {
706 real mhd_dmhd[10];
707 if( mhd_eval(mhd_dmhd, R[k], phi[k], z[k], t[k], includemode,
708 &sim.boozer_data, &sim.mhd_data, &sim.B_data) ) {
709 continue;
710 }
711 alpha[k] = mhd_dmhd[0];
712 dadr[k] = mhd_dmhd[2];
713 dadphi[k] = mhd_dmhd[3];
714 dadz[k] = mhd_dmhd[4];
715 dadt[k] = mhd_dmhd[1];
716 Phi[k] = mhd_dmhd[5];
717 dPhidr[k] = mhd_dmhd[7];
718 dPhidphi[k] = mhd_dmhd[8];
719 dPhidz[k] = mhd_dmhd[9];
720 dPhidt[k] = mhd_dmhd[6];
721 }
722}
723
746 sim_offload_data* sim_offload_data, real* B_offload_array,
747 real* boozer_offload_array, real* mhd_offload_array, int Neval,
748 real* R, real* phi, real* z, real* t, int includemode, real* mhd_br,
749 real* mhd_bphi, real* mhd_bz, real* mhd_er, real* mhd_ephi, real* mhd_ez,
750 real* mhd_phi) {
751
752 sim_data sim;
754 B_offload_array);
756 boozer_offload_array);
758 mhd_offload_array);
759 int onlypert = 1;
760 #pragma omp parallel for
761 for(int k = 0; k < Neval; k++) {
762 real pert_field[7];
763 if( mhd_perturbations(pert_field, R[k], phi[k], z[k], t[k], onlypert,
764 includemode, &sim.boozer_data, &sim.mhd_data,
765 &sim.B_data) ) {
766 continue;
767 }
768 mhd_br[k] = pert_field[0];
769 mhd_bphi[k] = pert_field[1];
770 mhd_bz[k] = pert_field[2];
771 mhd_er[k] = pert_field[3];
772 mhd_ephi[k] = pert_field[4];
773 mhd_ez[k] = pert_field[5];
774 mhd_phi[k] = pert_field[6];
775 }
776}
777
807 sim_offload_data* sim_offload_data, real* B_offload_array,
808 real* plasma_offload_array, int Neval, real* R, real* phi, real* z, real* t,
809 int Nv, real* va, real ma, real qa, real* F, real* Dpara, real* Dperp,
810 real* K, real* nu, real* Q, real* dQ, real* dDpara, real* clog,
811 real* mu0, real* mu1, real* dmu0) {
812
813 sim_data sim;
814 sim.mccc_data.usetabulated = 0;
816 B_offload_array);
818 plasma_offload_array);
819
820 /* Evaluate plasma parameters */
821 int n_species = plasma_get_n_species(&sim.plasma_data);
823 const real* mb = plasma_get_species_mass(&sim.plasma_data);
824
825 #pragma omp parallel for
826 for(int k=0; k<Neval; k++) {
827 real mufun[3] = {0., 0., 0.};
828
829 /* Evaluate rho as it is needed to evaluate plasma parameters */
830 real psi, rho[2];
831 if( B_field_eval_psi(&psi, R[k], phi[k], z[k], t[k], &sim.B_data) ) {
832 continue;
833 }
834 if( B_field_eval_rho(rho, psi, &sim.B_data) ) {
835 continue;
836 }
837
839 if( plasma_eval_densandtemp(nb, Tb, rho[0], R[k], phi[k], z[k], t[k],
840 &sim.plasma_data) ) {
841 continue;
842 }
843
844 /* Evaluate coefficients for different velocities */
845 for(int iv=0; iv<Nv; iv++) {
846
847 /* Loop through all plasma species */
848 for(int ib=0; ib<n_species; ib++) {
849
850 /* Coulomb logarithm */
851 real clogab[MAX_SPECIES];
852 mccc_coefs_clog(clogab, ma, qa, va[iv], n_species, mb, qb,
853 nb, Tb);
854
855 /* Special functions */
856 real vb = sqrt( 2 * Tb[ib] / mb[ib] );
857 real x = va[iv] / vb;
858 mccc_coefs_mufun(mufun, x, &sim.mccc_data);
859
860 /* Coefficients */
861 real Fb = mccc_coefs_F(ma, qa, mb[ib], qb[ib], nb[ib], vb,
862 clogab[ib], mufun[0]);
863 real Qb = mccc_coefs_Q(ma, qa, mb[ib], qb[ib], nb[ib], vb,
864 clogab[ib], mufun[0]);
865 real dQb = mccc_coefs_dQ(ma, qa, mb[ib], qb[ib], nb[ib], vb,
866 clogab[ib], mufun[2]);
867 real Dparab = mccc_coefs_Dpara(ma, qa, va[iv], qb[ib], nb[ib],
868 vb, clogab[ib], mufun[0]);
869 real Dperpb = mccc_coefs_Dperp(ma, qa, va[iv], qb[ib], nb[ib],
870 vb, clogab[ib], mufun[1]);
871 real dDparab = mccc_coefs_dDpara(ma, qa, va[iv], qb[ib], nb[ib],
872 vb, clogab[ib], mufun[0],
873 mufun[2]);
874 real Kb = mccc_coefs_K(va[iv], Dparab, dDparab, Qb);
875 real nub = mccc_coefs_nu(va[iv], Dperpb);
876
877 /* Store requested quantities */
878 int idx = ib*Nv*Neval + Nv * k + iv;
879 if(mu0 != NULL) { mu0[idx] = mufun[0]; }
880 if(mu1 != NULL) { mu1[idx] = mufun[1]; }
881 if(dmu0 != NULL) { dmu0[idx] = mufun[2]; }
882 if(clog != NULL) { clog[idx] = clogab[ib]; }
883 if(F != NULL) { F[idx] = Fb; }
884 if(Dpara != NULL) { Dpara[idx] = Dparab; }
885 if(Dperp != NULL) { Dperp[idx] = Dperpb; }
886 if(K != NULL) { K[idx] = Kb; }
887 if(nu != NULL) { nu[idx] = nub; }
888 if(Q != NULL) { Q[idx] = Qb; }
889 if(dQ != NULL) { dQ[idx] = dQb; }
890 if(dDpara != NULL) { dDpara[idx] = dDparab; }
891 }
892 }
893 }
894}
895
918 sim_offload_data* sim_offload_data, real* B_offload_array,
919 real* plasma_offload_array, real* neutral_offload_array,
920 real* asigma_offload_array,
921 int Neval, real* R, real* phi, real* z, real* t, int Nv, real* va,
922 int Aa, int Za, real ma, int reac_type, real* ratecoeff) {
923
924 sim_data sim;
926 B_offload_array);
928 plasma_offload_array);
930 neutral_offload_array);
932 asigma_offload_array);
933
934 const int* Zb = plasma_get_species_znum(&sim.plasma_data);
935 const int* Ab = plasma_get_species_anum(&sim.plasma_data);
936 int nion = plasma_get_n_species(&sim.plasma_data) - 1;
937 int nspec = neutral_get_n_species(&sim.neutral_data);
938
939 #pragma omp parallel for
940 for (int k=0; k < Neval; k++) {
941 real psi[1], rho[2], T0[1], n[MAX_SPECIES], T[MAX_SPECIES],
942 n0[MAX_SPECIES];
943 if( B_field_eval_psi(psi, R[k], phi[k], z[k], t[k], &sim.B_data) ) {
944 continue;
945 }
946 if( B_field_eval_rho(rho, psi[0], &sim.B_data) ) {
947 continue;
948 }
949 if( plasma_eval_densandtemp(n, T, rho[0], R[k], phi[k], z[k], t[k],
950 &sim.plasma_data) ) {
951 continue;
952 }
953 if( neutral_eval_t0(T0, rho[0], R[k], phi[k], z[k], t[k],
954 &sim.neutral_data) ) {
955 continue;
956 }
957 if( neutral_eval_n0(n0, rho[0], R[k], phi[k], z[k], t[k],
958 &sim.neutral_data) ) {
959 continue;
960 }
961 for (int j=0; j < Nv; j++) {
962 real E = (physlib_gamma_vnorm(va[j]) - 1.0) * ma * CONST_C*CONST_C;
963 real val;
964 switch (reac_type) {
965 case sigmav_CX:
966 if( asigma_eval_cx(
967 &val, Za, Aa, E, ma, nspec, Zb, Ab, T0[0], n0,
968 &sim.asigma_data) ) {
969 continue;
970 }
971 ratecoeff[Nv*k + j] = val;
972 break;
973 case sigmav_BMS:
974 if( asigma_eval_bms(
975 &val, Za, Aa, E, ma, nion, Zb, Ab, T[0], n,
976 &sim.asigma_data) ) {
977 continue;
978 }
979 ratecoeff[Nv*k + j] = val * n[0];
980 break;
981 default:
982 break;
983 }
984 }
985 }
986
987}
a5err B_field_eval_psi_dpsi(real psi_dpsi[4], real r, real phi, real z, real t, B_field_data *Bdata)
Evaluate poloidal flux psi and its derivatives.
Definition B_field.c:265
a5err B_field_eval_rho(real rho[2], real psi, B_field_data *Bdata)
Evaluate normalized poloidal flux rho and its psi derivative.
Definition B_field.c:327
a5err B_field_eval_psi(real *psi, real r, real phi, real z, real t, B_field_data *Bdata)
Evaluate poloidal flux psi.
Definition B_field.c:201
a5err B_field_eval_B_dB(real B_dB[15], real r, real phi, real z, real t, B_field_data *Bdata)
Evaluate magnetic field and its derivatives.
Definition B_field.c:547
a5err B_field_eval_rho_drho(real rho_drho[4], real r, real phi, real z, B_field_data *Bdata)
Evaluate normalized poloidal flux rho and its derivatives.
Definition B_field.c:410
int B_field_init(B_field_data *Bdata, B_field_offload_data *offload_data, real *offload_array)
Initialize magnetic field data struct on target.
Definition B_field.c:143
a5err B_field_get_axis_rz(real rz[2], B_field_data *Bdata, real phi)
Return magnetic axis Rz-coordinates.
Definition B_field.c:599
Header file for B_field.c.
int E_field_init(E_field_data *Edata, E_field_offload_data *offload_data, real *offload_array)
Initialize electric field data struct on target.
Definition E_field.c:116
a5err E_field_eval_E(real E[3], real r, real phi, real z, real t, E_field_data *Edata, B_field_data *Bdata)
Evaluate electric field.
Definition E_field.c:166
Header file for E_field.c.
Main header file for ASCOT5.
double real
Definition ascot5.h:85
#define MAX_SPECIES
Maximum number of plasma species.
Definition ascot5.h:95
a5err asigma_eval_cx(real *ratecoeff, int z_1, int a_1, real E, real mass, int nspec, const int *znum, const int *anum, real T_0, real *n_0, asigma_data *asigma_data)
Evaluate charge exchange rate coefficient.
Definition asigma.c:262
int asigma_init(asigma_data *asigma_data, asigma_offload_data *offload_data, real *offload_array)
Initializes atomic reaction data struct on target.
Definition asigma.c:126
a5err asigma_eval_bms(real *ratecoeff, int z_1, int a_1, real E, real mass, int nion, const int *znum, const int *anum, real T_e, real *n_i, asigma_data *asigma_data)
Evaluate beam stopping rate coefficient.
Definition asigma.c:308
Header file for asigma.c.
void boozer_init(boozer_data *boozerdata, boozer_offload_data *offload_data, real *offload_array)
Initialize boozer data struct on target.
Definition boozer.c:108
a5err boozer_eval_psithetazeta(real psithetazeta[12], int *isinside, real r, real phi, real z, B_field_data *Bdata, boozer_data *boozerdata)
Evaluate Boozer coordinates and partial derivatives.
Definition boozer.c:188
Header file for boozer.c.
Header file containing physical and mathematical constants.
#define CONST_M_E
Electron mass [kg]
Definition consts.h:38
#define CONST_C
Speed of light [m/s]
Definition consts.h:23
#define CONST_E
Elementary charge [C]
Definition consts.h:32
Header file for hdf5_bfield.c.
Header file for hdf5_boozer.c.
Header file for hdf5_efielc.c.
Header file for hdf5_helpers.h.
Header file for hdf5_interface.c.
Header file for hdf5_mhd.c.
Header file for hdf5_neutral.c.
Header file for hdf5_plasma.c.
Header file for hdf5_wall.c.
void libascot_mhd_eval(sim_offload_data *sim_offload_data, real *B_offload_array, real *boozer_offload_array, real *mhd_offload_array, int Neval, real *R, real *phi, real *z, real *t, int includemode, real *alpha, real *dadr, real *dadphi, real *dadz, real *dadt, real *Phi, real *dPhidr, real *dPhidphi, real *dPhidz, real *dPhidt)
Evaluate MHD perturbation potentials.
Definition libascot.c:689
void libascot_eval_ratecoeff(sim_offload_data *sim_offload_data, real *B_offload_array, real *plasma_offload_array, real *neutral_offload_array, real *asigma_offload_array, int Neval, real *R, real *phi, real *z, real *t, int Nv, real *va, int Aa, int Za, real ma, int reac_type, real *ratecoeff)
Evaluate atomic reaction rate coefficient.
Definition libascot.c:917
void libascot_plasma_eval_background(sim_offload_data *sim_offload_data, real *B_offload_array, real *plasma_offload_array, int Neval, real *R, real *phi, real *z, real *t, real *dens, real *temp)
Evaluate plasma density and temperature at given coordinates.
Definition libascot.c:409
void libascot_B_field_eval_B_dB(sim_offload_data *sim_offload_data, real *B_offload_array, int Neval, real *R, real *phi, real *z, real *t, real *BR, real *Bphi, real *Bz, real *BR_dR, real *BR_dphi, real *BR_dz, real *Bphi_dR, real *Bphi_dphi, real *Bphi_dz, real *Bz_dR, real *Bz_dphi, real *Bz_dz)
Evaluate magnetic field vector and derivatives at given coordinates.
Definition libascot.c:65
void libascot_eval_collcoefs(sim_offload_data *sim_offload_data, real *B_offload_array, real *plasma_offload_array, int Neval, real *R, real *phi, real *z, real *t, int Nv, real *va, real ma, real qa, real *F, real *Dpara, real *Dperp, real *K, real *nu, real *Q, real *dQ, real *dDpara, real *clog, real *mu0, real *mu1, real *dmu0)
Evaluate collision coefficients.
Definition libascot.c:806
void libascot_B_field_gradient_descent(sim_offload_data *sim_offload_data, real *B_offload_array, real psi[1], real rz[2], real step, real tol, int maxiter, int ascent)
Find psi on axis using the gradient descent method.
Definition libascot.c:257
void libascot_E_field_eval_E(sim_offload_data *sim_offload_data, real *B_offload_array, real *E_offload_array, int Neval, real *R, real *phi, real *z, real *t, real *ER, real *Ephi, real *Ez)
Evaluate electric field vector at given coordinates.
Definition libascot.c:320
void libascot_B_field_eval_rho(sim_offload_data *sim_offload_data, real *B_offload_array, int Neval, real *R, real *phi, real *z, real *t, real *rho, real *drhodpsi, real *psi, real *dpsidr, real *dpsidphi, real *dpsidz)
Evaluate normalized poloidal flux at given coordinates.
Definition libascot.c:113
int libascot_mhd_get_n_modes(sim_offload_data *sim_offload_data, real *mhd_offload_array)
Get number of MHD modes.
Definition libascot.c:623
void libascot_boozer_eval_fun(sim_offload_data *sim_offload_data, real *B_offload_array, real *boozer_offload_array, int Neval, real *R, real *phi, real *z, real *t, real *qprof, real *jac, real *jacB2)
Evaluate boozer coordinates related quantities.
Definition libascot.c:566
void libascot_mhd_get_mode_specs(sim_offload_data *sim_offload_data, real *mhd_offload_array, int *nmode, int *mmode, real *amplitude, real *omega, real *phase)
Get MHD mode amplitude, frequency, phase, and mode numbers.
Definition libascot.c:643
void libascot_B_field_get_axis(sim_offload_data *sim_offload_data, real *B_offload_array, int Neval, real *phi, real *Raxis, real *zaxis)
Get magnetic axis at given coordinates.
Definition libascot.c:151
void libascot_neutral_eval_density(sim_offload_data *sim_offload_data, real *B_offload_array, real *neutral_offload_array, int Neval, real *R, real *phi, real *z, real *t, real *dens)
Evaluate neutral density at given coordinates.
Definition libascot.c:454
void libascot_boozer_eval_psithetazeta(sim_offload_data *sim_offload_data, real *B_offload_array, real *boozer_offload_array, int Neval, real *R, real *phi, real *z, real *t, real *psi, real *theta, real *zeta, real *dpsidr, real *dpsidphi, real *dpsidz, real *dthetadr, real *dthetadphi, real *dthetadz, real *dzetadr, real *dzetadphi, real *dzetadz, real *rho)
Evaluate boozer coordinates and derivatives.
Definition libascot.c:507
void libascot_plasma_get_species_mass_and_charge(sim_offload_data *sim_offload_data, real *plasma_offload_array, real *mass, real *charge, int *anum, int *znum)
Get mass and charge of all plasma species.
Definition libascot.c:371
void libascot_mhd_eval_perturbation(sim_offload_data *sim_offload_data, real *B_offload_array, real *boozer_offload_array, real *mhd_offload_array, int Neval, real *R, real *phi, real *z, real *t, int includemode, real *mhd_br, real *mhd_bphi, real *mhd_bz, real *mhd_er, real *mhd_ephi, real *mhd_ez, real *mhd_phi)
Evaluate MHD perturbation EM-field components.
Definition libascot.c:745
void libascot_B_field_rhotheta2rz(sim_offload_data *sim_offload_data, real *B_offload_array, int Neval, real *rho, real *theta, real *phi, real t, int maxiter, real tol, real *r, real *z)
Map (rho, theta, phi) to (R,z) coordinates.
Definition libascot.c:188
int libascot_plasma_get_n_species(sim_offload_data *sim_offload_data, real *plasma_offload_array)
Get number of plasma species.
Definition libascot.c:352
Header file for math.c.
#define math_dot(a, b)
Calculate dot product a[3] dot b[3].
Definition math.h:28
#define math_cross(a, b, c)
Calculate cross product for 3D vectors c = a x b.
Definition math.h:31
#define math_norm(a)
Calculate norm of 3D vector a.
Definition math.h:64
Routines to evaluate coefficients needed to evaluate collisions.
#define mccc_coefs_Dpara(ma, qa, va, qb, nb, vb, clogab, mu0)
Evaluate non-relativistic parallel diffusion coefficient [m^2/s^3].
Definition mccc_coefs.h:103
#define mccc_coefs_dDpara(ma, qa, va, qb, nb, vb, clogab, mu0, dmu0)
Evaluate derivative of non-relativistic parallel diffusion coefficient [m/s^2].
Definition mccc_coefs.h:126
#define mccc_coefs_dQ(ma, qa, mb, qb, nb, vb, clogab, dmu0)
Evaluate derivative of non-relativistic drag coefficient [m/s^2].
Definition mccc_coefs.h:61
#define mccc_coefs_K(va, Dpara, dDpara, Q)
Evaluate guiding center drag coefficient [m/s^2].
Definition mccc_coefs.h:167
static void mccc_coefs_mufun(real mufun[3], real x, mccc_data *mdata)
Evaluate special functions needed by collision coefficients.
Definition mccc_coefs.h:275
#define mccc_coefs_Dperp(ma, qa, va, qb, nb, vb, clogab, mu1)
Evaluate non-relativistic perpendicular diffusion coefficient [m^2/s^3].
Definition mccc_coefs.h:150
#define mccc_coefs_nu(va, Dperp)
Evaluate pitch collision frequency [1/s].
Definition mccc_coefs.h:180
#define mccc_coefs_F(ma, qa, mb, qb, nb, vb, clogab, mu0)
Evaluate non-relativistic friction coefficient [m/s^2].
Definition mccc_coefs.h:80
static DECLARE_TARGET_END void mccc_coefs_clog(real *clogab, real ma, real qa, real va, int nspec, const real *mb, const real *qb, const real *nb, const real *Tb)
Evaluate Coulomb logarithm.
Definition mccc_coefs.h:228
#define mccc_coefs_Q(ma, qa, mb, qb, nb, vb, clogab, mu0)
Evaluate non-relativistic drag coefficient [m/s^2].
Definition mccc_coefs.h:43
int mhd_get_n_modes(mhd_data *mhddata)
Return number of modes.
Definition mhd.c:270
const real * mhd_get_amplitude(mhd_data *mhddata)
Return mode amplitudes.
Definition mhd.c:330
const int * mhd_get_nmode(mhd_data *mhddata)
Return mode toroidal numbers.
Definition mhd.c:290
int mhd_init(mhd_data *mhddata, mhd_offload_data *offload_data, real *offload_array)
Initialize MHD data struct on target.
Definition mhd.c:121
a5err mhd_perturbations(real pert_field[7], real r, real phi, real z, real t, int pertonly, int includemode, boozer_data *boozerdata, mhd_data *mhddata, B_field_data *Bdata)
Evaluate perturbed fields Btilde, Etilde and potential Phi explicitly.
Definition mhd.c:234
const int * mhd_get_mmode(mhd_data *mhddata)
Return mode poloidal numbers.
Definition mhd.c:310
const real * mhd_get_frequency(mhd_data *mhddata)
Return mode frequencies.
Definition mhd.c:350
a5err mhd_eval(real mhd_dmhd[10], real r, real phi, real z, real t, int includemode, boozer_data *boozerdata, mhd_data *mhddata, B_field_data *Bdata)
Evaluate the needed quantities from MHD mode for orbit following.
Definition mhd.c:178
const real * mhd_get_phase(mhd_data *mhddata)
Return mode phases.
Definition mhd.c:370
Header file for mhd.c.
int neutral_get_n_species(neutral_data *ndata)
Get the number of neutral species.
Definition neutral.c:225
int neutral_init(neutral_data *ndata, neutral_offload_data *offload_data, real *offload_array)
Initialize neutral data struct on target.
Definition neutral.c:106
a5err neutral_eval_n0(real *n0, real rho, real r, real phi, real z, real t, neutral_data *ndata)
Evaluate neutral density.
Definition neutral.c:147
a5err neutral_eval_t0(real *t0, real rho, real r, real phi, real z, real t, neutral_data *ndata)
Evaluate neutral temperature.
Definition neutral.c:189
Header file for neutral.c.
Methods to evaluate elementary physical quantities.
#define physlib_gamma_vnorm(v)
Evaluate Lorentz factor from velocity norm.
Definition physlib.h:21
const real * plasma_get_species_mass(plasma_data *pls_data)
Get mass of all plasma species.
Definition plasma.c:361
const int * plasma_get_species_znum(plasma_data *pls_data)
Get charge number of ion species.
Definition plasma.c:419
int plasma_get_n_species(plasma_data *pls_data)
Get the number of plasma species.
Definition plasma.c:331
const real * plasma_get_species_charge(plasma_data *pls_data)
Get charge of all plasma species.
Definition plasma.c:391
a5err plasma_eval_densandtemp(real *dens, real *temp, real rho, real r, real phi, real z, real t, plasma_data *pls_data)
Evaluate plasma density and temperature for all species.
Definition plasma.c:280
int plasma_init(plasma_data *pls_data, plasma_offload_data *offload_data, real *offload_array)
Initialize plasma data struct on target.
Definition plasma.c:135
const int * plasma_get_species_anum(plasma_data *pls_data)
Get atomic mass number of ion species.
Definition plasma.c:447
Header file for plasma.c.
Header file for simulate.c.
int usetabulated
Definition mccc.h:28
Simulation data struct.
Definition simulate.h:154
plasma_data plasma_data
Definition simulate.h:158
mhd_data mhd_data
Definition simulate.h:162
E_field_data E_data
Definition simulate.h:157
mccc_data mccc_data
Definition simulate.h:169
neutral_data neutral_data
Definition simulate.h:159
boozer_data boozer_data
Definition simulate.h:161
B_field_data B_data
Definition simulate.h:156
asigma_data asigma_data
Definition simulate.h:163
Simulation offload struct.
Definition simulate.h:55
B_field_offload_data B_offload_data
Definition simulate.h:57
plasma_offload_data plasma_offload_data
Definition simulate.h:59
neutral_offload_data neutral_offload_data
Definition simulate.h:60
mhd_offload_data mhd_offload_data
Definition simulate.h:63
asigma_offload_data asigma_offload_data
Definition simulate.h:64
boozer_offload_data boozer_offload_data
Definition simulate.h:62
E_field_offload_data E_offload_data
Definition simulate.h:58
Header file for wall.c.