Debian Codegraph @

src/atlas/grid/Tiles.h

raw
1 /*
2 * (C) Crown Copyright 2021 Met Office.
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 * In applying this licence, ECMWF does not waive the privileges and immunities
7 * granted to it by virtue of its status as an intergovernmental organisation
8 * nor does it submit to any jurisdiction.
9 */
10
11 #pragma once
12
13 #include <array>
14 #include <iostream>
15 #include <string>
16
17 #include "atlas/library/config.h"
18 #include "atlas/util/ObjectHandle.h"
19
20 //---------------------------------------------------------------------------------------------------------------------
21
22 // Forward declarations
23 namespace eckit {
24 class Parametrisation;
25 class Hash;
26 } // namespace eckit
27
28 //---------------------------------------------------------------------------------------------------------------------
29
30 namespace atlas {
31 class PointXY;
32 class PointLonLat;
33
34 namespace util {
35 class Config;
36 } // namespace util
37
38 namespace projection {
39 class Jacobian;
40 }
41
42 namespace grid {
43
44 #ifndef DOXYGEN_SHOULD_SKIP_THIS
45 namespace detail {
46 class CubedSphereTiles;
47 } // namespace detail
48 #endif
49
50 //---------------------------------------------------------------------------------------------------------------------
51
52 class CubedSphereTiles : DOXYGEN_HIDE(public util::ObjectHandle<atlas::grid::detail::CubedSphereTiles>) {
53 public:
54 using Spec = util::Config;
55
56 public:
57 using Handle::Handle;
58 CubedSphereTiles() = default;
59 CubedSphereTiles(const eckit::Parametrisation&);
60 CubedSphereTiles(const std::string&);
61
62 /// Type of the cubed-sphere tiles:
63 std::string type() const;
64
65 // These are offsets needed for transforming
66 // from xy space to the "archetypal base" tile.
67 std::array<std::array<double, 6>, 2> xy2abOffsets() const;
68
69 std::array<std::array<double, 6>, 2> ab2xyOffsets() const;
70
71 void rotate(idx_t t, double xyz[]) const;
72
73 void unrotate(idx_t t, double xyz[]) const;
74
75 // tile index from xy space
76 idx_t indexFromXY(const double xy[]) const;
77 idx_t indexFromXY(const PointXY& xy) const;
78
79 // tile index from longitude and latitude space
80 idx_t indexFromLonLat(const double lonlat[]) const;
81 idx_t indexFromLonLat(const PointLonLat& lonlat) const;
82
83 // enforceXYdomain reinforces the tile shape in xy space;
84 // if values move a miniscule amount outside the domain, it will be brought back in.
85 void enforceXYdomain(double xy[]) const;
86
87 idx_t size() const;
88
89 // this provides periodicity to each of the tiles by extending each tile over edges
90 // in a cross-like fashion. Periodicity of this form does not allow
91 // a "diagonal" extension over corners of the cube.
92 atlas::PointXY tileCubePeriodicity(const atlas::PointXY& xyExtended, const atlas::idx_t tile) const;
93
94 /// @brief Return the position of the tile centre in xy space.
95 const PointXY& tileCentre(size_t t) const;
96
97 /// @brief Return the Jacobian of xy with respect to the curvilinear
98 /// coordinates of the tile.
99 const projection::Jacobian& tileJacobian(size_t t) const;
100
101 private:
102 /// Output to stream
103 void print(std::ostream&) const;
104
105 friend std::ostream& operator<<(std::ostream& s, const CubedSphereTiles& cst);
106 };
107
108 } // namespace grid
109 } // namespace atlas