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[8]) const;
40 
41  /** Get the shape of the named array, taking into account the variable's
42  * dimensions as opposed to the mesh's dimensions. For instance the mesh
43  * extent may represent a volume while a variables extent may represent a
44  * slice. returns 0 if successful, -1 if an error occurred, 1 if the
45  * have_mesh_dims flag is missing. The latter is not necessarily an error.
46  */
47  int get_array_shape(const std::string &array_name,
48  unsigned long array_shape[4]) const;
49 
50  /** Get the shape of the named array, taking into account the variable's
51  * dimensions as opposed to the mesh's dimensions. If the call fails,
52  * an error is reported to the stderr stream.
53  */
54  std::tuple<unsigned long, unsigned long, unsigned long, unsigned long>
55  get_array_shape(const std::string &array_name) const
56  {
57  unsigned long array_shape[4] = {0};
58  if (this->get_array_shape(array_name, array_shape) < 0)
59  {
60  TECA_ERROR("Failed to get shape for \"" << array_name << "\"")
61  }
62  return std::make_tuple(array_shape[0], array_shape[1],
63  array_shape[2], array_shape[3]);
64  }
65 
66  /// get the number of points in the mesh
67  unsigned long get_number_of_points() const override;
68 
69  /// get the number of cells in the mesh
70  unsigned long get_number_of_cells() const override;
71 
72  /// Get the x coordinate array
74  { return m_coordinate_arrays->get("x"); }
75 
76  const_p_teca_variant_array get_x_coordinates() const
77  { return m_coordinate_arrays->get("x"); }
78 
79  /// Get the y coordinate array
81  { return m_coordinate_arrays->get("y"); }
82 
83  const_p_teca_variant_array get_y_coordinates() const
84  { return m_coordinate_arrays->get("y"); }
85 
86  /// Get the z coordinate array
88  { return m_coordinate_arrays->get("z"); }
89 
90  const_p_teca_variant_array get_z_coordinates() const
91  { return m_coordinate_arrays->get("z"); }
92 
93  /// Set the x coordinate array and x_coordinate_variable name
94  void set_x_coordinates(const std::string &name,
95  const p_teca_variant_array &array);
96 
97  /// Set the y coordinate array and y_coordinate_variable name
98  void set_y_coordinates(const std::string &name,
99  const p_teca_variant_array &array);
100 
101  /// set the z coordinate array and z_coordinate_variable name
102  void set_z_coordinates(const std::string &name,
103  const p_teca_variant_array &array);
104 
105  /// Update the x coordinate array
107 
108  /// Update the y coordinate array
110 
111  /// Update the z coordinate array
113 
114  /// Return the name of the class
115  std::string get_class_name() const override
116  { return "teca_cartesian_mesh"; }
117 
118  /// return an integer identifier uniquely naming the dataset type
119  int get_type_code() const override;
120 
121  /// @copydoc teca_dataset::copy(const const_p_teca_dataset &,allocator)
122  void copy(const const_p_teca_dataset &other,
123  allocator alloc = allocator::malloc) override;
124 
125  /// @copydoc teca_dataset::shallow_copy(const p_teca_dataset &)
126  void shallow_copy(const p_teca_dataset &other) override;
127 
128  /// Copy metadata. This is always a deep copy.
129  void copy_metadata(const const_p_teca_dataset &other) override;
130 
131  /// Swap the internals of the two objects
132  void swap(const p_teca_dataset &) override;
133 
134  /** Serialize the dataset to/from the given stream
135  * for I/O or communication
136  */
137  int to_stream(teca_binary_stream &) const override;
139 
140  // stream to/from human readable representation
141  int to_stream(std::ostream &) const override;
143 
144 #if defined(SWIG)
145 protected:
146 #else
147 public:
148 #endif
149  // NOTE: constructors are public to enable std::make_shared. do not use.
151 
152 private:
153  p_teca_array_collection m_coordinate_arrays;
154 };
155 
156 #endif
Serialize objects into a binary stream.
Definition: teca_binary_stream.h:17
An object representing data on a stretched Cartesian mesh.
Definition: teca_cartesian_mesh.h:12
void update_y_coordinates(const p_teca_variant_array &array)
Update the y coordinate array.
void update_x_coordinates(const p_teca_variant_array &array)
Update the x coordinate array.
int from_stream(teca_binary_stream &) override
deserialize the dataset from the given stream for I/O or communication
void copy(const const_p_teca_dataset &other, allocator alloc=allocator::malloc) override
void shallow_copy(const p_teca_dataset &other) override
unsigned long get_number_of_points() const override
get the number of points in the mesh
p_teca_variant_array get_z_coordinates()
Get the z coordinate array.
Definition: teca_cartesian_mesh.h:87
p_teca_variant_array get_y_coordinates()
Get the y coordinate array.
Definition: teca_cartesian_mesh.h:80
void swap(const p_teca_dataset &) override
Swap the internals of the two objects.
std::string get_class_name() const override
Return the name of the class.
Definition: teca_cartesian_mesh.h:115
p_teca_variant_array get_x_coordinates()
Get the x coordinate array.
Definition: teca_cartesian_mesh.h:73
void set_x_coordinates(const std::string &name, const p_teca_variant_array &array)
Set the x coordinate array and x_coordinate_variable name.
void update_z_coordinates(const p_teca_variant_array &array)
Update the z coordinate array.
int to_stream(std::ostream &) const override
send to stream in a human readable representation
void set_z_coordinates(const std::string &name, const p_teca_variant_array &array)
set the z coordinate array and z_coordinate_variable name
int get_type_code() const override
return an integer identifier uniquely naming the dataset type
int to_stream(teca_binary_stream &) const override
unsigned long get_number_of_cells() const override
get the number of cells in the mesh
void copy_metadata(const const_p_teca_dataset &other) override
Copy metadata. This is always a deep copy.
void set_y_coordinates(const std::string &name, const p_teca_variant_array &array)
Set the y coordinate array and y_coordinate_variable name.
virtual int from_stream(teca_binary_stream &)
deserialize the dataset from the given stream for I/O or communication
A base class for geometric data.
Definition: teca_mesh.h:20
p_teca_error_handler error_handler TECA_EXPORT
The global error handler instance.
TECA_EXPORT int get_array_extent(const teca_metadata &array_attributes, const unsigned long mesh_extent[8], unsigned long array_extent[8])
#define TECA_ERROR(_msg)
Constructs an error message and sends it to the stderr stream.
Definition: teca_common.h:161
std::shared_ptr< teca_variant_array > p_teca_variant_array
Definition: teca_variant_array.h:27
std::shared_ptr< const teca_variant_array > const_p_teca_variant_array
Definition: teca_variant_array.h:27