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