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