TECA
The Toolkit for Extreme Climate Analysis
teca_derived_quantity.h
1 #ifndef teca_derived_quantity_h
2 #define teca_derived_quantity_h
3 
4 #include "teca_programmable_algorithm.h"
5 #include "teca_metadata.h"
6 #include "teca_dataset.h"
7 #include "teca_shared_object.h"
8 
9 #include <string>
10 #include <vector>
11 
12 #if defined(__CUDACC__)
13 #pragma nv_diag_suppress = partial_override
14 #endif
15 
16 TECA_SHARED_OBJECT_FORWARD_DECL(teca_derived_quantity)
17 
18 /// a programmable algorithm specialized for simple array based computations
19 /**
20  * A programmable algorithm specialized for simple array based computations. A
21  * user provided callable(see set execute_callback) which operates on one or more
22  * arrays(the dependent variables) to produce a new array (the derived quantity).
23  * The purpose of this class is to implement the request and report phases of the
24  * pipeline consistently for this common use case. An implementation specific
25  * context(operation_name) differentiates between multiple instances in the same
26 pipeline.
27 */
29 {
30 public:
31  TECA_ALGORITHM_STATIC_NEW(teca_derived_quantity)
32  TECA_ALGORITHM_DELETE_COPY_ASSIGN(teca_derived_quantity)
34 
35  //using teca_programmable_algorithm::get_class_name;
36 
37  // report/initialize to/from Boost program options
38  // objects.
39  TECA_GET_ALGORITHM_PROPERTIES_DESCRIPTION()
40  TECA_SET_ALGORITHM_PROPERTIES()
41 
42  // set/get the list of arrays that are needed to produce
43  // the derived quantity
44  TECA_ALGORITHM_VECTOR_PROPERTY(std::string, dependent_variable)
45 
46  // set/get the array that is produced
47  TECA_ALGORITHM_PROPERTY(std::string, derived_variable)
48 
49  // set/get the contextual name that differentiates this
50  // instance from others in the same pipeline.
51  void set_operation_name(const std::string &v);
52 
53  const std::string &get_operation_name() const
54  { return this->operation_name; }
55 
56  std::string &get_operation_name()
57  { return this->operation_name; }
58 
59  // set the callable that implements to derived quantity
60  // computation
63 
64 protected:
66 
67 private:
68  //using teca_algorithm::get_output_metadata;
69 
70  // specialized report and request implementations that
71  // process the input and output array lists in a standardized
72  // manner.
73  teca_metadata get_output_metadata(unsigned int port,
74  const std::vector<teca_metadata> &input_md) override;
75 
76  std::vector<teca_metadata> get_upstream_request(
77  unsigned int port, const std::vector<teca_metadata> &input_md,
78  const teca_metadata &request) override;
79 
80  // hide the programmable algorithm report request callbacks
83 
86 
87  // extracts variable from incoming request if the property
88  // is not set
89  std::string get_derived_variable(const teca_metadata &request);
90 
91  // extracts dependent variables from the incoming request
92  // if the coresponding property is not set
93  void get_dependent_variables(const teca_metadata &request,
94  std::vector<std::string> &dep_vars);
95 
96  // set the name used in log files.
97  int set_name(const std::string &name) override;
98 
99 private:
100  std::string operation_name;
101  std::vector<std::string> dependent_variables;
102  std::string derived_variable;
103 };
104 
105 #if defined(__CUDACC__)
106 #pragma nv_diag_default = partial_override
107 #endif
108 #endif
teca_derived_quantity
a programmable algorithm specialized for simple array based computations
Definition: teca_derived_quantity.h:28
teca_metadata
A generic container for meta data in the form of name=value pairs.
Definition: teca_metadata.h:21
teca_programmable_algorithm::get_request_callback
const request_callback_t & get_request_callback() const
Definition: teca_programmable_algorithm.h:130
teca_programmable_algorithm::get_report_callback
const report_callback_t & get_report_callback() const
Definition: teca_programmable_algorithm.h:117
teca_programmable_algorithm::set_execute_callback
void set_execute_callback(const execute_callback_t &v)
Definition: teca_programmable_algorithm.h:142
teca_programmable_algorithm::set_report_callback
void set_report_callback(const report_callback_t &v)
Definition: teca_programmable_algorithm.h:117
teca_programmable_algorithm::get_execute_callback
const execute_callback_t & get_execute_callback() const
Definition: teca_programmable_algorithm.h:142
teca_programmable_algorithm
An algorithm implemented with user provided callbacks.
Definition: teca_programmable_algorithm.h:86
teca_programmable_algorithm::set_request_callback
void set_request_callback(const request_callback_t &v)
Definition: teca_programmable_algorithm.h:130
teca_shared_object.h
teca_error::TECA_EXPORT
p_teca_error_handler error_handler TECA_EXPORT
The global error handler instance.