From ef7ff32752a974b99aaab2501e309a0b00bdc3ce Mon Sep 17 00:00:00 2001 From: odlomax Date: Tue, 12 Nov 2024 11:47:16 +0000 Subject: [PATCH 01/31] Added grid class boilerplate. --- src/atlas/grid/CubedSphere2.cc | 7 +++++++ src/atlas/grid/CubedSphere2.h | 12 ++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 src/atlas/grid/CubedSphere2.cc create mode 100644 src/atlas/grid/CubedSphere2.h diff --git a/src/atlas/grid/CubedSphere2.cc b/src/atlas/grid/CubedSphere2.cc new file mode 100644 index 000000000..6e22465a8 --- /dev/null +++ b/src/atlas/grid/CubedSphere2.cc @@ -0,0 +1,7 @@ +#include "atlas/grid/CubedSphere2.h" + +namespace atlas { + +CubedSphereGrid2::CubedSphereGrid2() {} + +} // namespace atlas diff --git a/src/atlas/grid/CubedSphere2.h b/src/atlas/grid/CubedSphere2.h new file mode 100644 index 000000000..c6b85bbc6 --- /dev/null +++ b/src/atlas/grid/CubedSphere2.h @@ -0,0 +1,12 @@ +#pragma once + +#include "atlas/grid/Grid.h" + +namespace atlas { + +class CubedSphereGrid2 : public atlas::Grid { + public: + CubedSphereGrid2(); +}; + +} // namespace atlas From 8b083051cde33bd6b9a4da52d2787eb424f2c233 Mon Sep 17 00:00:00 2001 From: odlomax Date: Tue, 12 Nov 2024 16:15:26 +0000 Subject: [PATCH 02/31] Added simple concrete implementation. --- src/atlas/grid/CubedSphere2.cc | 7 ------- src/atlas/grid/CubedSphere2.h | 12 ------------ 2 files changed, 19 deletions(-) delete mode 100644 src/atlas/grid/CubedSphere2.cc delete mode 100644 src/atlas/grid/CubedSphere2.h diff --git a/src/atlas/grid/CubedSphere2.cc b/src/atlas/grid/CubedSphere2.cc deleted file mode 100644 index 6e22465a8..000000000 --- a/src/atlas/grid/CubedSphere2.cc +++ /dev/null @@ -1,7 +0,0 @@ -#include "atlas/grid/CubedSphere2.h" - -namespace atlas { - -CubedSphereGrid2::CubedSphereGrid2() {} - -} // namespace atlas diff --git a/src/atlas/grid/CubedSphere2.h b/src/atlas/grid/CubedSphere2.h deleted file mode 100644 index c6b85bbc6..000000000 --- a/src/atlas/grid/CubedSphere2.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include "atlas/grid/Grid.h" - -namespace atlas { - -class CubedSphereGrid2 : public atlas::Grid { - public: - CubedSphereGrid2(); -}; - -} // namespace atlas From 9eb6714a18435d9c24677d677c2aa9d45d4d4e7e Mon Sep 17 00:00:00 2001 From: mo-jonasganderton Date: Wed, 13 Nov 2024 10:17:50 +0000 Subject: [PATCH 03/31] Implement methods unrelated to iterators --- src/atlas/grid/detail/grid/CubedSphere2.cc | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/atlas/grid/detail/grid/CubedSphere2.cc b/src/atlas/grid/detail/grid/CubedSphere2.cc index b51de450a..bd89cdc14 100644 --- a/src/atlas/grid/detail/grid/CubedSphere2.cc +++ b/src/atlas/grid/detail/grid/CubedSphere2.cc @@ -125,6 +125,54 @@ PointXYZ CubedSphere2::tangent_to_xyz_coord(const PointXY& tan_coord, idx_t tile return PointXYZ::normalize(xyz); } +std::string CubedSphere2::name() const { + return name_; +} + +std::string CubedSphere::type() { + return name_; +} + +// Provide a unique identification hash for the grid and the projection. +void CubedSphere2::hash(eckit::Hash& h) const { + h.add("CubedSphere2"); + h.add(int(N_)); + + // also add projection information + projection().hash(h); + + // also add domain information, even though already encoded in grid. + domain().hash(h); +} + +// Return the bounding box for the grid, global +RectangularLonLatDomain CubedSphere2::lonlatBoundingBox() const { + return projection_ ? projection_.lonlatBoundingBox(computeDomain()) : domain(); +} + +idx_t CubedSphere2::size() const { + // Example from CubedSphere.h + // return accumulate(npts_.begin(), npts_.end(), 0); + + // For now, return expected size + return N_ * N_ * nTiles_; +} + +// Return the specification for the grid. +Grid::Spec CubedSphere2::spec() const { + // Copied from CubedSphere.cc + Grid::Spec grid_spec; + + if (name() == "cubedsphere2") { + grid_spec.set("type", type()); + } + else { + grid_spec.set("name", name()); + } + grid_spec.set("projection", projection().spec()); + return grid_spec; +} + } // namespace grid } // namespace detail } // namespace grid From fc87cc22f0671f658efcb0b4b2b0a3f48d04f5d3 Mon Sep 17 00:00:00 2001 From: mo-jonasganderton Date: Wed, 13 Nov 2024 11:14:16 +0000 Subject: [PATCH 04/31] Change name to CS-LFR--2 --- src/atlas/grid/detail/grid/CubedSphere2.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/atlas/grid/detail/grid/CubedSphere2.cc b/src/atlas/grid/detail/grid/CubedSphere2.cc index bd89cdc14..809f275b5 100644 --- a/src/atlas/grid/detail/grid/CubedSphere2.cc +++ b/src/atlas/grid/detail/grid/CubedSphere2.cc @@ -126,11 +126,11 @@ PointXYZ CubedSphere2::tangent_to_xyz_coord(const PointXY& tan_coord, idx_t tile } std::string CubedSphere2::name() const { - return name_; + return "CS-LFR-" + std::to_string(N_) + "-2"; } -std::string CubedSphere::type() { - return name_; +std::string CubedSphere2::type() const { + return type_; } // Provide a unique identification hash for the grid and the projection. @@ -163,11 +163,11 @@ Grid::Spec CubedSphere2::spec() const { // Copied from CubedSphere.cc Grid::Spec grid_spec; - if (name() == "cubedsphere2") { - grid_spec.set("type", type()); + if (type() == "cubedsphere2") { + grid_spec.set("name", name()); } else { - grid_spec.set("name", name()); + grid_spec.set("type", type()); } grid_spec.set("projection", projection().spec()); return grid_spec; From c31e01bffd2596ec4c26f2128921023e9491590a Mon Sep 17 00:00:00 2001 From: mo-jonasganderton Date: Wed, 13 Nov 2024 14:12:53 +0000 Subject: [PATCH 05/31] Fix hash and bounding box --- src/atlas/grid/detail/grid/CubedSphere2.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/atlas/grid/detail/grid/CubedSphere2.cc b/src/atlas/grid/detail/grid/CubedSphere2.cc index 809f275b5..94c5f06ac 100644 --- a/src/atlas/grid/detail/grid/CubedSphere2.cc +++ b/src/atlas/grid/detail/grid/CubedSphere2.cc @@ -135,7 +135,7 @@ std::string CubedSphere2::type() const { // Provide a unique identification hash for the grid and the projection. void CubedSphere2::hash(eckit::Hash& h) const { - h.add("CubedSphere2"); + h.add(name()); // use name() or type()? h.add(int(N_)); // also add projection information @@ -147,7 +147,7 @@ void CubedSphere2::hash(eckit::Hash& h) const { // Return the bounding box for the grid, global RectangularLonLatDomain CubedSphere2::lonlatBoundingBox() const { - return projection_ ? projection_.lonlatBoundingBox(computeDomain()) : domain(); + return GlobalDomain(); } idx_t CubedSphere2::size() const { From be15e65fb1f5b0c5792c9ce9d672e62786b78d61 Mon Sep 17 00:00:00 2001 From: mo-jonasganderton Date: Wed, 13 Nov 2024 15:05:12 +0000 Subject: [PATCH 06/31] Implement CubedSphere2::print() --- src/atlas/grid/detail/grid/CubedSphere2.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/atlas/grid/detail/grid/CubedSphere2.cc b/src/atlas/grid/detail/grid/CubedSphere2.cc index 94c5f06ac..d9683c697 100644 --- a/src/atlas/grid/detail/grid/CubedSphere2.cc +++ b/src/atlas/grid/detail/grid/CubedSphere2.cc @@ -173,6 +173,11 @@ Grid::Spec CubedSphere2::spec() const { return grid_spec; } +// Print the name of the Grid +void CubedSphere2::print(std::ostream& os) const { + os << "CubedSphere2(Name:" << name() << ")"; +} + } // namespace grid } // namespace detail } // namespace grid From 4f71180d86e751eae60ef23b57e50259d7c75b59 Mon Sep 17 00:00:00 2001 From: mo-jonasganderton Date: Thu, 14 Nov 2024 11:48:45 +0000 Subject: [PATCH 07/31] Calculate the lonlat for a given point index --- src/atlas/grid/CubedSphereGrid2.cc | 5 ++ src/atlas/grid/detail/grid/CubedSphere2.cc | 53 ---------------------- src/atlas/grid/detail/grid/CubedSphere2.h | 3 ++ 3 files changed, 8 insertions(+), 53 deletions(-) diff --git a/src/atlas/grid/CubedSphereGrid2.cc b/src/atlas/grid/CubedSphereGrid2.cc index 339e422df..fc5d4c3fb 100644 --- a/src/atlas/grid/CubedSphereGrid2.cc +++ b/src/atlas/grid/CubedSphereGrid2.cc @@ -13,4 +13,9 @@ CubedSphereGrid2::CubedSphereGrid2(idx_t resolution): CubedSphereGrid2::CubedSphereGrid2(const Grid& grid): Grid(grid), grid_(cubedsphere_grid2(get())) {} +// Temporarily here for testing lonlat() +void CubedSphereGrid2::printCubedSphere2() const { + get()->name(); +} + } // namespace atlas diff --git a/src/atlas/grid/detail/grid/CubedSphere2.cc b/src/atlas/grid/detail/grid/CubedSphere2.cc index d9683c697..b51de450a 100644 --- a/src/atlas/grid/detail/grid/CubedSphere2.cc +++ b/src/atlas/grid/detail/grid/CubedSphere2.cc @@ -125,59 +125,6 @@ PointXYZ CubedSphere2::tangent_to_xyz_coord(const PointXY& tan_coord, idx_t tile return PointXYZ::normalize(xyz); } -std::string CubedSphere2::name() const { - return "CS-LFR-" + std::to_string(N_) + "-2"; -} - -std::string CubedSphere2::type() const { - return type_; -} - -// Provide a unique identification hash for the grid and the projection. -void CubedSphere2::hash(eckit::Hash& h) const { - h.add(name()); // use name() or type()? - h.add(int(N_)); - - // also add projection information - projection().hash(h); - - // also add domain information, even though already encoded in grid. - domain().hash(h); -} - -// Return the bounding box for the grid, global -RectangularLonLatDomain CubedSphere2::lonlatBoundingBox() const { - return GlobalDomain(); -} - -idx_t CubedSphere2::size() const { - // Example from CubedSphere.h - // return accumulate(npts_.begin(), npts_.end(), 0); - - // For now, return expected size - return N_ * N_ * nTiles_; -} - -// Return the specification for the grid. -Grid::Spec CubedSphere2::spec() const { - // Copied from CubedSphere.cc - Grid::Spec grid_spec; - - if (type() == "cubedsphere2") { - grid_spec.set("name", name()); - } - else { - grid_spec.set("type", type()); - } - grid_spec.set("projection", projection().spec()); - return grid_spec; -} - -// Print the name of the Grid -void CubedSphere2::print(std::ostream& os) const { - os << "CubedSphere2(Name:" << name() << ")"; -} - } // namespace grid } // namespace detail } // namespace grid diff --git a/src/atlas/grid/detail/grid/CubedSphere2.h b/src/atlas/grid/detail/grid/CubedSphere2.h index 988bfc4a2..d4c1a7a93 100644 --- a/src/atlas/grid/detail/grid/CubedSphere2.h +++ b/src/atlas/grid/detail/grid/CubedSphere2.h @@ -139,6 +139,9 @@ class CubedSphere2 : public Grid { void lonlat(idx_t n, Point2& point) const; Point2 lonlat(idx_t n) const; + void lonlat(idx_t n, PointLonLat& point) const; + PointLonLat lonlat(idx_t n) const; + protected: void print(std::ostream&) const override; From 960a290874cb693077f88603487ce36f35f0999c Mon Sep 17 00:00:00 2001 From: mo-jonasganderton Date: Mon, 18 Nov 2024 15:39:49 +0000 Subject: [PATCH 08/31] Change lonlat and xy to use Point2 --- src/atlas/grid/detail/grid/CubedSphere2.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/atlas/grid/detail/grid/CubedSphere2.h b/src/atlas/grid/detail/grid/CubedSphere2.h index d4c1a7a93..f9d6402f8 100644 --- a/src/atlas/grid/detail/grid/CubedSphere2.h +++ b/src/atlas/grid/detail/grid/CubedSphere2.h @@ -139,8 +139,11 @@ class CubedSphere2 : public Grid { void lonlat(idx_t n, Point2& point) const; Point2 lonlat(idx_t n) const; - void lonlat(idx_t n, PointLonLat& point) const; - PointLonLat lonlat(idx_t n) const; + void lonlat(idx_t n, Point2& point) const; + Point2 lonlat(idx_t n) const; + + void xy(idx_t n, Point2& point) const {lonlat(n, point);} + Point2 xy(idx_t n) const {return lonlat(n);} protected: void print(std::ostream&) const override; From 633194e1d7633e6969957f2027f0d1ef38f961e5 Mon Sep 17 00:00:00 2001 From: mo-jonasganderton Date: Thu, 21 Nov 2024 16:30:21 +0000 Subject: [PATCH 09/31] Swap xy and lonlat methods --- src/atlas/grid/detail/grid/CubedSphere2.cc | 2 +- src/atlas/grid/detail/grid/CubedSphere2.h | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/atlas/grid/detail/grid/CubedSphere2.cc b/src/atlas/grid/detail/grid/CubedSphere2.cc index b51de450a..405d4056b 100644 --- a/src/atlas/grid/detail/grid/CubedSphere2.cc +++ b/src/atlas/grid/detail/grid/CubedSphere2.cc @@ -81,7 +81,7 @@ void CubedSphere2::lonlat(idx_t n, Point2& point) const { // Get the lonlat for a given index Point2 CubedSphere2::lonlat(idx_t n) const { Point2 point; - lonlat(n, point); + xy(n, point); return point; } diff --git a/src/atlas/grid/detail/grid/CubedSphere2.h b/src/atlas/grid/detail/grid/CubedSphere2.h index f9d6402f8..988bfc4a2 100644 --- a/src/atlas/grid/detail/grid/CubedSphere2.h +++ b/src/atlas/grid/detail/grid/CubedSphere2.h @@ -139,12 +139,6 @@ class CubedSphere2 : public Grid { void lonlat(idx_t n, Point2& point) const; Point2 lonlat(idx_t n) const; - void lonlat(idx_t n, Point2& point) const; - Point2 lonlat(idx_t n) const; - - void xy(idx_t n, Point2& point) const {lonlat(n, point);} - Point2 xy(idx_t n) const {return lonlat(n);} - protected: void print(std::ostream&) const override; From 040ea2a3db7752a454b5c8414330091945b275a5 Mon Sep 17 00:00:00 2001 From: mo-jonasganderton Date: Thu, 21 Nov 2024 16:32:21 +0000 Subject: [PATCH 10/31] Remove temporary testing method --- src/atlas/grid/CubedSphereGrid2.cc | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/atlas/grid/CubedSphereGrid2.cc b/src/atlas/grid/CubedSphereGrid2.cc index fc5d4c3fb..339e422df 100644 --- a/src/atlas/grid/CubedSphereGrid2.cc +++ b/src/atlas/grid/CubedSphereGrid2.cc @@ -13,9 +13,4 @@ CubedSphereGrid2::CubedSphereGrid2(idx_t resolution): CubedSphereGrid2::CubedSphereGrid2(const Grid& grid): Grid(grid), grid_(cubedsphere_grid2(get())) {} -// Temporarily here for testing lonlat() -void CubedSphereGrid2::printCubedSphere2() const { - get()->name(); -} - } // namespace atlas From 6e800f12b29d49e7b95ae4bab2b0302e4bae8193 Mon Sep 17 00:00:00 2001 From: mo-jonasganderton Date: Thu, 28 Nov 2024 10:52:19 +0000 Subject: [PATCH 11/31] Combine methods to calculate t,i,j into one simpler method --- src/atlas/grid/detail/grid/CubedSphere2.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/atlas/grid/detail/grid/CubedSphere2.h b/src/atlas/grid/detail/grid/CubedSphere2.h index 988bfc4a2..88f482e40 100644 --- a/src/atlas/grid/detail/grid/CubedSphere2.h +++ b/src/atlas/grid/detail/grid/CubedSphere2.h @@ -157,6 +157,10 @@ class CubedSphere2 : public Grid { static constexpr idx_t nTiles_ = 6; private: + using CSIndices = std::array; + + CSIndices get_cs_indices(gidx_t n) const; + std::string type_ = {"cubedsphere2"}; using Matrix = std::array, 3>; From ac6a8c09bccfa638ddd9a3245faa263b2aadb0da Mon Sep 17 00:00:00 2001 From: mo-jonasganderton Date: Thu, 28 Nov 2024 16:27:11 +0000 Subject: [PATCH 12/31] Change arrays to eckit matrices --- src/atlas/grid/detail/grid/CubedSphere2.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/atlas/grid/detail/grid/CubedSphere2.h b/src/atlas/grid/detail/grid/CubedSphere2.h index 88f482e40..5a9cd25bb 100644 --- a/src/atlas/grid/detail/grid/CubedSphere2.h +++ b/src/atlas/grid/detail/grid/CubedSphere2.h @@ -4,6 +4,7 @@ #include "atlas/runtime/Exception.h" #include "atlas/util/Config.h" #include "atlas/util/Point.h" +#include "eckit/maths/Matrix.h" namespace atlas { namespace grid { From 3560c0bde927beb219f528307308d14b4714b1f7 Mon Sep 17 00:00:00 2001 From: mo-jonasganderton Date: Thu, 28 Nov 2024 16:59:49 +0000 Subject: [PATCH 13/31] Clean up after tij methods change --- src/atlas/grid/detail/grid/CubedSphere2.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/atlas/grid/detail/grid/CubedSphere2.h b/src/atlas/grid/detail/grid/CubedSphere2.h index 5a9cd25bb..2e8d14801 100644 --- a/src/atlas/grid/detail/grid/CubedSphere2.h +++ b/src/atlas/grid/detail/grid/CubedSphere2.h @@ -158,10 +158,6 @@ class CubedSphere2 : public Grid { static constexpr idx_t nTiles_ = 6; private: - using CSIndices = std::array; - - CSIndices get_cs_indices(gidx_t n) const; - std::string type_ = {"cubedsphere2"}; using Matrix = std::array, 3>; From b1b5553f969222d430255587a142e8f356a15166 Mon Sep 17 00:00:00 2001 From: mo-jonasganderton Date: Thu, 28 Nov 2024 17:43:54 +0000 Subject: [PATCH 14/31] Use projection_.xy2lonlat in lonlat --- src/atlas/grid/detail/grid/CubedSphere2.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/atlas/grid/detail/grid/CubedSphere2.cc b/src/atlas/grid/detail/grid/CubedSphere2.cc index 405d4056b..b51de450a 100644 --- a/src/atlas/grid/detail/grid/CubedSphere2.cc +++ b/src/atlas/grid/detail/grid/CubedSphere2.cc @@ -81,7 +81,7 @@ void CubedSphere2::lonlat(idx_t n, Point2& point) const { // Get the lonlat for a given index Point2 CubedSphere2::lonlat(idx_t n) const { Point2 point; - xy(n, point); + lonlat(n, point); return point; } From 5a6a2029a72f43724bc222b5245c256223e04f88 Mon Sep 17 00:00:00 2001 From: mo-jonasganderton Date: Fri, 29 Nov 2024 11:03:49 +0000 Subject: [PATCH 15/31] Improve clarity of generation of xy point --- src/atlas/grid/detail/grid/CubedSphere2.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/atlas/grid/detail/grid/CubedSphere2.h b/src/atlas/grid/detail/grid/CubedSphere2.h index 2e8d14801..2c5075676 100644 --- a/src/atlas/grid/detail/grid/CubedSphere2.h +++ b/src/atlas/grid/detail/grid/CubedSphere2.h @@ -145,6 +145,7 @@ class CubedSphere2 : public Grid { private: using CSIndices = std::array; + using PointAlphaBeta = Point2; CSIndices get_cs_indices(gidx_t n) const; PointXY ij_to_tangent_coord(idx_t i, idx_t j) const; From a2cb41c7c05150ed24486eb453c4dc6c2ff15ec9 Mon Sep 17 00:00:00 2001 From: mo-jonasganderton Date: Mon, 2 Dec 2024 13:17:42 +0000 Subject: [PATCH 16/31] Add static_type() --- src/atlas/grid/detail/grid/CubedSphere2.cc | 6 +++++- src/atlas/grid/detail/grid/CubedSphere2.h | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/atlas/grid/detail/grid/CubedSphere2.cc b/src/atlas/grid/detail/grid/CubedSphere2.cc index b51de450a..344b23bb0 100644 --- a/src/atlas/grid/detail/grid/CubedSphere2.cc +++ b/src/atlas/grid/detail/grid/CubedSphere2.cc @@ -19,7 +19,11 @@ std::string CubedSphere2::name() const { } std::string CubedSphere2::type() const { - return type_; + return static_type(); +} + +std::string CubedSphere2::static_type() { + return "cubedsphere2"; } // Provide a unique identification hash for the grid and the projection. diff --git a/src/atlas/grid/detail/grid/CubedSphere2.h b/src/atlas/grid/detail/grid/CubedSphere2.h index 2c5075676..2dabdc9ba 100644 --- a/src/atlas/grid/detail/grid/CubedSphere2.h +++ b/src/atlas/grid/detail/grid/CubedSphere2.h @@ -113,6 +113,7 @@ class CubedSphere2 : public Grid { std::string name() const override; std::string type() const override; + static std::string static_type(); idx_t N() const {return N_;} void hash(eckit::Hash&) const override; From 7e0fd61f480e1eab171d8d0734ee2569a98be762 Mon Sep 17 00:00:00 2001 From: mo-jonasganderton Date: Mon, 2 Dec 2024 16:01:53 +0000 Subject: [PATCH 17/31] Initial implementation of a Cubed Sphere 2 grid builder --- src/atlas/grid/detail/grid/CubedSphere2.cc | 89 ++++++++++++++++++++++ src/atlas/grid/detail/grid/GridBuilder.cc | 2 + src/tests/grid/test_cubedsphere_2.cc | 9 +++ 3 files changed, 100 insertions(+) diff --git a/src/atlas/grid/detail/grid/CubedSphere2.cc b/src/atlas/grid/detail/grid/CubedSphere2.cc index 344b23bb0..d87f8c5e6 100644 --- a/src/atlas/grid/detail/grid/CubedSphere2.cc +++ b/src/atlas/grid/detail/grid/CubedSphere2.cc @@ -1,15 +1,23 @@ #include "atlas/grid/detail/grid/CubedSphere2.h" #include +#include +#include "atlas/grid/CubedSphereGrid2.h" +#include "atlas/grid/detail/grid/GridBuilder.h" +#include "atlas/grid/detail/grid/GridFactory.h" +#include "atlas/runtime/Exception.h" #include "eckit/geometry/Sphere.h" #include "eckit/utils/Hash.h" +#include "eckit/utils/Translator.h" namespace atlas { namespace grid { namespace detail { namespace grid { +static eckit::Translator to_int; + // Public methods CubedSphere2::CubedSphere2(idx_t resolution) : N_(resolution) {} @@ -129,6 +137,87 @@ PointXYZ CubedSphere2::tangent_to_xyz_coord(const PointXY& tan_coord, idx_t tile return PointXYZ::normalize(xyz); } +namespace { +GridFactoryBuilder __register_CubedSphere2(CubedSphere2::static_type()); +} + +static class cubedsphere2_lfric : public GridBuilder { +public: + cubedsphere2_lfric(): + GridBuilder("cubedsphere2_lfric", {"^[Cc][Ss][_-][Ll][Ff][Rr][-_]([1-9][0-9]*)[_-][2]$"}, + {"CS-LFR--2"}) {} + + void print(std::ostream& os) const override { + os << std::left << std::setw(20) << "CS-LFR--2" + << "Cubed sphere for LFRic"; + } + + // Factory constructor + const atlas::Grid::Implementation* create(const std::string& name, const Grid::Config& config) const override { + int id; + std::vector matches; + if (match(name, matches, id)) { + util::Config gridconf(config); + int N = to_int(matches[0]); + gridconf.set("type", type()); + gridconf.set("N", N); + return create(gridconf); + } + return nullptr; + } + + // Factory constructor + const atlas::Grid::Implementation* create(const Grid::Config& config) const override { + int N = 0; + if (not config.get("N", N)) { + throw_AssertionFailed("Could not find \"N\" in configuration of cubed sphere grid 2", Here()); + } + + return new CubedSphereGrid2::grid_t(N); + + // TODO: requires CubedSphereGrid2 constructor with projection + + // std::string name = "CS-LFR-" + std::to_string(N) + "-2"; + // util::Config projconf; + // projconf.set("type", "cubedsphere2"); + // projconf.set("tile.type", "cubedsphere2_lfric"); + + // // Shift projection by a longitude + // if (config.has("ShiftLon")) { + // double shiftLon = 0.0; + // config.get("ShiftLon", shiftLon); + // projconf.set("ShiftLon", shiftLon); + // } + + // // Apply a Schmidt transform + // if (config.has("DoSchmidt")) { + // bool doSchmidt = false; + // config.get("DoSchmidt", doSchmidt); + // if (doSchmidt) { + // double stretchFac; + // double targetLon; + // double targetLat; + // config.get("StretchFac", stretchFac); + // config.get("TargetLon", targetLon); + // config.get("TargetLat", targetLat); + // projconf.set("DoSchmidt", doSchmidt); + // projconf.set("StretchFac", stretchFac); + // projconf.set("TargetLon", targetLon); + // projconf.set("TargetLat", targetLat); + // } + // } + + // return new CubedSphereGrid2::grid_t(name, N, Projection(projconf)); + } + + void force_link() {} + +} cubedsphere2_lfric_; + +void force_link_CubedSphere2() { + cubedsphere2_lfric_.force_link(); +} + } // namespace grid } // namespace detail } // namespace grid diff --git a/src/atlas/grid/detail/grid/GridBuilder.cc b/src/atlas/grid/detail/grid/GridBuilder.cc index adfdda5f3..cfd63dfc4 100644 --- a/src/atlas/grid/detail/grid/GridBuilder.cc +++ b/src/atlas/grid/detail/grid/GridBuilder.cc @@ -121,6 +121,7 @@ static void init() { namespace detail { namespace grid { void force_link_CubedSphere(); +void force_link_CubedSphere2(); void force_link_Gaussian(); void force_link_LonLat(); void force_link_Regional(); @@ -130,6 +131,7 @@ void force_link_Regional_var_resolution(); const GridBuilder::Registry& GridBuilder::nameRegistry() { detail::grid::force_link_CubedSphere(); + detail::grid::force_link_CubedSphere2(); detail::grid::force_link_Gaussian(); detail::grid::force_link_LonLat(); detail::grid::force_link_Regional(); diff --git a/src/tests/grid/test_cubedsphere_2.cc b/src/tests/grid/test_cubedsphere_2.cc index 873371ec6..d47cea3c0 100644 --- a/src/tests/grid/test_cubedsphere_2.cc +++ b/src/tests/grid/test_cubedsphere_2.cc @@ -74,6 +74,15 @@ CASE("cubed_sphere_grid_kgo") { EXPECT(compare_2D_points(points_xy, kgo_lonlat)); } +CASE("cubed_sphere_grid_builder") { + const int n = 2; + const std::string name = "CS-LFR-" + std::to_string(n) + "-2"; + const Grid grid = Grid(name); + EXPECT(grid.name() == name); + EXPECT(grid.type() == "cubedsphere2"); + EXPECT(grid.size() == n * n * 6); +} + } // namespace } // namespace test } // namespace atlas From 50560858cc53686bdce5e9c0d0fd71bc9017527c Mon Sep 17 00:00:00 2001 From: mo-jonasganderton Date: Mon, 2 Dec 2024 16:29:46 +0000 Subject: [PATCH 18/31] Remove old variable type_ --- src/atlas/grid/detail/grid/CubedSphere2.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/atlas/grid/detail/grid/CubedSphere2.h b/src/atlas/grid/detail/grid/CubedSphere2.h index 2dabdc9ba..04713a70c 100644 --- a/src/atlas/grid/detail/grid/CubedSphere2.h +++ b/src/atlas/grid/detail/grid/CubedSphere2.h @@ -160,8 +160,6 @@ class CubedSphere2 : public Grid { static constexpr idx_t nTiles_ = 6; private: - std::string type_ = {"cubedsphere2"}; - using Matrix = std::array, 3>; /* From 5c1f2f0568bad2a405abbe3e66953946fe144408 Mon Sep 17 00:00:00 2001 From: mo-jonasganderton Date: Fri, 10 Jan 2025 13:55:37 +0000 Subject: [PATCH 19/31] Create CubedSphere2 with projection --- src/atlas/CMakeLists.txt | 2 + src/atlas/grid/CubedSphereGrid2.cc | 3 ++ src/atlas/grid/CubedSphereGrid2.h | 1 + src/atlas/grid/detail/grid/CubedSphere2.cc | 34 +++++++++++---- src/atlas/grid/detail/grid/CubedSphere2.h | 5 +++ .../detail/CubedSphere2ProjectionBase.cc | 41 +++++++++++++++++++ .../detail/CubedSphere2ProjectionBase.h | 40 ++++++++++++++++++ 7 files changed, 117 insertions(+), 9 deletions(-) create mode 100644 src/atlas/projection/detail/CubedSphere2ProjectionBase.cc create mode 100644 src/atlas/projection/detail/CubedSphere2ProjectionBase.h diff --git a/src/atlas/CMakeLists.txt b/src/atlas/CMakeLists.txt index 3ca0b5a41..42502405e 100644 --- a/src/atlas/CMakeLists.txt +++ b/src/atlas/CMakeLists.txt @@ -94,6 +94,8 @@ projection/detail/CubedSphereEquiDistProjection.cc projection/detail/CubedSphereEquiDistProjection.h projection/detail/CubedSphereProjectionBase.cc projection/detail/CubedSphereProjectionBase.h +projection/detail/CubedSphere2ProjectionBase.cc +projection/detail/CubedSphere2ProjectionBase.h projection/detail/LambertAzimuthalEqualAreaProjection.cc projection/detail/LambertAzimuthalEqualAreaProjection.h projection/detail/LambertConformalConicProjection.cc diff --git a/src/atlas/grid/CubedSphereGrid2.cc b/src/atlas/grid/CubedSphereGrid2.cc index 339e422df..9c2625133 100644 --- a/src/atlas/grid/CubedSphereGrid2.cc +++ b/src/atlas/grid/CubedSphereGrid2.cc @@ -13,4 +13,7 @@ CubedSphereGrid2::CubedSphereGrid2(idx_t resolution): CubedSphereGrid2::CubedSphereGrid2(const Grid& grid): Grid(grid), grid_(cubedsphere_grid2(get())) {} +CubedSphereGrid2::CubedSphereGrid2(idx_t resolution, Projection projection): + Grid(new grid::detail::grid::CubedSphere2(resolution, projection)) {} + } // namespace atlas diff --git a/src/atlas/grid/CubedSphereGrid2.h b/src/atlas/grid/CubedSphereGrid2.h index 5cf036c71..a2abab114 100644 --- a/src/atlas/grid/CubedSphereGrid2.h +++ b/src/atlas/grid/CubedSphereGrid2.h @@ -12,6 +12,7 @@ class CubedSphereGrid2 : public atlas::Grid { public: CubedSphereGrid2(idx_t resolution); CubedSphereGrid2(const Grid& grid); + CubedSphereGrid2(idx_t resolution, Projection projection); bool valid() const { return grid_; }; operator bool() const { return valid(); } diff --git a/src/atlas/grid/detail/grid/CubedSphere2.cc b/src/atlas/grid/detail/grid/CubedSphere2.cc index d87f8c5e6..ca9107c28 100644 --- a/src/atlas/grid/detail/grid/CubedSphere2.cc +++ b/src/atlas/grid/detail/grid/CubedSphere2.cc @@ -6,6 +6,7 @@ #include "atlas/grid/CubedSphereGrid2.h" #include "atlas/grid/detail/grid/GridBuilder.h" #include "atlas/grid/detail/grid/GridFactory.h" +#include "atlas/projection/detail/CubedSphere2ProjectionBase.h" #include "atlas/runtime/Exception.h" #include "eckit/geometry/Sphere.h" #include "eckit/utils/Hash.h" @@ -22,6 +23,25 @@ static eckit::Translator to_int; CubedSphere2::CubedSphere2(idx_t resolution) : N_(resolution) {} +CubedSphere2::CubedSphere2(idx_t resolution, Projection projection) : + Grid(), N_(resolution) { + + // Copy members + util::Config defaultProjConfig; + defaultProjConfig.set("type", "cubedsphere_equiangular"); + projection_ = projection ? projection : Projection(defaultProjConfig); + + // Domain + domain_ = GlobalDomain(); + + // using atlas::projection::detail::CubedSphere2ProjectionBase; + cs2_projection_ = dynamic_cast(projection_.get()); + if (not cs2_projection_) { + ATLAS_THROW_EXCEPTION("Provided projection " << projection_.type() + << " is incompatible with the CubedSphere2 grid type"); + } +} + std::string CubedSphere2::name() const { return "CS-LFR-" + std::to_string(N_) + "-2"; } @@ -173,14 +193,10 @@ static class cubedsphere2_lfric : public GridBuilder { throw_AssertionFailed("Could not find \"N\" in configuration of cubed sphere grid 2", Here()); } - return new CubedSphereGrid2::grid_t(N); - - // TODO: requires CubedSphereGrid2 constructor with projection - - // std::string name = "CS-LFR-" + std::to_string(N) + "-2"; - // util::Config projconf; - // projconf.set("type", "cubedsphere2"); - // projconf.set("tile.type", "cubedsphere2_lfric"); + std::string name = "CS-LFR-" + std::to_string(N) + "-2"; + util::Config projconf; + projconf.set("type", "cubedsphere2"); + projconf.set("tile.type", "cubedsphere2_lfric"); // // Shift projection by a longitude // if (config.has("ShiftLon")) { @@ -207,7 +223,7 @@ static class cubedsphere2_lfric : public GridBuilder { // } // } - // return new CubedSphereGrid2::grid_t(name, N, Projection(projconf)); + return new CubedSphereGrid2::grid_t(N, Projection(projconf)); } void force_link() {} diff --git a/src/atlas/grid/detail/grid/CubedSphere2.h b/src/atlas/grid/detail/grid/CubedSphere2.h index 04713a70c..d16425f5d 100644 --- a/src/atlas/grid/detail/grid/CubedSphere2.h +++ b/src/atlas/grid/detail/grid/CubedSphere2.h @@ -1,6 +1,7 @@ #pragma once #include "atlas/grid/detail/grid/Grid.h" +#include "atlas/projection/detail/CubedSphere2ProjectionBase.h" #include "atlas/runtime/Exception.h" #include "atlas/util/Config.h" #include "atlas/util/Point.h" @@ -11,6 +12,8 @@ namespace grid { namespace detail { namespace grid { +using atlas::projection::detail::CubedSphere2ProjectionBase; + class CubedSphere2 : public Grid { private: @@ -110,6 +113,7 @@ class CubedSphere2 : public Grid { using Spec = atlas::util::Config; CubedSphere2(idx_t resolution); + CubedSphere2(idx_t resolution, Projection projection); std::string name() const override; std::string type() const override; @@ -183,6 +187,7 @@ class CubedSphere2 : public Grid { {{ {-1, 0, 0}, {0, -1, 0}, {0, 0, -1} }} }}; + CubedSphere2ProjectionBase* cs2_projection_; // store pointer to dynamic_cast for convenience }; } // namespace grid diff --git a/src/atlas/projection/detail/CubedSphere2ProjectionBase.cc b/src/atlas/projection/detail/CubedSphere2ProjectionBase.cc new file mode 100644 index 000000000..84f316004 --- /dev/null +++ b/src/atlas/projection/detail/CubedSphere2ProjectionBase.cc @@ -0,0 +1,41 @@ +#include "CubedSphere2ProjectionBase.h" + +#include "atlas/runtime/Trace.h" +#include "atlas/projection/detail/ProjectionFactory.h" +#include "atlas/runtime/Exception.h" +#include "atlas/runtime/Trace.h" +#include "atlas/util/Config.h" +#include "eckit/utils/Hash.h" + +namespace atlas { +namespace projection { +namespace detail { + +using Spec = atlas::util::Config; + +CubedSphere2ProjectionBase::CubedSphere2ProjectionBase(const eckit::Parametrisation& params) { + ATLAS_TRACE("CubedSphere2ProjectionBase::CubedSphere2ProjectionBase"); +} + +Spec CubedSphere2ProjectionBase::spec() const { + Spec proj; + proj.set("type", static_type()); + return proj; +} + +Jacobian CubedSphere2ProjectionBase::jacobian(const PointLonLat& lonlat) const { + ATLAS_NOTIMPLEMENTED; +} + +void CubedSphere2ProjectionBase::hash(eckit::Hash& h) const { + // Add to hash + h.add(static_type()); +} + +namespace { +static ProjectionBuilder register_1(CubedSphere2ProjectionBase::static_type()); +} + +} // namespace detail +} // namespace projection +} // namespace atlas diff --git a/src/atlas/projection/detail/CubedSphere2ProjectionBase.h b/src/atlas/projection/detail/CubedSphere2ProjectionBase.h new file mode 100644 index 000000000..c7eb9f293 --- /dev/null +++ b/src/atlas/projection/detail/CubedSphere2ProjectionBase.h @@ -0,0 +1,40 @@ +#pragma once + +#include "atlas/domain/Domain.h" +#include "atlas/projection/Jacobian.h" +#include "atlas/projection/detail/ProjectionImpl.h" +#include "atlas/util/Config.h" + +namespace atlas { +namespace projection { +namespace detail { + +class CubedSphere2ProjectionBase final : public ProjectionImpl { +public: + CubedSphereProjectionBase(const eckit::Parametrisation&); + + static std::string static_type() { return "cubedsphere2"; } + std::string type() const override { return static_type(); } + void xy2lonlat(double crd[]) const {} + void lonlat2xy(double crd[]) const {} + + virtual Jacobian jacobian(const PointLonLat&) const override; + bool strictlyRegional() const override { return false; } + + virtual RectangularLonLatDomain lonlatBoundingBox(const Domain&) const override { + return GlobalDomain(); + } + + using Spec = atlas::util::Config; + + virtual Spec spec() const override; + + virtual std::string units() const override { return "degrees"; } + + virtual void hash(eckit::Hash&) const override; + +}; + +} // namespace detail +} // namespace projection +} // namespace atlas From 2aae5ae7f6381dbbd9cc98b9554f09e91f9c3886 Mon Sep 17 00:00:00 2001 From: mo-jonasganderton Date: Fri, 10 Jan 2025 14:02:31 +0000 Subject: [PATCH 20/31] Fix typo to use CubedSphere2ProjectionBase --- src/atlas/projection/detail/CubedSphere2ProjectionBase.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/atlas/projection/detail/CubedSphere2ProjectionBase.h b/src/atlas/projection/detail/CubedSphere2ProjectionBase.h index c7eb9f293..b6eff4060 100644 --- a/src/atlas/projection/detail/CubedSphere2ProjectionBase.h +++ b/src/atlas/projection/detail/CubedSphere2ProjectionBase.h @@ -11,7 +11,7 @@ namespace detail { class CubedSphere2ProjectionBase final : public ProjectionImpl { public: - CubedSphereProjectionBase(const eckit::Parametrisation&); + CubedSphere2ProjectionBase(const eckit::Parametrisation&); static std::string static_type() { return "cubedsphere2"; } std::string type() const override { return static_type(); } From 358ff93f563dab1efe32cc205bbfc5aac6d9c0e4 Mon Sep 17 00:00:00 2001 From: mo-jonasganderton Date: Mon, 13 Jan 2025 15:25:15 +0000 Subject: [PATCH 21/31] Remove commented code --- src/atlas/grid/detail/grid/CubedSphere2.cc | 25 ---------------------- 1 file changed, 25 deletions(-) diff --git a/src/atlas/grid/detail/grid/CubedSphere2.cc b/src/atlas/grid/detail/grid/CubedSphere2.cc index ca9107c28..dabab6e41 100644 --- a/src/atlas/grid/detail/grid/CubedSphere2.cc +++ b/src/atlas/grid/detail/grid/CubedSphere2.cc @@ -198,31 +198,6 @@ static class cubedsphere2_lfric : public GridBuilder { projconf.set("type", "cubedsphere2"); projconf.set("tile.type", "cubedsphere2_lfric"); - // // Shift projection by a longitude - // if (config.has("ShiftLon")) { - // double shiftLon = 0.0; - // config.get("ShiftLon", shiftLon); - // projconf.set("ShiftLon", shiftLon); - // } - - // // Apply a Schmidt transform - // if (config.has("DoSchmidt")) { - // bool doSchmidt = false; - // config.get("DoSchmidt", doSchmidt); - // if (doSchmidt) { - // double stretchFac; - // double targetLon; - // double targetLat; - // config.get("StretchFac", stretchFac); - // config.get("TargetLon", targetLon); - // config.get("TargetLat", targetLat); - // projconf.set("DoSchmidt", doSchmidt); - // projconf.set("StretchFac", stretchFac); - // projconf.set("TargetLon", targetLon); - // projconf.set("TargetLat", targetLat); - // } - // } - return new CubedSphereGrid2::grid_t(N, Projection(projconf)); } From 5751e2dcbb82e774f5219188c5ccaa32cb14c190 Mon Sep 17 00:00:00 2001 From: mo-jonasganderton Date: Mon, 13 Jan 2025 15:26:09 +0000 Subject: [PATCH 22/31] Change projection type name --- src/atlas/grid/detail/grid/CubedSphere2.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/atlas/grid/detail/grid/CubedSphere2.cc b/src/atlas/grid/detail/grid/CubedSphere2.cc index dabab6e41..a028cec33 100644 --- a/src/atlas/grid/detail/grid/CubedSphere2.cc +++ b/src/atlas/grid/detail/grid/CubedSphere2.cc @@ -28,7 +28,7 @@ CubedSphere2::CubedSphere2(idx_t resolution, Projection projection) : // Copy members util::Config defaultProjConfig; - defaultProjConfig.set("type", "cubedsphere_equiangular"); + defaultProjConfig.set("type", "cubedsphere2"); projection_ = projection ? projection : Projection(defaultProjConfig); // Domain From 142ed046bb9cff0d82d517d3bb74b7e1f5e836ae Mon Sep 17 00:00:00 2001 From: mo-jonasganderton Date: Thu, 6 Feb 2025 16:03:06 +0000 Subject: [PATCH 23/31] Enable CS2 grid builder in test --- src/tests/grid/test_cubedsphere_2.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/tests/grid/test_cubedsphere_2.cc b/src/tests/grid/test_cubedsphere_2.cc index d47cea3c0..5a38c38cd 100644 --- a/src/tests/grid/test_cubedsphere_2.cc +++ b/src/tests/grid/test_cubedsphere_2.cc @@ -36,8 +36,7 @@ CASE("cubed_sphere_instantiation") { CASE("constructor_with_grid") { auto grid_og = Grid("O32"); - // auto grid_cs = Grid("CS-LFR-4-2"); // The grid factory is implemented in the next PR - auto grid_cs = CubedSphereGrid2(4); + auto grid_cs = Grid("CS-LFR-4-2"); EXPECT( CubedSphereGrid2( grid_og ).valid() == false ); EXPECT( bool(CubedSphereGrid2( grid_og )) == false ); EXPECT( CubedSphereGrid2( grid_cs ).valid() == true ); From 38add695deeeefd2654e69a03800053125b3c8f1 Mon Sep 17 00:00:00 2001 From: mo-jonasganderton Date: Thu, 6 Feb 2025 16:03:48 +0000 Subject: [PATCH 24/31] Add grid_ to constructor with projection --- src/atlas/grid/CubedSphereGrid2.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/atlas/grid/CubedSphereGrid2.cc b/src/atlas/grid/CubedSphereGrid2.cc index 9c2625133..eec7fbce2 100644 --- a/src/atlas/grid/CubedSphereGrid2.cc +++ b/src/atlas/grid/CubedSphereGrid2.cc @@ -14,6 +14,6 @@ CubedSphereGrid2::CubedSphereGrid2(const Grid& grid): Grid(grid), grid_(cubedsphere_grid2(get())) {} CubedSphereGrid2::CubedSphereGrid2(idx_t resolution, Projection projection): - Grid(new grid::detail::grid::CubedSphere2(resolution, projection)) {} + Grid(new grid::detail::grid::CubedSphere2(resolution, projection)), grid_(cubedsphere_grid2(get())) {} } // namespace atlas From a1372b885093c01d6673d75c94604adeace62ae1 Mon Sep 17 00:00:00 2001 From: mo-jonasganderton Date: Thu, 6 Feb 2025 17:06:47 +0000 Subject: [PATCH 25/31] Remove unused PointAlphaBeta --- src/atlas/grid/detail/grid/CubedSphere2.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/atlas/grid/detail/grid/CubedSphere2.h b/src/atlas/grid/detail/grid/CubedSphere2.h index d16425f5d..3c67c40fc 100644 --- a/src/atlas/grid/detail/grid/CubedSphere2.h +++ b/src/atlas/grid/detail/grid/CubedSphere2.h @@ -150,7 +150,6 @@ class CubedSphere2 : public Grid { private: using CSIndices = std::array; - using PointAlphaBeta = Point2; CSIndices get_cs_indices(gidx_t n) const; PointXY ij_to_tangent_coord(idx_t i, idx_t j) const; From 06443d92ffd7e19cb7ab991db20ca10b0a3eb833 Mon Sep 17 00:00:00 2001 From: mo-jonasganderton Date: Thu, 6 Feb 2025 17:08:57 +0000 Subject: [PATCH 26/31] Remove unused eckit matrix --- src/atlas/grid/detail/grid/CubedSphere2.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/atlas/grid/detail/grid/CubedSphere2.h b/src/atlas/grid/detail/grid/CubedSphere2.h index 3c67c40fc..55ce7dd89 100644 --- a/src/atlas/grid/detail/grid/CubedSphere2.h +++ b/src/atlas/grid/detail/grid/CubedSphere2.h @@ -5,7 +5,6 @@ #include "atlas/runtime/Exception.h" #include "atlas/util/Config.h" #include "atlas/util/Point.h" -#include "eckit/maths/Matrix.h" namespace atlas { namespace grid { From 2b5666f2ce49eb8b5df15961abe01a792001c4c8 Mon Sep 17 00:00:00 2001 From: mo-jonasganderton Date: Fri, 7 Feb 2025 10:17:24 +0000 Subject: [PATCH 27/31] Remove commented code --- src/atlas/grid/detail/grid/CubedSphere2.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/src/atlas/grid/detail/grid/CubedSphere2.cc b/src/atlas/grid/detail/grid/CubedSphere2.cc index a028cec33..e5ee2be5e 100644 --- a/src/atlas/grid/detail/grid/CubedSphere2.cc +++ b/src/atlas/grid/detail/grid/CubedSphere2.cc @@ -34,7 +34,6 @@ CubedSphere2::CubedSphere2(idx_t resolution, Projection projection) : // Domain domain_ = GlobalDomain(); - // using atlas::projection::detail::CubedSphere2ProjectionBase; cs2_projection_ = dynamic_cast(projection_.get()); if (not cs2_projection_) { ATLAS_THROW_EXCEPTION("Provided projection " << projection_.type() From c7129d50134e28bcae3560ababc1e22c200cc6ec Mon Sep 17 00:00:00 2001 From: mo-jonasganderton Date: Wed, 12 Feb 2025 15:02:27 +0000 Subject: [PATCH 28/31] Remove cubed sphere 2 projection --- src/atlas/CMakeLists.txt | 2 - src/atlas/grid/detail/grid/CubedSphere2.cc | 12 +----- src/atlas/grid/detail/grid/CubedSphere2.h | 5 --- .../detail/CubedSphere2ProjectionBase.cc | 41 ------------------- .../detail/CubedSphere2ProjectionBase.h | 40 ------------------ 5 files changed, 2 insertions(+), 98 deletions(-) delete mode 100644 src/atlas/projection/detail/CubedSphere2ProjectionBase.cc delete mode 100644 src/atlas/projection/detail/CubedSphere2ProjectionBase.h diff --git a/src/atlas/CMakeLists.txt b/src/atlas/CMakeLists.txt index 42502405e..3ca0b5a41 100644 --- a/src/atlas/CMakeLists.txt +++ b/src/atlas/CMakeLists.txt @@ -94,8 +94,6 @@ projection/detail/CubedSphereEquiDistProjection.cc projection/detail/CubedSphereEquiDistProjection.h projection/detail/CubedSphereProjectionBase.cc projection/detail/CubedSphereProjectionBase.h -projection/detail/CubedSphere2ProjectionBase.cc -projection/detail/CubedSphere2ProjectionBase.h projection/detail/LambertAzimuthalEqualAreaProjection.cc projection/detail/LambertAzimuthalEqualAreaProjection.h projection/detail/LambertConformalConicProjection.cc diff --git a/src/atlas/grid/detail/grid/CubedSphere2.cc b/src/atlas/grid/detail/grid/CubedSphere2.cc index e5ee2be5e..aab885aea 100644 --- a/src/atlas/grid/detail/grid/CubedSphere2.cc +++ b/src/atlas/grid/detail/grid/CubedSphere2.cc @@ -6,7 +6,6 @@ #include "atlas/grid/CubedSphereGrid2.h" #include "atlas/grid/detail/grid/GridBuilder.h" #include "atlas/grid/detail/grid/GridFactory.h" -#include "atlas/projection/detail/CubedSphere2ProjectionBase.h" #include "atlas/runtime/Exception.h" #include "eckit/geometry/Sphere.h" #include "eckit/utils/Hash.h" @@ -28,17 +27,11 @@ CubedSphere2::CubedSphere2(idx_t resolution, Projection projection) : // Copy members util::Config defaultProjConfig; - defaultProjConfig.set("type", "cubedsphere2"); + defaultProjConfig.set("type", "lonlat"); projection_ = projection ? projection : Projection(defaultProjConfig); // Domain domain_ = GlobalDomain(); - - cs2_projection_ = dynamic_cast(projection_.get()); - if (not cs2_projection_) { - ATLAS_THROW_EXCEPTION("Provided projection " << projection_.type() - << " is incompatible with the CubedSphere2 grid type"); - } } std::string CubedSphere2::name() const { @@ -194,8 +187,7 @@ static class cubedsphere2_lfric : public GridBuilder { std::string name = "CS-LFR-" + std::to_string(N) + "-2"; util::Config projconf; - projconf.set("type", "cubedsphere2"); - projconf.set("tile.type", "cubedsphere2_lfric"); + projconf.set("type", "lonlat"); return new CubedSphereGrid2::grid_t(N, Projection(projconf)); } diff --git a/src/atlas/grid/detail/grid/CubedSphere2.h b/src/atlas/grid/detail/grid/CubedSphere2.h index 55ce7dd89..fd752e09b 100644 --- a/src/atlas/grid/detail/grid/CubedSphere2.h +++ b/src/atlas/grid/detail/grid/CubedSphere2.h @@ -1,7 +1,6 @@ #pragma once #include "atlas/grid/detail/grid/Grid.h" -#include "atlas/projection/detail/CubedSphere2ProjectionBase.h" #include "atlas/runtime/Exception.h" #include "atlas/util/Config.h" #include "atlas/util/Point.h" @@ -11,8 +10,6 @@ namespace grid { namespace detail { namespace grid { -using atlas::projection::detail::CubedSphere2ProjectionBase; - class CubedSphere2 : public Grid { private: @@ -184,8 +181,6 @@ class CubedSphere2 : public Grid { {{ {-1, 0, 0}, {0, 1, 0}, {0, 0, 1} }}, {{ {-1, 0, 0}, {0, -1, 0}, {0, 0, -1} }} }}; - - CubedSphere2ProjectionBase* cs2_projection_; // store pointer to dynamic_cast for convenience }; } // namespace grid diff --git a/src/atlas/projection/detail/CubedSphere2ProjectionBase.cc b/src/atlas/projection/detail/CubedSphere2ProjectionBase.cc deleted file mode 100644 index 84f316004..000000000 --- a/src/atlas/projection/detail/CubedSphere2ProjectionBase.cc +++ /dev/null @@ -1,41 +0,0 @@ -#include "CubedSphere2ProjectionBase.h" - -#include "atlas/runtime/Trace.h" -#include "atlas/projection/detail/ProjectionFactory.h" -#include "atlas/runtime/Exception.h" -#include "atlas/runtime/Trace.h" -#include "atlas/util/Config.h" -#include "eckit/utils/Hash.h" - -namespace atlas { -namespace projection { -namespace detail { - -using Spec = atlas::util::Config; - -CubedSphere2ProjectionBase::CubedSphere2ProjectionBase(const eckit::Parametrisation& params) { - ATLAS_TRACE("CubedSphere2ProjectionBase::CubedSphere2ProjectionBase"); -} - -Spec CubedSphere2ProjectionBase::spec() const { - Spec proj; - proj.set("type", static_type()); - return proj; -} - -Jacobian CubedSphere2ProjectionBase::jacobian(const PointLonLat& lonlat) const { - ATLAS_NOTIMPLEMENTED; -} - -void CubedSphere2ProjectionBase::hash(eckit::Hash& h) const { - // Add to hash - h.add(static_type()); -} - -namespace { -static ProjectionBuilder register_1(CubedSphere2ProjectionBase::static_type()); -} - -} // namespace detail -} // namespace projection -} // namespace atlas diff --git a/src/atlas/projection/detail/CubedSphere2ProjectionBase.h b/src/atlas/projection/detail/CubedSphere2ProjectionBase.h deleted file mode 100644 index b6eff4060..000000000 --- a/src/atlas/projection/detail/CubedSphere2ProjectionBase.h +++ /dev/null @@ -1,40 +0,0 @@ -#pragma once - -#include "atlas/domain/Domain.h" -#include "atlas/projection/Jacobian.h" -#include "atlas/projection/detail/ProjectionImpl.h" -#include "atlas/util/Config.h" - -namespace atlas { -namespace projection { -namespace detail { - -class CubedSphere2ProjectionBase final : public ProjectionImpl { -public: - CubedSphere2ProjectionBase(const eckit::Parametrisation&); - - static std::string static_type() { return "cubedsphere2"; } - std::string type() const override { return static_type(); } - void xy2lonlat(double crd[]) const {} - void lonlat2xy(double crd[]) const {} - - virtual Jacobian jacobian(const PointLonLat&) const override; - bool strictlyRegional() const override { return false; } - - virtual RectangularLonLatDomain lonlatBoundingBox(const Domain&) const override { - return GlobalDomain(); - } - - using Spec = atlas::util::Config; - - virtual Spec spec() const override; - - virtual std::string units() const override { return "degrees"; } - - virtual void hash(eckit::Hash&) const override; - -}; - -} // namespace detail -} // namespace projection -} // namespace atlas From dae5b7705cafb0d1db64f310c942728009f65430 Mon Sep 17 00:00:00 2001 From: mo-jonasganderton Date: Wed, 12 Feb 2025 16:39:22 +0000 Subject: [PATCH 29/31] Add test for rotated_lonlat projection --- src/tests/grid/test_cubedsphere_2.cc | 32 ++++++++++++++++++---------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/tests/grid/test_cubedsphere_2.cc b/src/tests/grid/test_cubedsphere_2.cc index 5a38c38cd..ed9daa9ad 100644 --- a/src/tests/grid/test_cubedsphere_2.cc +++ b/src/tests/grid/test_cubedsphere_2.cc @@ -8,16 +8,24 @@ namespace test { namespace { using Point2 = eckit::geometry::Point2; +// XY/lonlat for a Cubed Sphere, with N = 2 +std::vector kgo_lonlat { + {-22.5,20.941}, {22.5,20.941}, {-22.5,-20.941}, {22.5,-20.941}, {67.5,20.941}, {112.5,20.941}, + {67.5,-20.941}, {112.5,-20.941}, {157.5,20.941}, {-157.5,20.941}, {157.5,-20.941}, {-157.5,-20.941}, + {-112.5,20.941}, {-67.5,20.941}, {-112.5,-20.941}, {-67.5,-20.941}, {-45,59.6388}, {-135,59.6388}, + {45,59.6388}, {135,59.6388}, {45,-59.6388}, {135,-59.6388}, {-45,-59.6388}, {-135,-59.6388} +}; + template -bool compare_2D_points(std::vector a, std::vector b, double tolerance = 1e-4) { +bool compare_2D_points(std::vector a, std::vector b, bool print_diff = true, double tolerance = 1e-4) { // Uses a tolerance as the values are stored more precisely than they are printed ATLAS_ASSERT(a.size() == b.size()); bool equal = true; for (int i = 0; i < b.size(); ++i) { for (int j = 0; j < 2; ++j) { if (std::abs(b[i][j] - a[i][j]) > tolerance) { - std::cout << "[" << i << ", " << j << "]\n\t" << a[i][j] << " != " << b[i][j] - << "\n\tdiff = " << b[i][j] - a[i][j] << std::endl; + if (print_diff) std::cout << "[" << i << ", " << j << "]\n\t" << a[i][j] << " != " << b[i][j] + << "\n\tdiff = " << b[i][j] - a[i][j] << std::endl; equal = false; } } @@ -44,14 +52,6 @@ CASE("constructor_with_grid") { } CASE("cubed_sphere_grid_kgo") { - // Lonlat and XY are both currently lonlat positions - std::vector kgo_lonlat { // N = 2 - {-22.5,20.941}, {22.5,20.941}, {-22.5,-20.941}, {22.5,-20.941}, {67.5,20.941}, {112.5,20.941}, - {67.5,-20.941}, {112.5,-20.941}, {157.5,20.941}, {-157.5,20.941}, {157.5,-20.941}, {-157.5,-20.941}, - {-112.5,20.941}, {-67.5,20.941}, {-112.5,-20.941}, {-67.5,-20.941}, {-45,59.6388}, {-135,59.6388}, - {45,59.6388}, {135,59.6388}, {45,-59.6388}, {135,-59.6388}, {-45,-59.6388}, {-135,-59.6388} - }; - const Grid grid = CubedSphereGrid2(2); // LonLat @@ -82,6 +82,16 @@ CASE("cubed_sphere_grid_builder") { EXPECT(grid.size() == n * n * 6); } +CASE("cubed_sphere_rotated_lonlat") { + const auto grid_rotated = CubedSphereGrid2(2, Projection(util::Config("type", "rotated_lonlat")("north_pole", std::vector{4., 54.}))); + + std::vector points_lonlat; + for (const auto &lonlat : grid_rotated.lonlat()) { + points_lonlat.push_back(lonlat); + } + EXPECT(compare_2D_points(points_lonlat, kgo_lonlat, false) == false); +} + } // namespace } // namespace test } // namespace atlas From 3cf38e42910c4ffeed4f3752994414fd1a4242d9 Mon Sep 17 00:00:00 2001 From: mo-jonasganderton Date: Wed, 12 Feb 2025 16:44:52 +0000 Subject: [PATCH 30/31] Add check for unchanged XY points --- src/tests/grid/test_cubedsphere_2.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/tests/grid/test_cubedsphere_2.cc b/src/tests/grid/test_cubedsphere_2.cc index ed9daa9ad..5e2d0b845 100644 --- a/src/tests/grid/test_cubedsphere_2.cc +++ b/src/tests/grid/test_cubedsphere_2.cc @@ -85,6 +85,14 @@ CASE("cubed_sphere_grid_builder") { CASE("cubed_sphere_rotated_lonlat") { const auto grid_rotated = CubedSphereGrid2(2, Projection(util::Config("type", "rotated_lonlat")("north_pole", std::vector{4., 54.}))); + // Expect XY points to still match + std::vector points_xy; + for (const auto &xy : grid_rotated.xy()) { + points_xy.push_back(xy); + } + EXPECT(compare_2D_points(points_xy, kgo_lonlat) == true); + + // Expect lonlats to be different std::vector points_lonlat; for (const auto &lonlat : grid_rotated.lonlat()) { points_lonlat.push_back(lonlat); From 3c2da9cb541487e9a6ccc5ad6bb7d43a8fd561ed Mon Sep 17 00:00:00 2001 From: mo-jonasganderton Date: Wed, 12 Feb 2025 16:55:16 +0000 Subject: [PATCH 31/31] Remove duplicate test --- src/tests/grid/test_cubedsphere_2.cc | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/tests/grid/test_cubedsphere_2.cc b/src/tests/grid/test_cubedsphere_2.cc index 5e2d0b845..0939aa310 100644 --- a/src/tests/grid/test_cubedsphere_2.cc +++ b/src/tests/grid/test_cubedsphere_2.cc @@ -35,9 +35,10 @@ bool compare_2D_points(std::vector a, std::vector b, boo CASE("cubed_sphere_instantiation") { const int n = 2; - const Grid grid = CubedSphereGrid2(n); - - EXPECT(grid.name() == "CS-LFR-" + std::to_string(n) + "-2"); + const std::string name = "CS-LFR-" + std::to_string(n) + "-2"; + + const Grid grid = Grid(name); + EXPECT(grid.name() == name); EXPECT(grid.type() == "cubedsphere2"); EXPECT(grid.size() == n * n * 6); } @@ -73,15 +74,6 @@ CASE("cubed_sphere_grid_kgo") { EXPECT(compare_2D_points(points_xy, kgo_lonlat)); } -CASE("cubed_sphere_grid_builder") { - const int n = 2; - const std::string name = "CS-LFR-" + std::to_string(n) + "-2"; - const Grid grid = Grid(name); - EXPECT(grid.name() == name); - EXPECT(grid.type() == "cubedsphere2"); - EXPECT(grid.size() == n * n * 6); -} - CASE("cubed_sphere_rotated_lonlat") { const auto grid_rotated = CubedSphereGrid2(2, Projection(util::Config("type", "rotated_lonlat")("north_pole", std::vector{4., 54.})));