Langevin C++ source

Loading...
Searching...
No Matches
langevin_parameters.hpp
Go to the documentation of this file.
1
11
12#ifndef PARAMETERS_HPP
13#define PARAMETERS_HPP
14
20 struct Parameters
21{
22 public:
23 const double t_final=0;
24 const double dx=0;
25 const double dt=0;
26 const int random_seed=0;
27 const GridDimension grid_dimension=GridDimension::D1;
28 const int_vec_t grid_size={};
29 int n_cells=0;
30 int n_x=0;
31 int n_y=0;
32 int n_z=0;
33 const gt_vec_t grid_topologies = {};
34 const bc_vec_t boundary_conditions = {};
35 const dbl_vec_t bc_values={};
36 const InitialCondition initial_condition=InitialCondition::RANDOM_UNIFORM;
37 const dbl_vec_t ic_values={};
38 const IntegrationMethod integration_method=IntegrationMethod::RUNGE_KUTTA;
39
40 Parameters() = default;
41 Parameters(
42 const double t_final,
43 const double dx, const double dt,
44 const int rs,
45 const GridDimension gd,
46 const int_vec_t gs,
47 const gt_vec_t gts,
48 const bc_vec_t bcs,
49 const dbl_vec_t bcv,
50 const InitialCondition ic,
51 const dbl_vec_t icv,
52 const IntegrationMethod im
53 ) :
54 t_final(t_final),
55 dx(dx), dt(dt),
56 random_seed(rs),
57 grid_dimension(gd),
58 grid_size(gs),
59 grid_topologies(gts),
60 boundary_conditions(bcs),
61 bc_values(bcv),
62 initial_condition(ic),
63 ic_values(icv),
64 integration_method(im)
65 {
66 n_x = gs.at(0);
67 n_y = (gs.size()>1) ? gs.at(1) : 1;
68 n_z = (gs.size()>2) ? gs.at(2) : 1;
69 n_cells = n_x * n_y * n_z;
70 }
71
72 // Use overloading to provide alternate "printout" commands
73 std::string report(GridDimension gd)
74 {
75 switch (gd) {
76 case GridDimension::D1: return "1d";
77 case GridDimension::D2: return "2d";
78 case GridDimension::D3: return "3d";
79 default: return "Unknown";
80 }
81 }
82 std::string report(GridTopology gt)
83 {
84 switch (gt) {
85 case GridTopology::BOUNDED: return "bounded";
86 case GridTopology::PERIODIC: return "periodic";
87 default: return "Unknown";
88 }
89 }
90 std::string report(GridDimension gd, gt_vec_t gts)
91 {
92 std::string combo = "x edge:";
93 combo.append(report(gts.at(0)));
94 if (gd==GridDimension::D2 or gd==GridDimension::D3)
95 {
96 combo.append("; y edge:");
97 combo.append(report(gts.at(1)));
98 }
99 if (gd==GridDimension::D3)
100 {
101 combo.append("; z edge:");
102 combo.append(report(gts.at(2)));
103 }
104 return combo;
105 }
106 std::string report(BoundaryCondition bc)
107 {
108 switch (bc) {
109 case BoundaryCondition::FLOATING: return "floating";
110 case BoundaryCondition::FIXED_VALUE: return "fixed value";
111 case BoundaryCondition::FIXED_FLUX: return "fixed flux";
112 default: return "Unknown";
113 }
114 }
115 std::string report(GridDimension gd, bc_vec_t bcs)
116 {
117 std::string combo = "x0 edge:";
118 combo.append(report(bcs.at(0)));
119 combo.append(", x1 edge:");
120 combo.append(report(bcs.at(1)));
121 if (gd==GridDimension::D2 or gd==GridDimension::D3)
122 {
123 combo.append("; y0 edge:");
124 combo.append(report(bcs.at(2)));
125 combo.append(", y1 edge:");
126 combo.append(report(bcs.at(3)));
127 }
128 if (gd==GridDimension::D3)
129 {
130 combo.append("; z0 edge:");
131 combo.append(report(bcs.at(2)));
132 combo.append(", z1 edge:");
133 combo.append(report(bcs.at(2)));
134 }
135 return combo;
136 }
137 std::string report(InitialCondition ic)
138 {
139 switch (ic) {
140 case InitialCondition::RANDOM_UNIFORM: return "uniform random values";
141 case InitialCondition::RANDOM_GAUSSIAN: return "Gaussian random values";
142 case InitialCondition::CONSTANT_VALUE: return "constant value";
143 case InitialCondition::SINGLE_SEED: return "single seed";
144 default: return "Unknown";
145 }
146 }
147 std::string report(IntegrationMethod im)
148 {
149 switch (im) {
150 case IntegrationMethod::EULER: return "Euler";
151 case IntegrationMethod::RUNGE_KUTTA: return "Runge-Kutta";
152 default: return "Unknown";
153 }
154 }
155
156 void print()
157 {
158 // std::cout << std::endl;
159 std::cout << "t_final: " << t_final << std::endl;
160 std::cout << "dx: " << dx << std::endl;
161 std::cout << "dt: " << dt << std::endl;
162 // std::cout << std::endl;
163 std::cout << "random_seed: " << random_seed << std::endl;
164 std::cout << "grid_dimension: " << report(grid_dimension) << std::endl;
165 std::cout << "grid_size: ";
166 for (const auto& element : grid_size) {std::cout << element << " ";}
167 std::cout << std::endl;
168 std::cout << "n_cells: " << n_cells << std::endl;
169 std::cout << "grid_topologies: "
170 << report(grid_dimension, grid_topologies) << std::endl;
171 std::cout << "boundary_conditions: "
172 << report(grid_dimension, boundary_conditions) << std::endl;
173 std::cout << "bc_values: ";
174 for (const auto& element : bc_values) {std::cout << element << " ";}
175 std::cout << std::endl;
176 std::cout << "initial_condition: "
177 << report(initial_condition) << std::endl;
178 std::cout << "ic_values: ";
179 for (const auto& element : ic_values) {std::cout << element << " ";}
180 std::cout << std::endl;
181 std::cout << "integration_method: "
182 << report(integration_method) << std::endl;
183 std::cout << std::endl;
184 }
185};
186
187#endif
GridTopology
GridTopology
Grid boundary topology: only bounded or periodic (along all edges) implemented so far.
Definition langevin_enums.hpp:34
GridDimension
GridDimension
Density field grid dimension: only 1D or 2D grids implemented so far.
Definition langevin_enums.hpp:15
IntegrationMethod
IntegrationMethod
Deterministic integration method: default is 4th-order Runge-Kutta; can be explicit Euler.
Definition langevin_enums.hpp:58
InitialCondition
InitialCondition
Grid density field initial condition: random uniform or Gaussian variates; constant everywhere; or ce...
Definition langevin_enums.hpp:49
BoundaryCondition
BoundaryCondition
Grid boundary condition: floating/fixed value/fixed flux; application equally to all edges only for n...
Definition langevin_enums.hpp:41
gt_vec_t
std::vector< GridTopology > gt_vec_t
Type for specifying grid topology in each direction x, y, z...
Definition langevin_types.hpp:45
int_vec_t
std::vector< int > int_vec_t
Type for vectors of integers.
Definition langevin_types.hpp:21
dbl_vec_t
std::vector< double > dbl_vec_t
Type for vectors of doubles.
Definition langevin_types.hpp:19