XGCa
Data Types | Modules | Functions/Subroutines | Variables
resamp_mod.F90 File Reference
#include "t_coeff_mod_macro.h"
#include "adios_macro.h"
Include dependency graph for resamp_mod.F90:

Data Types

type  resamp_module::resamp_bin_type
 

Modules

module  resamp_module
 This module provides particle resampling capabilities.
 

Functions/Subroutines

subroutine resamp_module::set_cce_buffer_id (id, inode1, inode2)
 
subroutine resamp_module::set_cce_buffer_and_overlap_id (id1, id2, inode1, inode2)
 
subroutine resamp_module::resample_init (grid, inode1, inode2, dsmu, dvp, nmu, nvp, vp_max, mu_max, tile_size, bins, cce_sync_sendrcv)
 This routine initializes the resampling module and sets some global parameters such as v-grid size, etc. More...
 
subroutine resamp_module::resample_finalize (bins)
 This routine cleans up the resampling module. More...
 
subroutine resamp_module::resample_spall_setup (inode1, inode2, dsmu, dvp, nmu, nvp, vp_max, mu_max, cce_sync_sendrcv, tile_size)
 Resample the marker particles in XGC to improve phase-space coverage and reduce marker noise. More...
 
subroutine resamp_module::set_eq_bins (eq_bin, ineq_bin)
 
subroutine resamp_module::use_default_eq_bins ()
 
subroutine resamp_module::resample_one_sp (isp, cce_sync_sendrcv)
 Resample the marker particles of one species in XGC to improve phase-space coverage and reduce marker noise. More...
 
subroutine resamp_module::transpose_from_aos_wrapper (isp)
 
subroutine resamp_module::resample_spall_finish ()
 
subroutine resamp_module::build_bins (sp, bins, grid, cce_sync)
 Loops over particles, puts them in the appropriate bin, computes partial mean This routine sorts particles in the appropriate phase-space bin and computes the total charge in the bin. More...
 
subroutine resamp_module::add_to_bin (bin, ptli, ind)
 Adds the data of one particle to a phase-space bin. More...
 
subroutine resamp_module::destroy_bins (bins)
 Cleans up bin memory without deallocating the array of bins itself (can be kept for next species) More...
 
subroutine resamp_module::update_cmat (grid, psn, nconstraint, nptl, vert, patch, bary, tri, psi, B, bvec, spec, pindex, part, Cmat, op_mode)
 This subroutine sets up the matrix C (constraint matrix) with the coefficients needed to compute the conserved quantities charge, parallel momentum, magnetic moment, parallel and perp. kinetic energy and the grid charge on the vertices connected to the bin. Those quantities are then obtained by multiplying the matrix C with the delta-f (--> w1) weight vector from the right. This matrix forms the basis for the QP optimization program that finds the delta-f weights for the resampled particle set. More...
 
subroutine resamp_module::check_bin (bin, sp, cce_sync_sendrcv, resamp_auto_upsample_loc, resamp_auto_downsample_loc, resamp_var_resample_loc, outside_bin)
 This routine checks whether a bin needs to be resampled and determines the type of resampling (up-/down-/re-sampling). The chosen resampling option is stored in the bin data structure: 0) No resampling needed 1) Resampling due to high weight variance 2) Upsampling due to low particle count 3) Downsampling due to high particle count. More...
 
subroutine resamp_module::resample_bin (bin, grid, sp, psn, cce_sync_sendrcv, start_wr_pos, resamp_failed_bins_loc, resamp_upsample_failed_loc, resamp_downsample_failed_loc, resamp_resample_failed_loc, resamp_retried_bins_loc, resamp_retried_failed_loc, resamp_fullf_failed_loc, resamp_phvol_added_loc, resamp_var_inc_upsamp_loc, resamp_var_inc_downsamp_loc, dump_problem_bins, resamp_var_inc_loc, resamp_up_hist_loc, resamp_down_hist_loc)
 The actual process of resampling the particle set in a bin happens in this routine. A bin is passed as input, the pre-determined type of resampling is executed and the weights of the new particle set are computed with a QP optimization. If the optimization is successful, the old particle set in the input variable "sp" is replaced with the new particle set. More...
 
subroutine resamp_module::load_new_ptl (grid, new_ptl, bin_id, itr, p, psi)
 This routine loads new particles into a bin with uniform marker density in configuration space. Particles are drawn from a rectacngle enclosing the bin volume and are accepted if inside the Voronoi volume of the bin. A more efficient loading can be achieved by pre-selecting the triangle in which to load. This functionality will be provided in a separate function. More...
 
subroutine resamp_module::load_shift_p_ptl (grid, new_ptl, itr, p, psi, my_node, max_shift)
 This routine shifts the particles physical coordinates within the bin. Typically used when upsampling and copying particles so that they have a non-identical trajectory. More...
 
subroutine resamp_module::setup_fullf (ptli, spec_type, den, flow, temp_ev, bvec, B, psi)
 Evaluate the background density, temperature, flow, magnetic field and psi at the input particle's position. More...
 
subroutine resamp_module::get_new_fullf_weight (grid, psn, part, psi, B, flow, den, temp_ev, spec, tri, bary, mark_den, err)
 Compute the new full-f weight of the input particle \(w_0 = f/g\). Note that either \(w_0\) or \(f\) can be chosen freely, while the particle's phasespace volume \(\delta V = 1/g\) is determined by Liousville's theorem of phase space volume conservation. The distribution function \(f\) can in principle be anything here as long as the \(w_2\) weight is set accordingly. The goal is to choose \(w_0\) and \(w_2\) such that the weight evolution equation does not have to be changed. More...
 
subroutine resamp_module::setup_opt (nconstraint, part_num, Cmat, constraint, weights, n_eq_bin, n_ineq_bin, eq_bin, ineq_bin, grid_ineq_on, ineq_tol, positivity, ierr)
 This routine sets up the input for the QP optimization that computes the delta-f weights of the new particles. There are two types of constraints, bin and grid constraints. Bin constraints correspond to moments of the distribution function evaluated with nearest neighbor interpolation on the configuration space grid. Grid constraints correspond to moments evaluated with linear (barycentric) interpolation on the conf. space grid. Bin constraints can be enforced as equality and inequality constraints: use idx_constraint and idx_constraint2 to choose which constraint is an equality and which is an inequality constraint. Grid constraints are enforced as inequality constraints. Since grid constraints make the optimization problem much harder due to their large number, using them is optional (grid_ineq_on) A positivity constraint for the weights can be activated with the variable "positivity". This is used for full-f optimization. More...
 
subroutine resamp_module::restart_resample_set_params ()
 Move phase space density from the 5D grid over to the particles for restarting simulatin with a different grid. More...
 
subroutine resamp_module::restart_resample_restore_params ()
 Move phase space density from the 5D grid over to the particles for restarting simulatin with a different grid. More...
 
subroutine resamp_module::get_marker_velo (grid, psn, ptli, isp, velo, vrad)
 Evaluates the marker particle equations of motion. The results are the time derivatives of the marker position and parallel velocity (or rho, to be precise), as well as the radial velocity v.grad(psi). The results can be used in the moment preserving QP weight optimization. More...
 
subroutine resamp_module::get_sampling_ratio (grid)
 This routine upsamples the marker population in spall for a new configuration space grid. The new grid should be denser than the current grid, i.e. require upsampling, not downsampling. This is due to particle data locality. Upsampling to a denser mesh is done on the coarse mesh, while downsampling from a fine mesh is better done with particle data arranged for the coarse mesh. The routine reads in the vertex positions of the new mesh and runs a search for each of them to associate them with the vertices of the current mesh. The ratio of new mesh vertices per current mesh vertex is the upsampling ratio. If the upsampling ratio is smaller than unity, that vertex is skipped. More...
 
subroutine resamp_module::resamp_scale_phvol (grid, sp)
 Loops over particles and scales their phase space volume to account for particles added to empty bins. More...
 
subroutine resamp_module::f0_upsampling_set_params ()
 set parameters for f0 upsampling More...
 
subroutine resamp_module::f0_upsampling_restore_params ()
 restore parameters after f0 upsampling More...
 
integer function resamp_module::cce_do_resampling (idbuf)
 
integer function resamp_module::cce_buffer_sndrcvs_accessor (idbuf)
 
integer function resamp_module::get_cce_buffer_nb ()
 
subroutine resamp_module::set_cce_buffers (istep, idbuf)
 
subroutine resamp_module::cce_reset_particle_outside (grid, sp)
 
subroutine resamp_module::cce_buffer_snd_updated_bins (isp)
 
subroutine resamp_module::cce_buffer_rcv_updated_bins (isp)
 
logical function resamp_module::is_first_call ()
 
subroutine resamp_module::nrm_std_dev (npart, mean, weights, var)
 This routine computes the normalized standard deviation of a set of weights, without Bessel's correction. More...
 
subroutine resamp_module::output_bin (npnew, nconst, sp, bin, Cmat, constraint, bin_new_ptl, new_tri, new_psi, ierr, dump_problem_bins, weights)
 Routine for outputting a flagged resampling bin. This is typically due to either the failure of the quadratic program OR a high variance result, and is controlled by the input flag resamp_output_problem_bins. More...
 
subroutine resamp_module::get_v_part (smu_n, vp_n, mu, rho, temp, B, spec)
 This subroutine returns particle velocities given normalized v-grid coordinates. More...
 
subroutine resamp_module::poisson_disc (initial, corners, bin_part, bin_target, new_set, k)
 This routine returns the poisson disc sample of the new (upsamples) particles in normalized velocity coordinates (vp_n,smu_n) given initial pt locations). More...
 
logical function resamp_module::in_neighborhood (point, indices, grid, new_set, cellsize, radius_squared)
 This function is a helper for checking if a candidate point is in the neighborhood of the current set of disc samples. More...
 
logical function resamp_module::in_bin (point, corners)
 This function checks if a pair of normalized points lies within the rectangle given by corners. More...
 
subroutine resamp_module::get_v_n (smu_n, vp_n, B, temp_ev, part, spec)
 This subroutine returns normalized v-grid coordinates for a particle. More...
 
subroutine resamp_module::get_refer_v_n (smu_n, vp_n, smu_ref, vp_ref, bin_id, err)
 This subroutine returns reference velocity coordinates in the resampling bin. More...
 
real(kind=8) function, dimension(2, 2) resamp_module::local_lin_int (smu_ref, vp_ref)
 This function returns the 2x2 local element matrix of bilinear nodal interpolation coefficients corresponding to the particles reference coordinates in the cell. More...
 
subroutine resamp_module::find_bin (smu_n, vp_n, imu, ivp)
 This subroutine returns the v-grid bin a particle is in given its normalized coordinates, including high velocity bins. More...
 
subroutine resamp_module::refer_to_v_n (smu_ref, vp_ref, smu_n, vp_n, bin_id)
 This subroutine maps reference coordinates to normalized coordinates. More...
 
subroutine resamp_module::particle_not_in_vbin (smu_ref, vp_ref, smu_n, vp_n, bin, part, num_part, index, rtemp, B, b_grid)
 This subroutine is error handling for when a particle(usually generated) does not like in the correct velocity space bin. More...
 
subroutine resamp_module::get_tri_info (grid, part, node, itr, bary, psi)
 This subroutine returns the node, barycentric coordinates, triangle and psi value for a particle. More...
 
subroutine resamp_module::get_b_and_t (part, spec, node, bvec, B, temp_ev)
 This subroutine returns a particle's magnetic field and temperature used for velocity grid particle location. More...
 

Variables

integer resamp_module::resamp_rate = 2
 timesteps between subsequent resamples, placedholder, in practice ~ sml_f_source_period More...
 
real(8) resamp_module::resamp_var = 1D4
 threshold for relative standard deviation in bin for auto-resample More...
 
real(8) resamp_module::resamp_min_ratio = 0.5D0
 min ratio of (# of ptl)/(target # of ptl) in bin for auto-upsample More...
 
real(8) resamp_module::resamp_max_ratio = 1.5D0
 max ratio of (# of ptl)/(target # of ptl) in bin for auto-downsample More...
 
integer resamp_module::resamp_max_target = 4
 Overrides the number of constraints in determining the target # of ptl of a bin. More...
 
integer resamp_module::resamp_tile_size = 2
 Bin size on the velocity space grid in cells (not vertices) (input parameter) More...
 
integer resamp_module::resamp_tile_size_now = 2
 Used to override resamp_tile_size. More...
 
real(8) resamp_module::resamp_ineq_tol = 1D-4
 Threshold for relative error in the inequality constraints in the QP optimization. More...
 
logical resamp_module::resamp_restart = .false.
 Perform resampling before dumping the final restart file. More...
 
logical resamp_module::resamp_retry = .false.
 Retry QP optimization for failed bins with relaxed inequality constraints. More...
 
real(8) resamp_module::resamp_ineq_tol_max = 1D-3
 Maximal threshold for relative error in inequality constraints for retried bins. More...
 
real(8) resamp_module::resamp_highv_max = 10D0
 energy cutoff of the high velocity bins v_para>f0_vp_max and v_perp>f0_smu_max More...
 
real(8) resamp_module::resamp_highv_max_ratio = 4D0
 Downsampling threshold for high-velocity bins. More...
 
real(8) resamp_module::resamp_var_limit = 3D0
 Increase in relative bin variance for flagging for possible rejection. More...
 
logical resamp_module::resamp_discard_var_bins = .false.
 Discard resampled bins that increase the variance by factor of resamp_var_limit. More...
 
logical resamp_module::resamp_keep_upsamples = .false.
 Retain upsampling results with high variance, for filling for pseudoinverse. Only relevant if resamp_discard_var_bins is .true. More...
 
logical resamp_module::resamp_keep_downsamples = .false.
 Retain downsampling results with high variance, mainly for preventing buildup. Only relevant if resamp_discard_var_bins is .true. More...
 
character(len=200) resamp_module::resamp_node_file = 'dum.node'
 File containing the vertex positions of the mesh for which to resample. More...
 
integer resamp_module::resamp_nphi_new =1
 Number of poloidal planes in simulation with new mesh. More...
 
logical resamp_module::resamp_restart_read =.false.
 Whether to read a restart file written from a simulation with different grid. More...
 
logical resamp_module::resamp_fill_empty =.false.
 Whether to fill empty bins. More...
 
logical resamp_module::resamp_fullf_on =.false.
 Whether to resample the full-f weights in addition to delta-f weights. More...
 
logical resamp_module::resamp_grid_ineq_on =.false.
 Switch for using inequality constraints for the grid charge for resampling. More...
 
logical resamp_module::resamp_distribute_evenly_subbins =.false.
 Whether to fill/remove evenly in 1x1 velocity cells in the bin when resamp_tile_size > 1 and upsampling/downsampling. More...
 
logical resamp_module::resamp_fill_empty_subbins =.false.
 Whether to fill all empty 1x1 velocity cells in the bin and there are already particles in the bin. More...
 
logical resamp_module::resamp_fill_empty_subbins_skip_full_bins
 If resamp_fill_empty_subbins=.true., skip a bin if it is already filled enough to do the pseudo-inverse interpolation. More...
 
integer resamp_module::resamp_fill_empty_subbins_target =1
 If resamp_fill_empty_subbins=.true., minimum target of sub bins. More...
 
integer resamp_module::resamp_fill_empty_subbins_corner_cell_target =1
 If resamp_fill_empty_subbins=.true., minimum target of corner cells. More...
 
logical resamp_module::resamp_output_problem_bins =.false.
 Switch to output failed or high-variance bins as to .bp files. More...
 
character(16) resamp_module::resamp_up_choice ='random'
 option arg for upsampled new particle selection: 'random','copy','poisson' currently added random: random velocity coordinates for new particles in bin copy: add new particles as copies of old particles with largest absolute w0*w1 weight poision: add new particles as poisson disc samples generated from the old particle set.
More...
 
character(16) resamp_module::resamp_down_choice ='weight'
 option arg for downsampled new particle selection: 'random','weight','weight+replace','volume' weight: keep particles with largest w0*w1 absolute weight, deterministic weight+replace: keep particles with largest w0*w1 absolute weight, allow multiple copies of same particle if split weight is still larger than next unsplit particle volume: keep particles with largest phase space volume, deterministic More...
 
real(kind=8) resamp_module::resamp_max_shift = 1D-1
 maximum shift in local coordinates for 'copy', 'weight+replace' More...
 
real(kind=8), private resamp_module::resamp_bin_max_fac
 threshold for auto downsample More...
 
real(kind=8), private resamp_module::resamp_inv_bin_num
 Inverse of the number of macro bins in v-space. More...
 
integer, private resamp_module::resamp_nmu_in
 Number of cells on original vperp/mu grid (=f0_nmu) More...
 
integer, private resamp_module::resamp_nvp_in
 Number of cells on original v_para grid (=f0_nvp) More...
 
real(kind=8), private resamp_module::resamp_dsmu
 v_perp/mu spacing of original v-grid (=f0_dsmu) More...
 
real(kind=8), private resamp_module::resamp_dvp
 v_para spacing of original v-grid (=f0_dvp) More...
 
real(kind=8), private resamp_module::resamp_mu_max
 v_perp/mu cutoff of v-grid (=f0_mu_max) More...
 
real(kind=8), private resamp_module::resamp_vp_max
 v_para cutoff of v-grid (=f0_vp_max) More...
 
integer, private resamp_module::resamp_musize
 Number of sampling bins in v_perp/mu direction. More...
 
integer, private resamp_module::resamp_vpsize
 Number of sampling bins in v_para direction. More...
 
integer, private resamp_module::resamp_inode1
 Index of the first node of local patch of the configuration space mesh (=f0_inode1) More...
 
integer, private resamp_module::resamp_inode2
 Index of the last node of local patch of the configuration space mesh (=f0_inode2) More...
 
real(kind=8), dimension(:,:), allocatable, private resamp_module::resamp_den
 Reference density per species for normalization. More...
 
real(kind=8), dimension(:,:), allocatable, private resamp_module::resamp_t_ev
 Reference temperature per species for normalization. More...
 
real(kind=8), dimension(:,:), allocatable, private resamp_module::resamp_inv_ph_vol
 Inverse phase-space volume element. More...
 
real(kind=8), dimension(:), allocatable, private resamp_module::resamp_samp_ratio
 Upsampling ratio for restarts with finer grid. More...
 
logical, private resamp_module::resamp_restart_mode =.false.
 
real(kind=8), dimension(:), allocatable, private resamp_module::resamp_phvol_sum
 Sum of phase space volume of all particles on a node. More...
 
real(kind=8), dimension(:), allocatable, private resamp_module::resamp_phvol_added
 Sum of phase space volume of particles added in empty bins. More...
 
real(kind=8), dimension(:,:), allocatable, private resamp_module::p_save
 Holds barycentric coordinates for particles of current resampled species. More...
 
real(kind=8), dimension(:), allocatable, private resamp_module::psi_save
 Caches psi interpolation results for multiple use during resampling. More...
 
integer, parameter, private resamp_module::resamp_hist_size = 10
 Size of variance histogram for resampling statistics, bin width = 1 normalized std deviation. More...
 
integer, dimension(resamp_hist_size), private resamp_module::resamp_up_hist
 Histogram of upsampling results. More...
 
integer, dimension(resamp_hist_size), private resamp_module::resamp_down_hist
 Histogram of downsampling results. More...
 
integer, parameter, private resamp_module::resamp_nongridmom = 8
 Maximum Number of bin moments to be conserved. More...
 
integer, dimension(resamp_nongridmom), private resamp_module::resamp_eq_bin
 which constraints are active as equality constraints More...
 
integer, dimension(resamp_nongridmom), private resamp_module::resamp_ineq_bin
 which constraints are active as inequality constraints More...
 
integer, dimension(:), allocatable, private resamp_module::resamp_off_vgrid
 Counter for number of particles that are not on the v-grid. More...
 
integer, dimension(:), allocatable, private resamp_module::resamp_on_vgrid
 Counter for number of particles that are on the v-grid. More...
 
integer, dimension(:), allocatable, private resamp_module::tr_save
 
integer, private resamp_module::resamp_empty_bins
 Number of empty sampling bins. More...
 
integer, private resamp_module::resamp_resampled_bins
 Number of bins that were picked for re-/up-/down-sampling. More...
 
integer, private resamp_module::resamp_failed_bins
 Number of bins for which re-/up-/down-sampling failed. More...
 
integer, private resamp_module::resamp_var_resample
 Number of variance resampled bins. More...
 
integer, private resamp_module::resamp_resample_failed
 Number of bins for which variance resampling failed. More...
 
integer, private resamp_module::resamp_auto_upsample
 Number of upsampled bins. More...
 
integer, private resamp_module::resamp_upsample_failed
 Number of bins for which upsampling failed. More...
 
integer, private resamp_module::resamp_auto_downsample
 Number of downsampled bins. More...
 
integer, private resamp_module::resamp_downsample_failed
 Number of bins for which downsampling failed. More...
 
integer, private resamp_module::resamp_retried_bins
 Number of bins retried after failure. More...
 
integer, private resamp_module::resamp_retried_failed
 Number of bins failed again after retry. More...
 
integer, private resamp_module::resamp_fullf_failed
 Number of full-f failed bins. More...
 
integer, private resamp_module::resamp_wrong_particles
 Number of particles in wwrong bins. More...
 
integer, private resamp_module::resamp_var_inc_upsamp
 Number of bins that increased the variance tenfold while upsampling. More...
 
integer, private resamp_module::resamp_var_inc_downsamp
 Number of bins that increased the variance tenfold while downsampling. More...
 
integer, private resamp_module::resamp_var_inc
 Number of bins that increased the variance when resampling, RARE, usually result of ill-conditioning of matrix) More...
 
real(kind=8), private resamp_module::resamp_smu_fac
 Factor used in the context of tapering off the marker density at high velocity. More...
 
real(kind=8), private resamp_module::resamp_vp_fac
 Factor used in the context of tapering off the marker density at high velocity. More...
 
integer, private resamp_module::resamp_err_count1
 Counter for w0=0 errors in get_new_fullf_weight. More...
 
integer, private resamp_module::resamp_err_count2
 Counter for w0=0 errors in resample_bin. More...
 
integer, dimension(:,:), allocatable resamp_module::resamp_patches
 !< node numbers of vertices contained in triangle patch of voronoi cell More...
 
integer, dimension(:), allocatable resamp_module::resamp_patch_size
 total number of patch vertices in Voronoi cell More...
 
real(kind=8), dimension(:,:), allocatable resamp_module::resamp_patch_rzdims
 R-Z boundaries of the Voronoi-triangle patch. More...
 
integer resamp_module::cce_buffer_id
 Index of currently resampled buffer. More...
 
integer resamp_module::cce_buffer_first_node
 
integer resamp_module::cce_buffer_last_node
 node interval of current buffer More...
 
integer resamp_module::cce_grid_nnode
 Number of node on the grid. More...
 
integer, parameter resamp_module::cce_nbconstraint =5
 
real(kind=8), dimension(:,:,:,:,:,:), allocatable resamp_module::fbins
 
integer resamp_module::cce_inode1
 
integer resamp_module::cce_inode2
 
logical resamp_module::cce_skip_nodes
 
type(ptl_type), dimension(:), allocatable, target resamp_module::local_particles
 
type(resamp_bin_type), dimension(:,:,:), allocatable resamp_module::resamp_bins
 
logical resamp_module::tmp_resamp_fill_empty
 
logical resamp_module::tmp_resamp_retry
 
logical resamp_module::tmp_resamp_fullf_on
 
logical resamp_module::tmp_resamp_grid_ineq_on
 
logical resamp_module::tmp_resamp_fill_empty_subbins
 
logical resamp_module::tmp_resamp_distribute_evenly_subbins
 
logical resamp_module::tmp_resamp_fill_empty_subbins_skip_full_bins
 
real(8) resamp_module::tmp_resamp_var
 
real(8) resamp_module::tmp_resamp_min_ratio
 
real(8) resamp_module::tmp_resamp_max_ratio
 
integer resamp_module::tmp_resamp_tile_size
 
integer resamp_module::tmp_resamp_max_target
 
real(8) resamp_module::tmp_resamp_ineq_tol
 
real(8) resamp_module::tmp_resamp_ineq_tol_max
 
real(8) resamp_module::tmp_resamp_highv_max
 
real(8) resamp_module::tmp_resamp_highv_max_ratio
 
character(len=200) resamp_module::tmp_resamp_node_file
 
integer resamp_module::tmp_resamp_nphi_new
 
integer resamp_module::tmp_resamp_fill_empty_subbins_target
 
integer resamp_module::tmp_resamp_fill_empty_subbins_corner_cell_target
 
character(len=16) resamp_module::tmp_up_choice
 
character(len=16) resamp_module::tmp_down_choice