FV3 Bundle
oops/interface/Geometry.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2009-2016 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 nor
8  * does it submit to any jurisdiction.
9  */
10 
11 #ifndef OOPS_INTERFACE_GEOMETRY_H_
12 #define OOPS_INTERFACE_GEOMETRY_H_
13 
14 #include <ostream>
15 #include <string>
16 #include <vector>
17 
18 #include <boost/shared_ptr.hpp>
19 
21 #include "oops/util/Logger.h"
22 #include "oops/util/ObjectCounter.h"
23 #include "oops/util/Printable.h"
24 #include "oops/util/Timer.h"
25 
26 namespace eckit {
27  class Configuration;
28 }
29 
30 namespace oops {
31 
32 // -----------------------------------------------------------------------------
33 
34 template <typename MODEL>
35 class Geometry : public util::Printable,
36  private util::ObjectCounter<Geometry<MODEL> > {
37  typedef typename MODEL::Geometry Geometry_;
39 
40  public:
41  static const std::string classname() {return "oops::Geometry";}
42 
43  explicit Geometry(const eckit::Configuration &);
44  Geometry(const Geometry &);
45  explicit Geometry(boost::shared_ptr<const Geometry_>);
46  ~Geometry();
47 
48  std::vector<int> getDims() const; // grid dimensions (1 integer if unstructured;
49  // 2 if structured), should be consistent with the packing
50  std::vector<double> getLats() const; // one value per point on the 2D horizontal grid (packed)
51  std::vector<double> getLons() const; // one value per point on the 2D horizontal grid (packed)
52  std::vector<double> getLevs() const; // vertical unit (one column)
53  std::vector<double> getArea() const; // area of each level (one column)
54  std::vector<int> getMask(const int &) const; // one value per point on the 2D horizontal grid
55  // for a given level (for ocean for example)
56 
57 /// Interfacing
58  const Geometry_ & geometry() const {return *geom_;}
59 
60  GeometryIterator_ begin() const;
61  GeometryIterator_ end() const;
62 
63  private:
64  Geometry & operator=(const Geometry &);
65  void print(std::ostream &) const;
66  boost::shared_ptr<const Geometry_> geom_;
67 };
68 
69 // -----------------------------------------------------------------------------
70 
71 template <typename MODEL>
72 Geometry<MODEL>::Geometry(const eckit::Configuration & conf): geom_() {
73  Log::trace() << "Geometry<MODEL>::Geometry starting" << std::endl;
74  util::Timer timer(classname(), "Geometry");
75  geom_.reset(new Geometry_(conf));
76  Log::trace() << "Geometry<MODEL>::Geometry done" << std::endl;
77 }
78 
79 // -----------------------------------------------------------------------------
80 
81 template <typename MODEL>
82 Geometry<MODEL>::Geometry(const Geometry & other): geom_(other.geom_) {
83  Log::trace() << "Geometry<MODEL>::Geometry copy done" << std::endl;
84 }
85 
86 // -----------------------------------------------------------------------------
87 
88 template <typename MODEL>
89 Geometry<MODEL>::Geometry(boost::shared_ptr<const Geometry_> ptr): geom_(ptr) {
90  Log::trace() << "Geometry<MODEL>::Geometry shared_ptr done" << std::endl;
91 }
92 
93 // -----------------------------------------------------------------------------
94 
95 template <typename MODEL>
97  Log::trace() << "Geometry<MODEL>::~Geometry starting" << std::endl;
98  util::Timer timer(classname(), "~Geometry");
99  geom_.reset();
100  Log::trace() << "Geometry<MODEL>::~Geometry done" << std::endl;
101 }
102 
103 // -----------------------------------------------------------------------------
104 
105 template <typename MODEL>
106 std::vector<int> Geometry<MODEL>::getDims() const {
107  Log::trace() << "Geometry<MODEL>::getDims" << std::endl;
108  util::Timer timer(classname(), "getDims");
109  return geom_.getDims();
110 }
111 
112 // -----------------------------------------------------------------------------
113 
114 template <typename MODEL>
115 std::vector<double> Geometry<MODEL>::getLats() const {
116  Log::trace() << "Geometry<MODEL>::getLats" << std::endl;
117  util::Timer timer(classname(), "getLats");
118  return geom_.getLats();
119 }
120 
121 // -----------------------------------------------------------------------------
122 
123 template <typename MODEL>
124 std::vector<double> Geometry<MODEL>::getLons() const {
125  Log::trace() << "Geometry<MODEL>::getLons" << std::endl;
126  util::Timer timer(classname(), "getLons");
127  return geom_.getLons();
128 }
129 
130 // -----------------------------------------------------------------------------
131 
132 template <typename MODEL>
133 std::vector<double> Geometry<MODEL>::getLevs() const {
134  Log::trace() << "Geometry<MODEL>::getLevs" << std::endl;
135  util::Timer timer(classname(), "getLevs");
136  return geom_.getLevs();
137 }
138 
139 // -----------------------------------------------------------------------------
140 
141 template <typename MODEL>
142 std::vector<double> Geometry<MODEL>::getArea() const {
143  Log::trace() << "Geometry<MODEL>::getArea" << std::endl;
144  util::Timer timer(classname(), "getAra");
145  return geom_.getArea();
146 }
147 
148 // -----------------------------------------------------------------------------
149 
150 template <typename MODEL>
151 std::vector<int> Geometry<MODEL>::getMask(const int & ilev) const {
152  Log::trace() << "Geometry<MODEL>::getMask" << std::endl;
153  util::Timer timer(classname(), "getMask");
154  return geom_.getMask();
155 }
156 
157 // -----------------------------------------------------------------------------
158 
159 template <typename MODEL>
161  Log::trace() << "Geometry<MODEL>::begin starting" << std::endl;
162  util::Timer timer(classname(), "begin");
163  return GeometryIterator_(geom_->begin());
164  Log::trace() << "Geometry<MODEL>::begin done" << std::endl;
165 }
166 
167 // -----------------------------------------------------------------------------
168 
169 template <typename MODEL>
171  Log::trace() << "Geometry<MODEL>::end starting" << std::endl;
172  util::Timer timer(classname(), "end");
173  return GeometryIterator_(geom_->end());
174  Log::trace() << "Geometry<MODEL>::end done" << std::endl;
175 }
176 
177 // -----------------------------------------------------------------------------
178 
179 template <typename MODEL>
180 void Geometry<MODEL>::print(std::ostream & os) const {
181  Log::trace() << "Geometry<MODEL>::print starting" << std::endl;
182  util::Timer timer(classname(), "print");
183  os << *geom_;
184  Log::trace() << "Geometry<MODEL>::print done" << std::endl;
185 }
186 
187 // -----------------------------------------------------------------------------
188 
189 } // namespace oops
190 
191 #endif // OOPS_INTERFACE_GEOMETRY_H_
boost::shared_ptr< const Geometry_ > geom_
GeometryIterator_ end() const
std::vector< double > getArea() const
Definition: conf.py:1
void print(std::ostream &) const
std::vector< int > getMask(const int &) const
std::vector< int > getDims() const
MODEL::Geometry Geometry_
The namespace for the main oops code.
std::vector< double > getLevs() const
Geometry & operator=(const Geometry &)
std::vector< double > getLons() const
static const std::string classname()
const Geometry_ & geometry() const
Interfacing.
std::vector< double > getLats() const
Geometry(const eckit::Configuration &)
GeometryIterator< MODEL > GeometryIterator_
GeometryIterator_ begin() const