Flow123d  last_with_con_2.0.0-4-g42e6930
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 
14 
15 class FieldCommon;
16 
17 /**
18  * \brief This class is used for storing data that are copied from field.
19  *
20  *
21  */
22 template <class Value>
23 class OutputData : public OutputDataBase {
24 public:
25  typedef typename Value::element_type ElemType;
26 
27  /**
28  * \brief Constructor of templated OutputData
29  */
30  OutputData(const FieldCommon &field, unsigned int size);
31 
32 
33  /**
34  * \brief Destructor of OutputData
35  */
36  virtual ~OutputData() override;
37 
38 
39  /**
40  * Output data element on given index @p idx. Method for writing data
41  * to output stream.
42  *
43  * \note This method is used only by MSH file format.
44  */
45  void print(ostream &out_stream, unsigned int idx) override;
46 
47  /**
48  * \brief Print all data stored in output data
49  *
50  * TODO: indicate if the tensor data are output in column-first or raw-first order
51  * and possibly implement transposition. Set such property for individual file formats.
52  * Class OutputData stores always in raw-first order.
53  */
54  void print_all(ostream &out_stream) override;
55 
56  void print_all_yaml(ostream &out_stream, unsigned int precision) override;
57 
58  /**
59  * Store data element of given data value under given index.
60  */
61  void store_value(unsigned int idx, const Value& value);
62 
63  /**
64  * Add value to given index
65  */
66  void add(unsigned int idx, const Value& value);
67 
68  /**
69  * Reset values at given index
70  */
71  void zero(unsigned int idx);
72 
73  /**
74  * Normalize values at given index
75  */
76  void normalize(unsigned int idx, unsigned int divisor);
77 
78 private:
79 
80  /**
81  * Perform given function at given index
82  */
83  template <class Func>
84  void operate(unsigned int idx, const Value &val, const Func& func) {
85  ASSERT_LT_DBG(idx, this->n_values);
86  ElemType *ptr = this->data_ + idx*this->n_elem_;
87  for(unsigned int i_row = 0; i_row < this->n_rows; i_row++) {
88  for(unsigned int i_col = 0; i_col < this->n_cols; i_col++) {
89  if (i_row < val.n_rows() && i_col < val.n_cols())
90  func(*ptr, val(i_row, i_col));
91  else
92  func(*ptr, 0);
93  ptr++;
94  }
95  }
96  };
97 
98 
99  /**
100  * Computed data values for output stored as continuous buffer of their data elements.
101  * One data value has @p n_elem data elements (of type double, int or unsigned int).
102  */
103  ElemType *data_;
104 
105 
106  /**
107  * Auxiliary value
108  */
109  typename Value::return_type aux;
110 
111 
112  /**
113  * Auxiliary field value envelope over @p aux
114  */
115  Value val_aux;
116 
117 
118  /**
119  * Number of rows and cols in stored data element, valid values are (1,1)
120  * for scalar; (3,1) for vectors; (3,3) for tensors
121  */
122  unsigned int n_rows, n_cols;
123 
124 };
125 
126 
127 
128 
129 #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:84
void print_all_yaml(ostream &out_stream, unsigned int precision) override
Definition: output_data.cc:97
void print(ostream &out_stream, unsigned int idx) override
Definition: output_data.cc:70
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:23
void zero(unsigned int idx)
Definition: output_data.cc:130
OutputData(const FieldCommon &field, unsigned int size)
Constructor of templated OutputData.
Definition: output_data.cc:15
Value::element_type ElemType
Definition: output_data.hh:25
Value val_aux
Definition: output_data.hh:115
void add(unsigned int idx, const Value &value)
Definition: output_data.cc:122
void normalize(unsigned int idx, unsigned int divisor)
Definition: output_data.cc:138
virtual ~OutputData() override
Destructor of OutputData.
Definition: output_data.cc:57
unsigned int n_rows
Definition: output_data.hh:122
unsigned int n_cols
Definition: output_data.hh:122
Value::return_type aux
Definition: output_data.hh:109
ElemType * data_
Definition: output_data.hh:96
void store_value(unsigned int idx, const Value &value)
Definition: output_data.cc:114
void print_all(ostream &out_stream) override
Print all data stored in output data.
Definition: output_data.cc:86
#define ASSERT_LT_DBG(a, b)
Definition of comparative assert macro (Less Than) only for debug mode.
Definition: asserts.hh:300