|
bi-kappa 3.0.0
Monte Carlo particle samplers for plasma velocity and position distributions
|
Samples field-aligned velocities: an arbitrary parallel speed-squared distribution along B, with a Maxwellian perpendicular spread. More...
#include <field_aligned_velocity_generator.H>
Public Types | |
| using | result_type = std::array<RealType, 3> |
| A velocity {vx, vy, vz}. | |
| using | point_type = result_type |
| Same as result_type. | |
| using | speed_sq_pdf_function = std::function<RealType(RealType)> |
| The type of the density g(w) passed to define(). | |
Public Member Functions | |
| field_aligned_velocity_generator () | |
| Construct an undefined generator; call define() before drawing. | |
| field_aligned_velocity_generator (speed_sq_pdf_function speed_sq_pdf, RealType speed_sq_min, RealType speed_sq_max, RealType theta_perp, point_type ub, int parallel_sign, int probe_points=1024, int max_reject_tries=100000, RealType max_normalized_velocity=RealType(20.0)) | |
| Construct and call define() with these arguments. | |
| void | define (speed_sq_pdf_function speed_sq_pdf, RealType speed_sq_min, RealType speed_sq_max, RealType theta_perp, point_type ub, int parallel_sign, int probe_points=1024, int max_reject_tries=100000, RealType max_normalized_velocity=RealType(20.0)) |
| Configure the sampler: user-supplied law along the field, Maxwellian across it. | |
| void | seed (int s) |
| Reseed the internal engine and discard any variate cached from before, so that seed(s) followed by n draws gives the same values however many draws came first. | |
| void | reset () |
| Discard any state cached by the internal distributions, including the second normal variate of std::normal_distribution. | |
| template<typename GeneratorType> | |
| point_type | operator() (GeneratorType &gen) |
Draw one velocity from the engine gen instead of the internal one. | |
| point_type | operator() () |
| Draw one velocity from the internal engine; throws as operator()(gen) does. | |
| RealType | parallelSpeedSqMin () const |
| Lower end of the sampled v_par^2. | |
| RealType | parallelSpeedSqMax () const |
| Upper end of the sampled v_par^2. | |
| RealType | thetaPerp () const |
| Perpendicular thermal speed. | |
| point_type | ub () const |
| Field direction, as given. | |
| RealType | parallelSign () const |
| +1 or -1, as a RealType. | |
| RealType | max_normalized_velocity () const |
| Cap on each perpendicular component, in units of theta_perp; +infinity for no_cap(). | |
| RealType | pdfUpperBound () const |
| The rejection envelope: the largest probed value of g times 1.05, or 0 when speed_sq_min == speed_sq_max. | |
| point_type | rotate_from_fieldAligned_frame (const point_type &local, const point_type &ub) const |
Rotate local = {v_perp1, v_perp2, v_par} from field-aligned components to the global frame, for the field direction ub. | |
Static Public Member Functions | |
| static constexpr RealType | no_cap () |
Value of max_normalized_velocity that removes the perpendicular cap. | |
Samples field-aligned velocities: an arbitrary parallel speed-squared distribution along B, with a Maxwellian perpendicular spread.
The parallel component is w_par = v_par^2, drawn from a user-defined distribution g(w_par); the parallel speed is |v_par| = sqrt(w_par) and its direction is set by a fixed sign (+1 along B, -1 opposite B). (For a distribution originally posed in energy, w_par = v_par^2 = 2E_par/m, so the mass drops out.) If speed_sq_min == speed_sq_max, every sample has the single parallel speed sqrt(speed_sq_min). The two perpendicular components are independent Gaussians with N(0, theta_perp^2/2), i.e. a Maxwellian with thermal speed theta_perp (same convention as bi_maxwellian_distribution), each capped at max_normalized_velocity thermal speeds (default 20, as in bi_maxwellian_distribution). The result is returned in the global (lab) frame.
Definition at line 38 of file field_aligned_velocity_generator.H.
| using field_aligned_velocity_generator< RealType >::point_type = result_type |
Same as result_type.
Definition at line 42 of file field_aligned_velocity_generator.H.
| using field_aligned_velocity_generator< RealType >::result_type = std::array<RealType, 3> |
A velocity {vx, vy, vz}.
Definition at line 41 of file field_aligned_velocity_generator.H.
| using field_aligned_velocity_generator< RealType >::speed_sq_pdf_function = std::function<RealType(RealType)> |
The type of the density g(w) passed to define().
Definition at line 44 of file field_aligned_velocity_generator.H.
|
inline |
Construct an undefined generator; call define() before drawing.
The internal engine is seeded from std::random_device.
Definition at line 48 of file field_aligned_velocity_generator.H.
Referenced by field_aligned_velocity_generator().
|
inline |
Construct and call define() with these arguments.
Definition at line 61 of file field_aligned_velocity_generator.H.
References field_aligned_velocity_generator(), define(), max_normalized_velocity(), and ub().
|
inline |
Configure the sampler: user-supplied law along the field, Maxwellian across it.
| speed_sq_pdf | Your g(w) for the parallel component, whose argument is v_par squared, not v_par. Need not be normalized; must be finite, non-negative, and positive somewhere in range. |
| speed_sq_min | Lower end of the sampled v_par^2, >= 0. |
| speed_sq_max | Upper end, >= speed_sq_min. A hard support. If it equals speed_sq_min, every sample has the parallel speed sqrt(speed_sq_min) and speed_sq_pdf is not evaluated. |
| theta_perp | Thermal speed of the two perpendicular components, > 0. Each is N(0, theta_perp^2/2), the same convention as bi_maxwellian_distribution. |
| ub | Magnetic-field direction {bx,by,bz}. Need not be normalized; must be non-zero, with a length above about 1.5e-8 in double (3.5e-4 in float); see Field direction: ub. |
| parallel_sign | Exactly +1 (parallel component along ub) or -1 (opposite). This makes the result one-sided: every sample streams the same way along the field, which is what you want for a beam and not what you want for a symmetric population. For the symmetric case draw the sign yourself, or use bi_maxwellian_distribution / bi_kappa_distribution. |
| probe_points | Number of evenly spaced points, from speed_sq_min to speed_sq_max inclusive, at which g is evaluated once, here, to estimate its maximum; the largest value plus a 5% margin is the rejection envelope (pdfUpperBound()). See Rejection-sampler settings: probe_points, max_reject_tries for the silent-bias failure mode. Must be >= 64. |
| max_reject_tries | Candidate draws per sample before operator() throws. Must be > 0. |
| max_normalized_velocity | Cap on each perpendicular component in units of theta_perp: a pair with |v_perp_i| > cap*theta_perp is redrawn. Default 20, as in bi_maxwellian_distribution; no_cap() removes it. Must be > 0. |
| std::invalid_argument | on a null callable, a bad range, a zero or negative theta_perp, a ub shorter than the limit above, a parallel_sign other than +1 or -1, probe_points < 64, a non-positive max_reject_tries or cap, or a g that is nowhere positive in range. A NaN or infinite theta_perp and a ub with a NaN component are not rejected. |
Definition at line 118 of file field_aligned_velocity_generator.H.
References max_normalized_velocity(), reset(), and ub().
Referenced by field_aligned_velocity_generator(), and main().
|
inline |
Cap on each perpendicular component, in units of theta_perp; +infinity for no_cap().
Definition at line 272 of file field_aligned_velocity_generator.H.
Referenced by field_aligned_velocity_generator(), and define().
|
inlinestaticconstexpr |
Value of max_normalized_velocity that removes the perpendicular cap.
Definition at line 73 of file field_aligned_velocity_generator.H.
|
inline |
Draw one velocity from the internal engine; throws as operator()(gen) does.
Definition at line 261 of file field_aligned_velocity_generator.H.
|
inline |
Draw one velocity from the engine gen instead of the internal one.
| std::runtime_error | if called before define(), if max_reject_tries is exhausted, or if g returns a negative or non-finite value. |
Definition at line 221 of file field_aligned_velocity_generator.H.
References rotate_from_fieldAligned_frame().
|
inline |
+1 or -1, as a RealType.
Definition at line 270 of file field_aligned_velocity_generator.H.
|
inline |
Upper end of the sampled v_par^2.
Definition at line 267 of file field_aligned_velocity_generator.H.
|
inline |
Lower end of the sampled v_par^2.
Definition at line 266 of file field_aligned_velocity_generator.H.
|
inline |
The rejection envelope: the largest probed value of g times 1.05, or 0 when speed_sq_min == speed_sq_max.
Raise probe_points until this stops increasing.
Definition at line 275 of file field_aligned_velocity_generator.H.
|
inline |
|
inline |
Rotate local = {v_perp1, v_perp2, v_par} from field-aligned components to the global frame, for the field direction ub.
Throws std::invalid_argument if ub is numerically zero.
Definition at line 283 of file field_aligned_velocity_generator.H.
References ub().
Referenced by operator()().
|
inline |
Reseed the internal engine and discard any variate cached from before, so that seed(s) followed by n draws gives the same values however many draws came first.
Definition at line 202 of file field_aligned_velocity_generator.H.
References reset().
Referenced by main().
|
inline |
Perpendicular thermal speed.
Definition at line 268 of file field_aligned_velocity_generator.H.
|
inline |
Field direction, as given.
Definition at line 269 of file field_aligned_velocity_generator.H.
Referenced by field_aligned_velocity_generator(), define(), and rotate_from_fieldAligned_frame().