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  // set/get temporal metadata
25  TECA_DATASET_METADATA(time, double, 1)
26  TECA_DATASET_METADATA(calendar, std::string, 1)
27  TECA_DATASET_METADATA(time_units, std::string, 1)
28  TECA_DATASET_METADATA(time_step, unsigned long, 1)
29 
30  // set/get attribute metadata
31  TECA_DATASET_METADATA(attributes, teca_metadata, 1)
32 
33  // get the array collection for the given centering
34  // the centering enumeration is defined in teca_array_attributes
35  // the centering attribute is typically stored in array attribute
36  // metadata
37  p_teca_array_collection &get_arrays(int centering);
38  const_p_teca_array_collection get_arrays(int centering) const;
39 
40  /// @name point centered data
41  /** returns the array collection for point centered data */
42  ///@{
43  p_teca_array_collection &get_point_arrays()
44  { return m_impl->point_arrays; }
45 
46  const_p_teca_array_collection get_point_arrays() const
47  { return m_impl->point_arrays; }
48  ///@}
49 
50  /// @name cell centered data
51  /** returns the array collection for edge centered data */
52  ///@{
53  p_teca_array_collection &get_cell_arrays()
54  { return m_impl->cell_arrays; }
55 
56  const_p_teca_array_collection get_cell_arrays() const
57  { return m_impl->cell_arrays; }
58  ///@}
59 
60  /// @name edge centered data
61  /** returns the array collection for edge centered data */
62  ///@{
63  p_teca_array_collection &get_x_edge_arrays()
64  { return m_impl->x_edge_arrays; }
65 
66  const_p_teca_array_collection get_x_edge_arrays() const
67  { return m_impl->x_edge_arrays; }
68 
69  p_teca_array_collection &get_y_edge_arrays()
70  { return m_impl->y_edge_arrays; }
71 
72  const_p_teca_array_collection get_y_edge_arrays() const
73  { return m_impl->y_edge_arrays; }
74 
75  p_teca_array_collection &get_z_edge_arrays()
76  { return m_impl->z_edge_arrays; }
77 
78  const_p_teca_array_collection get_z_edge_arrays() const
79  { return m_impl->z_edge_arrays; }
80  ///@}
81 
82  /// @name face centered data
83  /** returns the array collection for face centered data */
84  ///@{
85  p_teca_array_collection &get_x_face_arrays()
86  { return m_impl->x_face_arrays; }
87 
88  const_p_teca_array_collection get_x_face_arrays() const
89  { return m_impl->x_face_arrays; }
90 
91  p_teca_array_collection &get_y_face_arrays()
92  { return m_impl->y_face_arrays; }
93 
94  const_p_teca_array_collection get_y_face_arrays() const
95  { return m_impl->y_face_arrays; }
96 
97  p_teca_array_collection &get_z_face_arrays()
98  { return m_impl->z_face_arrays; }
99 
100  const_p_teca_array_collection get_z_face_arrays() const
101  { return m_impl->z_face_arrays; }
102  ///@}
103 
104  /// @name non-geometric data
105  /** returns the array collection for uncentered data */
106  ///@{
107  p_teca_array_collection &get_information_arrays()
108  { return m_impl->info_arrays; }
109 
110  const_p_teca_array_collection get_information_arrays() const
111  { return m_impl->info_arrays; }
112  ///@}
113 
114  /// get the number of points in the mesh
115  virtual unsigned long get_number_of_points() const = 0;
116 
117  /// get the number of cells in the mesh
118  virtual unsigned long get_number_of_cells() const = 0;
119 
120  /// return true if the dataset is empty.
121  bool empty() const noexcept override;
122 
123  /// @copydoc teca_dataset::copy(const const_p_teca_dataset &,allocator)
124  void copy(const const_p_teca_dataset &other,
125  allocator alloc = allocator::malloc) override;
126 
127  /// @copydoc teca_dataset::shallow_copy(const p_teca_dataset &)
128  void shallow_copy(const p_teca_dataset &other) override;
129 
130  /** append array based data from another mesh. No consistency
131  * checks are performed. */
132  void append_arrays(const const_p_teca_mesh &);
133  void shallow_append_arrays(const p_teca_mesh &);
134 
135  /// swap internals of the two objects
136  void swap(const p_teca_dataset &) override;
137 
138  /** serialize the dataset to/from the given stream
139  * for I/O or communication */
140  int to_stream(teca_binary_stream &) const override;
141  int from_stream(teca_binary_stream &) override;
142 
143  /// stream to/from human readable representation
144  int to_stream(std::ostream &) const override;
145  int from_stream(std::istream &) override { return -1; }
146 
147 #if defined(SWIG)
148 protected:
149 #else
150 public:
151 #endif
152  // NOTE: constructors are public to enable std::make_shared. do not use.
153  teca_mesh();
154 
155 public:
156  struct impl_t
157  {
158  impl_t();
159  //
160  p_teca_array_collection cell_arrays;
161  p_teca_array_collection x_edge_arrays;
162  p_teca_array_collection y_edge_arrays;
163  p_teca_array_collection z_edge_arrays;
164  p_teca_array_collection x_face_arrays;
165  p_teca_array_collection y_face_arrays;
166  p_teca_array_collection z_face_arrays;
167  p_teca_array_collection point_arrays;
168  p_teca_array_collection info_arrays;
169  p_teca_array_collection invalid;
170  };
171  std::shared_ptr<impl_t> m_impl;
172 };
173 
174 #endif
teca_binary_stream
Serialize objects into a binary stream.
Definition: teca_binary_stream.h:16
teca_metadata
A generic container for meta data in the form of name=value pairs.
Definition: teca_metadata.h:21
teca_mesh
A base class for geometric data.
Definition: teca_mesh.h:19
teca_mesh::get_information_arrays
p_teca_array_collection & get_information_arrays()
Definition: teca_mesh.h:107
teca_dataset
Interface for TECA datasets.
Definition: teca_dataset.h:231
teca_mesh::impl_t
Definition: teca_mesh.h:156
teca_mesh::get_point_arrays
p_teca_array_collection & get_point_arrays()
Definition: teca_mesh.h:43
teca_py_array::copy
TECA_EXPORT bool copy(teca_variant_array *varr, PyObject *obj)
Copy values from the object into variant array.
Definition: teca_py_array.h:290
teca_mesh::get_x_face_arrays
p_teca_array_collection & get_x_face_arrays()
Definition: teca_mesh.h:85
teca_shared_object.h
teca_error::TECA_EXPORT
p_teca_error_handler error_handler TECA_EXPORT
The global error handler instance.
teca_mesh::get_cell_arrays
p_teca_array_collection & get_cell_arrays()
Definition: teca_mesh.h:53
teca_mesh::get_x_edge_arrays
p_teca_array_collection & get_x_edge_arrays()
Definition: teca_mesh.h:63