Debian Codegraph @

src/atlas/domain/Domain.h

raw
1 /*
2 * (C) Copyright 2013 ECMWF.
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 <string>
15
16 #include "atlas/library/config.h"
17 #include "atlas/util/ObjectHandle.h"
18
19 //---------------------------------------------------------------------------------------------------------------------
20
21 // Forward declarations
22 namespace eckit {
23 class Parametrisation;
24 class Hash;
25 } // namespace eckit
26
27 //---------------------------------------------------------------------------------------------------------------------
28
29 namespace atlas {
30 class PointXY;
31
32 namespace util {
33 class Config;
34 } // namespace util
35
36 #ifndef DOXYGEN_SHOULD_SKIP_THIS
37 namespace domain {
38 class Domain;
39 class GlobalDomain;
40 class ZonalBandDomain;
41 class RectangularDomain;
42 class RectangularLonLatDomain;
43 } // namespace domain
44 #endif
45
46 //---------------------------------------------------------------------------------------------------------------------
47
48 class Domain : DOXYGEN_HIDE(public util::ObjectHandle<atlas::domain::Domain>) {
49 public:
50 using Spec = util::Config;
51
52 public:
53 using Handle::Handle;
54 Domain() = default;
55 Domain(const eckit::Parametrisation&);
56
57 /// Type of the domain
58 std::string type() const;
59
60 /// Checks if the point is contained in the domain
61 bool contains(double x, double y) const;
62
63 /// Checks if the point is contained in the domain
64 bool contains(const PointXY& p) const;
65
66 // Specification of Domain
67 Spec spec() const;
68
69 /// Check if domain represents the complete globe surface
70 bool global() const;
71
72 /// Check if domain does not represent any area on the globe surface
73 bool empty() const;
74
75 /// Add domain to the given hash
76 void hash(eckit::Hash&) const;
77
78 /// Check if grid includes the North pole (can only be true when units are in
79 /// degrees)
80 bool containsNorthPole() const;
81
82 /// Check if grid includes the South pole (can only be true when units are in
83 /// degrees)
84 bool containsSouthPole() const;
85
86 /// String that defines units of the domain ("degrees" or "meters")
87 std::string units() const;
88
89 private:
90 /// Output to stream
91 void print(std::ostream&) const;
92
93 friend std::ostream& operator<<(std::ostream& s, const Domain& d);
94 };
95
96 //---------------------------------------------------------------------------------------------------------------------
97
98 class RectangularDomain : public Domain {
99 public:
100 using Interval = std::array<double, 2>;
101
102 public:
103 using Domain::Domain;
104 RectangularDomain(): Domain() {}
105 RectangularDomain(const Interval& x, const Interval& y, const std::string& units = "degrees");
106
107 RectangularDomain(const Domain&);
108
109 operator bool() const { return domain_; }
110
111 /// Checks if the x-value is contained in the domain
112 bool contains_x(double x) const;
113
114 /// Checks if the y-value is contained in the domain
115 bool contains_y(double y) const;
116
117 bool zonal_band() const;
118
119 double xmin() const;
120 double xmax() const;
121 double ymin() const;
122 double ymax() const;
123
124 private:
125 const ::atlas::domain::RectangularDomain* domain_;
126 };
127
128 //---------------------------------------------------------------------------------------------------------------------
129
130 class RectangularLonLatDomain : public RectangularDomain {
131 public:
132 using RectangularDomain::RectangularDomain;
133 RectangularLonLatDomain(const Interval& x, const Interval& y): RectangularDomain(x, y, "degrees") {}
134 RectangularLonLatDomain(const double& north, const double& west, const double& south, const double& east):
135 RectangularLonLatDomain({west, east}, {south, north}) {}
136
137 operator bool() const { return RectangularDomain::operator bool() && units() == "degrees"; }
138
139 double west() const { return xmin(); }
140 double east() const { return xmax(); }
141 double north() const { return ymax(); }
142 double south() const { return ymin(); }
143 };
144
145 //---------------------------------------------------------------------------------------------------------------------
146
147 class ZonalBandDomain : public RectangularLonLatDomain {
148 public:
149 using Interval = std::array<double, 2>;
150
151 public:
152 using RectangularLonLatDomain::RectangularLonLatDomain;
153 ZonalBandDomain(const Interval& y, const double& west);
154 ZonalBandDomain(const Interval& y);
155 ZonalBandDomain(const Domain&);
156
157 operator bool() const { return domain_; }
158
159 private:
160 const ::atlas::domain::ZonalBandDomain* domain_;
161 };
162
163 //---------------------------------------------------------------------------------------------------------------------
164
165 class GlobalDomain : public ZonalBandDomain {
166 public:
167 GlobalDomain(const double& west);
168 GlobalDomain();
169 GlobalDomain(const Domain&);
170
171 operator bool() const { return domain_; }
172
173 private:
174 const ::atlas::domain::GlobalDomain* domain_;
175 };
176
177 //---------------------------------------------------------------------------------------------------------------------
178
179 } // namespace atlas