Vlasiator ebf0dd394 on dev (v5.4.0 + 1054 commits)
Loading...
Searching...
No Matches
particleparameters.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 <map>
23#include <iostream>
24#include "particleparameters.h"
25#include "distribution.h"
26#include "../readparameters.h"
27#include "physconst.h"
28
30
33std::string P::mode = std::string("distribution");
34Real P::init_x = 0;
35Real P::init_y = 0;
36Real P::init_z = 0;
37
38Real P::dt = 0;
42uint64_t P::num_particles = 0;
43std::string P::V_field_name = "V";
44std::string P::rho_field_name = "rho";
45bool P::divide_rhov_by_rho = false;
46
47std::default_random_engine::result_type P::random_seed = 1;
48Distribution* (*P::distribution)(std::default_random_engine&) = NULL;
53
57
61
68
77
79 Readparameters::add("particles.input_filename_pattern","Printf() like pattern giving the field input filenames.",
80 std::string("bulk.%07i.vlsv"));
81 Readparameters::add("particles.output_filename_pattern","Printf() like pattern giving the particle output filenames.",
82 std::string("particles.%07i.vlsv"));
83 Readparameters::add("particles.mode","Mode to run the particle pusher in.",std::string("distribution"));
84
85 Readparameters::add("particles.init_x", "Particle starting point, x-coordinate (meters).", 0);
86 Readparameters::add("particles.init_y", "Particle starting point, y-coordinate (meters).", 0);
87 Readparameters::add("particles.init_z", "Particle starting point, z-coordinate (meters).", 0);
88
89 Readparameters::add("particles.dt", "Particle pusher timestep",0);
90 Readparameters::add("particles.input_dt", "Time spacing (seconds) of input files",1.);
91 Readparameters::add("particles.start_time", "Simulation time (seconds) for particle start.",0);
92 Readparameters::add("particles.end_time", "Simulation time (seconds) at which particle simulation stops.",0);
93 Readparameters::add("particles.num_particles", "Number of particles to simulate.",10000);
94 Readparameters::add("particles.V_field_name", "Name of the Velocity data set in the input files", "V");
95 Readparameters::add("particles.rho_field_name", "Name of the Density data set in the input files", "rho");
96 Readparameters::add("particles.divide_rhov_by_rho", "Do the input file store rho_v and rho separately?", false);
97 Readparameters::add("particles.random_seed", "Random seed for particle creation.",1);
98 Readparameters::add("particles.distribution", "Type of distribution function to sample particles from.",
99 std::string("maxwell"));
100 Readparameters::add("particles.temperature", "Temperature of the particle distribution",1e6);
101 Readparameters::add("particles.particle_vel", "Initial velocity of the particles (in the plasma rest frame)",0);
102 Readparameters::add("particles.mass", "Mass of the test particles",PhysicalConstantsSI::mp);
103 Readparameters::add("particles.charge", "Charge of the test particles",PhysicalConstantsSI::e);
104
105 Readparameters::add("particles.boundary_behaviour_x",
106 "What to do with particles that reach the x boundaries (DELETE/REFLECT/PERIODIC)",std::string("DELETE"));
107 Readparameters::add("particles.boundary_behaviour_y",
108 "What to do with particles that reach the y boundaries (DELETE/REFLECT/PERIODIC)",std::string("PERIODIC"));
109 Readparameters::add("particles.boundary_behaviour_z",
110 "What to do with particles that reach the z boundaries (DELETE/REFLECT/PERIODIC)",std::string("PERIODIC"));
111
112 // Parameters for the precipitation mode
113 Readparameters::add("particles.inner_boundary", "Distance of the inner boundary from the coordinate centre (meters)",
114 30e6);
115 Readparameters::add("particles.precipitation_start_x", "X-Coordinate at which precipitation injection starts (meters)",
116 -200e6);
117 Readparameters::add("particles.precipitation_stop_x", "X-Coordinate at which precipitation injection stops (meters)",
118 -50e6);
119
120 // Parameters for shock reflection mode
121 Readparameters::add("particles.reflect_start_y",
122 "Y-Coordinate of the bottom end of the parabola, at which shock reflection scenario particles are injected", 60e6);
123 Readparameters::add("particles.reflect_stop_y",
124 "Y-Coordinate of the bottom end of the parabola, at which shock reflection scenario particles are injected", 60e6);
125 Readparameters::add("particles.reflect_y_scale",
126 "Curvature scale of the injection parabola for the reflection scenario", 60e6);
127 Readparameters::add("particles.reflect_x_offset",
128 "X-Coordinate of the tip of the injection parabola for the reflection scenario", 40e6);
129 Readparameters::add("particles.reflect_upstream_boundary",
130 "Distance from particle injection point at which particles are to be counted as 'reflected'", 10e6);
131 Readparameters::add("particles.reflect_downstream_boundary",
132 "Distance from particle injection point at which particles are to be counted as 'transmitted'", 10e6);
133
134 // Parameters for ip shock injection test mode
135 Readparameters::add("particles.ipshock_inject_x0",
136 "X-Coordinate of the lower edge of particle injection region for the ipShock scenario", -1.e6);
137 Readparameters::add("particles.ipshock_inject_x1",
138 "X-Coordinate of the upper edge of particle injection region for the ipShock scenario", 1.e6);
139 Readparameters::add("particles.ipshock_inject_y0",
140 "Y-Coordinate of the lower edge of particle injection region for the ipShock scenario", -1.e6);
141 Readparameters::add("particles.ipshock_inject_y1",
142 "Y-Coordinate of the upper edge of particle injection region for the ipShock scenario", 1.e6);
143 Readparameters::add("particles.ipshock_inject_z0",
144 "Z-Coordinate of the lower edge of particle injection region for the ipShock scenario", -1.e6);
145 Readparameters::add("particles.ipshock_inject_z1",
146 "Z-Coordinate of the upper edge of particle injection region for the ipShock scenario", 1.e6);
147 Readparameters::add("particles.ipshock_transmit",
148 "X-Coordinate of threshold for where particles are counted as transmitted for the ipShock scenario", -10.e6);
149 Readparameters::add("particles.ipshock_reflect",
150 "X-Coordinate of threshold for where particles are counted as reflected for the ipShock scenario", 10.e6);
151
152 return true;
153}
154
156 Readparameters::get("particles.input_filename_pattern",P::input_filename_pattern);
157 Readparameters::get("particles.output_filename_pattern",P::output_filename_pattern);
158
159 Readparameters::get("particles.mode",P::mode);
160
161 Readparameters::get("particles.init_x",P::init_x);
162 Readparameters::get("particles.init_y",P::init_y);
163 Readparameters::get("particles.init_z",P::init_z);
164
165 Readparameters::get("particles.dt",P::dt);
166 Readparameters::get("particles.input_dt", P::input_dt);
167 Readparameters::get("particles.start_time",P::start_time);
168 Readparameters::get("particles.end_time",P::end_time);
169 Readparameters::get("particles.num_particles",P::num_particles);
170 if(P::dt == 0 || P::end_time == P::start_time) {
171 std::cerr << "Error end_time == start_time! Won't do anything (and will probably crash now)." << std::endl;
172 return false;
173 }
174 Readparameters::get("particles.V_field_name",P::V_field_name);
175 Readparameters::get("particles.rho_field_name",P::rho_field_name);
176 Readparameters::get("particles.divide_rhov_by_rho",P::divide_rhov_by_rho);
177
178 Readparameters::get("particles.random_seed",P::random_seed);
179
180 /* Look up particle distribution generator */
181 std::string distribution_name;
182 Readparameters::get("particles.distribution",distribution_name);
183
184 std::map<std::string, Distribution*(*)(std::default_random_engine&)> distribution_lookup;
185 distribution_lookup["maxwell"]=&createDistribution<Maxwell_Boltzmann>;
186 distribution_lookup["monoenergetic"]=&createDistribution<Monoenergetic>;
187 distribution_lookup["kappa2"]=&createDistribution<Kappa2>;
188 distribution_lookup["kappa6"]=&createDistribution<Kappa6>;
189
190 if(distribution_lookup.find(distribution_name) == distribution_lookup.end()) {
191 std::cerr << "Error: particles.distribution value \"" << distribution_name
192 << "\" does not specify a valid distribution!" << std::endl;
193 return false;
194 } else {
195 P::distribution = distribution_lookup[distribution_name];
196 }
197
198 Readparameters::get("particles.temperature",P::temperature);
199 Readparameters::get("particles.particle_vel",P::particle_vel);
200
201 // Boundaries
202 std::map<std::string, Boundary*(*)(int)> boundaryLookup;
203 boundaryLookup["DELETE"] = &createBoundary<OpenBoundary>;
204 boundaryLookup["REFLECT"] = &createBoundary<ReflectBoundary>;
205 boundaryLookup["PERIODIC"] = &createBoundary<PeriodicBoundary>;
206 std::string tempstring;
207 Readparameters::get("particles.boundary_behaviour_x",tempstring);
208 if(boundaryLookup.find(tempstring) == boundaryLookup.end()) {
209 std::cerr << "Error: invalid boundary condition \"" << tempstring << "\" in x-direction" << std::endl;
210 exit(0);
211 } else {
212 P::boundary_behaviour_x = boundaryLookup[tempstring](0);
213 }
214 Readparameters::get("particles.boundary_behaviour_y",tempstring);
215 if(boundaryLookup.find(tempstring) == boundaryLookup.end()) {
216 std::cerr << "Error: invalid boundary condition \"" << tempstring << "\" in y-direction" << std::endl;
217 exit(0);
218 } else {
219 P::boundary_behaviour_y = boundaryLookup[tempstring](1);
220 }
221 Readparameters::get("particles.boundary_behaviour_z",tempstring);
222 if(boundaryLookup.find(tempstring) == boundaryLookup.end()) {
223 std::cerr << "Error: invalid boundary condition \"" << tempstring << "\" in z-direction" << std::endl;
224 exit(0);
225 } else {
226 P::boundary_behaviour_z = boundaryLookup[tempstring](2);
227 }
228
229 Readparameters::get("particles.inner_boundary", P::precip_inner_boundary);
230 Readparameters::get("particles.precipitation_start_x", P::precip_start_x);
231 Readparameters::get("particles.precipitation_stop_x", P::precip_stop_x);
232
233 Readparameters::get("particles.reflect_start_y", P::reflect_start_y);
234 Readparameters::get("particles.reflect_stop_y", P::reflect_stop_y);
235 Readparameters::get("particles.reflect_y_scale", P::reflect_y_scale);
236 Readparameters::get("particles.reflect_x_offset", P::reflect_x_offset);
237 Readparameters::get("particles.reflect_upstream_boundary", P::reflect_upstream_boundary);
238 Readparameters::get("particles.reflect_downstream_boundary", P::reflect_downstream_boundary);
239
240 Readparameters::get("particles.ipshock_inject_x0", P::ipshock_inject_x0);
241 Readparameters::get("particles.ipshock_inject_x1", P::ipshock_inject_x1);
242 Readparameters::get("particles.ipshock_inject_y0", P::ipshock_inject_y0);
243 Readparameters::get("particles.ipshock_inject_y1", P::ipshock_inject_y1);
244 Readparameters::get("particles.ipshock_inject_z0", P::ipshock_inject_z0);
245 Readparameters::get("particles.ipshock_inject_z1", P::ipshock_inject_z1);
246 Readparameters::get("particles.ipshock_transmit", P::ipshock_transmit);
247 Readparameters::get("particles.ipshock_reflect", P::ipshock_reflect);
248
249 return true;
250}
Boundary * createBoundary(int dimension)
Definition boundaries.h:181
static const double mp
Definition physconst.h:53
static const double e
Definition physconst.h:55
static void get(const std::string &name, std::string &value)
static void add(const std::string &name, const std::string &desc, const std::string &defValue)
Parameters P
float Real
Definition definitions.h:41
Distribution * createDistribution(std::default_random_engine &rand)
static Real dt
Definition parameters.h:55
static std::default_random_engine::result_type random_seed
static Boundary * boundary_behaviour_x
static std::string rho_field_name
static Real reflect_downstream_boundary
static std::string mode
static Real precip_inner_boundary
static Real ipshock_inject_y1
static Boundary * boundary_behaviour_z
static std::string input_filename_pattern
static Real ipshock_inject_z1
static Boundary * boundary_behaviour_y
static std::string output_filename_pattern
static bool divide_rhov_by_rho
static uint64_t num_particles
static Real ipshock_inject_z0
static Real ipshock_inject_x1
static Real ipshock_inject_x0
static Real reflect_upstream_boundary
static Real ipshock_inject_y0
static std::string V_field_name