Utilities#
- struphy.pic.sampling_kernels.set_particles_symmetric_3d_3v(numbers: float[:, :], markers: float[:, :])[source]#
- struphy.pic.sampling_kernels.set_particles_symmetric_2d_3v(numbers: float[:, :], markers: float[:, :])[source]#
- struphy.pic.sampling_kernels.tile_int_kernel(fun: float[:, :, :], x_wts: float[:], y_wts: float[:], z_wts: float[:], out: float[:, :, :])[source]#
Compute integrals over all tiles in a single sorting box.
- Parameters:
fun (xp.ndarray) – The integrand evaluated at the quadrature points (meshgrid).
x_wts (xp.ndarray) – Quadrature weights for tile integral.
y_wts (xp.ndarray) – Quadrature weights for tile integral.
z_wts (xp.ndarray) – Quadrature weights for tile integral.
out (xp.ndarray) – The result holding all tile integrals in one sorting box.
- Licensing:
This code is distributed under the MIT license.
- Authors:
Original FORTRAN77 version of i4_sobol by Bennett Fox. MATLAB version by John Burkardt. PYTHON version by Corrado Chisari
Original Python version of is_prime by Corrado Chisari
Original MATLAB versions of other functions by John Burkardt. PYTHON versions by Corrado Chisari
Original code is available from http://people.sc.fsu.edu/~jburkardt/py_src/sobol/sobol.html
- struphy.pic.sobol_seq.i4_bit_hi1(n)[source]#
i4_bit_hi1 returns the position of the high 1 bit base 2 in an integer.
Example
+——+————-+—– | N | Binary | BIT +——|————-+—– | 0 | 0 | 0 | 1 | 1 | 1 | 2 | 10 | 2 | 3 | 11 | 2 | 4 | 100 | 3 | 5 | 101 | 3 | 6 | 110 | 3 | 7 | 111 | 3 | 8 | 1000 | 4 | 9 | 1001 | 4 | 10 | 1010 | 4 | 11 | 1011 | 4 | 12 | 1100 | 4 | 13 | 1101 | 4 | 14 | 1110 | 4 | 15 | 1111 | 4 | 16 | 10000 | 5 | 17 | 10001 | 5 | 1023 | 1111111111 | 10 | 1024 | 10000000000 | 11 | 1025 | 10000000001 | 11
- Parameters:
Input
N (integer)
measured. (the integer to be)
nonpositive (N should be nonnegative. If N is)
0. (the value will always be)
Output
BIT (integer)
2. (the number of bits base)
- struphy.pic.sobol_seq.i4_bit_lo0(n)[source]#
I4_BIT_LO0 returns the position of the low 0 bit base 2 in an integer.
Example
+——+————+—- | N | Binary | BIT +——+————+—- | 0 | 0 | 1 | 1 | 1 | 2 | 2 | 10 | 1 | 3 | 11 | 3 | 4 | 100 | 1 | 5 | 101 | 2 | 6 | 110 | 1 | 7 | 111 | 4 | 8 | 1000 | 1 | 9 | 1001 | 2 | 10 | 1010 | 1 | 11 | 1011 | 3 | 12 | 1100 | 1 | 13 | 1101 | 2 | 14 | 1110 | 1 | 15 | 1111 | 5 | 16 | 10000 | 1 | 17 | 10001 | 2 | 1023 | 1111111111 | 1 | 1024 | 0000000000 | 1 | 1025 | 0000000001 | 1
- Parameters:
Input
N (integer)
measured. (the integer to be)
nonnegative. (N should be)
Output
BIT (integer)
bit. (the position of the low 1)
- struphy.pic.sobol_seq.i4_sobol_generate(dim_num, n, skip=1)[source]#
i4_sobol_generate generates a Sobol dataset.
- Parameters:
Input
dim_num (integer)
dimension. (the spatial)
Input
N (integer)
generate. (the number of points to)
Input
SKIP (integer)
skip. (the number of initial points to)
Output (M,N)
R (real)
- struphy.pic.sobol_seq.i4_sobol(dim_num, seed)[source]#
i4_sobol generates a new quasirandom Sobol vector with each call.
- Discussion:
The routine adapts the ideas of Antonov and Saleev.
- Reference:
Antonov, Saleev, USSR Computational Mathematics and Mathematical Physics, Volume 19, 1980, pages 252 - 256.
Paul Bratley, Bennett Fox, Algorithm 659: Implementing Sobol’s Quasirandom Sequence Generator, ACM Transactions on Mathematical Software, Volume 14, Number 1, pages 88-100, 1988.
Bennett Fox, Algorithm 647: Implementation and Relative Efficiency of Quasirandom Sequence Generators, ACM Transactions on Mathematical Software, Volume 12, Number 4, pages 362-376, 1986.
Ilya Sobol, USSR Computational Mathematics and Mathematical Physics, Volume 16, pages 236-242, 1977.
Ilya Sobol, Levitan, The Production of Points Uniformly Distributed in a Multidimensional Cube (in Russian), Preprint IPM Akad. Nauk SSSR, Number 40, Moscow 1976.
- Parameters:
Input
DIM_NUM (integer)
dimensions. (the number of spatial)
40. (DIM_NUM must satisfy 1 <= DIM_NUM <=)
Input/output
SEED (integer)
sequence. (the "seed" for the)
quasirandom (This is essentially the index in the sequence of the)
output (value to be generated. On)
the (SEED has been set to)
value (appropriate next)
SEED+1. (usually simply)
input (If SEED is less than 0 on)
0. (it is treated as though it were)
first (An input value of 0 requests the)
Output (DIM_NUM)
QUASI (real)
- struphy.pic.sobol_seq.i4_uniform(a, b, seed)[source]#
i4_uniform returns a scaled pseudorandom I4.
- Discussion:
The pseudorandom number will be scaled to be uniformly distributed between A and B.
- Reference:
Paul Bratley, Bennett Fox, Linus Schrage, A Guide to Simulation, Springer Verlag, pages 201-202, 1983.
Pierre L’Ecuyer, Random Number Generation, in Handbook of Simulation, edited by Jerry Banks, Wiley Interscience, page 95, 1998.
Bennett Fox, Algorithm 647: Implementation and Relative Efficiency of Quasirandom Sequence Generators, ACM Transactions on Mathematical Software, Volume 12, Number 4, pages 362-376, 1986.
Peter Lewis, Allen Goodman, James Miller A Pseudo-Random Number Generator for the System/360, IBM Systems Journal, Volume 8, pages 136-143, 1969.
- Parameters:
Input
A (integer)
B
values. (the minimum and maximum acceptable)
Input
SEED (integer)
generator. (a seed for the random number)
Output
C (integer)
integer. (the randomly chosen)
Output
SEED
seed. (the updated)
- struphy.pic.sobol_seq.prime_ge(n)[source]#
PRIME_GE returns the smallest prime greater than or equal to N.
Example
+—–+——— | N | PRIME_GE +—–+——— | -10 | 2 | 1 | 2 | 2 | 2 | 3 | 3 | 4 | 5 | 5 | 5 | 6 | 7 | 7 | 7 | 8 | 11 | 9 | 11 | 10 | 11
- Parameters:
Input
N (integer)
bounded. (the number to be)
Output
P (integer)
greater (the smallest prime number that is)
N. (than or equal to)
- struphy.pic.sobol_seq.is_prime(n)[source]#
is_prime returns True if N is a prime number, False otherwise
- Parameters:
Input
N (integer)
checked. (the number to be)
Output
value (boolean)
False (True or)
- class struphy.pic.utilities.LoadingParameters(Np: int | None = None, ppc: int | None = None, ppb: int = 10, loading: Literal['pseudo_random', 'sobol_standard', 'sobol_antithetic', 'external', 'restart', 'tesselation'] = 'pseudo_random', seed: int | None = None, moments: tuple | None = None, spatial: Literal['uniform', 'disc'] = 'uniform', specific_markers: tuple[tuple] | None = None, n_quad: int = 1, dir_exrernal: str | None = None, dir_particles: str | None = None, dir_particles_abs: str | None = None, restart_key: str | None = None)[source]#
Bases:
objectParameters for particle loading.
- Parameters:
Np (int) – Total number of particles to load.
ppc (int) – Particles to load per cell if a grid is defined. Cells are defined from
domain_array.ppb (int) – Particles to load per sorting box. Sorting boxes are defined from
boxes_per_dim.loading (OptsLoading) – How to load markers: multiple options for Monte-Carlo, or “tesselation” for positioning them on a regular grid.
seed (int) – Seed for random generator. If None, no seed is taken.
moments (tuple) – Mean velocities and temperatures for the Gaussian sampling distribution. If None, these are auto-calculated form the given background.
spatial (OptsSpatialLoading) – Draw uniformly in eta, or draw uniformly on the “disc” image of (eta1, eta2).
specific_markers (tuple[tuple]) – Each entry is a tuple of phase space coordinates (floats) of a specific marker to be initialized.
n_quad (int) – Number of quadrature points for tesselation.
dir_external (str) – Load markers from external .hdf5 file (absolute path).
dir_particles_abs (str) – Load markers from restart .hdf5 file (absolute path).
dir_particles (str) – Load markers from restart .hdf5 file (relative path to output folder).
restart_key (str) – Key in .hdf5 file’s restart/ folder where marker array is stored.
- class struphy.pic.utilities.WeightsParameters(control_variate: bool = False, reject_weights: bool = False, threshold: float = 0.0)[source]#
Bases:
objectParamters for particle weights.
- Parameters:
control_variate (bool) – Whether to use a control variate for noise reduction.
reject_weights (bool) – Whether to reject weights below threshold.
threshold (float) – Threshold for rejecting weights.
- class struphy.pic.utilities.BoundaryParameters(bc: tuple[Literal['periodic', 'reflect']] = ('periodic', 'periodic', 'periodic'), bc_refill=None, bc_sph: tuple[Literal['periodic', 'mirror', 'fixed']] = ('periodic', 'periodic', 'periodic'))[source]#
Bases:
objectParameters for particle boundary and sph reconstruction boundary conditions.
- Parameters:
bc (tuple[OptsMarkerBC]) – Boundary conditions for particle movement. Either ‘remove’, ‘reflect’, ‘periodic’ or ‘refill’ in each direction.
bc_refill (list) – Either ‘inner’ or ‘outer’.
bc_sph (tuple[OptsRecontructBC]) – Boundary conditions for sph kernel reconstruction.
- class struphy.pic.utilities.BinningPlot(slice: str = 'e1', n_bins: int | tuple[int] = 128, ranges: tuple[float] | tuple[tuple[float]] = (0.0, 1.0), divide_by_jac: bool = True)[source]#
Bases:
objectBinning plot of marker distribution in phase space.
- Parameters:
slice (str) – Coordinate-slice in phase space to bin. A combination of “e1”, “e2”, “e3”, “v1”, etc., separated by an underscore “_”. For example, “e1” showas a 1D binning plot over eta1, whereas “e1_v1” shows a 2D binning plot over eta1 and v1.
n_bins (int | tuple[int]) – Number of bins for each coordinate.
ranges (tuple[int] | tuple[tuple[int]] = (0.0, 1.0)) – Binning range (as an interval in R) for each coordinate.
divide_by_jac (bool) – Whether to divide by the Jacobian determinant (volume-to-0-form).
- property bin_edges: tuple#
- property f: ndarray#
The binned distribution function (full-f).
- property df: ndarray#
The binned distribution function minus the background (delta-f).
- class struphy.pic.utilities.KernelDensityPlot(pts_e1: int = 16, pts_e2: int = 16, pts_e3: int = 1)[source]#
Bases:
objectSPH density plot in configuration space.
- Parameters:
pts_e1 (int) – Number of evaluation points in each direction.
pts_e2 (int) – Number of evaluation points in each direction.
pts_e3 (int) – Number of evaluation points in each direction.
- property plot_pts: tuple#
- property n_sph: ndarray#
The evaluated density.
- struphy.pic.utilities.get_kinetic_energy_particles(fe_coeffs, derham, domain, particles)[source]#
This function is for getting kinetic energy of the case when canonical momentum is used, rather than velocity
- Parameters:
fe_coeffs (psydac.linalg.stencil.StencilVector or psydac.linalg.block.BlockVector) – FE coefficients of 1 form, i.e., vector potential.
derham (struphy.feec.psydac_derham.Derham) – Discrete Derham complex.
particles (struphy.pic.particles.Particles6D) – Particles object.
- struphy.pic.utilities.get_electron_thermal_energy(density_0_form, derham, domain, nel1, nel2, nel3, nqs1, nqs2, nqs3)[source]#
This function is for getting kinetic energy of the case when canonical momentum is used, rather than velocity
- Parameters:
density_0_form (psydac.linalg.stencil.StencilVector) – values of density at quadrature points, 3-form.
derham (struphy.feec.psydac_derham.Derham) – Discrete Derham complex.