@@ -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;
0 commit comments