TECA
The Toolkit for Extreme Climate Analysis
teca_arakawa_c_grid.h
1 #ifndef teca_arakawa_c_grid_h
2 #define teca_arakawa_c_grid_h
3 
4 #include "teca_config.h"
5 #include "teca_mesh.h"
6 #include "teca_shared_object.h"
7 #include "teca_variant_array.h"
8 #include "teca_array_collection.h"
9 
10 #include <map>
11 #include <string>
12 
13 TECA_SHARED_OBJECT_FORWARD_DECL(teca_arakawa_c_grid)
14 
15 /// A representation of mesh based data on an Arkawa C Grid.
16 /**
17  * The Arakawa C grid is defined by various combinations of horizontal and
18  * vertical centerings.
19  *
20  * The horizontal centerings occur at so called mass or M points, U points,
21  * and V points. These centerings are depicted in the following diagram:
22  *
23  * > *-------V-------*
24  * > | |
25  * > | |
26  * > | |
27  * > U M U
28  * > | |
29  * > | |
30  * > | |
31  * > *-------V-------*
32  *
33  * The horizontal coordinates are stored in 2d arrays. Assuming the mass
34  * coordinate arrays have dimension [nx, ny], then the U coordinate arrays
35  * have dimension [nx + 1, ny], and the V coordinate arrays have dimension
36  * [nx, ny + 1].
37  *
38  * The vertical centerings occur at so called M points and W points. These
39  * centerings are depicted in the following diagram.
40  *
41  * > *-------W-------*
42  * > | |
43  * > | |
44  * > | |
45  * > | M |
46  * > | |
47  * > | |
48  * > | |
49  * > *-------W-------*
50  *
51  * The vertical coordinates are stored in 1d arrays. Assuming the M vertical
52  * coordinate has the dimension [nz], then the W coordinate has dimension
53  * [nz + 1].
54  *
55  * The 3d mesh dimensions can be obtained from mesh metadata, as well as
56  * coordinate array names, and array attributes describing the data type,
57  * units, etc.
58  *
59  * Variables may exist on one of a number of permutations of horizontal and
60  * vertical centerings, array attributes contains the centering metadata.
61  *
62  * See also:
63  * "A Description of the Advanced Research WRF Model Version 4",
64  * NCAR/TN-556+STR
65  *
66  * "Grids in Numerical Weather and Climate Models"
67  * http://dx.doi.org/10.5772/55922
68  */
70 {
71 public:
72  TECA_DATASET_STATIC_NEW(teca_arakawa_c_grid)
73  TECA_DATASET_NEW_INSTANCE()
74  TECA_DATASET_NEW_COPY()
75 
76  virtual ~teca_arakawa_c_grid() = default;
77 
78  // set/get metadata
79  TECA_DATASET_METADATA(whole_extent, unsigned long, 6)
80  TECA_DATASET_METADATA(extent, unsigned long, 6)
81  TECA_DATASET_METADATA(bounds, double, 6)
82 
83  // flag set if the boundary in the given direction is periodic
84  TECA_DATASET_METADATA(periodic_in_x, int, 1)
85  TECA_DATASET_METADATA(periodic_in_y, int, 1)
86  TECA_DATASET_METADATA(periodic_in_z, int, 1)
87 
88  /// get the number of points in the mesh
89  unsigned long get_number_of_points() const override;
90 
91  /// get the number of cells in the mesh
92  unsigned long get_number_of_cells() const override;
93 
94  // get the names of the m, and v horizontal coordinate arrays
95  // these should not need to be modified
96  TECA_DATASET_METADATA(m_x_coordinate_variable, std::string, 1)
97  TECA_DATASET_METADATA(m_y_coordinate_variable, std::string, 1)
98  TECA_DATASET_METADATA(u_x_coordinate_variable, std::string, 1)
99  TECA_DATASET_METADATA(u_y_coordinate_variable, std::string, 1)
100  TECA_DATASET_METADATA(v_x_coordinate_variable, std::string, 1)
101  TECA_DATASET_METADATA(v_y_coordinate_variable, std::string, 1)
102 
103  // get the names of the m and w vertical coordinate arrays
104  // these should not need to be modified
105  TECA_DATASET_METADATA(m_z_coordinate_variable, std::string, 1)
106  TECA_DATASET_METADATA(w_z_coordinate_variable, std::string, 1)
107 
108  // get the name of the time axis arrays
109  // this should not need to be modified
110  TECA_DATASET_METADATA(t_coordinate_variable, std::string, 1)
111 
112  // get m,u, and v horizontal coordinate arrays
113  p_teca_variant_array get_m_x_coordinates();
114  p_teca_variant_array get_m_y_coordinates();
115  const_p_teca_variant_array get_m_x_coordinates() const;
116  const_p_teca_variant_array get_m_y_coordinates() const;
117 
118  p_teca_variant_array get_u_x_coordinates();
119  p_teca_variant_array get_u_y_coordinates();
120  const_p_teca_variant_array get_u_x_coordinates() const;
121  const_p_teca_variant_array get_u_y_coordinates() const;
122 
123  p_teca_variant_array get_v_x_coordinates();
124  p_teca_variant_array get_v_y_coordinates();
125  const_p_teca_variant_array get_v_x_coordinates() const;
126  const_p_teca_variant_array get_v_y_coordinates() const;
127 
128  // get m and w z coordinate array
129  p_teca_variant_array get_m_z_coordinates();
130  const_p_teca_variant_array get_m_z_coordinates() const;
131 
132  p_teca_variant_array get_w_z_coordinates();
133  const_p_teca_variant_array get_w_z_coordinates() const;
134 
135  // get t coordinate array
136  p_teca_variant_array get_t_coordinates();
137  const_p_teca_variant_array get_t_coordinates() const;
138 
139  // set m,u, and v horizontal coordinate arrays
140  void set_m_x_coordinates(const std::string &name,
141  const p_teca_variant_array &a);
142 
143  void set_m_y_coordinates(const std::string &name,
144  const p_teca_variant_array &a);
145 
146  void set_u_x_coordinates(const std::string &name,
147  const p_teca_variant_array &a);
148 
149  void set_u_y_coordinates(const std::string &name,
150  const p_teca_variant_array &a);
151 
152  void set_v_x_coordinates(const std::string &name,
153  const p_teca_variant_array &a);
154 
155  void set_v_y_coordinates(const std::string &name,
156  const p_teca_variant_array &a);
157 
158  // get m and w z coordinate array
159  void set_m_z_coordinates(const std::string &name,
160  const p_teca_variant_array &a);
161 
162  void set_w_z_coordinates(const std::string &name,
163  const p_teca_variant_array &a);
164 
165  // set t coordinate array
166  void set_t_coordinates(const std::string &name,
167  const p_teca_variant_array &a);
168 
169  // return a unique string identifier
170  std::string get_class_name() const override
171  { return "teca_arakawa_c_grid"; }
172 
173  // return the type code
174  int get_type_code() const override;
175 
176  /// @copydoc teca_dataset::copy(const const_p_teca_dataset &,allocator)
177  void copy(const const_p_teca_dataset &other,
178  allocator alloc = allocator::malloc) override;
179 
180  /// @copydoc teca_dataset::shallow_copy(const p_teca_dataset &)
181  void shallow_copy(const p_teca_dataset &other) override;
182 
183  // copy metadata. always a deep copy.
184  void copy_metadata(const const_p_teca_dataset &other) override;
185 
186  // swap internals of the two objects
187  void swap(const p_teca_dataset &) override;
188 
189  // return true if the dataset is empty.
190  bool empty() const noexcept override;
191 
192  // serialize the dataset to/from the given stream
193  // for I/O or communication
194  int to_stream(teca_binary_stream &) const override;
195  int from_stream(teca_binary_stream &) override;
196 
197  // stream to/from human readable representation
198  int to_stream(std::ostream &) const override;
199  using teca_dataset::from_stream;
200 
201 #if defined(SWIG)
202 protected:
203 #else
204 public:
205 #endif
206  // NOTE: constructors are public to enable std::make_shared. do not use.
208 
209 private:
210  struct impl_t
211  {
212  impl_t();
213 
214  p_teca_variant_array m_x_coordinates;
215  p_teca_variant_array m_y_coordinates;
216  p_teca_variant_array u_x_coordinates;
217  p_teca_variant_array u_y_coordinates;
218  p_teca_variant_array v_x_coordinates;
219  p_teca_variant_array v_y_coordinates;
220  p_teca_variant_array m_z_coordinates;
221  p_teca_variant_array w_z_coordinates;
222  p_teca_variant_array t_coordinates;
223  };
224  std::shared_ptr<impl_t> m_impl;
225 };
226 
227 #endif
A representation of mesh based data on an Arkawa C Grid.
Definition: teca_arakawa_c_grid.h:70
void copy_metadata(const const_p_teca_dataset &other) override
copy metadata. always a deep copy.
void shallow_copy(const p_teca_dataset &other) override
bool empty() const noexcept override
void swap(const p_teca_dataset &) override
swap internals of the two objects
void copy(const const_p_teca_dataset &other, allocator alloc=allocator::malloc) override
Serialize objects into a binary stream.
Definition: teca_binary_stream.h:17
Interface for TECA datasets.
Definition: teca_dataset.h:232
A base class for geometric data.
Definition: teca_mesh.h:20
p_teca_error_handler error_handler TECA_EXPORT
The global error handler instance.
std::shared_ptr< teca_variant_array > p_teca_variant_array
Definition: teca_variant_array.h:27
std::shared_ptr< const teca_variant_array > const_p_teca_variant_array
Definition: teca_variant_array.h:27