|
bi-kappa 3.0.0
Monte Carlo particle samplers for plasma velocity and position distributions
|
Bi-Maxwellian distribution for 3D velocity sampling. More...
#include <bi_maxwellian_distribution.H>
Classes | |
| class | param_type |
| The parameters of a bi_maxwellian_distribution: theta_perp, theta_par, ub and the velocity cap. More... | |
Public Types | |
| using | result_type = std::array<RealType, 3> |
| A velocity {vx, vy, vz}. | |
| using | point_type = result_type |
| Same as result_type. | |
Public Member Functions | |
| bi_maxwellian_distribution () | |
| Construct with theta_perp = theta_par = 1, ub = {0, 0, 1} and a cap of 20. | |
| bi_maxwellian_distribution (RealType theta_perp, RealType theta_par=RealType(1.0), point_type ub=point_type({RealType(0.0), RealType(0.0), RealType(1.0)}), RealType max_normalized_velocity=RealType(20.0)) | |
| Construct and call define() with these arguments. | |
| bi_maxwellian_distribution (const param_type ¶ms) | |
| Construct from a parameter set. | |
| void | define (const param_type ¶ms) |
Replace all parameters with params, then call reset(). | |
| void | define (RealType theta_perp, RealType theta_par=RealType(1.0), point_type ub=point_type({RealType(0.0), RealType(0.0), RealType(1.0)}), RealType max_normalized_velocity=RealType(20.0)) |
| Configure the sampler. | |
| void | define (const param_type ¶ms, int seed) |
define(params), after seeding the internal engine with seed as seed() does. | |
| void | define (RealType theta_perp, RealType theta_par, point_type ub, RealType max_normalized_velocity, int seed) |
define() with all four parameters, after seeding the internal engine with seed as seed() does (seed >= 0 reproducible, seed < 0 from std::random_device). | |
| void | theta_perp (RealType value) |
| Set theta_perp, keeping the other parameters; throws as define() does. | |
| void | theta_par (RealType value) |
| Set theta_par, keeping the other parameters; throws as define() does. | |
| void | ub (const point_type &value) |
| Set the field direction, keeping the other parameters. | |
| void | max_normalized_velocity (RealType value) |
| Set the velocity cap, keeping the other parameters. | |
| param_type | param () const |
| The current parameters, for example to test param().capped(). | |
| RealType | theta_perp () const |
| Perpendicular thermal speed. | |
| RealType | theta_par () const |
| Parallel thermal speed. | |
| point_type | ub () const |
| Field direction, as given. | |
| RealType | max_normalized_velocity () const |
| Velocity cap in thermal speeds; +infinity for no_cap(). | |
| 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 the normal variate cached by std::normal_distribution. | |
| template<typename GeneratorType> | |
| result_type | operator() (GeneratorType &gen) |
Draw one velocity from the engine gen instead of the internal one. | |
| result_type | operator() () |
| Draw one velocity from the internal engine. | |
| template<typename GeneratorType> | |
| result_type | operator() (GeneratorType &gen, const param_type ¶ms) |
Draw one velocity from gen with the parameters params instead of the stored ones. | |
| 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. | |
| bool | operator== (const bi_maxwellian_distribution &other) const |
| True if the two samplers have equal parameters. Engine state is not compared. | |
| bool | operator!= (const bi_maxwellian_distribution &other) const |
| Negation of operator==. | |
Static Public Member Functions | |
| static constexpr RealType | no_cap () |
| Value of the cap that selects the uncapped sampler: +infinity. | |
Bi-Maxwellian distribution for 3D velocity sampling.
Components are independent Gaussians with anisotropic thermal widths: Vx ~ N(0, theta_perp^2/2), Vy ~ N(0, theta_perp^2/2), Vz ~ N(0, theta_par^2/2).
Definition at line 29 of file bi_maxwellian_distribution.H.
| using bi_maxwellian_distribution< RealType >::point_type = result_type |
Same as result_type.
Definition at line 33 of file bi_maxwellian_distribution.H.
| using bi_maxwellian_distribution< RealType >::result_type = std::array<RealType, 3> |
A velocity {vx, vy, vz}.
Definition at line 32 of file bi_maxwellian_distribution.H.
|
inline |
Construct with theta_perp = theta_par = 1, ub = {0, 0, 1} and a cap of 20.
The internal engine is seeded from std::random_device.
Definition at line 121 of file bi_maxwellian_distribution.H.
|
inlineexplicit |
Construct and call define() with these arguments.
The internal engine is seeded from std::random_device; call seed() for a reproducible stream.
Definition at line 125 of file bi_maxwellian_distribution.H.
|
inlineexplicit |
Construct from a parameter set.
The internal engine is seeded from std::random_device.
Definition at line 137 of file bi_maxwellian_distribution.H.
|
inline |
Replace all parameters with params, then call reset().
Definition at line 148 of file bi_maxwellian_distribution.H.
Referenced by bi_maxwellian_distribution(), define(), main(), max_normalized_velocity(), theta_par(), theta_perp(), and ub().
|
inline |
define(params), after seeding the internal engine with seed as seed() does.
Definition at line 191 of file bi_maxwellian_distribution.H.
Referenced by define().
|
inline |
|
inline |
Configure the sampler.
| theta_perp | Thermal speed of the two components transverse to ub, > 0. Each is N(0, theta_perp^2/2) – a speed, not a temperature: theta = sqrt(2*k_B*T/m). |
| theta_par | Thermal speed along ub, > 0. |
| ub | Magnetic-field direction {bx,by,bz} in the global frame. 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. |
| max_normalized_velocity | Velocity cap in thermal speeds (default 20), or no_cap() for the bi-Maxwellian distribution itself. A finite value selects a different, bounded target distribution; see The velocity cap. Must be > 0; passing 0 to mean "no cap" throws. |
| std::invalid_argument | if either theta is zero or negative, or max_normalized_velocity is not positive (NaN included). |
ub, and it does not reject a NaN or infinite theta. A ub that is zero, or shorter than the limit above, passes define() and makes every draw throw std::invalid_argument("ub must be a non-zero vector").Definition at line 183 of file bi_maxwellian_distribution.H.
|
inline |
Velocity cap in thermal speeds; +infinity for no_cap().
Definition at line 244 of file bi_maxwellian_distribution.H.
|
inline |
Set the velocity cap, keeping the other parameters.
Unlike the other setters, this one changes which distribution is sampled, not merely its parameters. Pass no_cap() to return to the bi-Maxwellian distribution itself; passing 0 to mean "no cap" throws, as every non-positive value does.
Definition at line 228 of file bi_maxwellian_distribution.H.
|
inlinestaticconstexpr |
Value of the cap that selects the uncapped sampler: +infinity.
In this mode each draw is three Gaussians with no outer acceptance-rejection loop, and the samples follow the bi-Maxwellian distribution itself.
It must be passed explicitly, because the default cap is 20:
bi_maxwellian_distribution<double> d(1.0, 2.0, {0,0,1},
bi_maxwellian_distribution<double>::no_cap());
With a finite cap the sampled distribution is instead that distribution conditioned on all normalized components lying inside the component-wise box – a different, bounded distribution with its own normalization. The cap is tested in the field-aligned frame, before the rotation into the global frame, so the returned components are not individually bounded by cap*theta unless ub is {0,0,1}; the box rotates with ub.
Definition at line 111 of file bi_maxwellian_distribution.H.
Referenced by main().
|
inline |
Negation of operator==.
Definition at line 395 of file bi_maxwellian_distribution.H.
|
inline |
Draw one velocity from the internal engine.
Definition at line 273 of file bi_maxwellian_distribution.H.
|
inline |
Draw one velocity from the engine gen instead of the internal one.
Definition at line 266 of file bi_maxwellian_distribution.H.
|
inline |
Draw one velocity from gen with the parameters params instead of the stored ones.
| std::invalid_argument | if the field direction of params is numerically zero; std::runtime_error after 10^6 consecutive rejections by a finite cap. |
Definition at line 283 of file bi_maxwellian_distribution.H.
|
inline |
True if the two samplers have equal parameters. Engine state is not compared.
Definition at line 389 of file bi_maxwellian_distribution.H.
|
inline |
The current parameters, for example to test param().capped().
Definition at line 238 of file bi_maxwellian_distribution.H.
|
inline |
|
inline |
Rotate local = {v_perp1, v_perp2, v_par} from field-aligned components to the global frame, for the field direction ub.
The perpendicular axes are the ones the sampler uses. Throws std::invalid_argument if ub is numerically zero.
Definition at line 334 of file bi_maxwellian_distribution.H.
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 251 of file bi_maxwellian_distribution.H.
|
inline |
Parallel thermal speed.
Definition at line 241 of file bi_maxwellian_distribution.H.
|
inline |
Set theta_par, keeping the other parameters; throws as define() does.
Definition at line 212 of file bi_maxwellian_distribution.H.
|
inline |
Perpendicular thermal speed.
Definition at line 240 of file bi_maxwellian_distribution.H.
|
inline |
Set theta_perp, keeping the other parameters; throws as define() does.
Definition at line 206 of file bi_maxwellian_distribution.H.
|
inline |
Field direction, as given.
Definition at line 242 of file bi_maxwellian_distribution.H.
|
inline |
Set the field direction, keeping the other parameters.
Definition at line 218 of file bi_maxwellian_distribution.H.