TECA
The Toolkit for Extreme Climate Analysis
teca_mesh.h
1 #ifndef teca_mesh_h
2 #define teca_mesh_h
3 
4 #include "teca_config.h"
5 #include "teca_dataset.h"
6 #include "teca_metadata.h"
7 #include "teca_array_collection.h"
8 #include "teca_shared_object.h"
9 
10 TECA_SHARED_OBJECT_FORWARD_DECL(teca_mesh)
11 
12 /// A base class for geometric data.
13 /**
14  * The mesh declares containers for typical geometrically associated data
15  * such as point, cell, face and edge centered data arrays and defines
16  * the APIs for accessing them. APIs for accessing common metadata such
17  * as time related metadata are declared here.
18  */
20 {
21 public:
22  ~teca_mesh() = default;
23 
24  /// @name temporal metadata
25  /** Specifies the temporal extents of the data and the calendaring system
26  * used to define the time axis.
27  */
28  ///@{
29  TECA_DATASET_METADATA(temporal_bounds, double, 2)
30  TECA_DATASET_METADATA(temporal_extent, unsigned long, 2)
31  TECA_DATASET_METADATA(calendar, std::string, 1)
32  TECA_DATASET_METADATA(time_units, std::string, 1)
33 
34  /// Set the temporal_extent to a single time step
35  void set_time_step(const unsigned long &val);
36 
37  /** Get the time step. note: no checking is done to ensure that the temporal
38  * extent has only a single step.
39  */
40  int get_time_step(unsigned long &val) const;
41 
42  /// Set the temporal bounds to a single time value.
43  void set_time(const double &val);
44 
45  /** Get the time. note: no checking is done to ensure that the temporal
46  * extent/bounds have only a single step.
47  */
48  int get_time(double &val) const;
49  ///@}
50 
51  /// @name attribute metadata
52  /** Provides access to the array attributes metadata, which contains
53  * information such as dimensions, units, data type, description, etc.
54  */
55  ///@{
56  TECA_DATASET_METADATA(attributes, teca_metadata, 1)
57  ///@}
58 
59  /// @name arrays
60  /** get the array collection for the given centering the centering
61  * enumeration is defined in teca_array_attributes the centering attribute
62  * is typically stored in array attribute metadata
63  */
64  p_teca_array_collection &get_arrays(int centering);
65  const_p_teca_array_collection get_arrays(int centering) const;
66 
67  /// @name point centered data
68  /** returns the array collection for point centered data */
69  ///@{
70  p_teca_array_collection &get_point_arrays()
71  { return m_impl->point_arrays; }
72 
73  const_p_teca_array_collection get_point_arrays() const
74  { return m_impl->point_arrays; }
75  ///@}
76 
77  /// @name cell centered data
78  /** returns the array collection for edge centered data */
79  ///@{
80  p_teca_array_collection &get_cell_arrays()
81  { return m_impl->cell_arrays; }
82 
83  const_p_teca_array_collection get_cell_arrays() const
84  { return m_impl->cell_arrays; }
85  ///@}
86 
87  /// @name edge centered data
88  /** returns the array collection for edge centered data */
89  ///@{
90  p_teca_array_collection &get_x_edge_arrays()
91  { return m_impl->x_edge_arrays; }
92 
93  const_p_teca_array_collection get_x_edge_arrays() const
94  { return m_impl->x_edge_arrays; }
95 
96  p_teca_array_collection &get_y_edge_arrays()
97  { return m_impl->y_edge_arrays; }
98 
99  const_p_teca_array_collection get_y_edge_arrays() const
100  { return m_impl->y_edge_arrays; }
101 
102  p_teca_array_collection &get_z_edge_arrays()
103  { return m_impl->z_edge_arrays; }
104 
105  const_p_teca_array_collection get_z_edge_arrays() const
106  { return m_impl->z_edge_arrays; }
107  ///@}
108 
109  /// @name face centered data
110  /** returns the array collection for face centered data */
111  ///@{
112  p_teca_array_collection &get_x_face_arrays()
113  { return m_impl->x_face_arrays; }
114 
115  const_p_teca_array_collection get_x_face_arrays() const
116  { return m_impl->x_face_arrays; }
117 
118  p_teca_array_collection &get_y_face_arrays()
119  { return m_impl->y_face_arrays; }
120 
121  const_p_teca_array_collection get_y_face_arrays() const
122  { return m_impl->y_face_arrays; }
123 
124  p_teca_array_collection &get_z_face_arrays()
125  { return m_impl->z_face_arrays; }
126 
127  const_p_teca_array_collection get_z_face_arrays() const
128  { return m_impl->z_face_arrays; }
129  ///@}
130 
131  /// @name non-geometric data
132  /** returns the array collection for uncentered data */
133  ///@{
134  p_teca_array_collection &get_information_arrays()
135  { return m_impl->info_arrays; }
136 
137  const_p_teca_array_collection get_information_arrays() const
138  { return m_impl->info_arrays; }
139  ///@}
140 
141  /// get the number of points in the mesh
142  virtual unsigned long get_number_of_points() const = 0;
143 
144  /// get the number of cells in the mesh
145  virtual unsigned long get_number_of_cells() const = 0;
146 
147  /// return true if the dataset is empty.
148  bool empty() const noexcept override;
149 
150  /// @copydoc teca_dataset::copy(const const_p_teca_dataset &,allocator)
151  void copy(const const_p_teca_dataset &other,
152  allocator alloc = allocator::malloc) override;
153 
154  /// @copydoc teca_dataset::shallow_copy(const p_teca_dataset &)
155  void shallow_copy(const p_teca_dataset &other) override;
156 
157  /** append array based data from another mesh. No consistency
158  * checks are performed. */
159  void append_arrays(const const_p_teca_mesh &);
160  void shallow_append_arrays(const p_teca_mesh &);
161 
162  /// swap internals of the two objects
163  void swap(const p_teca_dataset &) override;
164 
165  /** serialize the dataset to/from the given stream
166  * for I/O or communication */
167  int to_stream(teca_binary_stream &) const override;
168  int from_stream(teca_binary_stream &) override;
169 
170  /// stream to/from human readable representation
171  int to_stream(std::ostream &) const override;
172  int from_stream(std::istream &) override { return -1; }
173 
174 #if defined(SWIG)
175 protected:
176 #else
177 public:
178 #endif
179  /// @note constructors are public to enable std::make_shared. do not use.
181 
182 public:
183  struct impl_t
184  {
185  impl_t();
186  //
187  p_teca_array_collection cell_arrays;
188  p_teca_array_collection x_edge_arrays;
189  p_teca_array_collection y_edge_arrays;
190  p_teca_array_collection z_edge_arrays;
191  p_teca_array_collection x_face_arrays;
192  p_teca_array_collection y_face_arrays;
193  p_teca_array_collection z_face_arrays;
194  p_teca_array_collection point_arrays;
195  p_teca_array_collection info_arrays;
196  p_teca_array_collection invalid;
197  };
198  std::shared_ptr<impl_t> m_impl;
199 };
200 
201 #endif
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
virtual unsigned long get_number_of_cells() const =0
get the number of cells in the mesh
p_teca_array_collection & get_cell_arrays()
Definition: teca_mesh.h:80
p_teca_array_collection & get_information_arrays()
Definition: teca_mesh.h:134
bool empty() const noexcept override
return true if the dataset is empty.
p_teca_array_collection & get_x_edge_arrays()
Definition: teca_mesh.h:90
virtual unsigned long get_number_of_points() const =0
get the number of points in the mesh
p_teca_array_collection & get_x_face_arrays()
Definition: teca_mesh.h:112
A generic container for meta data in the form of name=value pairs.
Definition: teca_metadata.h:22
p_teca_error_handler error_handler TECA_EXPORT
The global error handler instance.
TECA_EXPORT bool copy(teca_variant_array *varr, PyObject *obj)
Copy values from the object into variant array.
Definition: teca_py_array.h:290
Definition: teca_mesh.h:184