Semi-Lagrangian Library
Modular library for kinetic and gyrokinetic simulations of plasmas in fusion energy devices.
|
Module for a particle group with linearized-backward-flow (lbf) resamplings.
Derived types and interfaces | |
type | sll_t_int_list_element |
linked lists of integers, used in some of the module routines More... | |
type | sll_t_int_list_element_ptr |
a pointer type is needed for arrays of lists More... | |
type | sll_t_particle_group_2d2v_lbf |
Group of sll_t_particle_group_2d2v_lbf. More... | |
Functions/Subroutines | |
pure real(kind=f64) function, dimension(3) | get_x_2d2v_lbf (self, i) |
Getters ----------------------------------------------------------------------------------------------------------------—. More... | |
pure real(kind=f64) function, dimension(3) | get_v_2d2v_lbf (self, i) |
Get the velocity of a particle. More... | |
pure real(kind=f64) function | get_charge_2d2v_lbf (self, i, i_weight) |
Get charge of a particle (q * particle_weight) More... | |
pure real(kind=f64) function | get_mass_2d2v_lbf (self, i, i_weight) |
Get mass of a particle ( m * particle_weight) More... | |
pure real(kind=f64) function, dimension(self%n_weights) | get_weights_2d2v_lbf (self, i) |
Get weights of a particle. More... | |
pure real(kind=f64) function | get_common_weight_2d2v_lbf (self) |
Set the common weight. More... | |
subroutine | set_x_2d2v_lbf (self, i, x) |
Setters ----------------------------------------------------------------------------------------------------------------—. More... | |
subroutine | set_v_2d2v_lbf (self, i, x) |
Set the velocity of a particle. More... | |
subroutine | set_weights_2d2v_lbf (self, i, x) |
Set the weights of a particle. More... | |
subroutine | set_common_weight_2d2v_lbf (self, x) |
Set the common weight. More... | |
subroutine | initialize_particle_group_2d2v_lbf (self, species_charge, species_mass, domain_is_x_periodic, domain_is_y_periodic, remap_degree, remapping_grid_eta_min, remapping_grid_eta_max, remapping_sparse_grid_max_levels, n_particles_x, n_particles_y, n_particles_vx, n_particles_vy, n_weights) |
Initializer ------------------------------------------------------------------------------------------------------------— Initialize particle group. More... | |
subroutine, public | sll_s_new_particle_group_2d2v_lbf_ptr (particle_group, species_charge, species_mass, domain_is_x_periodic, domain_is_y_periodic, remap_degree, remapping_grid_eta_min, remapping_grid_eta_max, remapping_sparse_grid_max_levels, n_particles_x, n_particles_y, n_particles_vx, n_particles_vy) |
Constructor for abstract type. More... | |
subroutine | delete_particle_group_2d2v_lbf (self) |
Destructor -------------------------------------------------------------------------------------------------------------—. More... | |
subroutine | sample (self, target_total_charge, enforce_total_charge, init_f_params, rand_seed, rank, world_size) |
sample (layer for resample procedure) ----------------------------------------------------------------------------------— this routine essentially does 2 things: More... | |
subroutine | resample (self, target_total_charge, enforce_total_charge, init_f_params, rand_seed, rank, world_size) |
resample (and sample) --------------------------------------------------------------------------------------------------— this routine essentially does 2 things: More... | |
subroutine | write_known_density_on_remapping_grid (self, distribution_params) |
write_known_density_on_remapping_grid ----------------------------------------------------------------------------------— this routine writes a given distribution on the interpolation (sparse grid) nodes to further approximate it More... | |
subroutine | reset_particles_positions (self) |
reset_particles_positions ----------------------------------------------------------------------------------------------— reset the particles on the initial (cartesian) grid – we use the (multi-purpose) lbf grid – NOTE: particles will be located at the center of each cell (to avoid a particular treatment of periodic domains) More... | |
integer(kind=i32) function | get_neighbor_index (self, k, dim, dir) |
get_neighbor_index -----------------------------------------------------------------------------------------------------— returns the index of the specified particle neighbor (defines the particle connectivity) More... | |
subroutine | reset_particles_weights_with_direct_interpolation (self, target_total_charge, enforce_total_charge) |
reset_particles_weights_with_direct_interpolation ----------------------------------------------------------------------— compute (and set) the particle weights using a direct interpolation (here, sparse grid) – does not change the position of the deposition particles More... | |
real(kind=f64) function | interpolate_value_of_remapped_f (self, eta) |
interpolate_value_of_remapped_f ----------------------------------------------------------------------------------------— computes the value of the (last) remapped density f using the interpolation tool – for now, assuming only sparse grid interpolation More... | |
subroutine | reconstruct_f_lbf (self, reconstruction_set_type, given_grid_4d, given_array_4d, reconstruct_f_on_last_node, target_total_charge, enforce_total_charge) |
macro for the lbf approximation of a transported density (reconstruct_f_lbf) below -------------------------------------— More... | |
subroutine | reconstruct_f_lbf_on_remapping_grid (self) |
reconstruct_f_lbf_on_remapping_grid ------------------------------------------------------------------------------------— layer for reconstruct_f_lbf, when reconstructing f on the remapping grid More... | |
subroutine | reconstruct_f_lbf_on_given_grid (self, given_grid_4d, given_array_4d, reconstruct_f_on_last_node, target_total_charge, enforce_total_charge) |
reconstruct_f_lbf_on_remapping_grid ------------------------------------------------------------------------------------— layer for reconstruct_f_lbf, when reconstructing f on a given grid More... | |
subroutine | get_ltp_deformation_matrix (self, k, mesh_period_x, mesh_period_y, h_particles_x, h_particles_y, h_particles_vx, h_particles_vy, x_k, y_k, vx_k, vy_k, d11, d12, d13, d14, d21, d22, d23, d24, d31, d32, d33, d34, d41, d42, d43, d44) |
get_ltp_deformation_matrix ---------------------------------------------------------------------------------------------— Compute the coefficients of the particle 'deformation' matrix which actually approximates the Jacobian matrix of the exact backward flow (defined between the current time and that of the particle initialization – or the last particle remapping) at the current particle position. More... | |
subroutine | periodic_correction (p_group, x, y) |
periodic_correction ----------------------------------------------------------------------------------------------------— puts the point (x,y) back into the computational domain if periodic in x or y (or both) otherwise, does nothing More... | |
type(sll_t_int_list_element) function, pointer | sll_f_add_element_in_int_list (head, new_element) |
sll_f_add_element_in_int_list ------------------------------------------------------------------------------------------— list management More... | |
subroutine | convert_4d_index_to_1d (k, j_x, j_y, j_vx, j_vy, n_parts_x, n_parts_y, n_parts_vx, n_parts_vy) |
convert_4d_index_to_1d -------------------------------------------------------------------------------------------------— given the 4d index of a node on a cartesian grid, returns its 1d index in some assumed order see inverse function convert_1d_index_to_4d More... | |
subroutine | convert_1d_index_to_4d (j_x, j_y, j_vx, j_vy, k, n_parts_x, n_parts_y, n_parts_vx, n_parts_vy) |
convert_1d_index_to_4d -------------------------------------------------------------------------------------------------— given the 1d index of a node on a cartesian grid (with some assumed order), returns its 4d index see inverse function convert_4d_index_to_1d More... | |
subroutine | get_1d_cell_containing_point (j, x, x_min, h) |
get_1d_cell_containing_point -------------------------------------------------------------------------------------------— elementary function to compute the index j of the 1d cell containing a point x, ie x_min + (j-1)*h <= x < x_min + j*h bounds check should be performed outside this routine More... | |
subroutine | update_closest_particle_arrays (k_part, x_aux, y_aux, vx_aux, vy_aux, i, j, l, m, h_cell_x, h_cell_y, h_cell_vx, h_cell_vy, closest_particle, closest_particle_distance) |
update_closest_particle_arrays -----------------------------------------------------------------------------------------— update the arrays closest_particle and closest_particle_distance with the index of the given particle if closer to what had been stored up to now. More... | |
Variables | |
integer(kind=i32), parameter | sll_p_lbf_remapping_grid = 1 |
possible values for the parameter reconstruction_set_type in the reconstruction routine More... | |
integer(kind=i32), parameter | sll_p_lbf_given_grid = 2 |
|
private |
convert_1d_index_to_4d -------------------------------------------------------------------------------------------------— given the 1d index of a node on a cartesian grid (with some assumed order), returns its 4d index see inverse function convert_4d_index_to_1d
here, k_aux = (j_vy-1) + (j_vx-1) * n_parts_vy + (j_y-1) * n_parts_vy * n_parts_vx + (j_x-1) * n_parts_vy * n_parts_vx * n_parts_y
here, k_aux = (j_vx-1) + (j_y-1) * n_parts_vx + (j_x-1) * n_parts_vx * n_parts_y
here, k_aux = (j_y-1) + (j_x-1) * n_parts_y
here, k_aux = (j_x-1)
Definition at line 2094 of file sll_m_particle_group_2d2v_lbf.F90.
|
private |
convert_4d_index_to_1d -------------------------------------------------------------------------------------------------— given the 4d index of a node on a cartesian grid, returns its 1d index in some assumed order see inverse function convert_1d_index_to_4d
Definition at line 2064 of file sll_m_particle_group_2d2v_lbf.F90.
|
private |
Destructor -------------------------------------------------------------------------------------------------------------—.
[in,out] | self | particle group |
Definition at line 443 of file sll_m_particle_group_2d2v_lbf.F90.
|
private |
get_1d_cell_containing_point -------------------------------------------------------------------------------------------— elementary function to compute the index j of the 1d cell containing a point x, ie x_min + (j-1)*h <= x < x_min + j*h bounds check should be performed outside this routine
Definition at line 2133 of file sll_m_particle_group_2d2v_lbf.F90.
|
private |
Get charge of a particle (q * particle_weight)
[in] | self | particle group |
[in] | i | particle index |
[in] | i_weight | weight index to be used (default: 1) - not needed now |
Definition at line 186 of file sll_m_particle_group_2d2v_lbf.F90.
|
private |
Set the common weight.
[in] | self | particle group |
Definition at line 231 of file sll_m_particle_group_2d2v_lbf.F90.
|
private |
get_ltp_deformation_matrix ---------------------------------------------------------------------------------------------— Compute the coefficients of the particle 'deformation' matrix which actually approximates the Jacobian matrix of the exact backward flow (defined between the current time and that of the particle initialization – or the last particle remapping) at the current particle position.
Note: the 'deformation matrix' terminology comes from the LTP method, but with the lbf reconstruction method we are not deforming particles anymore. This matrix is just used as the approximate backward Jacobian matrix
It is computed in two steps:
Note: when computing finite differences in a periodic dimension (say x), one must be careful since two values of F_x can be close in the periodic interval but distant by almost L_x in the (stored) [0,L_x[ representation. To account for this (frequent) phenomenon we do the following: when the difference DF (see example above) is larger than L_x/2, we make it smaller by adding +/- L_x to it. Note that here we could very well be making the slope smaller than what it should actually be: indeed if the function F^n_x is having a steep slope at z^0_k which adds one (or several) periods L_x to DF then our modification will artificially lower the slope. But this is impossible to prevent in full generality (indeed: a steep slope crossing the 0 or L_x value will be lowered anyway in the [0,L_x[ representation) and should not be frequent (indeed it only happens when F^n_x has high derivatives and the particle grid is coarse, which will lead to bad approximations anyhow).
[out] | y_k | particle center in physical space |
[out] | vy_k | particle center in velocity space |
[out] | d14 | coefs of matrix D (backward Jacobian) |
Compute the forward Jacobian matrix J_k
---— d/d_x terms
no right neighbor is available, use a non-centered finite difference
no left neighbor is available, use a non-centered finite difference
---— d/d_y terms
no right neighbor is available, use a non-centered finite difference
no left neighbor is available, use a non-centered finite difference
---— d/d_vx terms
no right neighbor is available, use a non-centered finite difference
no left neighbor is available, use a non-centered finite difference
---— d/d_vy terms
no right neighbor is available, use a non-centered finite difference
no left neighbor is available, use a non-centered finite difference
Compute D_k the inverse of J_k
Definition at line 1586 of file sll_m_particle_group_2d2v_lbf.F90.
|
private |
Get mass of a particle ( m * particle_weight)
[in] | self | particle group |
[in] | i | particle index |
[in] | i_weight | weight index to be used (default: 1) - not needed now |
Definition at line 203 of file sll_m_particle_group_2d2v_lbf.F90.
|
private |
get_neighbor_index -----------------------------------------------------------------------------------------------------— returns the index of the specified particle neighbor (defines the particle connectivity)
[in] | k | particle index |
[in] | dim | neighbor dimension |
[in] | dir | neighbor direction (-1: left, 1:right) |
Definition at line 633 of file sll_m_particle_group_2d2v_lbf.F90.
|
private |
Get the velocity of a particle.
[in] | self | particle group |
[in] | i | particle index |
Definition at line 172 of file sll_m_particle_group_2d2v_lbf.F90.
|
private |
Get weights of a particle.
[in] | self | particle group |
[in] | i | no. of the particle |
Definition at line 220 of file sll_m_particle_group_2d2v_lbf.F90.
|
private |
Getters ----------------------------------------------------------------------------------------------------------------—.
Get the physical coordinates of a particle
[in] | self | particle group |
[in] | i | particle index |
Definition at line 160 of file sll_m_particle_group_2d2v_lbf.F90.
|
private |
Initializer ------------------------------------------------------------------------------------------------------------— Initialize particle group.
[in,out] | self | particle group |
[in] | n_weights | number of weights per particle (only 1 for now) |
create the species object for this particle group
A. discretization of the flow: the flow grid is the 4d cartesian grid where the backward flow is linearized in this deterministic case, the particles are initially located at the center of each flow cell
B. discretization of the remapped f, with sparse grids
C. array of sparse grid coefficients for remapped_f
this array is to store temporary values of remapped f, while those of previously remapped f still needed
Definition at line 287 of file sll_m_particle_group_2d2v_lbf.F90.
|
private |
interpolate_value_of_remapped_f ----------------------------------------------------------------------------------------— computes the value of the (last) remapped density f using the interpolation tool – for now, assuming only sparse grid interpolation
[in] | eta | Position where to interpolate |
Definition at line 798 of file sll_m_particle_group_2d2v_lbf.F90.
|
private |
periodic_correction ----------------------------------------------------------------------------------------------------— puts the point (x,y) back into the computational domain if periodic in x or y (or both) otherwise, does nothing
Definition at line 2033 of file sll_m_particle_group_2d2v_lbf.F90.
|
private |
macro for the lbf approximation of a transported density (reconstruct_f_lbf) below -------------------------------------—
reconstruct_f_lbf -------------------------------------------------------------------------------------------------------— reconstruct point values of the transported f using a bsl approximation based on linearized backward flows (lbf) values are reconstructed on different grids, depending on reconstruction_set_type:
index of particle closest to the center of each flow cell
array of integer linked lists (declared below) useful when remapping on sparse grids (can also simplify the code when remapping on cartesian grids which do not match with the flow cells? but maybe too costly)
<<g>> cartesian grid pointer to the remapping grid
the flow cells are the cells where the flow will be linearized
results from [[get_ltp_deformation_matrix]]
coordinates of particle k at time n and time 0
coordinates of a reconstruction point at time 0, absolute
coordinates of a reconstruction point at time 0, relative to the nearby reference particle (= closest to cell center)
getting the parameters of the flow grid (where the bwd flow is linearized)
reconstruction will be done through local linearization of the bwd flow in flow cells. these flow cells are defined by the lbf_grid but we may not need all of them (if reconstructing f on a given grid, see below)
A. preparation of the point sets where f will be reconstructed, depending on the cases
=> prepare the array of linked lists that will store the node indices contained in the flow cells (one list per cell)
then loop to store the sparse grid node indices in linked lists corresponding to the flow cells that contain them
get node coordinates:
find the index (j_x,j_y,j_vx,j_vy) of the flow cell containing this node (same piece of code as below)
discard if flow cell is off-bounds
increment the proper linked list
then use the given 4d grid and write values in given array
if the given grid is strictly contained in the lbf grid, we can reduce the number of flow cells where f is reconstructed
B. Preparatory work for the linearization of the flow on the flow cells: find out the closest particle to each cell center, by looping over all particles and noting which flow cell contains it. (The leftmost flow cell in each dimension may not be complete.)
find absolute (x_k,y_k,vx_k,vy_k) coordinates for k-th particle.
which flow cell is this particle in?
discard this particle if off-bounds
C. loop on the flow cells (main loop): on each flow cell, we
here the domain corresponds to the Poisson mesh
here the domain corresponds to the Poisson mesh
Find the particle which is closest to the cell center – and if we do not have it yet, look on the neighboring cells
In this flow cell we will use the k-th backward flow, requires the deformation matrix of the k-th particle
Find position of particle k at time 0
initially the particles are on the center of the lbf cells (also the flow grid)
node coordinates relative to current particle position
find z_t0 = (x_t0, y_t0, vx_t0, vy_t0), the position of the node at time = 0 using the affine bwd flow
put back z_t0 inside domain (if needed) to enforce periodic boundary conditions
now (x_t0, y_t0, vx_t0, vy_t0) is the (approx) position of the node at time t=0
interpolate and store nodal value on ad-hoc array
loop over the grid points inside this flow cell:
points in the grid are of the form d(i) = g_grid_d_min + (i-1) * h_g_grid_d, i = 1, .. g_num_points_d (with d = x, y, vx or vy and g_num_points_d = g_num_cells_d or g_num_cells_d+1 , depending on the periodicity) and this flow cell has the form [flow_grid_d_min + (j-1) * h_flow_grid_d, flow_grid_d_min + j * h_flow_grid_d[ so eta_d(i) is in this flow cell if i_min <= i <= i_max where i_min = ceiling( (flow_grid_min - g_grid_d_min + (j-1)*h_flow_grid_d)/h_g_grid_d + 1 ) and i_max = ceiling( (flow_grid_min - g_grid_d_min + (j) *h_flow_grid_d)/h_g_grid_d + 1 ) - 1
C.3 reconstruct the value of f at z_i = (x,y,vx,vy) for this we need z_t0, the position of the z_i at time = 0, using the affine backward flow
put back z_t0 inside domain (if needed) to enforce periodic boundary conditions
now (x_t0, y_t0, vx_t0, vy_t0) is the (approx) position of the node z_i at time t=0
interpolation here may use sparse grid or splines, depending on the method chosen for self
C.4 write the reconstructed value at proper place
this is the end of the (fourfold) loop on the grid nodes
and this is the end of (fourfold) loop on the flow cells
Definition at line 844 of file sll_m_particle_group_2d2v_lbf.F90.
|
private |
reconstruct_f_lbf_on_remapping_grid ------------------------------------------------------------------------------------— layer for reconstruct_f_lbf, when reconstructing f on a given grid
Definition at line 1533 of file sll_m_particle_group_2d2v_lbf.F90.
|
private |
reconstruct_f_lbf_on_remapping_grid ------------------------------------------------------------------------------------— layer for reconstruct_f_lbf, when reconstructing f on the remapping grid
Definition at line 1506 of file sll_m_particle_group_2d2v_lbf.F90.
|
private |
resample (and sample) --------------------------------------------------------------------------------------------------— this routine essentially does 2 things:
A. write the nodal values of the target density f, then compute the new interpolation coefs
write initial density f0 on remapping grid
reconstruct transported density fn on remapping grid with the lbf method
compute the sparse grid interpolation coefs for remapped_f, using the nodal values stored in the tmp array
B. reset the particles on the cartesian grid
since the remapping tool has been reset, computing the weights can be done with straightforward interpolation (flow = Id)
not needed for now, but prevents warnings
Definition at line 483 of file sll_m_particle_group_2d2v_lbf.F90.
|
private |
reset_particles_positions ----------------------------------------------------------------------------------------------— reset the particles on the initial (cartesian) grid – we use the (multi-purpose) lbf grid – NOTE: particles will be located at the center of each cell (to avoid a particular treatment of periodic domains)
Definition at line 556 of file sll_m_particle_group_2d2v_lbf.F90.
|
private |
reset_particles_weights_with_direct_interpolation ----------------------------------------------------------------------— compute (and set) the particle weights using a direct interpolation (here, sparse grid) – does not change the position of the deposition particles
set the particle group common_weight to 1 (will be a factor of each particle weight)
5 is the first weight index
5 is the first weight index
Definition at line 742 of file sll_m_particle_group_2d2v_lbf.F90.
|
private |
sample (layer for resample procedure) ----------------------------------------------------------------------------------— this routine essentially does 2 things:
Below this line are functions specific to the lbf particles with resampling --------------------------------------------— * locates the particles on an initial cartesian grid,
[in] | init_f_params | parameters of the initial distribution |
Definition at line 461 of file sll_m_particle_group_2d2v_lbf.F90.
|
private |
Set the common weight.
[in,out] | self | particle group |
[in] | x | common weight |
Definition at line 276 of file sll_m_particle_group_2d2v_lbf.F90.
|
private |
Set the velocity of a particle.
[in,out] | self | particle group |
[in] | i | particle index |
[in] | x | component 1 and 2 hold the particle velocity to be set |
Definition at line 254 of file sll_m_particle_group_2d2v_lbf.F90.
|
private |
Set the weights of a particle.
[in,out] | self | particle group |
[in] | i | particle index |
[in] | x | particle weight(s) to be set |
Definition at line 265 of file sll_m_particle_group_2d2v_lbf.F90.
|
private |
Setters ----------------------------------------------------------------------------------------------------------------—.
Set the position of a particle
[in,out] | self | particle group |
[in] | i | particle index |
[in] | x | components 1 and 2 hold the particle position to be set |
Definition at line 243 of file sll_m_particle_group_2d2v_lbf.F90.
|
private |
sll_f_add_element_in_int_list ------------------------------------------------------------------------------------------— list management
Definition at line 2054 of file sll_m_particle_group_2d2v_lbf.F90.
subroutine, public sll_m_particle_group_2d2v_lbf::sll_s_new_particle_group_2d2v_lbf_ptr | ( | class( sll_c_particle_group_base ), intent(out), pointer | particle_group, |
real(kind=f64), intent(in) | species_charge, | ||
real(kind=f64), intent(in) | species_mass, | ||
logical, intent(in) | domain_is_x_periodic, | ||
logical, intent(in) | domain_is_y_periodic, | ||
integer(kind=i32), intent(in) | remap_degree, | ||
real(kind=f64), dimension(4), intent(in) | remapping_grid_eta_min, | ||
real(kind=f64), dimension(4), intent(in) | remapping_grid_eta_max, | ||
integer(kind=i32), dimension(4), intent(in) | remapping_sparse_grid_max_levels, | ||
integer(kind=i32), intent(in) | n_particles_x, | ||
integer(kind=i32), intent(in) | n_particles_y, | ||
integer(kind=i32), intent(in) | n_particles_vx, | ||
integer(kind=i32), intent(in) | n_particles_vy | ||
) |
Constructor for abstract type.
Definition at line 386 of file sll_m_particle_group_2d2v_lbf.F90.
|
private |
update_closest_particle_arrays -----------------------------------------------------------------------------------------— update the arrays closest_particle and closest_particle_distance with the index of the given particle if closer to what had been stored up to now.
[in] | x_aux | x_particle - flow_grid_x_min |
[in] | y_aux | idem |
[in] | vx_aux | idem |
[in] | vy_aux | idem |
if new particle is closer to center, keep the new one
Definition at line 2145 of file sll_m_particle_group_2d2v_lbf.F90.
|
private |
write_known_density_on_remapping_grid ----------------------------------------------------------------------------------— this routine writes a given distribution on the interpolation (sparse grid) nodes to further approximate it
Definition at line 528 of file sll_m_particle_group_2d2v_lbf.F90.
|
private |
Definition at line 61 of file sll_m_particle_group_2d2v_lbf.F90.
|
private |
possible values for the parameter reconstruction_set_type in the reconstruction routine
Definition at line 60 of file sll_m_particle_group_2d2v_lbf.F90.