ASCOT5
Loading...
Searching...
No Matches
Functions
simulate.c File Reference

Simulation is initialized and run from here. More...

#include <string.h>
#include <unistd.h>
#include "endcond.h"
#include "offload.h"
#include "particle.h"
#include "plasma.h"
#include "random.h"
#include "simulate.h"
#include "print.h"
#include "simulate/simulate_ml_adaptive.h"
#include "simulate/simulate_gc_adaptive.h"
#include "simulate/simulate_gc_fixed.h"
#include "simulate/simulate_fo_fixed.h"
#include "simulate/mccc/mccc.h"
#include "gctransform.h"
#include "asigma.h"
#include "copytogpu.h"

Go to the source code of this file.

Functions

void sim_monitor (char *filename, volatile int *n, volatile int *finished)
 Monitor simulation progress.
 
void simulate (int id, int n_particles, particle_state *p, sim_offload_data *sim_offload, offload_package *offload_data, real *offload_array, int *int_offload_array, real *diag_offload_array)
 Execute marker simulation.
 
void simulate_init_offload (sim_offload_data *sim)
 Initializes simulation settings.
 
void sim_init (sim_data *sim, sim_offload_data *offload_data)
 Initialize simulation data struct on target.
 

Detailed Description

Simulation is initialized and run from here.

This module acts as an interface through which different types of simulations are initialized and run. This module handles no IO operations (with the exception of writing of progress update), no offloading (only unpacking and initialization is done here).

Thread level parallelisation is done here and the threads have shared access on the data once it has been initialized. However, threads should only modify marker and diagnostic data.

Definition in file simulate.c.

Function Documentation

◆ sim_monitor()

void sim_monitor ( char * filename,
volatile int * n,
volatile int * finished )

Monitor simulation progress.

This function contains a loop that is repeated until all markers have finished simulation. Loops are executed at interval defined by A5_PRINTPROGRESSINTERVAL in ascot5.h.

At each loop, number of markers that have finished simulation is written to output file, along with time spent on simulation and estimated time remaining for the simulation to finish.

Parameters
filenamepointer to file where progress is written. File is opened and closed outside this function
npointer to number of total markers in simulation queue
finishedpointer to number of finished markers in simulation queue

Definition at line 422 of file simulate.c.

◆ simulate()

void simulate ( int id,
int n_particles,
particle_state * p,
sim_offload_data * sim_offload,
offload_package * offload_data,
real * offload_array,
int * int_offload_array,
real * diag_offload_array )

Execute marker simulation.

This simulates markers using given inputs and options. All different types of simulations are initialized and run via this function.

This function proceeds as follows:

  1. Input offload data is unpacked and initialized by calling respective init functions.
  2. Meta data (e.g. random number generator) is initialized.
  3. Markers are put into simulation queue.
  4. Threads are spawned. One thread is dedicated for monitoring progress, if monitoring is active.
  5. Other threads execute marker simulation using the mode the user has chosen.
  • Process continues once all markers have been simulated and each thread has finished. Monitoring is also terminated.
  1. (If hybrid mode is active) Markers with hybrid end condition active are placed on a new queue, and they have their end condition deactivated and they are simulated with simulate_fo_fixed.c until they have met some other end condition. Threads are spawned and progress is monitored as previously.
  2. Simulation data is deallocated except for data that is mapped back to host.
  3. Execution returns to host where this function was called.
Parameters
idtarget id where this function is executed, zero if on host
n_particlestotal number of markers to be simulated
ppointer to array storing all marker states to be simulated
sim_offloadpointer to simulation offload data
offload_datapointer to the rest of the offload data
offload_arraypointer to input data offload array
int_offload_arraypointer to input data int offload array
diag_offload_arraypointer to diagnostics offload array
Todo
Reorganize this function so that it conforms to documentation.

Definition at line 80 of file simulate.c.

◆ simulate_init_offload()

void simulate_init_offload ( sim_offload_data * sim)

Initializes simulation settings.

This function adjusts simulation settings, e.g. how physics are included, according to the given simulation data. This function should only be called once right after input data has been read.

Parameters
simsimulation offload struct which has all fields initialized

Definition at line 349 of file simulate.c.

◆ sim_init()

void sim_init ( sim_data * sim,
sim_offload_data * offload_data )

Initialize simulation data struct on target.

This function copies the simulation parameters from the offload struct to the struct on the target.

Parameters
simpointer to data struct on target
offload_datapointer to offload data struct

Definition at line 365 of file simulate.c.