17 #include "eckit/types/Types.h" 19 #include "atlas/array.h" 20 #include "atlas/grid/Spacing.h" 21 #include "atlas/grid/Tiles.h" 22 #include "atlas/grid/detail/grid/Grid.h" 23 #include "atlas/library/config.h" 24 #include "atlas/projection/detail/CubedSphereProjectionBase.h" 25 #include "atlas/runtime/Exception.h" 26 #include "atlas/runtime/Log.h" 27 #include "atlas/util/CoordinateEnums.h" 28 #include "atlas/util/Object.h" 29 #include "atlas/util/ObjectHandle.h" 52 struct ComputePointXY {
53 ComputePointXY(
const CubedSphere& grid ) : grid_( grid ) {}
59 struct ComputePointLonLat {
60 ComputePointLonLat(
const CubedSphere& grid ) : grid_( grid ) {}
65 class PointTIJ :
public std::array<idx_t, 3> {
67 using std::array<idx_t, 3>::array;
68 idx_t t()
const {
return data()[0]; }
69 idx_t i()
const {
return data()[1]; }
70 idx_t j()
const {
return data()[2]; }
71 idx_t& t() {
return data()[0]; }
72 idx_t& i() {
return data()[1]; }
73 idx_t& j() {
return data()[2]; }
76 struct ComputePointTIJ {
77 ComputePointTIJ(
const CubedSphere& grid ) : grid_( grid ) {}
88 template <
typename Base,
typename ComputePo
int>
89 class CubedSphereIterator :
public Base {
94 CubedSphereIterator(
const CubedSphere& grid,
bool begin =
true ) :
96 i_( begin ? 0 : grid_.N() ),
97 j_( begin ? 0 : grid_.N() ),
99 size_( grid_.size() ),
100 n_( begin ? 0 : size_ ),
101 compute_point{grid_} {
103 if ( grid_.inGrid( i_, j_, t_ ) ) {
104 compute_point( i_, j_, t_, point_ );
109 virtual bool next(
typename Base::value_type& point ) {
111 compute_point( i_, j_, t_, point );
112 std::unique_ptr<int[]> ijt = grid_.nextElement( i_, j_, t_ );
123 virtual const typename Base::reference operator*()
const {
return point_; }
126 virtual const Base& operator++() {
127 std::unique_ptr<int[]> ijt = grid_.nextElement( i_, j_, t_ );
133 compute_point( i_, j_, t_, point_ );
139 virtual const Base& operator+=(
typename Base::difference_type distance ) {
144 for (
int n = 0; n < d; n++ ) {
145 std::unique_ptr<int[]> ijt = grid_.nextElement( i_, j_, t_ );
152 compute_point( i_, j_, t_, point_ );
159 virtual typename Base::difference_type distance(
const Base& other )
const {
160 const auto& _other =
static_cast<const CubedSphereIterator&
>( other );
161 typename Base::difference_type d = 0;
166 for (
int n = 0; n < grid_.size(); n++ ) {
167 if ( i == _other.i_ && j == _other.j_ && t == _other.t_ ) {
171 std::unique_ptr<int[]> ijt = grid_.nextElement( i, j, t );
177 ATLAS_ASSERT( !found,
"CubedSphereIterator.distance: cycled entire grid without finding other" );
182 virtual bool operator==(
const Base& other )
const {
183 return i_ ==
static_cast<const CubedSphereIterator&
>( other ).i_ &&
184 j_ == static_cast<const CubedSphereIterator&>( other ).j_ &&
185 t_ ==
static_cast<const CubedSphereIterator&
>( other ).t_;
189 virtual bool operator!=(
const Base& other )
const {
190 return i_ !=
static_cast<const CubedSphereIterator&
>( other ).i_ ||
191 j_ != static_cast<const CubedSphereIterator&>( other ).j_ ||
192 t_ !=
static_cast<const CubedSphereIterator&
>( other ).t_;
196 virtual std::unique_ptr<Base> clone()
const {
197 auto result =
new CubedSphereIterator( grid_,
false );
201 result->point_ = point_;
202 result->size_ = size_;
204 return std::unique_ptr<Base>( result );
213 typename Base::value_type point_;
214 ComputePoint compute_point;
221 using IteratorXY = CubedSphereIterator<Grid::IteratorXY, ComputePointXY>;
222 using IteratorLonLat = CubedSphereIterator<Grid::IteratorLonLat, ComputePointLonLat>;
225 using IteratorTIJ = CubedSphereIterator<IteratorTIJ_Base, ComputePointTIJ>;
227 static std::string static_type();
238 virtual idx_t size()
const override {
return accumulate( npts_.begin(), npts_.end(), 0 ); }
241 virtual Spec spec()
const override;
242 virtual std::string
name()
const override;
243 virtual std::string type()
const override;
246 inline idx_t N()
const {
return N_; }
254 inline double xsPlusIndex(
idx_t idx,
idx_t t )
const {
255 return static_cast<double>( xs_[t] ) + static_cast<double>( idx );
258 inline double xsrMinusIndex(
idx_t idx,
idx_t t )
const {
259 return static_cast<double>( xsr_[t] ) - static_cast<double>( idx );
262 inline double ysPlusIndex(
idx_t idx,
idx_t t )
const {
263 return static_cast<double>( ys_[t] ) + static_cast<double>( idx );
266 inline double ysrMinusIndex(
idx_t idx,
idx_t t )
const {
267 return static_cast<double>( ysr_[t] ) - static_cast<double>( idx );
273 std::vector<std::function<double( int, int, int )>> xtile;
274 std::vector<std::function<double( int, int, int )>> ytile;
280 crd[0] = xtile.at( t )( i, j, t );
281 crd[1] = ytile.at( t )( i, j, t );
282 crd[2] =
static_cast<double>( t );
286 return PointXY( xtile.at( t )( i, j, t ), ytile.at( t )( i, j, t ) );
291 this->xyt( i, j, t, crd );
292 this->xyt2xy( crd, xy );
297 this->xy( i, j, t, crd );
298 return PointXY( crd[0], crd[1] );
305 this->xy( i, j, t, lonlat );
306 projection_.xy2lonlat( lonlat );
311 this->lonlat( i, j, t, lonlat );
318 constexpr
idx_t tmax = 5;
319 if ( t >= 0 && t <= tmax ) {
320 if ( j >= jmin_[t] && j <= jmax_[t] ) {
321 if ( i >= imin_[t][j] && i <= imax_[t][j] ) {
333 constexpr
idx_t tmax = 5;
335 idx_t jmax = jmax_[tmax];
337 if ( i == imax_[tmax][jmax] ) {
349 std::unique_ptr<int[]> nextElement(
const idx_t i,
const idx_t j,
const idx_t t )
const {
350 std::unique_ptr<int[]> ijt(
new int[3] );
356 if ( i < imax_[t][j] ) {
363 if ( i == imax_[t][j] ) {
364 if ( j < jmax_[t] ) {
372 if ( j == jmax_[t] ) {
373 if ( t < nTiles_ - 1 ) {
381 if ( t == nTiles_ - 1 ) {
388 ijt[2] = nTiles_ - 1;
400 virtual std::unique_ptr<Grid::IteratorXY> xy_begin()
const override {
401 return std::unique_ptr<Grid::IteratorXY>(
new IteratorXY( *
this ) );
403 virtual std::unique_ptr<Grid::IteratorXY> xy_end()
const override {
404 return std::unique_ptr<Grid::IteratorXY>(
new IteratorXY( *
this,
false ) );
406 virtual std::unique_ptr<Grid::IteratorLonLat> lonlat_begin()
const override {
407 return std::unique_ptr<Grid::IteratorLonLat>(
new IteratorLonLat( *
this ) );
409 virtual std::unique_ptr<Grid::IteratorLonLat> lonlat_end()
const override {
410 return std::unique_ptr<Grid::IteratorLonLat>(
new IteratorLonLat( *
this,
false ) );
412 virtual std::unique_ptr<IteratorTIJ> tij_begin()
const {
413 return std::unique_ptr<IteratorTIJ>(
new IteratorTIJ( *
this ) );
415 virtual std::unique_ptr<IteratorTIJ> tij_end()
const {
416 return std::unique_ptr<IteratorTIJ>(
new IteratorTIJ( *
this,
false ) );
421 Config meshgenerator()
const override;
423 Config partitioner()
const override;
425 const std::string& stagger()
const {
return stagger_; }
428 virtual void print( std::ostream& )
const override;
430 virtual void hash( eckit::Hash& )
const override;
434 Domain computeDomain()
const;
437 void xy2xyt(
const double xy[],
double xyt[] )
const;
439 void xyt2xy(
const double xyt[],
double xy[] )
const;
446 static const idx_t nTiles_ = 6;
451 double xsr_[nTiles_];
452 double ysr_[nTiles_];
455 std::vector<int> npts_;
457 std::string tileType_;
459 std::array<idx_t, 6> jmin_;
460 std::array<idx_t, 6> jmax_;
461 std::vector<std::vector<idx_t>> imin_;
462 std::vector<std::vector<idx_t>> imax_;
464 std::string stagger_;
467 std::string name_ = {
"cubedsphere"};
470 std::array<std::array<double, 6>, 2> tiles_offsets_xy2ab_;
471 std::array<std::array<double, 6>, 2> tiles_offsets_ab2xy_;
std::string hash() const
Definition: Grid.cc:127
virtual void print(std::ostream &) const override
Fill provided me.
Definition: CubedSphere.cc:232
This file contains classes and functions working on points.
Point in longitude-latitude coordinate system.
Definition: Point.h:103
Definition: Projection.h:49
Definition: CubedSphere.h:224
virtual std::string name() const override
Human readable name (may not be unique)
Definition: CubedSphere.cc:53
Definition: CubedSphere.h:49
virtual idx_t size() const override
Definition: CubedSphere.h:238
virtual RectangularLonLatDomain lonlatBoundingBox() const override
Definition: CubedSphere.cc:254
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
Definition: CubedSphereProjectionBase.h:24
Configuration class used to construct various atlas components.
Definition: Config.h:27