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#include "gitver.h"
29
31
32#include "hdf5_interface.h"
33#include "hdf5io/hdf5_helpers.h"
34#include "hdf5io/hdf5_bfield.h"
35#include "hdf5io/hdf5_efield.h"
36#include "hdf5io/hdf5_plasma.h"
37#include "hdf5io/hdf5_wall.h"
38#include "hdf5io/hdf5_neutral.h"
39#include "hdf5io/hdf5_boozer.h"
40#include "hdf5io/hdf5_mhd.h"
41
42
66 sim_data* sim, 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 #pragma omp parallel for
72 for(int k = 0; k < Neval; k++) {
73 real B[15];
74 if( B_field_eval_B_dB(B, R[k], phi[k], z[k], t[k], &sim->B_data) ) {
75 continue;
76 }
77 BR[k] = B[0];
78 Bphi[k] = B[4];
79 Bz[k] = B[8];
80 BR_dR[k] = B[1];
81 BR_dphi[k] = B[2];
82 BR_dz[k] = B[3];
83 Bphi_dR[k] = B[5];
84 Bphi_dphi[k] = B[6];
85 Bphi_dz[k] = B[7];
86 Bz_dR[k] = B[9];
87 Bz_dphi[k] = B[10];
88 Bz_dz[k] = B[11];
89 }
90}
91
109 sim_data* sim, int Neval,
110 real* R, real* phi, real* z, real* t, real* rho, real* drhodpsi, real* psi,
111 real* dpsidr, real* dpsidphi, real* dpsidz) {
112
113 #pragma omp parallel for
114 for(int k = 0; k < Neval; k++) {
115 real rhoval[2], psival[4];
116 if( B_field_eval_psi_dpsi(psival, R[k], phi[k], z[k], t[k],
117 &sim->B_data) ) {
118 continue;
119 }
120 psi[k] = psival[0];
121 dpsidr[k] = psival[1];
122 dpsidphi[k] = psival[2];
123 dpsidz[k] = psival[3];
124 if( B_field_eval_rho(rhoval, psival[0], &sim->B_data) ) {
125 continue;
126 }
127 rho[k] = rhoval[0];
128 drhodpsi[k] = rhoval[1];
129 }
130}
131
142 sim_data* sim, int Neval, real* phi, real* Raxis, real* zaxis) {
143
144 #pragma omp parallel for
145 for(int k = 0; k < Neval; k++) {
146 real axisrz[2];
147 if( B_field_get_axis_rz(axisrz, &sim->B_data, phi[k]) ) {
148 continue;
149 }
150 Raxis[k] = axisrz[0];
151 zaxis[k] = axisrz[1];
152 }
153}
154
174 sim_data* sim, int Neval,
175 real* rho, real* theta, real* phi, real t, int maxiter, real tol,
176 real* r, real* z) {
177
178 #pragma omp parallel for
179 for(int j=0; j<Neval; j++) {
180 real axisrz[2];
181 real rhodrho[4];
182 if( B_field_get_axis_rz(axisrz, &sim->B_data, phi[j]) ) {
183 continue;
184 }
185 if( B_field_eval_rho_drho(rhodrho, axisrz[0], phi[j], axisrz[1],
186 &sim->B_data)) {
187 continue;
188 }
189 if( rhodrho[0] > rho[j] ) {
190 /* Due to padding, rho might not be exactly zero on the axis so we
191 * return the axis position for small values of queried rho */
192 r[j] = axisrz[0];
193 z[j] = axisrz[1];
194 continue;
195 }
196
197 real x = 1e-1;
198 real rj, zj;
199 real costh = cos(theta[j]);
200 real sinth = sin(theta[j]);
201 for(int i=0; i<maxiter; i++) {
202 rj = axisrz[0] + x * costh;
203 zj = axisrz[1] + x * sinth;
204 if( B_field_eval_rho_drho(rhodrho, rj, phi[j], zj, &sim->B_data) ) {
205 break;
206 }
207 if( fabs(rho[j] - rhodrho[0]) < tol ) {
208 r[j] = rj;
209 z[j] = zj;
210 break;
211 }
212
213 real drhodx = costh * rhodrho[1] + sinth * rhodrho[3];
214 x = x - (rhodrho[0] - rho[j]) / drhodx;
215 if( x < 0 ) {
216 /* Try again starting closer from the axis */
217 x = (x + (rhodrho[0] - rho[j]) / drhodx) / 2;
218 }
219 }
220 }
221}
222
238 sim_data* sim, real psi[1],
239 real rz[2], real step, real tol, int maxiter, int ascent) {
240
241 if(ascent) {
242 step = -1 * step;
243 }
244
245 real phi = 0.0, time = 0.0;
246 real psidpsi[4], nextrz[2];
247 B_field_eval_psi_dpsi(psidpsi, rz[0], phi, rz[1], time, &sim->B_data);
248
249 int iter = 0;
250 while(1) {
251 if( B_field_eval_psi_dpsi(psidpsi, rz[0], phi, rz[1], time,
252 &sim->B_data) ) {
253 break;
254 }
255 nextrz[0] = rz[0] - step * psidpsi[1];
256 nextrz[1] = rz[1] - step * psidpsi[3];
257
258 // Check convergence
259 if(sqrt( (nextrz[0] - rz[0]) * (nextrz[0] - rz[0])
260 + (nextrz[1] - rz[1]) * (nextrz[1] - rz[1]) ) < tol) {
261 psi[0] = psidpsi[0];
262 rz[0] = nextrz[0];
263 rz[1] = nextrz[1];
264
265 // Add a bit of padding
267 psidpsi, rz[0], phi, rz[1], time, &sim->B_data);
268 psi[0] = psi[0] + (tol * psidpsi[1] + tol * psidpsi[3]);
269 break;
270 }
271
272 rz[0] = nextrz[0];
273 rz[1] = nextrz[1];
274 iter++;
275
276 if(iter == maxiter) {
277 break;
278 }
279 }
280}
281
282
299 sim_data* sim, real psi[1],
300 real rzphi[3], real phimin, real phimax, real step, real tol, int maxiter,
301 int ascent) {
302
303 if(ascent) {
304 step = -1 * step;
305 }
306
307 real time = 0.0;
308 real psidpsi[4], nextrzphi[3];
309 B_field_eval_psi_dpsi(psidpsi, rzphi[0], rzphi[2], rzphi[1], time,
310 &sim->B_data);
311
312 int iter = 0;
313 while(1) {
314 if( B_field_eval_psi_dpsi(psidpsi, rzphi[0], rzphi[2], rzphi[1], time,
315 &sim->B_data) ) {
316 break;
317 }
318 nextrzphi[0] = rzphi[0] - step * psidpsi[1]; // R
319 nextrzphi[1] = rzphi[1] - step * psidpsi[3]; // z
320 nextrzphi[2] = rzphi[2] - step/rzphi[0] * psidpsi[2]; /* phi. phidpsi[2]
321 is dimensionless,
322 must divide by R
323 because in
324 cylindrical
325 co-ordinates */
326
327 /* Check that phi remained inside the sector. If not, use the value on
328 the sector boundary. */
329 if (nextrzphi[2] > phimax) {nextrzphi[2] = phimax;}
330 if (nextrzphi[2] < phimin) {nextrzphi[2]=phimin;}
331
332 /* Check convergence (phi difference must be multiplied by R to get
333 the arc length which has dimensions of L) */
334 if(sqrt( (nextrzphi[0] - rzphi[0]) * (nextrzphi[0] - rzphi[0])
335 + (nextrzphi[1] - rzphi[1]) * (nextrzphi[1] - rzphi[1])
336 + rzphi[0]*(nextrzphi[2] - rzphi[2]) *
337 rzphi[0]*(nextrzphi[2] - rzphi[2])) < tol){
338 psi[0] = psidpsi[0];
339 rzphi[0] = nextrzphi[0];
340 rzphi[1] = nextrzphi[1];
341 rzphi[2] = nextrzphi[2];
342
343 // Add a bit of padding
345 psidpsi, rzphi[0], rzphi[2], rzphi[1], time, &sim->B_data);
346 psi[0] = psi[0]
347 + (tol * ( psidpsi[1] + psidpsi[2]/rzphi[0] + psidpsi[3] ));
348 break;
349 }
350
351 rzphi[0] = nextrzphi[0];
352 rzphi[1] = nextrzphi[1];
353 rzphi[2] = nextrzphi[2];
354 iter++;
355
356 if(iter == maxiter) {
357 break;
358 }
359 }
360}
361
376 sim_data* sim, int Neval, real* R, real* phi, real* z, real* t,
377 real* ER, real* Ephi, real* Ez) {
378
379 #pragma omp parallel for
380 for(int k = 0; k < Neval; k++) {
381 real E[3];
382 if( E_field_eval_E(E, R[k], phi[k], z[k], t[k],
383 &sim->E_data, &sim->B_data) ) {
384 continue;
385 }
386 ER[k] = E[0];
387 Ephi[k] = E[1];
388 Ez[k] = E[2];
389 }
390}
391
402
413 sim_data* sim, real* mass, real* charge, int* anum, int* znum) {
414
415 int n_species = plasma_get_n_species(&sim->plasma_data);
416 const real* m = plasma_get_species_mass(&sim->plasma_data);
418 const int* a = plasma_get_species_anum(&sim->plasma_data);
419 const int* z = plasma_get_species_znum(&sim->plasma_data);
420 mass[0] = CONST_M_E;
421 charge[0] = -CONST_E;
422 anum[0] = 0;
423 znum[0] = 0;
424 for(int i=1; i<n_species; i++) {
425 mass[i] = m[i];
426 charge[i] = q[i];
427 anum[i] = a[i-1];
428 znum[i] = z[i-1];
429 }
430}
431
445 sim_data* sim, int Neval, real* R, real* phi, real* z, real* t,
446 real* dens, real* temp) {
447
448 int n_species = plasma_get_n_species(&sim->plasma_data);
449
450 #pragma omp parallel for
451 for(int k = 0; k < Neval; k++) {
452 real psi[1], rho[2], n[MAX_SPECIES], T[MAX_SPECIES];
453 if( B_field_eval_psi(psi, R[k], phi[k], z[k], t[k], &sim->B_data) ) {
454 continue;
455 }
456 if( B_field_eval_rho(rho, psi[0], &sim->B_data) ) {
457 continue;
458 }
459 if( plasma_eval_densandtemp(n, T, rho[0], R[k], phi[k], z[k], t[k],
460 &sim->plasma_data) ) {
461 continue;
462 }
463 for(int i=0; i<n_species; i++) {
464 dens[k + i*Neval] = n[i];
465 temp[k + i*Neval] = T[i]/CONST_E;
466 }
467 }
468}
469
482 sim_data* sim, int Neval, real* R, real* phi, real* z, real* t, real* dens) {
483
484 #pragma omp parallel for
485 for(int k = 0; k < Neval; k++) {
486 real psi[1], rho[2], n0[1];
487 if( B_field_eval_psi(psi, R[k], phi[k], z[k], t[k], &sim->B_data) ) {
488 continue;
489 }
490 if( B_field_eval_rho(rho, psi[0], &sim->B_data) ) {
491 continue;
492 }
493 if( neutral_eval_n0(n0, rho[0], R[k], phi[k], z[k], t[k],
494 &sim->neutral_data) ) {
495 continue;
496 }
497 dens[k] = n0[0];
498 }
499}
500
525 sim_data* sim, int Neval,
526 real* R, real* phi, real* z, real* t, real* psi, real* theta, real* zeta,
527 real* dpsidr, real* dpsidphi, real* dpsidz, real* dthetadr,
528 real* dthetadphi, real* dthetadz, real* dzetadr, real* dzetadphi,
529 real* dzetadz, real* rho) {
530
531 #pragma omp parallel for
532 for(int k = 0; k < Neval; k++) {
533 int isinside;
534 real psithetazeta[12], rhoval[2];
535 if( boozer_eval_psithetazeta(psithetazeta, &isinside, R[k], phi[k],
536 z[k], &sim->B_data, &sim->boozer_data) ) {
537 continue;
538 }
539 if(!isinside) {
540 continue;
541 }
542 if( B_field_eval_rho(rhoval, psithetazeta[0], &sim->B_data) ) {
543 continue;
544 }
545 psi[k] = psithetazeta[0];
546 theta[k] = psithetazeta[4];
547 zeta[k] = psithetazeta[8];
548 dpsidr[k] = psithetazeta[1];
549 dpsidphi[k] = psithetazeta[2];
550 dpsidz[k] = psithetazeta[3];
551 dthetadr[k] = psithetazeta[5];
552 dthetadphi[k] = psithetazeta[6];
553 dthetadz[k] = psithetazeta[7];
554 dzetadr[k] = psithetazeta[9];
555 dzetadphi[k] = psithetazeta[10];
556 dzetadz[k] = psithetazeta[11];
557 rho[k] = rhoval[0];
558 }
559}
560
575 sim_data* sim, int Neval, real* R, real* phi, real* z, real* t,
576 real* qprof, real* jac, real* jacB2) {
577
578 #pragma omp parallel for
579 for(int k = 0; k < Neval; k++) {
580 int isinside;
581 real psithetazeta[12], B[15];
582 if( boozer_eval_psithetazeta(psithetazeta, &isinside, R[k], phi[k],
583 z[k], &sim->B_data, &sim->boozer_data) ) {
584 continue;
585 }
586 if(!isinside) {
587 continue;
588 }
589 if( B_field_eval_B_dB(B, R[k], phi[k], z[k], t[k], &sim->B_data) ) {
590 continue;
591 }
592
593 real bvec[] = {B[0], B[4], B[8]};
594 real gradpsi[] = {psithetazeta[1],
595 psithetazeta[2]/R[k],
596 psithetazeta[3]};
597 real gradtheta[] = {psithetazeta[5],
598 psithetazeta[6]/R[k],
599 psithetazeta[7]};
600 real gradzeta[] = {psithetazeta[9],
601 psithetazeta[10]/R[k],
602 psithetazeta[11]};
603
604 real veca[3], vecb[3];
605
606 math_cross(gradpsi, gradzeta, veca);
607 math_cross(gradpsi, gradtheta, vecb);
608 qprof[k] = (veca[1] - bvec[1]) / vecb[1];
609
610 math_cross(gradtheta, gradzeta, veca);
611 jac[k] = -1.0 / math_dot(veca, gradpsi);
612 jacB2[k] = jac[k]*math_norm(bvec)*math_norm(bvec);
613 }
614}
615
624
625 return mhd_get_n_modes(&sim->mhd_data);
626}
627
639 sim_data* sim, int* nmode, int* mmode, real* amplitude, real* omega,
640 real* phase) {
641
642 int n_modes = mhd_get_n_modes(&sim->mhd_data);
643 const int* n = mhd_get_nmode(&sim->mhd_data);
644 const int* m = mhd_get_mmode(&sim->mhd_data);
645 const real* a = mhd_get_amplitude(&sim->mhd_data);
646 const real* o = mhd_get_frequency(&sim->mhd_data);
647 const real* p = mhd_get_phase(&sim->mhd_data);
648 for(int i=0; i<n_modes; i++) {
649 nmode[i] = n[i];
650 mmode[i] = m[i];
651 amplitude[i] = a[i];
652 omega[i] = o[i];
653 phase[i] = p[i];
654 }
655}
656
679 sim_data* sim, int Neval,
680 real* R, real* phi, real* z, real* t, int includemode,
681 real* alpha, real* dadr, real* dadphi, real* dadz, real* dadt, real* Phi,
682 real* dPhidr, real* dPhidphi, real* dPhidz, real* dPhidt) {
683
684 #pragma omp parallel for
685 for(int k = 0; k < Neval; k++) {
686 real mhd_dmhd[10];
687 if( mhd_eval(mhd_dmhd, R[k], phi[k], z[k], t[k], includemode,
688 &sim->boozer_data, &sim->mhd_data, &sim->B_data) ) {
689 continue;
690 }
691 alpha[k] = mhd_dmhd[0];
692 dadr[k] = mhd_dmhd[2];
693 dadphi[k] = mhd_dmhd[3];
694 dadz[k] = mhd_dmhd[4];
695 dadt[k] = mhd_dmhd[1];
696 Phi[k] = mhd_dmhd[5];
697 dPhidr[k] = mhd_dmhd[7];
698 dPhidphi[k] = mhd_dmhd[8];
699 dPhidz[k] = mhd_dmhd[9];
700 dPhidt[k] = mhd_dmhd[6];
701 }
702}
703
723 sim_data* sim, int Neval,
724 real* R, real* phi, real* z, real* t, int includemode, real* mhd_br,
725 real* mhd_bphi, real* mhd_bz, real* mhd_er, real* mhd_ephi, real* mhd_ez,
726 real* mhd_phi) {
727
728 int onlypert = 1;
729 #pragma omp parallel for
730 for(int k = 0; k < Neval; k++) {
731 real pert_field[7];
732 if( mhd_perturbations(pert_field, R[k], phi[k], z[k], t[k], onlypert,
733 includemode, &sim->boozer_data, &sim->mhd_data,
734 &sim->B_data) ) {
735 continue;
736 }
737 mhd_br[k] = pert_field[0];
738 mhd_bphi[k] = pert_field[1];
739 mhd_bz[k] = pert_field[2];
740 mhd_er[k] = pert_field[3];
741 mhd_ephi[k] = pert_field[4];
742 mhd_ez[k] = pert_field[5];
743 mhd_phi[k] = pert_field[6];
744 }
745}
746
774 sim_data* sim, int Neval, real* R, real* phi, real* z, real* t,
775 int Nv, real* va, real ma, real qa, real* F, real* Dpara, real* Dperp,
776 real* K, real* nu, real* Q, real* dQ, real* dDpara, real* clog,
777 real* mu0, real* mu1, real* dmu0) {
778
779 /* Evaluate plasma parameters */
780 int n_species = plasma_get_n_species(&sim->plasma_data);
781 const real* qb = plasma_get_species_charge(&sim->plasma_data);
782 const real* mb = plasma_get_species_mass(&sim->plasma_data);
783
784 #pragma omp parallel for
785 for(int k=0; k<Neval; k++) {
786 real mufun[3] = {0., 0., 0.};
787
788 /* Evaluate rho as it is needed to evaluate plasma parameters */
789 real psi, rho[2];
790 if( B_field_eval_psi(&psi, R[k], phi[k], z[k], t[k], &sim->B_data) ) {
791 continue;
792 }
793 if( B_field_eval_rho(rho, psi, &sim->B_data) ) {
794 continue;
795 }
796
798 if( plasma_eval_densandtemp(nb, Tb, rho[0], R[k], phi[k], z[k], t[k],
799 &sim->plasma_data) ) {
800 continue;
801 }
802
803 /* Evaluate coefficients for different velocities */
804 for(int iv=0; iv<Nv; iv++) {
805
806 /* Loop through all plasma species */
807 for(int ib=0; ib<n_species; ib++) {
808
809 /* Coulomb logarithm */
810 real clogab[MAX_SPECIES];
811 mccc_coefs_clog(clogab, ma, qa, va[iv], n_species, mb, qb,
812 nb, Tb);
813
814 /* Special functions */
815 real vb = sqrt( 2 * Tb[ib] / mb[ib] );
816 real x = va[iv] / vb;
817 mccc_coefs_mufun(mufun, x, &sim->mccc_data);
818
819 /* Coefficients */
820 real Fb = mccc_coefs_F(ma, qa, mb[ib], qb[ib], nb[ib], vb,
821 clogab[ib], mufun[0]);
822 real Qb = mccc_coefs_Q(ma, qa, mb[ib], qb[ib], nb[ib], vb,
823 clogab[ib], mufun[0]);
824 real dQb = mccc_coefs_dQ(ma, qa, mb[ib], qb[ib], nb[ib], vb,
825 clogab[ib], mufun[2]);
826 real Dparab = mccc_coefs_Dpara(ma, qa, va[iv], qb[ib], nb[ib],
827 vb, clogab[ib], mufun[0]);
828 real Dperpb = mccc_coefs_Dperp(ma, qa, va[iv], qb[ib], nb[ib],
829 vb, clogab[ib], mufun[1]);
830 real dDparab = mccc_coefs_dDpara(ma, qa, va[iv], qb[ib], nb[ib],
831 vb, clogab[ib], mufun[0],
832 mufun[2]);
833 real Kb = mccc_coefs_K(va[iv], Dparab, dDparab, Qb);
834 real nub = mccc_coefs_nu(va[iv], Dperpb);
835
836 /* Store requested quantities */
837 int idx = ib*Nv*Neval + Nv * k + iv;
838 if(mu0 != NULL) { mu0[idx] = mufun[0]; }
839 if(mu1 != NULL) { mu1[idx] = mufun[1]; }
840 if(dmu0 != NULL) { dmu0[idx] = mufun[2]; }
841 if(clog != NULL) { clog[idx] = clogab[ib]; }
842 if(F != NULL) { F[idx] = Fb; }
843 if(Dpara != NULL) { Dpara[idx] = Dparab; }
844 if(Dperp != NULL) { Dperp[idx] = Dperpb; }
845 if(K != NULL) { K[idx] = Kb; }
846 if(nu != NULL) { nu[idx] = nub; }
847 if(Q != NULL) { Q[idx] = Qb; }
848 if(dQ != NULL) { dQ[idx] = dQb; }
849 if(dDpara != NULL) { dDpara[idx] = dDparab; }
850 }
851 }
852 }
853}
854
873 sim_data* sim,
874 int Neval, real* R, real* phi, real* z, real* t, int Nv, real* va,
875 int Aa, int Za, real ma, int reac_type, real* ratecoeff) {
876
877 const int* Zb = plasma_get_species_znum(&sim->plasma_data);
878 const int* Ab = plasma_get_species_anum(&sim->plasma_data);
879 int nion = plasma_get_n_species(&sim->plasma_data) - 1;
880 int nspec = neutral_get_n_species(&sim->neutral_data);
881
882 #pragma omp parallel for
883 for (int k=0; k < Neval; k++) {
884 real psi[1], rho[2], T0[1], n[MAX_SPECIES], T[MAX_SPECIES],
885 n0[MAX_SPECIES];
886 if( B_field_eval_psi(psi, R[k], phi[k], z[k], t[k], &sim->B_data) ) {
887 continue;
888 }
889 if( B_field_eval_rho(rho, psi[0], &sim->B_data) ) {
890 continue;
891 }
892 if( plasma_eval_densandtemp(n, T, rho[0], R[k], phi[k], z[k], t[k],
893 &sim->plasma_data) ) {
894 continue;
895 }
896 if( neutral_eval_t0(T0, rho[0], R[k], phi[k], z[k], t[k],
897 &sim->neutral_data) ) {
898 continue;
899 }
900 if( neutral_eval_n0(n0, rho[0], R[k], phi[k], z[k], t[k],
901 &sim->neutral_data) ) {
902 continue;
903 }
904 for (int j=0; j < Nv; j++) {
905 real E = (physlib_gamma_vnorm(va[j]) - 1.0) * ma * CONST_C*CONST_C;
906 real val;
907 switch (reac_type) {
908 case sigmav_CX:
909 if( asigma_eval_cx(
910 &val, Za, Aa, E, ma, nspec, Zb, Ab, T0[0], n0,
911 &sim->asigma_data) ) {
912 continue;
913 }
914 ratecoeff[Nv*k + j] = val;
915 break;
916 case sigmav_BMS:
917 if( asigma_eval_bms(
918 &val, Za, Aa, E, ma, nion, Zb, Ab, T[0], n,
919 &sim->asigma_data) ) {
920 continue;
921 }
922 ratecoeff[Nv*k + j] = val * n[0];
923 break;
924 default:
925 break;
926 }
927 }
928 }
929
930}
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:166
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:228
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:102
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:449
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:312
a5err B_field_get_axis_rz(real rz[2], B_field_data *Bdata, real phi)
Return magnetic axis Rz-coordinates.
Definition B_field.c:501
Header file for B_field.c.
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:82
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:191
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:237
Header file for asigma.c.
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:124
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_neutral_eval_density(sim_data *sim, int Neval, real *R, real *phi, real *z, real *t, real *dens)
Evaluate neutral density at given coordinates.
Definition libascot.c:481
void libascot_E_field_eval_E(sim_data *sim, 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:375
void libascot_eval_collcoefs(sim_data *sim, 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:773
void libascot_boozer_eval_fun(sim_data *sim, int Neval, real *R, real *phi, real *z, real *t, real *qprof, real *jac, real *jacB2)
Evaluate boozer coordinates related quantities.
Definition libascot.c:574
void libascot_B_field_gradient_descent_3d(sim_data *sim, real psi[1], real rzphi[3], real phimin, real phimax, real step, real tol, int maxiter, int ascent)
Find one psi minimum using the gradient descent method for 3D field inside a sector (phimin < phi < p...
Definition libascot.c:298
void libascot_eval_ratecoeff(sim_data *sim, 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:872
void libascot_mhd_eval_perturbation(sim_data *sim, 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:722
int libascot_plasma_get_n_species(sim_data *sim)
Get number of plasma species.
Definition libascot.c:399
void libascot_mhd_get_mode_specs(sim_data *sim, int *nmode, int *mmode, real *amplitude, real *omega, real *phase)
Get MHD mode amplitude, frequency, phase, and mode numbers.
Definition libascot.c:638
void libascot_plasma_eval_background(sim_data *sim, 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:444
void libascot_boozer_eval_psithetazeta(sim_data *sim, 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:524
int libascot_mhd_get_n_modes(sim_data *sim)
Get number of MHD modes.
Definition libascot.c:623
void libascot_B_field_rhotheta2rz(sim_data *sim, 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:173
void libascot_B_field_eval_B_dB(sim_data *sim, 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_B_field_get_axis(sim_data *sim, int Neval, real *phi, real *Raxis, real *zaxis)
Get magnetic axis at given coordinates.
Definition libascot.c:141
void libascot_plasma_get_species_mass_and_charge(sim_data *sim, real *mass, real *charge, int *anum, int *znum)
Get mass and charge of all plasma species.
Definition libascot.c:412
void libascot_mhd_eval(sim_data *sim, 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:678
void libascot_B_field_gradient_descent(sim_data *sim, 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:237
void libascot_B_field_eval_rho(sim_data *sim, 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:108
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:183
const real * mhd_get_amplitude(mhd_data *mhddata)
Return mode amplitudes.
Definition mhd.c:243
const int * mhd_get_nmode(mhd_data *mhddata)
Return mode toroidal numbers.
Definition mhd.c:203
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:147
const int * mhd_get_mmode(mhd_data *mhddata)
Return mode poloidal numbers.
Definition mhd.c:223
const real * mhd_get_frequency(mhd_data *mhddata)
Return mode frequencies.
Definition mhd.c:263
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:91
const real * mhd_get_phase(mhd_data *mhddata)
Return mode phases.
Definition mhd.c:283
Header file for mhd.c.
int neutral_get_n_species(neutral_data *ndata)
Get the number of neutral species.
Definition neutral.c:151
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:73
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:115
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:267
const int * plasma_get_species_znum(plasma_data *pls_data)
Get charge number of ion species.
Definition plasma.c:325
int plasma_get_n_species(plasma_data *pls_data)
Get the number of plasma species.
Definition plasma.c:237
const real * plasma_get_species_charge(plasma_data *pls_data)
Get charge of all plasma species.
Definition plasma.c:297
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:186
const int * plasma_get_species_anum(plasma_data *pls_data)
Get atomic mass number of ion species.
Definition plasma.c:353
Header file for plasma.c.
Header file for simulate.c.
Simulation data struct.
Definition simulate.h:57
plasma_data plasma_data
Definition simulate.h:61
mhd_data mhd_data
Definition simulate.h:65
E_field_data E_data
Definition simulate.h:60
mccc_data mccc_data
Definition simulate.h:72
neutral_data neutral_data
Definition simulate.h:62
boozer_data boozer_data
Definition simulate.h:64
B_field_data B_data
Definition simulate.h:59
asigma_data asigma_data
Definition simulate.h:66
Header file for wall.c.