Debian Codegraph @

src/atlas/projection/detail/CubedSphereProjectionBase.h

raw
1 /*
2 * (C) Copyright 2020 UCAR
3 *
4 * This software is licensed under the terms of the Apache Licence Version 2.0
5 * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6 */
7
8 #pragma once
9
10 #include "atlas/grid/Tiles.h"
11 #include "atlas/library/config.h"
12 #include "atlas/projection/Jacobian.h"
13 #include "atlas/projection/detail/ProjectionImpl.h"
14 #include "eckit/config/Parametrisation.h"
15 #include "eckit/utils/Hash.h"
16
17 namespace atlas {
18 class CubedSphereTiles;
19 }
20
21 namespace atlas {
22 namespace projection {
23 namespace detail {
24
25 class CubedSphereProjectionBase : public ProjectionImpl {
26 public:
27 using ProjectionImpl::jacobian;
28
29 // constructor
30 CubedSphereProjectionBase(const eckit::Parametrisation&);
31
32 void hash(eckit::Hash&) const;
33
34 const atlas::grid::CubedSphereTiles& getCubedSphereTiles() const { return tiles_; };
35
36 /// @brief Convert (x, y) coordinate to (alpha, beta) on tile t.
37 ///
38 /// @details Converts the Atlas xy coordinates to the angular coordinates
39 /// described of tile t, described by by Ronchi et al. (1996,
40 /// Journal of Computational Physics, 124, 93).
41 /// Note that the xy coordinate must lie within the domain
42 /// (x <= xmin && x >= xmax) || (y <= ymin && y >= ymax) where
43 /// xmin, xmax, ymin and ymax are the boundaries of tile t.
44 ///@{
45 Point2 xy2alphabeta(const Point2& xy, idx_t t) const;
46 virtual void xy2alphabeta(double crd[], idx_t t) const = 0;
47 ///@}
48
49 /// @brief Convert (alpha, beta) coordinate to (x, y) on tile t.
50 ///
51 /// @details Performs the inverse of xy2alpha beta. Note that the result is
52 /// degenerate when abs(alpha) > 45 && abs(beta) > 45 &&
53 /// abs(alpha) == abs(beta). In these circumstances, the method
54 /// will return the anticlockwise-most of the two possible
55 /// values.
56 ///@{
57 Point2 alphabeta2xy(const Point2& alphabeta, idx_t t) const;
58 virtual void alphabeta2xy(double crd[], idx_t) const = 0;
59 ///@}
60
61 /// @brief Convert (lon, lat) coordinate to (alpha, beta) on tile t
62 ///
63 /// @details Converts the lon lat coordinates to the angular coordinates
64 /// described of tile t, described by by Ronchi et al. (1996,
65 /// Journal of Computational Physics, 124, 93).
66 /// @{
67 Point2 lonlat2alphabeta(const Point2& lonlat, idx_t t) const;
68 virtual void lonlat2alphabeta(double crd[], idx_t) const = 0;
69 /// @}
70
71 /// @brief Convert (lon, lat) coordinate to (alpha, beta) on tile t
72 ///
73 /// @details Performs the inverse of lonlat2alphabeta.
74 ///
75 Point2 alphabeta2lonlat(const Point2& alphabeta, idx_t t) const;
76 virtual void alphabeta2lonlat(double crd[], idx_t) const = 0;
77
78 /// @brief Jacobian of (x, y) with respect to (lon, lat) on tile t
79 ///
80 /// @details Returns the Jacobian
81 /// ∂x/∂λ, ∂x/∂φ
82 /// ∂y/∂λ, ∂y/∂φ
83 /// for tile t.
84 virtual Jacobian jacobian(const PointLonLat& lonlat, idx_t t) const = 0;
85
86 /// @brief Jacobian of (alpha, beta) with respect to (lon, lat) on tile t
87 ///
88 /// @details Returns the Jacobian
89 /// ∂α/∂λ, ∂α/∂φ
90 /// ∂β/∂λ, ∂β/∂φ
91 /// for tile t.
92 virtual Jacobian alphabetaJacobian(const PointLonLat& lonlat, idx_t t) const = 0;
93
94 protected:
95 // projection and inverse projection
96 void xy2lonlat_post(double xyz[], const idx_t t, double crd[]) const;
97 void lonlat2xy_pre(double crd[], idx_t& t, double xyz[]) const;
98
99 void xy2alphabetat(const double xy[], idx_t& t, double ab[]) const;
100 void alphabetat2xy(const idx_t t, const double ab[], double xy[]) const;
101
102 private:
103 atlas::grid::CubedSphereTiles tiles_;
104 // Shift entire grid
105 double shiftLon_;
106 // Schmidt transform
107 bool doSchmidt_;
108 double stretchFac_;
109 double targetLon_;
110 double targetLat_;
111
112 std::array<std::array<double, 6>, 2> tiles_offsets_ab2xy_;
113 std::array<std::array<double, 6>, 2> tiles_offsets_xy2ab_;
114 };
115
116 } // namespace detail
117 } // namespace projection
118 } // namespace atlas