18#include "hdf5io/hdf5_dist.h"
34 int iphi,
int iz,
real* ppara,
real* pperp);
59 strcpy(sim->
qid, qid);
61 int mpi_rank = 0, mpi_root = 0;
64 "Tag %s\nBranch %s\n\n", GIT_VERSION, GIT_BRANCH);
74 "\nInitializing output failed.\n"
75 "See stderr for details.\n");
80 real m1, q1, m2, q2, mprod1, qprod1, mprod2, qprod2, Q;
82 reaction, &m1, &q1, &m2, &q2, &mprod1, &qprod1, &mprod2, &qprod2, &Q);
84 int n_r=0, n_phi=0, n_z=0;
85 if(react1->
type == 1) {
90 else if(react1->
type == 2) {
96 #pragma omp parallel for
97 for(
int iR = 0; iR < n_r; iR++) {
108 for(
int iphi = 0; iphi < n_phi; iphi++) {
109 for(
int iz = 0; iz < n_z; iz++) {
112 if(density1 > 0 && density2 > 0) {
114 react1, react2, m1, m2, n, iR, iphi, iz,
115 ppara1, pperp1, ppara2, pperp2);
116 for(
int i = 0; i < n; i++) {
119 i, m1, m2, mprod1, mprod2, Q,
120 ppara1, pperp1, ppara2, pperp2, &vcom2,
121 pparaprod1, pperpprod1, pparaprod2, pperpprod2);
122 real E = 0.5 * ( m1 * m2 ) / ( m1 + m2 ) * vcom2;
124 real weight = density1 * density2 * sqrt(vcom2)
133 if( 0 <= ippara && ippara < prod1->n_ppara &&
134 0 <= ipperp && ipperp < prod1->n_pperp) {
136 iR, iphi, iz, ippara, ipperp, 0, 0,
148 if( 0 <= ippara && ippara < prod2->n_ppara &&
149 0 <= ipperp && ipperp < prod2->n_pperp) {
151 iR, iphi, iz, ippara, ipperp, 0, 0,
177 int c1 = (int)rint(q1 /
CONST_E);
178 int c2 = (int)rint(q2 /
CONST_E);
179 int cprod1 = (int)rint(qprod1 /
CONST_E);
180 int cprod2 = (int)rint(qprod2 /
CONST_E);
188 sprintf(path,
"/results/afsi_%s/reaction", sim->
qid);
189 hid_t reactiondata = H5Gcreate2(f, path, H5P_DEFAULT, H5P_DEFAULT,
191 if(reactiondata < 0) {
192 print_err(
"Failed to write reaction data.\n");
197 if(H5LTmake_dataset_double(reactiondata,
"m1", 1, &size, &m1)) {
198 print_err(
"Failed to write reaction data.\n");
201 if(H5LTmake_dataset_double(reactiondata,
"m2", 1, &size, &m2)) {
202 print_err(
"Failed to write reaction data.\n");
205 if(H5LTmake_dataset_double(reactiondata,
"mprod1", 1, &size, &mprod1)) {
206 print_err(
"Failed to write reaction data.\n");
209 if(H5LTmake_dataset_double(reactiondata,
"mprod2", 1, &size, &mprod2)) {
210 print_err(
"Failed to write reaction data.\n");
213 if(H5LTmake_dataset_double(reactiondata,
"q", 1, &size, &q)) {
214 print_err(
"Failed to write reaction data.\n");
217 if(H5LTmake_dataset_int(reactiondata,
"q1", 1, &size, &c1)) {
218 print_err(
"Failed to write reaction data.\n");
221 if(H5LTmake_dataset_int(reactiondata,
"q2", 1, &size, &c2)) {
222 print_err(
"Failed to write reaction data.\n");
225 if(H5LTmake_dataset_int(reactiondata,
"qprod1", 1, &size, &cprod1)) {
226 print_err(
"Failed to write reaction data.\n");
229 if(H5LTmake_dataset_int(reactiondata,
"qprod2", 1, &size, &cprod2)) {
230 print_err(
"Failed to write reaction data.\n");
233 if(H5Gclose(reactiondata)) {
234 print_err(
"Failed to write reaction data.\n");
238 sprintf(path,
"/results/afsi_%s/prod1dist5d", sim->
qid);
240 print_err(
"Warning: 5D distribution could not be written.\n");
242 sprintf(path,
"/results/afsi_%s/prod2dist5d", sim->
qid);
244 print_err(
"Warning: 5D distribution could not be written.\n");
247 print_err(
"Failed to close the file.\n");
274 if(react1->
type == 1) {
277 else if(react1->
type == 2) {
279 react1->
dist_thermal, m1, n, iR, iphi, iz, ppara1, pperp1);
282 if(react2->
type == 1) {
285 else if(react2->
type == 2) {
287 react2->
dist_thermal, m2, n, iR, iphi, iz, ppara2, pperp2);
318 real v1x = cos(rn1) * pperp1[i] / m1;
319 real v1y = sin(rn1) * pperp1[i] / m1;
320 real v1z = ppara1[i] / m1;
322 real v2x = cos(rn2) * pperp2[i] / m2;
323 real v2y = sin(rn2) * pperp2[i] / m2;
324 real v2z = ppara2[i] / m2;
326 *vcom2 = (v1x - v2x) * (v1x - v2x)
327 + (v1y - v2y) * (v1y - v2y)
328 + (v1z - v2z) * (v1z - v2z);
332 v_cm[0] = ( m1 * v1x + m2 * v2x ) / ( m1 + m2 );
333 v_cm[1] = ( m1 * v1y + m2 * v2y ) / ( m1 + m2 );
334 v_cm[2] = ( m1 * v1z + m2 * v2z ) / ( m1 + m2 );
338 + 0.5 * m1 * ( (v1x - v_cm[0])*(v1x - v_cm[0])
339 + (v1y - v_cm[1])*(v1y - v_cm[1])
340 + (v1z - v_cm[2])*(v1z - v_cm[2]) )
341 + 0.5 * m2 * ( (v2x - v_cm[0])*(v2x - v_cm[0])
342 + (v2y - v_cm[1])*(v2y - v_cm[1])
343 + (v2z - v_cm[2])*(v2z - v_cm[2]) );
349 real theta = acos( 2 * ( rn2 - 0.5 ) );
350 real vnorm = sqrt( 2.0 * ekin / ( mprod2 * ( 1.0 + mprod2 / mprod1 ) ) );
353 v2_cm[0] = vnorm * sin(theta) * cos(phi);
354 v2_cm[1] = vnorm * sin(theta) * sin(phi);
355 v2_cm[2] = vnorm * cos(theta);
358 real vprod1[3], vprod2[3];
359 vprod1[0] = -(mprod2/mprod1) * v2_cm[0] + v_cm[0];
360 vprod1[1] = -(mprod2/mprod1) * v2_cm[1] + v_cm[1];
361 vprod1[2] = -(mprod2/mprod1) * v2_cm[2] + v_cm[2];
362 vprod2[0] = v2_cm[0] + v_cm[0];
363 vprod2[1] = v2_cm[1] + v_cm[1];
364 vprod2[2] = v2_cm[2] + v_cm[2];
367 pparaprod1[i] = vprod1[2] * mprod1;
368 pperpprod1[i] = sqrt( vprod1[0]*vprod1[0] + vprod1[1]*vprod1[1] ) * mprod1;
369 pparaprod2[i] = vprod2[2] * mprod2;
370 pperpprod2[i] = sqrt( vprod2[0]*vprod2[0] + vprod2[1]*vprod2[1] ) * mprod2;
388 for(
int ippara = 0; ippara < dist->
n_ppara; ippara++) {
389 for(
int ipperp = 0; ipperp < dist->
n_pperp; ipperp++) {
390 if(ippara == 0 && ipperp == 0) {
396 cumdist[ippara*dist->
n_pperp+ipperp] =
397 cumdist[ippara*dist->
n_pperp+ipperp-1]
399 iR, iphi, iz, ippara, ipperp, 0, 0, dist->
step_6,
405 for(
int ippara = 0; ippara < dist->
n_ppara; ippara++) {
406 for(
int ipperp = 0; ipperp < dist->
n_pperp; ipperp++) {
407 cumdist[ippara*dist->
n_pperp+ipperp] /=
412 for(
int i = 0; i < n; i++) {
444 int iphi,
int iz,
real* ppara,
real* pperp) {
445 int ind = iR * (data->
n_phi * data->
n_z) + iphi * data->
n_z + iz;
448 for(
int i = 0; i < n; i++) {
449 real r1, r2, r3, r4, E;
454 E = -temp * ( log(r1) + log(r2) * r3 * r3 );
457 pperp[i] = sqrt( ( 1 - r4*r4 ) * 2 * E * mass);
458 ppara[i] = r4 * sqrt(2 * E * mass);
472 if(dist->
type == 1) {
479 iR, iphi, iz, ippara, ipperp, 0, 0,
488 else if(dist->
type == 2) {
509 if(dist->
type == 1) {
515 else if(dist->
type == 2) {
531 printf(
"%d %le %le\n", dist1->
n_r, dist1->
min_r, dist1->
max_r);
533 printf(
"%d %le %le\n", dist1->
n_z, dist1->
min_z, dist1->
max_z);
537 printf(
"%d %le %le\n", dist1->
n_q, dist1->
min_q, dist1->
max_q);
543 for(
int i = 0; i < ncell; i++) {
547 printf(
"%le\n", sum);
566 real temperature = 1e3;
578 for(
int i = 0; i < n; i++) {
579 printf(
"%le %le\n", ppara[i], pperp[i]);
void afsi_run(sim_data *sim, Reaction reaction, int n, afsi_data *react1, afsi_data *react2, real mult, dist_5D_data *prod1, dist_5D_data *prod2)
Calculate fusion source from two arbitrary ion distributions.
void afsi_sample_thermal(afsi_thermal_data *data, real mass, int n, int iR, int iphi, int iz, real *ppara, real *pperp)
Sample ppara and pperp from a thermal (Maxwellian) population.
void afsi_test_thermal()
Test thermal source.
real afsi_get_volume(afsi_data *dist, int iR)
Get physical volume of a distribution cell.
void afsi_sample_5D(dist_5D_data *dist, int n, int iR, int iphi, int iz, real *ppara, real *pperp)
Sample ppara and pperp from a 5D distribution.
void afsi_compute_product_momenta(int i, real m1, real m2, real mprod1, real mprod2, real Q, real *ppara1, real *pperp1, real *ppara2, real *pperp2, real *vcom2, real *pparaprod1, real *pperpprod1, real *pparaprod2, real *pperpprod2)
Compute momenta of reaction products.
real afsi_get_density(afsi_data *dist, int iR, int iphi, int iz)
Get particle density.
void afsi_sample_reactant_momenta(afsi_data *react1, afsi_data *react2, real m1, real m2, int n, int iR, int iphi, int iz, real *ppara1, real *pperp1, real *ppara2, real *pperp2)
Sample velocities from reactant distributions.
void afsi_test_dist(dist_5D_data *dist1)
Test distribution.
Main header file for ASCOT5.
void boschhale_reaction(Reaction reaction, real *m1, real *q1, real *m2, real *q2, real *mprod1, real *qprod1, real *mprod2, real *qprod2, real *Q)
Get masses and charges of particles participating in the reaction and the released energy.
real boschhale_sigma(Reaction reaction, real E)
Estimate cross-section for a given fusion reaction.
Header file for boschdale.c.
Reaction
Available reactions.
Header file containing physical and mathematical constants.
#define CONST_U
Atomic mass unit in kilograms [kg]
#define CONST_E
Elementary charge [C]
size_t dist_5D_index(int i_r, int i_phi, int i_z, int i_ppara, int i_pperp, int i_time, int i_q, size_t step_6, size_t step_5, size_t step_4, size_t step_3, size_t step_2, size_t step_1)
Function for calculating the index in the histogram array.
int dist_5D_init(dist_5D_data *data)
Initializes distribution from offload data.
Header file for dist_5D.c.
int hdf5_dist_write_5D(hid_t f, char *path, dist_5D_data *dist)
Write 5D distribution to an existing result group.
herr_t hdf5_close(hid_t file_id)
Close access to given hdf5 file identifier. A negative value is returned on failure.
hid_t hdf5_open(const char *filename)
Open a hdf5 file for reading and writing. A negative value is returned on failure.
Header file for hdf5_helpers.h.
int hdf5_interface_init_results(sim_data *sim, char *qid, char *run)
Initialize run group.
void hdf5_generate_qid(char *qid)
Generate an identification number for a run.
Header file for hdf5_interface.c.
Macros for printing console output.
#define print_out0(v, rank, root,...)
Print to standard output only for root process.
#define print_err(...)
Print to standard error.
Header file for random.c.
#define random_uniform(data)
#define random_init(data, seed)
void simulate_init(sim_data *sim)
Initialize simulation data struct.
Header file for simulate.c.
Wrapper around input data structures.
afsi_thermal_data * dist_thermal
Structure for passing in 2D thermal temperature and density.