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