bi-kappa 3.0.0
Monte Carlo particle samplers for plasma velocity and position distributions
Loading...
Searching...
No Matches
bi_maxwellian_distribution< RealType > Class Template Reference

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 &params)
 Construct from a parameter set.
void define (const param_type &params)
 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 &params, 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 &params)
 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.

Detailed Description

template<typename RealType = double>
class bi_maxwellian_distribution< RealType >

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).

dist.define(1.0, 2.0, {0, 0, 1}); // theta_perp, theta_par, ub
auto v = dist(); // {vx, vy, vz}, global frame
bi_maxwellian_distribution()
Construct with theta_perp = theta_par = 1, ub = {0, 0, 1} and a cap of 20.
void define(const param_type &params)
Replace all parameters with params, then call reset().
Note
The cap defaults to 20 thermal speeds, as in bi_kappa_distribution. For a bi-Maxwellian the probability beyond it is negligible. Pass no_cap() to sample the bi-Maxwellian distribution itself; see no_cap() and param_type::capped().
See also
Usage examples for more recipes (seeding, external RNG, reconfiguration).

Definition at line 29 of file bi_maxwellian_distribution.H.

Member Typedef Documentation

◆ point_type

template<typename RealType = double>
using bi_maxwellian_distribution< RealType >::point_type = result_type

Same as result_type.

Definition at line 33 of file bi_maxwellian_distribution.H.

◆ result_type

template<typename RealType = double>
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.

Constructor & Destructor Documentation

◆ bi_maxwellian_distribution() [1/3]

template<typename RealType = double>
bi_maxwellian_distribution< RealType >::bi_maxwellian_distribution ( )
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.

◆ bi_maxwellian_distribution() [2/3]

template<typename RealType = double>
bi_maxwellian_distribution< RealType >::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) )
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.

◆ bi_maxwellian_distribution() [3/3]

template<typename RealType = double>
bi_maxwellian_distribution< RealType >::bi_maxwellian_distribution ( const param_type & params)
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.

Member Function Documentation

◆ define() [1/4]

template<typename RealType = double>
void bi_maxwellian_distribution< RealType >::define ( const param_type & params)
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().

◆ define() [2/4]

template<typename RealType = double>
void bi_maxwellian_distribution< RealType >::define ( const param_type & params,
int seed )
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().

◆ define() [3/4]

template<typename RealType = double>
void bi_maxwellian_distribution< RealType >::define ( RealType theta_perp,
RealType theta_par,
point_type ub,
RealType max_normalized_velocity,
int seed )
inline

define() with all four parameters, after seeding the internal engine with seed as seed() does (seed >= 0 reproducible, seed < 0 from std::random_device).

Definition at line 195 of file bi_maxwellian_distribution.H.

◆ define() [4/4]

template<typename RealType = double>
void bi_maxwellian_distribution< RealType >::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) )
inline

Configure the sampler.

Parameters
theta_perpThermal 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_parThermal speed along ub, > 0.
ubMagnetic-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_velocityVelocity 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.
Note
To seed reproducibly, either call seed() afterwards or use the overload taking a trailing int: >= 0 is reproducible, < 0 reseeds from std::random_device.
Exceptions
std::invalid_argumentif either theta is zero or negative, or max_normalized_velocity is not positive (NaN included).
Note
define() does not check 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").
See also
Parameter reference for the full table, Choosing a sampler to compare samplers.

Definition at line 183 of file bi_maxwellian_distribution.H.

◆ max_normalized_velocity() [1/2]

template<typename RealType = double>
RealType bi_maxwellian_distribution< RealType >::max_normalized_velocity ( ) const
inline

Velocity cap in thermal speeds; +infinity for no_cap().

Definition at line 244 of file bi_maxwellian_distribution.H.

◆ max_normalized_velocity() [2/2]

template<typename RealType = double>
void bi_maxwellian_distribution< RealType >::max_normalized_velocity ( RealType value)
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.

◆ no_cap()

template<typename RealType = double>
constexpr RealType bi_maxwellian_distribution< RealType >::no_cap ( )
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.

See also
The velocity cap, which describes the same construction for bi_kappa_distribution.

Definition at line 111 of file bi_maxwellian_distribution.H.

Referenced by main().

◆ operator!=()

template<typename RealType = double>
bool bi_maxwellian_distribution< RealType >::operator!= ( const bi_maxwellian_distribution< RealType > & other) const
inline

Negation of operator==.

Definition at line 395 of file bi_maxwellian_distribution.H.

◆ operator()() [1/3]

template<typename RealType = double>
result_type bi_maxwellian_distribution< RealType >::operator() ( )
inline

Draw one velocity from the internal engine.

Returns
{vx, vy, vz} in the global frame.

Definition at line 273 of file bi_maxwellian_distribution.H.

◆ operator()() [2/3]

template<typename RealType = double>
template<typename GeneratorType>
result_type bi_maxwellian_distribution< RealType >::operator() ( GeneratorType & gen)
inline

Draw one velocity from the engine gen instead of the internal one.

Returns
{vx, vy, vz} in the global frame.

Definition at line 266 of file bi_maxwellian_distribution.H.

◆ operator()() [3/3]

template<typename RealType = double>
template<typename GeneratorType>
result_type bi_maxwellian_distribution< RealType >::operator() ( GeneratorType & gen,
const param_type & params )
inline

Draw one velocity from gen with the parameters params instead of the stored ones.

Exceptions
std::invalid_argumentif 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.

◆ operator==()

template<typename RealType = double>
bool bi_maxwellian_distribution< RealType >::operator== ( const bi_maxwellian_distribution< RealType > & other) const
inline

True if the two samplers have equal parameters. Engine state is not compared.

Definition at line 389 of file bi_maxwellian_distribution.H.

◆ param()

template<typename RealType = double>
param_type bi_maxwellian_distribution< RealType >::param ( ) const
inline

The current parameters, for example to test param().capped().

Definition at line 238 of file bi_maxwellian_distribution.H.

◆ reset()

template<typename RealType = double>
void bi_maxwellian_distribution< RealType >::reset ( )
inline

Discard the normal variate cached by std::normal_distribution.

Called by seed() and by every define() overload.

Definition at line 259 of file bi_maxwellian_distribution.H.

Referenced by define(), and seed().

◆ rotate_from_fieldAligned_frame()

template<typename RealType = double>
point_type bi_maxwellian_distribution< RealType >::rotate_from_fieldAligned_frame ( const point_type & local,
const point_type & ub ) const
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()().

◆ seed()

template<typename RealType = double>
void bi_maxwellian_distribution< RealType >::seed ( int s)
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.

◆ theta_par() [1/2]

template<typename RealType = double>
RealType bi_maxwellian_distribution< RealType >::theta_par ( ) const
inline

Parallel thermal speed.

Definition at line 241 of file bi_maxwellian_distribution.H.

◆ theta_par() [2/2]

template<typename RealType = double>
void bi_maxwellian_distribution< RealType >::theta_par ( RealType value)
inline

Set theta_par, keeping the other parameters; throws as define() does.

Definition at line 212 of file bi_maxwellian_distribution.H.

◆ theta_perp() [1/2]

template<typename RealType = double>
RealType bi_maxwellian_distribution< RealType >::theta_perp ( ) const
inline

Perpendicular thermal speed.

Definition at line 240 of file bi_maxwellian_distribution.H.

◆ theta_perp() [2/2]

template<typename RealType = double>
void bi_maxwellian_distribution< RealType >::theta_perp ( RealType value)
inline

Set theta_perp, keeping the other parameters; throws as define() does.

Definition at line 206 of file bi_maxwellian_distribution.H.

◆ ub() [1/2]

template<typename RealType = double>
point_type bi_maxwellian_distribution< RealType >::ub ( ) const
inline

Field direction, as given.

Definition at line 242 of file bi_maxwellian_distribution.H.

◆ ub() [2/2]

template<typename RealType = double>
void bi_maxwellian_distribution< RealType >::ub ( const point_type & value)
inline

Set the field direction, keeping the other parameters.

Definition at line 218 of file bi_maxwellian_distribution.H.


The documentation for this class was generated from the following file: