2 #define FUNCTIONS_HPP 1 33 int Nprocs_in_time, Nprocs_in_depth;
36 std::vector<double> time, depth, latitude, longitude;
37 int Ntime = -1, Ndepth = -1, Nlat = -1, Nlon = -1;
38 int full_Ntime = -1, full_Ndepth = -1;
41 MPI_Comm MPI_Comm_Global = MPI_COMM_WORLD;
42 MPI_Comm MPI_subcomm_sametimes;
43 MPI_Comm MPI_subcomm_samedepths;
46 std::vector<double> areas;
49 bool compute_radial_vel =
false,
50 use_depth_derivatives =
false,
51 depth_is_elevation =
false,
52 depth_is_increasing =
true;
55 std::map< std::string , std::vector<double> > variables;
59 std::vector< std::string > region_names;
60 std::map< std::string, std::vector<bool> > regions;
61 std::vector<double> region_areas, region_areas_water_only;
64 std::vector<double> coarse_map_lat, coarse_map_lon, coarse_map_areas;
67 std::vector<bool> mask, reference_mask, mask_DEPTH;
71 std::vector<int> myCounts, myStarts;
81 void load_time(
const std::string dim_name,
const std::string filename );
82 void load_depth(
const std::string dim_name,
const std::string filename );
83 void load_latitude(
const std::string dim_name,
const std::string filename );
84 void load_longitude(
const std::string dim_name,
const std::string filename );
87 void compute_cell_areas();
90 void load_variable(
const std::string var_name,
91 const std::string var_name_in_file,
92 const std::string filename,
93 const bool read_mask =
true,
94 const bool load_counts =
true,
95 const bool do_splits =
true );
98 void load_region_definitions(
const std::string filename,
99 const std::string dim_name,
100 const std::string var_name,
101 const MPI_Comm = MPI_COMM_WORLD );
102 void compute_region_areas();
105 void prepare_for_coarsened_grids(
const std::string filename,
106 const MPI_Comm = MPI_COMM_WORLD );
109 void check_processor_divisions(
const int Nprocs_in_time_input,
110 const int Nprocs_in_depth_input,
111 const MPI_Comm = MPI_COMM_WORLD );
115 void gather_variable_across_depth(
const std::vector<double> & var,
116 std::vector<double> & gathered_var )
const ;
117 void gather_mask_across_depth(
const std::vector<bool> & var,
118 std::vector<bool> & gathered_var
122 size_t local_index(
const int Itime,
127 size_t global_index(
const int Itime,
131 const std::string merge_kind
133 size_t index_local_to_global(
const size_t index,
const std::string merge_kind )
const;
134 size_t index_global_to_local(
const size_t index,
const std::string merge_kind )
const;
135 void index1to4_local(
const size_t index,
136 int & Itime,
int & Idepth,
int & Ilat,
int & Ilon
138 void index1to4_global(
const size_t index,
139 int & Itime,
int & Idepth,
int & Ilat,
int & Ilon,
140 const std::string merge_kind
147 std::vector<double> & areas,
148 const std::vector<double> & longitude,
149 const std::vector<double> & latitude);
151 size_t Index(
const int Itime,
const int Idepth,
const int Ilat,
const int Ilon,
152 const int Ntime,
const int Ndepth,
const int Nlat,
const int Nlon );
155 int & Itime,
int & Idepth,
int & Ilat,
int & Ilon,
156 const int & Ntime,
const int & Ndepth,
const int & Nlat,
const int & Nlon );
158 double distance(
const double lon1,
const double lat1,
159 const double lon2,
const double lat2,
160 const double Llon = 0,
const double Llat = 0);
163 std::vector<double> & local_kernel,
166 const int Ilat,
const int Ilon,
167 const int LAT_lb,
const int LAT_ub);
170 std::vector<double> & KE,
171 std::vector<double> * u1,
172 std::vector<double> * u2,
173 std::vector<double> * u3,
174 const std::vector<bool> & mask,
179 std::vector<double> & u_x,
180 std::vector<double> & u_y,
181 std::vector<double> & u_z,
182 const std::vector<double> & u_r,
183 const std::vector<double> & u_lon,
184 const std::vector<double> & u_lat,
201 std::vector<double> & u_r,
202 std::vector<double> & u_lon,
203 std::vector<double> & u_lat,
204 const std::vector<double> & u_x,
205 const std::vector<double> & u_y,
206 const std::vector<double> & u_z,
223 const std::vector<double> & scales,
224 const MPI_Comm comm = MPI_COMM_WORLD);
228 const std::vector<double> & scales,
229 const MPI_Comm comm = MPI_COMM_WORLD
233 std::vector<double*> & coarse_val,
234 const std::vector<
const std::vector<double>*> & fields,
236 const int Itime,
const int Idepth,
const int Ilat,
const int Ilon,
240 const std::vector<bool> & use_mask,
241 const std::vector<double> & local_kernel,
242 const std::vector<double> * weight = NULL
251 double & vort_lon_tmp,
252 double & vort_lat_tmp,
254 double & OkuboWeiss_tmp,
256 const std::vector<double> & u_r,
257 const std::vector<double> & u_lon,
258 const std::vector<double> & u_lat,
259 const int Itime,
const int Idepth,
const int Ilat,
const int Ilon);
262 std::vector<double> & vort_r,
263 std::vector<double> & vort_lon,
264 std::vector<double> & vort_lat,
265 std::vector<double> & vel_div,
266 std::vector<double> & OkuboWeiss,
268 const std::vector<double> & u_r,
269 const std::vector<double> & u_lon,
270 const std::vector<double> & u_lat,
271 const MPI_Comm comm = MPI_COMM_WORLD);
274 double & uxux_tmp,
double & uxuy_tmp,
double & uxuz_tmp,
275 double & uyuy_tmp,
double & uyuz_tmp,
double & uzuz_tmp,
276 double & vort_ux_tmp,
double & vort_uy_tmp,
double & vort_uz_tmp,
277 const std::vector<double> & u_x,
278 const std::vector<double> & u_y,
279 const std::vector<double> & u_z,
280 const std::vector<double> & vort_r,
282 const int Itime,
const int Idepth,
const int Ilat,
const int Ilon,
283 const int LAT_lb,
const int LAT_ub,
285 const std::vector<double> & local_kernel);
288 std::vector<double> & energy_transfer,
290 const std::vector<double> & ux,
291 const std::vector<double> & uy,
292 const std::vector<double> & uz,
293 const std::vector<double> & uxux,
294 const std::vector<double> & uxuy,
295 const std::vector<double> & uxuz,
296 const std::vector<double> & uyuy,
297 const std::vector<double> & uyuz,
298 const std::vector<double> & uzuz,
299 const MPI_Comm comm = MPI_COMM_WORLD);
302 std::vector<double> & energy_transfer,
304 const std::vector<double> & ux,
305 const std::vector<double> & uy,
306 const std::vector<double> & uz,
307 const std::vector<double> & uxux,
308 const std::vector<double> & uxuy,
309 const std::vector<double> & uxuz,
310 const std::vector<double> & uyuy,
311 const std::vector<double> & uyuz,
312 const std::vector<double> & uzuz,
313 const MPI_Comm comm = MPI_COMM_WORLD);
316 std::vector<double> & energy_transfer,
318 const std::vector<double> & ulon,
319 const std::vector<double> & ulat,
320 const std::vector<double> & ulon_ulon,
321 const std::vector<double> & ulon_ulat,
322 const std::vector<double> & ulat_ulat,
323 const MPI_Comm comm = MPI_COMM_WORLD
327 std::vector<double> & enstrophy_transfer,
329 const std::vector<double> & ux,
330 const std::vector<double> & uy,
331 const std::vector<double> & uz,
332 const std::vector<double> & coarse_vort_r,
333 const std::vector<double> & vort_ux,
334 const std::vector<double> & vort_uy,
335 const std::vector<double> & vort_uz,
336 const MPI_Comm comm = MPI_COMM_WORLD);
338 void compute_Lambda_rotational(
339 std::vector<double> & Lambda_rot,
340 const std::vector<double> & coarse_vort_r,
341 const std::vector<double> & coarse_vort_lon,
342 const std::vector<double> & coarse_vort_lat,
343 const std::vector<double> & coarse_rho,
344 const std::vector<double> & coarse_p,
345 const int Ntime,
const int Ndepth,
const int Nlat,
const int Nlon,
346 const std::vector<double> & longitude,
347 const std::vector<double> & latitude,
348 const std::vector<bool> & mask,
349 const double scale_factor
353 void compute_Lambda_full(
354 std::vector<double> & Lambda,
355 const std::vector<double> & coarse_u_r,
356 const std::vector<double> & coarse_u_lon,
357 const std::vector<double> & coarse_u_lat,
358 const std::vector<double> & tilde_u_r,
359 const std::vector<double> & tilde_u_lon,
360 const std::vector<double> & tilde_u_lat,
361 const std::vector<double> & coarse_p,
366 const std::vector<double> & longitude,
367 const std::vector<double> & latitude,
368 const std::vector<bool> & mask
371 void compute_Lambda_nonlin_model(
372 std::vector<double> & Lambda_nonlin,
373 const std::vector<double> & coarse_u_r,
374 const std::vector<double> & coarse_u_lon,
375 const std::vector<double> & coarse_u_lat,
376 const std::vector<double> & coarse_rho,
377 const std::vector<double> & coarse_p,
378 const int Ntime,
const int Ndepth,
const int Nlat,
const int Nlon,
379 const std::vector<double> & longitude,
380 const std::vector<double> & latitude,
381 const std::vector<bool> & mask,
382 const double scale_factor
395 std::vector<double> & div_J,
397 const std::vector<double> & u_x,
398 const std::vector<double> & u_y,
399 const std::vector<double> & u_z,
400 const std::vector<double> & uxux,
401 const std::vector<double> & uxuy,
402 const std::vector<double> & uxuz,
403 const std::vector<double> & uyuy,
404 const std::vector<double> & uyuz,
405 const std::vector<double> & uzuz,
406 const std::vector<double> & coarse_p,
407 const MPI_Comm comm = MPI_COMM_WORLD
411 std::vector<double> & means,
412 const std::vector<double> & field,
413 const std::vector<double> & areas,
418 const std::vector<bool> & mask);
423 const std::vector<double> & latitude,
430 const std::vector<double> & longitude,
432 const double centre_lat,
433 const double curr_lat,
437 const std::vector<double> * scales = NULL);
443 std::vector<double> & longitude,
444 std::vector<double> & latitude
448 const std::vector<double> & latitude,
449 std::vector<bool> & mask,
458 std::vector<double> & field_to_roll,
459 const std::string dimension,
460 const int roll_count,
470 void extend_latitude_to_poles(
471 const std::vector<double> & original_latitude,
472 std::vector<double> & extended_latitude,
473 int & orig_Ilat_start,
474 const bool IS_DEGREES =
false,
475 const MPI_Comm comm = MPI_COMM_WORLD
478 void extend_field_to_poles(
479 std::vector<double> & array_to_extend,
481 const std::vector<double> & extended_latitude,
485 void extend_mask_to_poles(
486 std::vector<bool> & mask_to_extend,
488 const std::vector<double> & extended_latitude,
489 const int Ilat_start,
513 void add_to_record(
const double delta,
const std::string record_name );
524 std::map< std::string, double > time_records;
545 const std::string getCmdOption(
546 const std::string &option,
547 const std::string &default_value =
"",
548 const bool help =
false,
549 const std::string &description =
"" 555 bool cmdOptionExists(
const std::string &option)
const;
561 void getFilterScales(
562 std::vector<double> &filter_scales,
563 const std::string &argname,
564 const bool help =
false 571 void getListofStrings(
572 std::vector<std::string> &list_of_strings,
573 const std::string &argname,
574 const bool help =
false,
575 const std::string &description =
"" 579 std::vector <std::string> tokens;
588 void print_header_info( );
void KE_from_vels(std::vector< double > &KE, std::vector< double > *u1, std::vector< double > *u2, std::vector< double > *u3, const std::vector< bool > &mask, const double rho0=constants::rho0)
Compute (local) KE density from the provided velocities.
Definition: KE_from_vels.cpp:16
void Index1to4(const size_t index, int &Itime, int &Idepth, int &Ilat, int &Ilon, const int &Ntime, const int &Ndepth, const int &Nlat, const int &Nlon)
Convenience tool to convert logical index to physical index (time, depth, lat, lon).
Definition: Index1to4.cpp:18
void compute_div_transport(std::vector< double > &div_J, const dataset &source_data, const std::vector< double > &u_x, const std::vector< double > &u_y, const std::vector< double > &u_z, const std::vector< double > &uxux, const std::vector< double > &uxuy, const std::vector< double > &uxuz, const std::vector< double > &uyuy, const std::vector< double > &uyuz, const std::vector< double > &uzuz, const std::vector< double > &coarse_p, const MPI_Comm comm=MPI_COMM_WORLD)
Compute KE transport caused by div(J)
Definition: compute_div_transport.cpp:92
const double rho0
Mean fluid density.
Definition: constants.hpp:76
void vel_Cart_to_Spher_at_point(double &u_r, double &u_lon, double &u_lat, const double u_x, const double u_y, const double u_z, const double lon, const double lat)
Convert single Cartesian velocity to spherical velocity.
Definition: vel_Cart_to_Spher_at_point.cpp:28
void get_lon_bounds(int &LON_lb, int &LON_ub, const std::vector< double > &longitude, const int Ilon, const double centre_lat, const double curr_lat, const double scale)
Get longitude integratation bounds for a specific latitude.
Definition: get_lon_bounds.cpp:22
void compute_Pi_shift_deriv(std::vector< double > &energy_transfer, const dataset &source_data, const std::vector< double > &ux, const std::vector< double > &uy, const std::vector< double > &uz, const std::vector< double > &uxux, const std::vector< double > &uxuy, const std::vector< double > &uxuz, const std::vector< double > &uyuy, const std::vector< double > &uyuz, const std::vector< double > &uzuz, const MPI_Comm comm=MPI_COMM_WORLD)
Compute the energy transfer through the current filter scale.
Definition: compute_Pi_shift_deriv.cpp:21
void compute_Z(std::vector< double > &enstrophy_transfer, const dataset &source_data, const std::vector< double > &ux, const std::vector< double > &uy, const std::vector< double > &uz, const std::vector< double > &coarse_vort_r, const std::vector< double > &vort_ux, const std::vector< double > &vort_uy, const std::vector< double > &vort_uz, const MPI_Comm comm=MPI_COMM_WORLD)
Compute the enstrophy transfer through the current filter scale.
Definition: compute_Z.cpp:25
size_t Index(const int Itime, const int Idepth, const int Ilat, const int Ilon, const int Ntime, const int Ndepth, const int Nlat, const int Nlon)
Convenience tool to convert physical index (time, depth, lat, lon) to a logical index.
Definition: Index.cpp:19
void compute_vorticity(std::vector< double > &vort_r, std::vector< double > &vort_lon, std::vector< double > &vort_lat, std::vector< double > &vel_div, std::vector< double > &OkuboWeiss, const dataset &source_data, const std::vector< double > &u_r, const std::vector< double > &u_lon, const std::vector< double > &u_lat, const MPI_Comm comm=MPI_COMM_WORLD)
Wrapper for computing vorticity.
Definition: compute_vorticity.cpp:22
double depotential_temperature(const double p, const double theta)
Convert potential temperature to actual temperature following equation 1.154a from Vallis (p...
Definition: depotential_temperature.cpp:13
void get_lat_bounds(int &LAT_lb, int &LAT_ub, const std::vector< double > &latitude, const int Ilat, const double scale)
Get latitude bounds for coarse-graining.
Definition: get_lat_bounds.cpp:19
double kernel(const double distance, const double scale)
Primary kernel function coarse-graining procedure (G in publications)
Definition: kernel.cpp:30
void mask_out_pole(const std::vector< double > &latitude, std::vector< bool > &mask, const int Ntime, const int Ndepth, const int Nlat, const int Nlon)
If the grid includes the poles (lat = 90 degrees), then mask it out.
Definition: mask_out_pole.cpp:21
void filtering(const dataset &source_data, const std::vector< double > &scales, const MPI_Comm comm=MPI_COMM_WORLD)
Main filtering driver.
Definition: filtering.cpp:23
void compute_vorticity_at_point(double &vort_r_tmp, double &vort_lon_tmp, double &vort_lat_tmp, double &div_tmp, double &OkuboWeiss_tmp, const dataset &source_data, const std::vector< double > &u_r, const std::vector< double > &u_lon, const std::vector< double > &u_lat, const int Itime, const int Idepth, const int Ilat, const int Ilon)
Compute the vorticity, divergnce, and OkuboWeiss at a point.
Definition: compute_vorticity_at_point.cpp:24
void roll_field(std::vector< double > &field_to_roll, const std::string dimension, const int roll_count, const int Ntime, const int Ndepth, const int Nlat, const int Nlon)
Roll field along dimension.
Definition: roll_field.cpp:19
void vel_Cart_to_Spher(std::vector< double > &u_r, std::vector< double > &u_lon, std::vector< double > &u_lat, const std::vector< double > &u_x, const std::vector< double > &u_y, const std::vector< double > &u_z, const dataset &source_data)
Wrapper that applies vel_Spher_to_Cart_at_point to every point in the domain.
Definition: vel_Cart_to_Spher.cpp:13
Class to store main variables.
Definition: functions.hpp:24
void compute_local_kernel(std::vector< double > &local_kernel, const double scale, const dataset &source_data, const int Ilat, const int Ilon, const int LAT_lb, const int LAT_ub)
Compute an array of the kernel values from a given reference point to every other point in the domain...
Definition: compute_local_kernel.cpp:22
void convert_coordinates(std::vector< double > &longitude, std::vector< double > &latitude)
Apply degree->radian conversion, if necessary. Applied in-place.
Definition: convert_coordinates.cpp:19
void compute_spatial_average(std::vector< double > &means, const std::vector< double > &field, const std::vector< double > &areas, const int Ntime, const int Ndepth, const int Nlat, const int Nlon, const std::vector< bool > &mask)
Given a field, compute the horizontal average.
Definition: compute_spatial_average.cpp:21
void filtering_helmholtz(const dataset &source_data, const std::vector< double > &scales, const MPI_Comm comm=MPI_COMM_WORLD)
Main filtering driver for Helmholtz decomposed data.
Definition: filtering_helmholtz.cpp:24
double kernel_alpha(void)
Compute alpha value for kernel (for baroclinic transfer)
Definition: kernel_alpha.cpp:12
void apply_filter_at_point(std::vector< double *> &coarse_val, const std::vector< const std::vector< double > *> &fields, const dataset &source_data, const int Itime, const int Idepth, const int Ilat, const int Ilon, const int LAT_lb, const int LAT_ub, const double scale, const std::vector< bool > &use_mask, const std::vector< double > &local_kernel, const std::vector< double > *weight=NULL)
Compute filtered field at a single point.
Definition: apply_filter_at_point.cpp:25
Provide namespace for global constants (physical and computational).
void compute_Pi_Helmholtz(std::vector< double > &energy_transfer, const dataset &source_data, const std::vector< double > &ulon, const std::vector< double > &ulat, const std::vector< double > &ulon_ulon, const std::vector< double > &ulon_ulat, const std::vector< double > &ulat_ulat, const MPI_Comm comm=MPI_COMM_WORLD)
Compute the energy transfer through the current filter scale.
Definition: compute_Pi_Helmholtz.cpp:22
Class for storing internal timings.
Definition: functions.hpp:499
double equation_of_state(const double T, const double S, const double p)
UNESCO 1981 equation of state.
Definition: equation_of_state.cpp:18
int get_omp_chunksize(const int Nlat, const int Nlon)
Compute openmp chunk size for OMP for loops.
Definition: get_omp_chunksize.cpp:18
void vel_Spher_to_Cart(std::vector< double > &u_x, std::vector< double > &u_y, std::vector< double > &u_z, const std::vector< double > &u_r, const std::vector< double > &u_lon, const std::vector< double > &u_lat, const dataset &source_data)
Wrapper that applies vel_Spher_to_Cart_at_point to every point in the domain.
Definition: vel_Spher_to_Cart.cpp:13
void vel_Spher_to_Cart_at_point(double &u_x, double &u_y, double &u_z, const double u_r, const double u_lon, const double u_lat, const double lon, const double lat)
Convert single spherical velocity to Cartesian velocity.
Definition: vel_Spher_to_Cart_at_point.cpp:28
bool string_to_bool(std::string str)
Convert string to boolean.
Definition: string_to_bool.cpp:12
double distance(const double lon1, const double lat1, const double lon2, const double lat2, const double Llon=0, const double Llat=0)
Compute the distance (in metres) between two points in the domain.
Definition: distance.cpp:25
const bool FILTER_OVER_LAND
Boolean to indicate whether or not land values should be filled in with coarse-grained results...
Definition: constants.hpp:127
void apply_filter_at_point_for_quadratics(double &uxux_tmp, double &uxuy_tmp, double &uxuz_tmp, double &uyuy_tmp, double &uyuz_tmp, double &uzuz_tmp, double &vort_ux_tmp, double &vort_uy_tmp, double &vort_uz_tmp, const std::vector< double > &u_x, const std::vector< double > &u_y, const std::vector< double > &u_z, const std::vector< double > &vort_r, const dataset &source_data, const int Itime, const int Idepth, const int Ilat, const int Ilon, const int LAT_lb, const int LAT_ub, const double scale, const std::vector< double > &local_kernel)
Compute filtered quadratic velocities at a single point.
Definition: apply_filter_at_point_for_quadratics.cpp:34
void print_compile_info(const std::vector< double > *scales=NULL)
Print summary of compile-time variables.
Definition: print_compile_info.cpp:16
void compute_Pi(std::vector< double > &energy_transfer, const dataset &source_data, const std::vector< double > &ux, const std::vector< double > &uy, const std::vector< double > &uz, const std::vector< double > &uxux, const std::vector< double > &uxuy, const std::vector< double > &uxuz, const std::vector< double > &uyuy, const std::vector< double > &uyuz, const std::vector< double > &uzuz, const MPI_Comm comm=MPI_COMM_WORLD)
Compute the energy transfer through the current filter scale.
Definition: compute_Pi.cpp:21
void compute_areas(std::vector< double > &areas, const std::vector< double > &longitude, const std::vector< double > &latitude)
Compute the area of each computational cell.
Definition: compute_areas.cpp:19