TECA
The Toolkit for Extreme Climate Analysis
teca_cartesian_mesh.h
1 #ifndef teca_cartesian_mesh_h
2 #define teca_cartesian_mesh_h
3 
4 #include "teca_config.h"
5 #include "teca_mesh.h"
6 #include "teca_shared_object.h"
7 
8 TECA_SHARED_OBJECT_FORWARD_DECL(teca_cartesian_mesh)
9 
10 /// An object representing data on a stretched Cartesian mesh.
12 {
13 public:
14  TECA_DATASET_STATIC_NEW(teca_cartesian_mesh)
15  TECA_DATASET_NEW_INSTANCE()
16  TECA_DATASET_NEW_COPY()
17 
18  virtual ~teca_cartesian_mesh() = default;
19 
20  // Set/get metadata
21  TECA_DATASET_METADATA(whole_extent, unsigned long, 6)
22  TECA_DATASET_METADATA(extent, unsigned long, 6)
23  TECA_DATASET_METADATA(bounds, double, 6)
24  TECA_DATASET_METADATA(periodic_in_x, int, 1)
25  TECA_DATASET_METADATA(periodic_in_y, int, 1)
26  TECA_DATASET_METADATA(periodic_in_z, int, 1)
27  TECA_DATASET_METADATA(x_coordinate_variable, std::string, 1)
28  TECA_DATASET_METADATA(y_coordinate_variable, std::string, 1)
29  TECA_DATASET_METADATA(z_coordinate_variable, std::string, 1)
30  TECA_DATASET_METADATA(t_coordinate_variable, std::string, 1)
31 
32  /** Get the extent of the named array, taking into account the variable's
33  * dimensions as opposed to the mesh's dimensions. For instance the mesh
34  * extent may represent a volume while a variables extent may represent a
35  * slice. returns 0 if successful, -1 if an error occurred, 1 if the
36  * have_mesh_dims flag is missing. The latter is not necessarily an error.
37  */
38  int get_array_extent(const std::string &array_name,
39  unsigned long array_extent[6]);
40 
41  /// get the number of points in the mesh
42  unsigned long get_number_of_points() const override;
43 
44  /// get the number of cells in the mesh
45  unsigned long get_number_of_cells() const override;
46 
47  /// Get the x coordinate array
48  p_teca_variant_array get_x_coordinates()
49  { return m_coordinate_arrays->get("x"); }
50 
51  const_p_teca_variant_array get_x_coordinates() const
52  { return m_coordinate_arrays->get("x"); }
53 
54  /// Get the y coordinate array
56  { return m_coordinate_arrays->get("y"); }
57 
58  const_p_teca_variant_array get_y_coordinates() const
59  { return m_coordinate_arrays->get("y"); }
60 
61  /// Get the z coordinate array
63  { return m_coordinate_arrays->get("z"); }
64 
65  const_p_teca_variant_array get_z_coordinates() const
66  { return m_coordinate_arrays->get("z"); }
67 
68  /// Set the x coordinate array and x_coordinate_variable name
69  void set_x_coordinates(const std::string &name,
70  const p_teca_variant_array &array);
71 
72  /// Set the y coordinate array and y_coordinate_variable name
73  void set_y_coordinates(const std::string &name,
74  const p_teca_variant_array &array);
75 
76  /// set the z coordinate array and z_coordinate_variable name
77  void set_z_coordinates(const std::string &name,
78  const p_teca_variant_array &array);
79 
80  /// Update the x coordinate array
81  void update_x_coordinates(const p_teca_variant_array &array);
82 
83  /// Update the y coordinate array
84  void update_y_coordinates(const p_teca_variant_array &array);
85 
86  /// Update the z coordinate array
87  void update_z_coordinates(const p_teca_variant_array &array);
88 
89  /// Return the name of the class
90  std::string get_class_name() const override
91  { return "teca_cartesian_mesh"; }
92 
93  /// return an integer identifier uniquely naming the dataset type
94  int get_type_code() const override;
95 
96  /// @copydoc teca_dataset::copy(const const_p_teca_dataset &,allocator)
97  void copy(const const_p_teca_dataset &other,
98  allocator alloc = allocator::malloc) override;
99 
100  /// @copydoc teca_dataset::shallow_copy(const p_teca_dataset &)
101  void shallow_copy(const p_teca_dataset &other) override;
102 
103  /// Copy metadata. This is always a deep copy.
104  void copy_metadata(const const_p_teca_dataset &other) override;
105 
106  /// Swap the internals of the two objects
107  void swap(const p_teca_dataset &) override;
108 
109  /** Serialize the dataset to/from the given stream
110  * for I/O or communication
111  */
112  int to_stream(teca_binary_stream &) const override;
113  int from_stream(teca_binary_stream &) override;
114 
115  // stream to/from human readable representation
116  int to_stream(std::ostream &) const override;
117  using teca_dataset::from_stream;
118 
119 #if defined(SWIG)
120 protected:
121 #else
122 public:
123 #endif
124  // NOTE: constructors are public to enable std::make_shared. do not use.
126 
127 private:
128  p_teca_array_collection m_coordinate_arrays;
129 };
130 
131 #endif
teca_binary_stream
Serialize objects into a binary stream.
Definition: teca_binary_stream.h:16
teca_cartesian_mesh::get_y_coordinates
p_teca_variant_array get_y_coordinates()
Get the y coordinate array.
Definition: teca_cartesian_mesh.h:55
teca_mesh
A base class for geometric data.
Definition: teca_mesh.h:19
teca_cartesian_mesh
An object representing data on a stretched Cartesian mesh.
Definition: teca_cartesian_mesh.h:11
const_p_teca_variant_array
std::shared_ptr< const teca_variant_array > const_p_teca_variant_array
Definition: teca_variant_array.h:27
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_shared_object.h
teca_cartesian_mesh::get_z_coordinates
p_teca_variant_array get_z_coordinates()
Get the z coordinate array.
Definition: teca_cartesian_mesh.h:62
p_teca_variant_array
std::shared_ptr< teca_variant_array > p_teca_variant_array
Definition: teca_variant_array.h:27
teca_cartesian_mesh::get_class_name
std::string get_class_name() const override
Return the name of the class.
Definition: teca_cartesian_mesh.h:90
teca_metadata_util::get_array_extent
TECA_EXPORT int get_array_extent(const teca_metadata &array_attributes, const unsigned long mesh_extent[6], unsigned long array_extent[6])
teca_error::TECA_EXPORT
p_teca_error_handler error_handler TECA_EXPORT
The global error handler instance.