-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathtools.h
More file actions
290 lines (211 loc) · 12.1 KB
/
Copy pathtools.h
File metadata and controls
290 lines (211 loc) · 12.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
// Copyright 2020, the Aether Development Team (see doc/dev_team.md for members)
// Full license can be found in License.md
#ifndef INCLUDE_TOOLS_H_
#define INCLUDE_TOOLS_H_
// ----------------------------------------------------------------------------
// Structure for a 2x2 matrix for a cubesphere:
// ----------------------------------------------------------------------------
struct mat_2x2{
arma_mat A11;
arma_mat A12;
arma_mat A21;
arma_mat A22;
};
// -----------------------------------------------------------------------------
// find interpolation coefficients for a 1D interpolator
// inX is the grid you are interpolating FROM
// outX is the position you want to interpolate TO
// outIndex and outRatio are the interpolation coefficents
// -----------------------------------------------------------------------------
bool find_interpolation_coefficients(arma_vec inX,
arma_vec outX,
arma_vec &outIndex,
arma_vec &outRatio);
// -----------------------------------------------------------------------------
// This takes the index and ratio determined in the above function and
// uses them to interpolate.
// -----------------------------------------------------------------------------
arma_vec interpolate1d(arma_vec inY,
arma_vec &index,
arma_vec &ratio);
// -----------------------------------------------------------------------------
// Set all of the ghost cells to a constant value that is fed in.
// This is primarily for testing of message passing.
// -----------------------------------------------------------------------------
void set_gcs_to_value(arma_cube &var_scgc,
precision_t value,
int64_t nGCs);
// ----------------------------------------------------------------------------
// Fix corners in an arma cube
// - basically fill in the corners with values near them
// ----------------------------------------------------------------------------
void fill_corners(arma_cube &values, int64_t nGCs);
// -----------------------------------------------------------------------------
// add cMember into a string just before last period
// -----------------------------------------------------------------------------
std::string add_cmember(std::string inString);
// ----------------------------------------------------------------------
// Display an armadillo vector
// ----------------------------------------------------------------------
void display_vector(arma_vec vec);
// ----------------------------------------------------------------------
// synchronize a (boolean) variable across all processors
// ----------------------------------------------------------------------
bool sync_across_all_procs(bool value);
// ----------------------------------------------------------------------------
// Find max across all processors and return value to everyone
// ----------------------------------------------------------------------------
precision_t sync_max_across_all_procs(precision_t value);
// ----------------------------------------------------------------------------
// Find min across all processors and return value to everyone
// ----------------------------------------------------------------------------
precision_t sync_min_across_all_procs(precision_t value);
// ----------------------------------------------------------------------------
// Calculate the average value across all processors
// ----------------------------------------------------------------------
precision_t sync_mean_across_all_procs(precision_t value);
// ----------------------------------------------------------------------
// Generate a vector of normally distributed random doubles
// ----------------------------------------------------------------------
std::vector<double> get_normal_random_vect(double mean,
double std,
int64_t nValues,
int seed);
// ----------------------------------------------------------------------
// Generate a vector of uniformly distributed random unsigned ints
// ----------------------------------------------------------------------
std::vector<unsigned int> get_random_unsigned_vect(int64_t nValues,
int seed);
// ----------------------------------------------------------------------
// Make a vector of arma cubes:
// ----------------------------------------------------------------------
std::vector<arma_cube> make_cube_vector(int64_t nLons,
int64_t nLats,
int64_t nAlts,
int64_t nComps);
// ----------------------------------------------------------------------
// Take the dot product between two armadilo cubes
// ----------------------------------------------------------------------
arma_cube dot_product(std::vector<arma_cube> vec1,
std::vector<arma_cube> vec2);
// ----------------------------------------------------------------------
// Take the cross product between two arma cubes
// ----------------------------------------------------------------------
std::vector<arma_cube> cross_product(std::vector<arma_cube> vec1,
std::vector<arma_cube> vec2);
// ----------------------------------------------------------------------
// Convert an armadillo vector to a c++ vector
// ----------------------------------------------------------------------
std::vector<precision_t> make_vector_from_fvec(arma_vec in_fvec);
// ----------------------------------------------------------------------
// Convert a c++ vector to an armadillo vector
// ----------------------------------------------------------------------
arma_vec make_fvec_from_vector(std::vector<precision_t> in_vector);
// ----------------------------------------------------------------------
// Convert an integer to a 0-padded string
// ----------------------------------------------------------------------
std::string tostr(int64_t num_to_convert, int64_t zero_padding_len);
// ----------------------------------------------------------------------
// Convert a string to a number
// ----------------------------------------------------------------------
precision_t str_to_num(std::string input);
// ----------------------------------------------------------------------
// Read a json from a file
// ----------------------------------------------------------------------
json read_json(std::string json_file);
// ----------------------------------------------------------------------
// Write a json to a file
// ----------------------------------------------------------------------
bool write_json(std::string json_file, json json_output);
// ----------------------------------------------------------------------
// Compare two numbers and fail if the difference is too large
// ----------------------------------------------------------------------
bool compare(precision_t value1, precision_t value2);
// ----------------------------------------------------------------------
// calculate mean of vector
// ----------------------------------------------------------------------
precision_t mean(std::vector<precision_t> values);
// ----------------------------------------------------------------------
// calculate standard deviation of vector
// ----------------------------------------------------------------------
precision_t standard_deviation(std::vector<precision_t> values);
//-------------------------------------------------------------
// Get min, mean, and max of an arma_cube
//-------------------------------------------------------------
std::vector<precision_t> get_min_mean_max(const arma_cube &value);
//-------------------------------------------------------------
// Find the name of given species in neutrals and ions. Throw
// exception if not found
//-------------------------------------------------------------
const arma_cube& find_species_density(const std::string &name,
Neutrals &neutrals,
Ions &ions);
//-------------------------------------------------------------
// Get min, mean, and max of either a neutral or ion species
//-------------------------------------------------------------
std::vector<precision_t> get_min_mean_max_density(const std::string &name,
Neutrals &neutrals,
Ions &ions);
//-------------------------------------------------------------
// Checks whether two arma vectors are approximately equal
//-------------------------------------------------------------
bool is_approx_equal(arma_vec &vec1, arma_vec &vec2, precision_t tol);
//-------------------------------------------------------------
// Overload col vector function with row vec
//-------------------------------------------------------------
bool is_approx_equal(Row<precision_t> &vec1, Row<precision_t> &vec2, precision_t tol);
//-------------------------------------------------------------
// Checks whether a vector is constant (all values the same)
// Method uses variance as a factor
//-------------------------------------------------------------
bool is_approx_constant(arma_vec &vec, precision_t tol);
// --------------------------------------------------------------------------
// Convert spherical vector (velocities) to reference (contravariant) vector
// Units of the velocities and transformation laws must be the same
// u and v are spherical velocities
// u1 and u2 are contravariant velocities
// --------------------------------------------------------------------------
void sphvect2ref(arma_mat& u, arma_mat& v, arma_mat& u1, arma_mat& u2, mat_2x2 &A_inv_mat);
// --------------------------------------------------------------------------
// Convert spherical vector (velocities) to reference (contravariant) vector
// Units of the velocities and transformation laws must be the same
// u and v are spherical velocities
// u1 and u2 are contravariant velocities
// --------------------------------------------------------------------------
void refvect2sph(arma_mat &u1, arma_mat &u2, arma_mat &u, arma_mat &v, mat_2x2 &A_mat);
//-----------------------------------------------------------------------
// Checks if armacube(s) has all finite values, if not, adds them to
// errors in report class
//-----------------------------------------------------------------------
bool all_finite(arma_cube cube, std::string name);
bool all_finite(std::vector<arma_cube> cubes, std::string name);
//-----------------------------------------------------------------------
// Takes an index of an armacube and converts it to latitude,
// longitude, and altitude
//-----------------------------------------------------------------------
std::vector<int> index_to_ijk(arma_cube cube, int index);
//-----------------------------------------------------------------------
// Inserts 3 nans and 3 inf into the specified armacube(s)
//-----------------------------------------------------------------------
std::vector<int> insert_indefinites(arma_cube &cube);
//-----------------------------------------------------------------------
// Returns a vector of ints as a string with spaces in between
//-----------------------------------------------------------------------
std::string print_nan_vector(std::vector<int> input, arma_cube cube);
//-----------------------------------------------------------------------
// Returns whether a given arma cube has all finite values
//-----------------------------------------------------------------------
bool is_finite(arma_cube &cube);
//-----------------------------------------------------------------------
//Returns whether the double/float value is a nan or infinity
//-----------------------------------------------------------------------
bool is_nan_inf(double value);
//-----------------------------------------------------------------------
// Returns vector of indefinite values
//-----------------------------------------------------------------------
std::vector<int> indef_vector(arma_cube cube);
// --------------------------------------------------------------------------
// Project a point described by lon and lat to a point on a surface of the 2-2-2 cube
// --------------------------------------------------------------------------
arma_vec sphere_to_cube(precision_t lon_in, precision_t lat_in);
#endif // INCLUDE_TOOLS_H_