atlas
Tiles.h
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 grid {
39 
40 #ifndef DOXYGEN_SHOULD_SKIP_THIS
41 namespace detail {
42 class CubedSphereTiles;
43 } // namespace detail
44 #endif
45 
46 //---------------------------------------------------------------------------------------------------------------------
47 
48 class CubedSphereTiles : DOXYGEN_HIDE( public util::ObjectHandle<atlas::grid::detail::CubedSphereTiles> ) {
49 public:
50  using Spec = util::Config;
51 
52 public:
53  using Handle::Handle;
54  CubedSphereTiles() = default;
55  CubedSphereTiles( const eckit::Parametrisation& );
56  CubedSphereTiles( const std::string& );
57 
59  std::string type() const;
60 
61  // These are offsets needed for transforming
62  // from xy space to the "archetypal base" tile.
63  std::array<std::array<double, 6>, 2> xy2abOffsets() const;
64 
65  std::array<std::array<double, 6>, 2> ab2xyOffsets() const;
66 
67  void rotate( idx_t t, double xyz[] ) const;
68 
69  void unrotate( idx_t t, double xyz[] ) const;
70 
71  // tile index from xy space
72  idx_t indexFromXY( const double xy[] ) const;
73 
74  // tile index from longitude and latitude space
75  idx_t indexFromLonLat( const double lonlat[] ) const;
76 
77  // enforceXYdomain reinforces the tile shape in xy space;
78  // if values move a miniscule amount outside the domain, it will be brought back in.
79  void enforceXYdomain( double xy[] ) const;
80 
81  idx_t size() const;
82 
83  // this provides periodicity to each of the tiles by extending each tile over edges
84  // in a cross-like fashion. Periodicity of this form does not allow
85  // a "diagonal" extension over corners of the cube.
86  atlas::PointXY tileCubePeriodicity( const atlas::PointXY& xyExtended, const atlas::idx_t tile ) const;
87 
88 private:
90  void print( std::ostream& ) const;
91 
92  friend std::ostream& operator<<( std::ostream& s, const CubedSphereTiles& cst );
93 };
94 
95 } // namespace grid
96 } // namespace atlas
Definition: Domain.h:19
Definition: Tiles.h:48
Point in arbitrary XY-coordinate system.
Definition: Point.h:40
Contains all atlas classes and methods.
Definition: atlas-grids.cc:33
long idx_t
Integer type for indices in connectivity tables.
Definition: config.h:42
Configuration class used to construct various atlas components.
Definition: Config.h:27