16 #include "atlas/grid/Spacing.h" 17 #include "atlas/grid/detail/grid/Grid.h" 18 #include "atlas/grid/detail/spacing/LinearSpacing.h" 19 #include "atlas/library/config.h" 20 #include "atlas/runtime/Exception.h" 21 #include "atlas/util/Object.h" 22 #include "atlas/util/ObjectHandle.h" 41 struct ComputePointXY {
42 ComputePointXY(
const Structured& grid ) : grid_( grid ), ny_( grid_.ny() ) {}
45 grid_.xy( i, j, point.data() );
51 struct ComputePointLonLat {
52 ComputePointLonLat(
const Structured& grid ) : grid_( grid ), ny_( grid_.ny() ) {}
55 grid_.lonlat( i, j, point.data() );
62 template <
typename Base,
typename ComputePo
int>
63 class StructuredIterator :
public Base {
65 StructuredIterator(
const Structured& grid,
bool begin =
true ) :
66 grid_( grid ), ny_( grid_.ny() ), i_( 0 ), j_( begin ? 0 : grid_.ny() ), compute_point{grid_} {
67 if ( j_ != ny_ && grid_.size() ) {
68 compute_point( i_, j_, point_ );
71 virtual bool next(
typename Base::value_type& point ) {
72 if ( j_ < ny_ && i_ < grid_.nx( j_ ) ) {
73 compute_point( i_++, j_, point );
75 if ( i_ == grid_.nx( j_ ) ) {
84 virtual const typename Base::reference operator*()
const {
return point_; }
86 virtual const Base& operator++() {
88 if ( i_ == grid_.nx( j_ ) ) {
92 compute_point( i_, j_, point_ );
96 virtual const Base& operator+=(
typename Base::difference_type distance ) {
98 while ( j_ != ny_ && d >= ( grid_.nx( j_ ) - i_ ) ) {
99 d -= ( grid_.nx( j_ ) - i_ );
104 compute_point( i_, j_, point_ );
108 virtual typename Base::difference_type distance(
const Base& other )
const {
109 const auto& _other =
static_cast<const StructuredIterator&
>( other );
110 typename Base::difference_type d = 0;
113 while ( j < _other.j_ ) {
114 d += grid_.nx( j ) - i;
122 virtual bool operator==(
const Base& other )
const {
123 return j_ ==
static_cast<const StructuredIterator&
>( other ).j_ &&
124 i_ == static_cast<const StructuredIterator&>( other ).i_;
127 virtual bool operator!=(
const Base& other )
const {
128 return i_ !=
static_cast<const StructuredIterator&
>( other ).i_ ||
129 j_ != static_cast<const StructuredIterator&>( other ).j_;
132 virtual std::unique_ptr<Base> clone()
const {
133 auto result =
new StructuredIterator( grid_,
false );
136 result->point_ = point_;
137 return std::unique_ptr<Base>( result );
145 typename Base::value_type point_;
146 ComputePoint compute_point;
150 using IteratorXY = StructuredIterator<Grid::IteratorXY, ComputePointXY>;
151 using IteratorLonLat = StructuredIterator<Grid::IteratorLonLat, ComputePointLonLat>;
158 template <
typename NVector>
159 Implementation(
const std::array<double, 2>& interval,
const NVector& N,
bool endpoint =
true );
161 Implementation(
const std::array<double, 2>& interval, std::initializer_list<int>&& N,
162 bool endpoint =
true );
166 Implementation(
const std::vector<Spacing>& );
168 Implementation(
const Config& );
170 Implementation(
const std::vector<Config>& );
172 Implementation(
const std::vector<spacing::LinearSpacing::Params>& );
174 idx_t ny()
const {
return ny_; }
177 idx_t nxmin()
const {
return nxmin_; }
180 idx_t nxmax()
const {
return nxmax_; }
183 const std::vector<idx_t>& nx()
const {
return nx_; }
186 const std::vector<double>& xmin()
const {
return xmin_; }
189 const std::vector<double>& xmax()
const {
return xmax_; }
192 const std::vector<double>& dx()
const {
return dx_; }
195 double min()
const {
return min_; }
198 double max()
const {
return max_; }
202 std::string type()
const;
205 void reserve(
idx_t ny );
211 std::vector<idx_t>
nx_;
212 std::vector<double>
xmin_;
213 std::vector<double>
xmax_;
214 std::vector<double>
dx_;
226 XSpace(
const std::vector<Spacing>& );
228 XSpace(
const std::vector<spacing::LinearSpacing::Params>& );
231 template <
typename NVector>
232 XSpace(
const std::array<double, 2>& interval,
const NVector& N,
bool endpoint =
true );
234 XSpace(
const std::array<double, 2>& interval, std::initializer_list<int>&& N,
bool endpoint =
true );
238 XSpace(
const std::vector<Config>& );
240 idx_t ny()
const {
return impl_->ny(); }
243 idx_t nxmin()
const {
return impl_->nxmin(); }
246 idx_t nxmax()
const {
return impl_->nxmax(); }
249 const std::vector<idx_t>&
nx()
const {
return impl_->nx(); }
252 const std::vector<double>&
xmin()
const {
return impl_->xmin(); }
255 const std::vector<double>&
xmax()
const {
return impl_->xmax(); }
258 const std::vector<double>&
dx()
const {
return impl_->dx(); }
261 double min()
const {
return impl_->min(); }
264 double max()
const {
return impl_->max(); }
268 std::string type()
const {
return impl_->type(); }
277 static std::string static_type();
288 virtual Spec spec()
const override;
295 virtual std::string
name()
const override;
297 virtual std::string type()
const override;
299 inline idx_t ny()
const {
return static_cast<idx_t>(
y_.size() ); }
303 inline idx_t nxmax()
const {
return nxmax_; }
305 inline idx_t nxmin()
const {
return nxmin_; }
307 inline const std::vector<idx_t>& nx()
const {
return nx_; }
309 inline const std::vector<double>& y()
const {
return y_; }
311 inline double dx(
idx_t j )
const {
return dx_[j]; }
313 inline double xmin(
idx_t j )
const {
return xmin_[j]; }
315 inline double x(
idx_t i,
idx_t j )
const {
return xmin_[j] +
static_cast<double>( i ) *
dx_[j]; }
317 inline double y(
idx_t j )
const {
return y_[j]; }
319 inline void xy(
idx_t i,
idx_t j,
double crd[] )
const {
328 void lonlat(
idx_t i,
idx_t j,
double crd[] )
const {
330 projection_.xy2lonlat( crd );
333 inline bool reduced()
const {
return nxmax() != nxmin(); }
337 const XSpace& xspace()
const {
return xspace_; }
338 const YSpace& yspace()
const {
return yspace_; }
340 virtual std::unique_ptr<Grid::IteratorXY> xy_begin()
const override {
341 return std::unique_ptr<Grid::IteratorXY>(
new IteratorXY( *
this ) );
343 virtual std::unique_ptr<Grid::IteratorXY> xy_end()
const override {
344 return std::unique_ptr<Grid::IteratorXY>(
new IteratorXY( *
this,
false ) );
346 virtual std::unique_ptr<Grid::IteratorLonLat> lonlat_begin()
const override {
347 return std::unique_ptr<Grid::IteratorLonLat>(
new IteratorLonLat( *
this ) );
349 virtual std::unique_ptr<Grid::IteratorLonLat> lonlat_end()
const override {
350 return std::unique_ptr<Grid::IteratorLonLat>(
new IteratorLonLat( *
this,
false ) );
356 if ( ( gidx < 0 ) || ( gidx >=
jglooff_.back() ) ) {
357 throw_Exception(
"Structured::index2ij: gidx out of bounds", Here() );
360 while ( jb - ja > 1 ) {
361 idx_t jm = ( ja + jb ) / 2;
373 Config meshgenerator()
const override;
374 Config partitioner()
const override;
378 virtual void print( std::ostream& )
const override;
380 virtual void hash( eckit::Hash& )
const override;
384 void computeTruePeriodicity();
386 Domain computeDomain()
const;
388 void crop(
const Domain& );
401 std::vector<double>
y_;
422 std::string name_ = {
"structured"};
425 mutable std::string type_;
429 void atlas__grid__Structured__delete(
Structured* This );
430 const Structured* atlas__grid__Structured(
char* identifier );
432 Structured* atlas__grid__regular__RegularGaussian(
long N );
433 Structured* atlas__grid__reduced__ReducedGaussian_int(
int nx[],
long ny );
434 Structured* atlas__grid__reduced__ReducedGaussian_long(
long nx[],
long ny );
435 Structured* atlas__grid__reduced__ReducedGaussian_int_projection(
int nx[],
long ny,
436 const Projection::Implementation*
projection );
437 Structured* atlas__grid__reduced__ReducedGaussian_long_projection(
long nx[],
long ny,
438 const Projection::Implementation* projection );
439 Structured* atlas__grid__regular__RegularLonLat(
long nx,
long ny );
440 Structured* atlas__grid__regular__ShiftedLonLat(
long nx,
long ny );
441 Structured* atlas__grid__regular__ShiftedLon(
long nx,
long ny );
442 Structured* atlas__grid__regular__ShiftedLat(
long nx,
long ny );
455 void atlas__grid__Structured__y_array(
Structured* This,
const double*& lats,
idx_t& size );
456 int atlas__grid__Structured__reduced(
Structured* This );
virtual RectangularLonLatDomain lonlatBoundingBox() const override
Definition: Structured.cc:699
std::string hash() const
Definition: Grid.cc:127
Structured Grid.
Definition: Structured.h:39
double max() const
Value of maximum x over entire grid.
Definition: Structured.h:264
This file contains classes and functions working on points.
virtual void print(std::ostream &) const override
Fill provided me.
Definition: Structured.cc:645
Point in longitude-latitude coordinate system.
Definition: Point.h:103
Definition: Projection.h:49
bool periodic_x_
Periodicity in x-direction.
Definition: Structured.h:416
const std::vector< double > & dx() const
Value of longitude increment.
Definition: Structured.h:258
const Projection & projection() const
Definition: Grid.h:113
virtual std::string name() const override
Human readable name Either the name is the one given at construction as a canonical named grid...
Definition: Structured.cc:44
const std::vector< double > & xmin() const
Value of minimum longitude per latitude [default=0].
Definition: Structured.h:252
std::vector< double > dx_
Value of longitude increment.
Definition: Structured.h:413
std::vector< double > y_
Latitude values.
Definition: Structured.h:401
const std::vector< double > & xmax() const
Value of maximum longitude per latitude [default=0].
Definition: Structured.h:255
double min() const
Value of minimum x over entire grid.
Definition: Structured.h:261
std::vector< gidx_t > jglooff_
Per-row offset.
Definition: Structured.h:419
std::vector< double > xmin_
Value of minimum longitude per latitude [default=0].
Definition: Structured.h:407
virtual idx_t size() const override
Definition: Structured.h:286
long gidx_t
Integer type for global indices.
Definition: config.h:34
Definition: Structured.h:154
std::vector< idx_t > nx_
Number of points per latitude.
Definition: Structured.h:404
Point in arbitrary XY-coordinate system.
Definition: Point.h:40
std::vector< double > xmax_
Value of maximum longitude per latitude [default=0].
Definition: Structured.h:410
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
const std::vector< idx_t > & nx() const
Number of points per latitude.
Definition: Structured.h:249
Configuration class used to construct various atlas components.
Definition: Config.h:27
idx_t npts_
Total number of unique points in the grid.
Definition: Structured.h:398