Vlasiator ebf0dd394 on dev (v5.4.0 + 1054 commits)
Loading...
Searching...
No Matches
distribution.cpp
Go to the documentation of this file.
1/*
2 * This file is part of Vlasiator.
3 * Copyright 2010-2016 Finnish Meteorological Institute
4 *
5 * For details of usage, see the COPYING file and read the "Rules of the Road"
6 * at http://www.physics.helsinki.fi/vlasiator/
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22#include <random>
23#include "distribution.h"
24#include "particles.h"
25
26Distribution::Distribution(std::default_random_engine& _rand) : rand(_rand) {
29}
30Maxwell_Boltzmann::Maxwell_Boltzmann(std::default_random_engine& _rand) :
31 Distribution(_rand), velocity_distribution {std::normal_distribution<Real>(0., sqrt(ParticleParameters::temperature * PhysicalConstantsSI::k / mass))} {}
32
33Monoenergetic::Monoenergetic(std::default_random_engine& _rand) : Distribution(_rand) {
35}
36
37double Kappa::find_v_for_r(double rand) {
38
39 /* Use binary search to find this value */
40 int step = lookup_size/2;
41 int a=lookup_size/2;
42 double diff;
43 do {
44 step = ceil(step*.5);
45
46 diff = rand-lookup[a];
47 if(diff < 0) {
48 a-=step;
49 } else {
50 a+=step;
51 }
52 a = (a<lookup_size-1)?(a):(lookup_size-1);
53 } while(step > 1);
54
55 /* Final step adjustment */
56 if(rand < lookup[a]) {
57 a--;
58 }
59
60 /* Special case for the upper bound: Extrapolate the last bin */
61 if(a+1 > lookup_size-1) {
62 return maxw0/lookup_size*
64 }
65 /* Linear interpolate between the two neighbouring entries */
66 return maxw0/lookup_size*(a + (rand-lookup[a])/(lookup[a+1]-lookup[a]));
67}
68
69Kappa6::Kappa6(std::default_random_engine& _rand) : Kappa(_rand) {
71 w0 = sqrt(2.* kT *(6. - 1.5)/(6. * mass));
73}
74Kappa2::Kappa2(std::default_random_engine& _rand) : Kappa(_rand) {
76 w0 = sqrt(2.* kT *(2. - 1.5)/(2. * mass));
78}
79
80
sqrt(1.0+vA *vA/(c *c))) % Ion-acoustic wave cS
std::default_random_engine & rand
Distribution(std::default_random_engine &_rand, Real _mass, Real _charge)
virtual void generate_lookup()
Kappa2(std::default_random_engine &_rand, double _mass, double _charge, double _w0, double _maxw0)
virtual void generate_lookup()
Kappa6(std::default_random_engine &_rand, double _mass, double _charge, double _w0, double _maxw0)
Real w0
std::vector< Real > lookup
Real find_v_for_r(Real rand)
static const int lookup_size
Kappa(std::default_random_engine &_rand, Real _mass, Real _charge, Real _w0, Real _maxw0)
Real maxw0
Maxwell_Boltzmann(std::default_random_engine &_rand, Real _mass, Real _charge, Real kT)
std::normal_distribution< Real > velocity_distribution
virtual Particle next_particle()
Monoenergetic(std::default_random_engine &_rand, Real _mass, Real _charge, Real _vel)
static const double k
Definition physconst.h:62
float Real
Definition definitions.h:41
#define Vec3d
const int k