Flow123d  release_2.1.0-87-gfbc1563
output_data.hh
Go to the documentation of this file.
1 /*
2  * output_data.hh
3  *
4  * Created on: Jun 28, 2016
5  * Author: jb
6  */
7 
8 #ifndef SRC_IO_OUTPUT_DATA_HH_
9 #define SRC_IO_OUTPUT_DATA_HH_
10 
11 #include "io/output_data_base.hh"
12 #include "system/asserts.hh"
13 #include <type_traits>
14 
15 
16 class FieldCommon;
17 
18 /**
19  * \brief This class is used for storing data that are copied from field.
20  *
21  *
22  */
23 template <class Value>
24 class OutputData : public OutputDataBase {
25 public:
26  typedef typename Value::element_type ElemType;
27 
28  /**
29  * \brief Constructor of templated OutputData
30  */
31  OutputData(const FieldCommon &field, unsigned int size);
32 
33 
34  /**
35  * \brief Destructor of OutputData
36  */
37  virtual ~OutputData() override;
38 
39 
40  /**
41  * Output data element on given index @p idx. Method for writing data
42  * to output stream.
43  *
44  * \note This method is used only by MSH file format.
45  */
46  void print_ascii(ostream &out_stream, unsigned int idx) override;
47 
48  /**
49  * \brief Print all data stored in output data ro ascii format
50  *
51  * TODO: indicate if the tensor data are output in column-first or raw-first order
52  * and possibly implement transposition. Set such property for individual file formats.
53  * Class OutputData stores always in raw-first order.
54  */
55  void print_ascii_all(ostream &out_stream) override;
56 
57  /**
58  * \brief Print all data stored in output data to appended binary format
59  */
60  void print_binary_all(ostream &out_stream, bool print_data_size = true) override;
61 
62  void print_all_yaml(ostream &out_stream, unsigned int precision) override;
63 
64  /**
65  * Store data element of given data value under given index.
66  */
67  void store_value(unsigned int idx, const Value& value);
68 
69  /**
70  * Add value to given index
71  */
72  void add(unsigned int idx, const Value& value);
73 
74  /**
75  * Reset values at given index
76  */
77  void zero(unsigned int idx);
78 
79  /**
80  * Normalize values at given index
81  */
82  void normalize(unsigned int idx, unsigned int divisor);
83 
84  /**
85  * Find minimal and maximal range of stored data
86  */
87  void get_min_max_range(double &min, double &max) override;
88 
89 private:
90 
91  /**
92  * Perform given function at given index
93  */
94  template <class Func>
95  void operate(unsigned int idx, const Value &val, const Func& func) {
96  ASSERT_LT_DBG(idx, this->n_values);
97  ElemType *ptr = this->data_ + idx*this->n_elem_;
98  for(unsigned int i_row = 0; i_row < this->n_rows; i_row++) {
99  for(unsigned int i_col = 0; i_col < this->n_cols; i_col++) {
100  if (i_row < val.n_rows() && i_col < val.n_cols())
101  func(*ptr, val(i_row, i_col));
102  else
103  func(*ptr, 0);
104  ptr++;
105  }
106  }
107  };
108 
109 
110  /**
111  * Computed data values for output stored as continuous buffer of their data elements.
112  * One data value has @p n_elem data elements (of type double, int or unsigned int).
113  */
114  ElemType *data_;
115 
116 
117  /**
118  * Auxiliary value
119  */
120  typename Value::return_type aux;
121 
122 
123  /**
124  * Auxiliary field value envelope over @p aux
125  */
126  Value val_aux;
127 
128 
129  /**
130  * Number of rows and cols in stored data element, valid values are (1,1)
131  * for scalar; (3,1) for vectors; (3,3) for tensors
132  */
133  unsigned int n_rows, n_cols;
134 
135 };
136 
137 
138 
139 
140 #endif /* SRC_IO_OUTPUT_DATA_HH_ */
Common abstract parent of all Field<...> classes.
Definition: field_common.hh:60
Common parent class for templated OutputData.
void operate(unsigned int idx, const Value &val, const Func &func)
Definition: output_data.hh:95
void print_all_yaml(ostream &out_stream, unsigned int precision) override
Definition: output_data.cc:117
void print_binary_all(ostream &out_stream, bool print_data_size=true) override
Print all data stored in output data to appended binary format.
Definition: output_data.cc:99
void print_ascii(ostream &out_stream, unsigned int idx) override
Definition: output_data.cc:71
Definitions of ASSERTS.
unsigned int n_values
NumCompValueType n_elem_
This class is used for storing data that are copied from field.
Definition: output_data.hh:24
void zero(unsigned int idx)
Definition: output_data.cc:165
OutputData(const FieldCommon &field, unsigned int size)
Constructor of templated OutputData.
Definition: output_data.cc:15
static constexpr bool value
Definition: json.hpp:87
Value::element_type ElemType
Definition: output_data.hh:26
void get_min_max_range(double &min, double &max) override
Definition: output_data.cc:131
Value val_aux
Definition: output_data.hh:126
void add(unsigned int idx, const Value &value)
Definition: output_data.cc:157
void normalize(unsigned int idx, unsigned int divisor)
Definition: output_data.cc:173
virtual ~OutputData() override
Destructor of OutputData.
Definition: output_data.cc:58
unsigned int n_rows
Definition: output_data.hh:133
unsigned int n_cols
Definition: output_data.hh:133
Value::return_type aux
Definition: output_data.hh:120
void print_ascii_all(ostream &out_stream) override
Print all data stored in output data ro ascii format.
Definition: output_data.cc:87
ElemType * data_
Definition: output_data.hh:107
void store_value(unsigned int idx, const Value &value)
Definition: output_data.cc:149
#define ASSERT_LT_DBG(a, b)
Definition of comparative assert macro (Less Than) only for debug mode.
Definition: asserts.hh:300