Skip to content

Commit ce962ed

Browse files
authored
Merge pull request #184 from AetherModel/messagepass_grids
This is for message passing between two grids within Aether.
2 parents c6fa64f + 5cd781c commit ce962ed

File tree

8 files changed

+716
-128
lines changed

8 files changed

+716
-128
lines changed

include/calc_grid_derived.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,14 @@ arma_vec calc_bin_widths(arma_vec centers);
1919
// ----------------------------------------------------------------------------
2020
// A helper function for mapping grids
2121
// ----------------------------------------------------------------------------
22-
bool grid_match(Grid gGrid,
23-
Grid mGrid,
22+
bool grid_match(Grid &gGrid,
23+
Grid &mGrid,
2424
Quadtree gQuadtree,
2525
Quadtree mQuadtree);
2626

27+
bool get_data_from_other_grid(Grid &gGrid,
28+
Grid &mGrid,
29+
arma_cube &gData,
30+
arma_cube &mData);
31+
2732
#endif // INCLUDE_CALC_GRID_DERIVED_H_

include/grid.h

Lines changed: 81 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,53 @@ struct cubesphere_chars {
4545
// Grid class
4646
// ----------------------------------------------------------------------------
4747

48-
class Grid {
48+
struct interp_coef_t {
49+
// The point is inside the cube of:
50+
// [iRow, iRow+1], [iCol, iCol+1] [iAlt, iAlt+1]
51+
uint64_t iRow;
52+
uint64_t iCol;
53+
uint64_t iAlt;
54+
// The coefficients along row, column and altitude
55+
precision_t rRow;
56+
precision_t rCol;
57+
precision_t rAlt;
58+
// Whether the point is within this grid or not
59+
bool in_grid;
60+
// If this is set to true:
61+
bool above_grid, below_grid;
62+
// do interpolation in lat and lon, but extrapolate in altitude
63+
};
64+
65+
struct grid_to_grid_t {
66+
int64_t iProcTo;
67+
int64_t nPts;
68+
int64_t nPtsReceive;
69+
std::vector<struct interp_coef_t> interpCoefs;
70+
std::vector<precision_t *> valueToSend;
71+
std::vector<precision_t *> valueToReceive;
72+
};
4973

74+
class Grid {
5075
public:
5176
int iGridShape_ = -1;
52-
// Armidillo Cube Versions:
77+
// The index and coefficient used for interpolation
78+
// Each point is processed by the function set_interpolation_coefs and stored
79+
// in the form of this structure.
80+
// If the point is out of the grid, in_grid = false and all other members are undefined
81+
82+
std::vector<struct grid_to_grid_t> gridToGridCoefs;
83+
arma::Cube<int> gridToGridMap;
84+
85+
// Armadillo Cube Versions:
5386
// Cell Center Coordinates
5487
arma_cube geoLon_scgc, geoX_scgc;
5588
arma_cube geoLat_scgc, geoY_scgc;
5689
arma_cube geoAlt_scgc, geoZ_scgc;
5790
arma_cube geoLocalTime_scgc;
5891

92+
// This is an array for testing things:
93+
arma_cube test_scgc;
94+
5995
// Reference coordinate
6096
arma_cube refx_scgc, refy_scgc;
6197

@@ -508,6 +544,21 @@ class Grid {
508544
bool areLocsGeo = true,
509545
bool areLocsIJK = true);
510546

547+
/**
548+
* \brief Set the interpolation coefficients
549+
* \param Lons The longitude of points
550+
* \param Lats The latitude of points
551+
* \param Alts The altitude of points
552+
* \pre This instance is an geo grid
553+
* \pre Lons, Lats and Alts have the same size
554+
* \return list of interpolation coefficients
555+
*/
556+
557+
std::vector<struct interp_coef_t> get_interpolation_coefs(
558+
const std::vector<precision_t> &Lons,
559+
const std::vector<precision_t> &Lats,
560+
const std::vector<precision_t> &Alts);
561+
511562
/**
512563
* \brief Set the interpolation coefficients for the dipole grid
513564
* \param Lons The longitude of points
@@ -530,6 +581,8 @@ class Grid {
530581
* an empty vector if the data is not the same size as the geo grid.
531582
*/
532583
std::vector<precision_t> get_interpolation_values(const arma_cube &data) const;
584+
std::vector<precision_t> get_interpolation_values(arma_cube data,
585+
std::vector<struct interp_coef_t> coefArray);
533586

534587
private:
535588
bool IsGeoGrid;
@@ -608,22 +661,24 @@ class Grid {
608661
precision_t alt_max;
609662
};
610663

664+
// Return the index of the last element that has altitude smaller than or euqal to the input
665+
uint64_t search_altitude(const precision_t alt_in) const;
611666
// The index and coefficient used for interpolation
612667
// Each point is processed by the function set_interpolation_coefs and stored
613668
// in the form of this structure.
614669
// If the point is out of the grid, in_grid = false and all other members are undefined
615-
struct interp_coef_t {
616-
// The point is inside the cube of [iRow, iRow+1], [iCol, iCol+1], [iAlt, iAlt+1]
617-
uint64_t iRow;
618-
uint64_t iCol;
619-
uint64_t iAlt;
620-
// The coefficients along row, column and altitude
621-
precision_t rRow;
622-
precision_t rCol;
623-
precision_t rAlt;
624-
// Whether the point is within this grid or not
625-
bool in_grid;
626-
};
670+
//struct interp_coef_t {
671+
// // The point is inside the cube of [iRow, iRow+1], [iCol, iCol+1], [iAlt, iAlt+1]
672+
// uint64_t iRow;
673+
// uint64_t iCol;
674+
// uint64_t iAlt;
675+
// // The coefficients along row, column and altitude
676+
// precision_t rRow;
677+
// precision_t rCol;
678+
// precision_t rAlt;
679+
// // Whether the point is within this grid or not
680+
// bool in_grid;
681+
//};
627682

628683
// Calculate the range of a spherical grid
629684
void get_sphere_grid_range(struct sphere_range &sr) const;
@@ -633,19 +688,19 @@ class Grid {
633688
void get_dipole_grid_range(struct dipole_range &dr) const;
634689

635690
// Helper function for set_interpolation_coefs
636-
void set_interp_coef_sphere(const sphere_range &sr,
637-
const precision_t lon_in,
638-
const precision_t lat_in,
639-
const precision_t alt_in);
640-
void set_interp_coef_cubesphere(const cubesphere_range &cr,
641-
const precision_t lon_in,
642-
const precision_t lat_in,
643-
const precision_t alt_in);
691+
struct interp_coef_t get_interp_coef_sphere(const sphere_range &sr,
692+
const precision_t lon_in,
693+
const precision_t lat_in,
694+
const precision_t alt_in);
695+
struct interp_coef_t get_interp_coef_cubesphere(const cubesphere_range &cr,
696+
const precision_t lon_in,
697+
const precision_t lat_in,
698+
const precision_t alt_in);
644699
// (note these are magnetic coordinates)
645-
void set_interp_coef_dipole(const dipole_range &dr,
646-
const precision_t lon_in,
647-
const precision_t lat_in,
648-
const precision_t alt_in);
700+
struct interp_coef_t get_interp_coef_dipole(const dipole_range &dr,
701+
const precision_t lon_in,
702+
const precision_t lat_in,
703+
const precision_t alt_in);
649704

650705
// Processed interpolation coefficients
651706
std::vector<struct interp_coef_t> interp_coefs;

src/advance.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ bool advance(Planets &planet,
4646
didWork = neutralsMag.check_for_nonfinites("Top of Advance - ion grid");
4747
}
4848

49+
// here we are going to grab stuff from the neutral grid and put it on the
50+
// ion grid
51+
didWork = get_data_from_other_grid(gGrid, mGrid, neutrals.temperature_scgc, mGrid.test_scgc);
52+
4953
json dummy = indices.get_all_indices(time.get_current());
5054

5155
gGrid.calc_sza(planet, time);

src/grid.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ Grid::Grid(std::string gridtype) {
9797
geoAlt_scgc.set_size(nX, nY, nZ);
9898
geoLocalTime_scgc.set_size(nX, nY, nZ);
9999

100+
test_scgc.set_size(nX, nY, nZ);
101+
test_scgc.zeros();
102+
100103
refx_scgc.set_size(nX, nY, nZ);
101104
refy_scgc.set_size(nX, nY, nZ);
102105
refx_angle.set_size(nX, nY, nZ);

0 commit comments

Comments
 (0)