TECA
The Toolkit for Extreme Climate Analysis
teca_mesh.h
1 #ifndef teca_mesh_h
2 #define teca_mesh_h
3 
4 #include "teca_dataset.h"
5 #include "teca_metadata.h"
6 #include "teca_array_collection.h"
7 #include "teca_shared_object.h"
8 
9 TECA_SHARED_OBJECT_FORWARD_DECL(teca_mesh)
10 
11 /// A base class for geometric data.
12 /**
13  * The mesh declares containers for typical geometrically associated data
14  * such as point, cell, face and edge centered data arrays and defines
15  * the APIs for accessing them. APIs for accessing common metadata such
16  * as time related metadata are declared here.
17  */
18 class teca_mesh : public teca_dataset
19 {
20 public:
21  ~teca_mesh() = default;
22 
23  // set/get temporal metadata
24  TECA_DATASET_METADATA(time, double, 1)
25  TECA_DATASET_METADATA(calendar, std::string, 1)
26  TECA_DATASET_METADATA(time_units, std::string, 1)
27  TECA_DATASET_METADATA(time_step, unsigned long, 1)
28 
29  // set/get attribute metadata
30  TECA_DATASET_METADATA(attributes, teca_metadata, 1)
31 
32  // get the array collection for the given centering
33  // the centering enumeration is defined in teca_array_attributes
34  // the centering attribute is typically stored in array attribute
35  // metadata
36  p_teca_array_collection &get_arrays(int centering);
37  const_p_teca_array_collection get_arrays(int centering) const;
38 
39  /// @name point centered data
40  /** returns the array collection for point centered data */
41  ///@{
42  p_teca_array_collection &get_point_arrays()
43  { return m_impl->point_arrays; }
44 
45  const_p_teca_array_collection get_point_arrays() const
46  { return m_impl->point_arrays; }
47  ///@}
48 
49  /// @name cell centered data
50  /** returns the array collection for edge centered data */
51  ///@{
52  p_teca_array_collection &get_cell_arrays()
53  { return m_impl->cell_arrays; }
54 
55  const_p_teca_array_collection get_cell_arrays() const
56  { return m_impl->cell_arrays; }
57  ///@}
58 
59  /// @name edge centered data
60  /** returns the array collection for edge centered data */
61  ///@{
62  p_teca_array_collection &get_x_edge_arrays()
63  { return m_impl->x_edge_arrays; }
64 
65  const_p_teca_array_collection get_x_edge_arrays() const
66  { return m_impl->x_edge_arrays; }
67 
68  p_teca_array_collection &get_y_edge_arrays()
69  { return m_impl->y_edge_arrays; }
70 
71  const_p_teca_array_collection get_y_edge_arrays() const
72  { return m_impl->y_edge_arrays; }
73 
74  p_teca_array_collection &get_z_edge_arrays()
75  { return m_impl->z_edge_arrays; }
76 
77  const_p_teca_array_collection get_z_edge_arrays() const
78  { return m_impl->z_edge_arrays; }
79  ///@}
80 
81  /// @name face centered data
82  /** returns the array collection for face centered data */
83  ///@{
84  p_teca_array_collection &get_x_face_arrays()
85  { return m_impl->x_face_arrays; }
86 
87  const_p_teca_array_collection get_x_face_arrays() const
88  { return m_impl->x_face_arrays; }
89 
90  p_teca_array_collection &get_y_face_arrays()
91  { return m_impl->y_face_arrays; }
92 
93  const_p_teca_array_collection get_y_face_arrays() const
94  { return m_impl->y_face_arrays; }
95 
96  p_teca_array_collection &get_z_face_arrays()
97  { return m_impl->z_face_arrays; }
98 
99  const_p_teca_array_collection get_z_face_arrays() const
100  { return m_impl->z_face_arrays; }
101  ///@}
102 
103  /// @name non-geometric data
104  /** returns the array collection for uncentered data */
105  ///@{
106  p_teca_array_collection &get_information_arrays()
107  { return m_impl->info_arrays; }
108 
109  const_p_teca_array_collection get_information_arrays() const
110  { return m_impl->info_arrays; }
111  ///@}
112 
113  /// get the number of points in the mesh
114  virtual unsigned long get_number_of_points() const = 0;
115 
116  /// get the number of cells in the mesh
117  virtual unsigned long get_number_of_cells() const = 0;
118 
119  /// return true if the dataset is empty.
120  bool empty() const noexcept override;
121 
122  /** copy data and metadata. shallow copy uses reference
123  * counting, while copy duplicates the data. */
124  void copy(const const_p_teca_dataset &) override;
125  void shallow_copy(const p_teca_dataset &) override;
126 
127  /** append array based data from another mesh. No consistency
128  * checks are performed. */
129  void append_arrays(const const_p_teca_mesh &);
130  void shallow_append_arrays(const p_teca_mesh &);
131 
132  /// swap internals of the two objects
133  void swap(const p_teca_dataset &) override;
134 
135  /** serialize the dataset to/from the given stream
136  * for I/O or communication */
137  int to_stream(teca_binary_stream &) const override;
138  int from_stream(teca_binary_stream &) override;
139 
140  /// stream to/from human readable representation
141  int to_stream(std::ostream &) const override;
142  int from_stream(std::istream &) override { return -1; }
143 
144 protected:
145  teca_mesh();
146 
147 public:
148  struct impl_t
149  {
150  impl_t();
151  //
152  p_teca_array_collection cell_arrays;
153  p_teca_array_collection x_edge_arrays;
154  p_teca_array_collection y_edge_arrays;
155  p_teca_array_collection z_edge_arrays;
156  p_teca_array_collection x_face_arrays;
157  p_teca_array_collection y_face_arrays;
158  p_teca_array_collection z_face_arrays;
159  p_teca_array_collection point_arrays;
160  p_teca_array_collection info_arrays;
161  p_teca_array_collection invalid;
162  };
163  std::shared_ptr<impl_t> m_impl;
164 };
165 
166 #endif
teca_binary_stream
Serialize objects into a binary stream.
Definition: teca_binary_stream.h:15
teca_metadata
A generic container for meta data in the form of name=value pairs.
Definition: teca_metadata.h:18
teca_mesh
A base class for geometric data.
Definition: teca_mesh.h:18
teca_mesh::get_information_arrays
p_teca_array_collection & get_information_arrays()
Definition: teca_mesh.h:106
teca_dataset
Interface for TECA datasets.
Definition: teca_dataset.h:216
teca_mesh::impl_t
Definition: teca_mesh.h:148
teca_mesh::get_point_arrays
p_teca_array_collection & get_point_arrays()
Definition: teca_mesh.h:42
teca_mesh::get_x_face_arrays
p_teca_array_collection & get_x_face_arrays()
Definition: teca_mesh.h:84
teca_shared_object.h
teca_mesh::get_cell_arrays
p_teca_array_collection & get_cell_arrays()
Definition: teca_mesh.h:52
teca_mesh::get_x_edge_arrays
p_teca_array_collection & get_x_edge_arrays()
Definition: teca_mesh.h:62
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