17 const Real kappa = 2.0;
18 const Real theta_perp = 1.0;
19 const Real theta_par = 2.0;
23 const int n_particle = 50000;
25 std::cout <<
"=== Example 1: BiKappaDistribution ===" << std::endl;
30 biKappa.
define(kappa, theta_perp, theta_par, {0,0,1},
33 std::ofstream out(
"samples_bikappa.txt");
34 for (
int i = 0; i < n_particle; ++i) {
36 out << v[0] <<
" " << v[1] <<
" " << v[2] <<
"\n";
38 std::cout <<
"wrote " << n_particle <<
" samples to samples_bikappa.txt" << std::endl;
41 std::cout <<
"\n=== Example 2: BiMaxwellianDistribution ===" << std::endl;
44 biMaxwell.
define(theta_perp, theta_par, {0,0,1},
47 std::ofstream out(
"samples_bimaxwellian.txt");
48 for (
int i = 0; i < n_particle; ++i) {
50 out << v[0] <<
" " << v[1] <<
" " << v[2] <<
"\n";
52 std::cout <<
"wrote " << n_particle <<
" samples to samples_bimaxwellian.txt" << std::endl;
55 std::cout <<
"\n=== Example 3: general_velocity_generator (isotropic Maxwellian via w=|v|^2) ==="
62 const Real theta_iso = theta_perp;
63 auto speedSqPdf = [theta_iso](
Real w) ->
Real {
64 return std::sqrt(w) * std::exp(-w / (theta_iso * theta_iso));
67 velocityGen.
define(speedSqPdf,
68 static_cast<Real>(0.0),
69 static_cast<Real>(25.0));
70 velocityGen.
seed(20030410);
72 std::ofstream out(
"samples_general_velocity.txt");
73 for (
int i = 0; i < n_particle; ++i) {
75 out << v[0] <<
" " << v[1] <<
" " << v[2] <<
"\n";
77 std::cout <<
"wrote " << n_particle <<
" samples to samples_general_velocity.txt"
81 std::cout <<
"\n=== Example 4: general_position_generator (rho=1+sin(x)sin(y)) ===" << std::endl;
83 auto rho = [](
const position_point_type &x) ->
Real {
84 return 1 + std::sin(x[0]) * std::sin(x[1]);
86 static double pi = 3.14159;
88 positionGen.
define(2, {-pi, -pi}, {pi, pi}, rho);
89 positionGen.
seed(20030410);
91 std::ofstream out(
"samples_general_position.txt");
92 for (
int i = 0; i < n_particle; ++i) {
93 const position_point_type x = positionGen();
94 out << x[0] <<
" " << x[1] <<
"\n";
96 std::cout <<
"wrote " << n_particle <<
" samples to samples_general_position.txt"
100 std::cout <<
"\n=== Example 5: field_aligned_velocity_generator (uniform w_par, B=(1,1,1)) ==="
108 const Real w_max_par = 4.0;
109 auto parallelSpeedSqPdf = [](
Real) ->
Real {
return Real(1.0); };
111 fieldAlignedGen.
define(parallelSpeedSqPdf,
112 static_cast<Real>(0.0),
117 fieldAlignedGen.
seed(20030410);
119 std::ofstream out(
"samples_field_aligned.txt");
120 for (
int i = 0; i < n_particle; ++i) {
122 out << v[0] <<
" " << v[1] <<
" " << v[2] <<
"\n";
124 std::cout <<
"wrote " << n_particle <<
" samples to samples_field_aligned.txt"
Bi-Kappa distribution class for sampling 3D velocity vectors.
void define(const param_type ¶ms)
Replace all parameters with params (already validated by its constructor), then call reset().
static constexpr RealType no_cap()
Value of the cap that selects the uncapped sampler: +infinity.
result_type point_type
Same as result_type.
Bi-Maxwellian distribution for 3D velocity sampling.
result_type point_type
Same as result_type.
static constexpr RealType no_cap()
Value of the cap that selects the uncapped sampler: +infinity.
void define(const param_type ¶ms)
Replace all parameters with params, then call reset().
Samples field-aligned velocities: an arbitrary parallel speed-squared distribution along B,...
void seed(int s)
Reseed the internal engine and discard any variate cached from before, so that seed(s) followed by n ...
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.
result_type point_type
Same as result_type.
Samples positions in 1D/2D/3D from a user density rho(x), rho(x,y), or rho(x,y,z).
void define(int dimension, const point_type &lower_bounds, const point_type &upper_bounds, density_function density_function, int probe_points=4096, int max_reject_tries=200000)
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 ...
result_type point_type
Same as result_type.
Samples velocities from a user-defined speed-squared distribution g(w).
void seed(int s)
Reseed the internal engine and discard any variate cached from before, so that seed(s) followed by n ...
result_type point_type
Same as result_type.
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.