|
bi-kappa 3.0.0
Monte Carlo particle samplers for plasma velocity and position distributions
|
Samples velocities from a user-defined speed-squared distribution g(w). More...
#include <general_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 | |
| general_velocity_generator () | |
| Construct an undefined generator; call define() before drawing. | |
| general_velocity_generator (speed_sq_pdf_function speed_sq_pdf, RealType speed_sq_min, RealType speed_sq_max, int probe_points=1024, int max_reject_tries=100000) | |
| Construct and call define() with these arguments. | |
| void | define (speed_sq_pdf_function speed_sq_pdf, RealType speed_sq_min, RealType speed_sq_max, int probe_points=1024, int max_reject_tries=100000) |
| Configure the sampler. | |
| 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. | |
| 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 | speedSqMin () const |
| Lower end of the sampled w. | |
| RealType | speedSqMax () const |
| Upper end of the sampled w. | |
| RealType | pdfUpperBound () const |
| The rejection envelope: the largest probed value of g times 1.05, or 0 when speed_sq_min == speed_sq_max. | |
Samples velocities from a user-defined speed-squared distribution g(w).
The sampled value is w = |V|^2, so the speed is |V| = sqrt(w) and the direction is isotropic in 3D. (For a distribution originally posed in energy, w = |V|^2 = 2E/m, so the mass drops out of this generator entirely.) If speed_sq_min == speed_sq_max, every sample has the single speed sqrt(speed_sq_min).
Definition at line 30 of file general_velocity_generator.H.
| using general_velocity_generator< RealType >::point_type = result_type |
Same as result_type.
Definition at line 34 of file general_velocity_generator.H.
| using general_velocity_generator< RealType >::result_type = std::array<RealType, 3> |
A velocity {vx, vy, vz}.
Definition at line 33 of file general_velocity_generator.H.
| using general_velocity_generator< RealType >::speed_sq_pdf_function = std::function<RealType(RealType)> |
The type of the density g(w) passed to define().
Definition at line 36 of file general_velocity_generator.H.
|
inline |
Construct an undefined generator; call define() before drawing.
The internal engine is seeded from std::random_device.
Definition at line 40 of file general_velocity_generator.H.
Referenced by general_velocity_generator().
|
inline |
Construct and call define() with these arguments.
Definition at line 51 of file general_velocity_generator.H.
References general_velocity_generator(), and define().
|
inline |
Configure the sampler.
Estimates the rejection envelope here, once, so a badly chosen probe_points is a configuration-time decision.
| speed_sq_pdf | Your g(w), whose argument is the speed squared, not the speed. Need not be normalized – any non-negative function proportional to the density works. Must be finite and non-negative wherever it is evaluated, and positive somewhere in range. |
| speed_sq_min | Lower end of the sampled w range, >= 0. |
| speed_sq_max | Upper end, >= speed_sq_min. This is a hard support: speeds beyond sqrt(speed_sq_max) are never produced, so choose it to cover the tail you care about. If it equals speed_sq_min, every sample has the speed sqrt(speed_sq_min) and speed_sq_pdf is not evaluated. |
| 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()). If g has a peak narrow enough to fall between probes, the envelope is too low and the sampled distribution is silently wrong; raise this until pdfUpperBound() stops increasing. Must be >= 64. |
| max_reject_tries | Candidate draws one sample may consume before operator() throws. Must be > 0. Exhausting it usually means g is tiny over most of [min,max]; narrowing the range fixes it better than raising this. |
| std::invalid_argument | on a null callable, a negative speed_sq_min, speed_sq_max < speed_sq_min, probe_points < 64, a non-positive max_reject_tries, or a g that is nowhere positive in range. |
Definition at line 93 of file general_velocity_generator.H.
References reset().
Referenced by general_velocity_generator(), and main().
|
inline |
Draw one velocity from the internal engine; throws as operator()(gen) does.
Definition at line 207 of file general_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 179 of file general_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 216 of file general_velocity_generator.H.
|
inline |
|
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 159 of file general_velocity_generator.H.
References reset().
Referenced by main().
|
inline |
Upper end of the sampled w.
Definition at line 213 of file general_velocity_generator.H.
|
inline |
Lower end of the sampled w.
Definition at line 212 of file general_velocity_generator.H.