Flow123d  release_3.0.0-695-g67d21c4
element_data_cache_base.hh
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License version 3 as published by the
7  * Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12  *
13  *
14  * @file element_data_cache_base.hh
15  * @brief
16  */
17 
18 #ifndef ELEMENT_DATA_CACHE_BASE_HH_
19 #define ELEMENT_DATA_CACHE_BASE_HH_
20 
21 
22 
23 #include <ostream>
24 #include <string>
25 #include <istream>
26 #include "system/system.hh"
27 
28 class Tokenizer;
29 
30 
32 public:
33 
34  /**
35  * Number of components of element data stored in the database.
36  */
38  N_SCALAR = 1,
39  N_VECTOR = 3,
41  };
42 
43  /// Types of VTK value
46  } VTKValueType;
47 
48  /// Constructor.
50  : time_(-std::numeric_limits<double>::infinity()),
51  field_name_("") {}
52 
53  /// Destructor
54  virtual ~ElementDataCacheBase() {}
55 
56  /// Getter for time of cache
57  double get_time()
58  { return time_; }
59 
60  /// Getter for quantity name of cache
61  std::string field_input_name()
62  { return field_input_name_; }
63 
64  /// Check if cache stored actual data
65  bool is_actual(double time, std::string field_name) {
66  return (time_ == time) && (field_input_name_ == field_name);
67  }
68 
69  /**
70  * Read ascii data of given \p i_row from tokenizer
71  */
72  virtual void read_ascii_data(Tokenizer &tok, unsigned int n_components, unsigned int i_row)=0;
73 
74  /**
75  * Read binary data of given \p i_row from data stream
76  */
77  virtual void read_binary_data(std::istream &data_stream, unsigned int n_components, unsigned int i_row)=0;
78 
79  /**
80  * Print one value at given index in ascii format
81  */
82  virtual void print_ascii(ostream &out_stream, unsigned int idx) = 0;
83 
84  /**
85  * Print all data in ascii format at once stored in database
86  */
87  virtual void print_ascii_all(ostream &out_stream) = 0;
88 
89  /**
90  * Print all data in binary format at once stored in database
91  */
92  virtual void print_binary_all(ostream &out_stream, bool print_data_size = true) = 0;
93 
94  /**
95  * Print stored values in the YAML format (using JSON like arrays).
96  * Used for output of observe values.
97  */
98  virtual void print_all_yaml(ostream &out_stream, unsigned int precision) = 0;
99 
100  /**
101  * Find minimal and maximal range of stored data
102  */
103  virtual void get_min_max_range(double &min, double &max) = 0;
104 
105  /**
106  * Set string representation of SI units.
107  */
108  void set_field_units(std::string unit_string) {
109  this->field_units_ = unit_string;
110  }
111 
112  /**
113  * Set string representation of SI units.
114  */
115  void set_n_values(unsigned int n_values) {
116  this->n_values_ = n_values;
117  }
118 
119  /**
120  * Get string representation of SI units.
121  */
122  inline std::string field_units() {
123  return this->field_units_;
124  }
125 
126  /**
127  * Get number of data values.
128  */
129  inline unsigned int n_values() {
130  return this->n_values_;
131  }
132 
133  /**
134  * Get number of data elements per data value.
135  */
137  return this->n_elem_;
138  }
139 
140  /// Get type of stored data
141  inline VTKValueType vtk_type() {
142  return this->vtk_type_;
143  }
144 
145  /**
146  * Get dof_handler_hash_ value.
147  */
148  inline std::size_t dof_handler_hash() const {
149  return this->dof_handler_hash_;
150  }
151 
152  /**
153  * Set dof_handler_hash_ value.
154  */
155  inline void set_dof_handler_hash(std::size_t hash) {
156  this->dof_handler_hash_ = hash;
157  }
158 
159 protected:
160  template <class T>
161  void set_vtk_type() {
166  } else if ( std::is_same<T, int>::value ) {
168  } else {
169  ASSERT(false).error("Unsupported VTK type");
170  }
171  }
172 
173  /// time step stored in cache
174  double time_;
175 
176  /// name of field stored in cache
177  std::string field_input_name_;
178  std::string field_name_;
179 
180  /**
181  * Data copied from Field.
182  */
183  std::string field_units_;
184 
185  /**
186  * Number of data values.
187  */
188  unsigned int n_values_;
189 
190  /**
191  * Number of data elements per data value.
192  */
194 
195  /// Type of stored data
196  VTKValueType vtk_type_;
197 
198  /// Hash of DOF handler (attribute of native VTK data)
199  std::size_t dof_handler_hash_;
200 };
201 
202 
203 #endif /* ELEMENT_DATA_CACHE_BASE_HH_ */
double time_
time step stored in cache
void set_dof_handler_hash(std::size_t hash)
VTKValueType vtk_type()
Get type of stored data.
virtual void print_ascii(ostream &out_stream, unsigned int idx)=0
std::string field_input_name()
Getter for quantity name of cache.
virtual void print_binary_all(ostream &out_stream, bool print_data_size=true)=0
virtual ~ElementDataCacheBase()
Destructor.
void set_n_values(unsigned int n_values)
double get_time()
Getter for time of cache.
#define ASSERT(expr)
Allow use shorter versions of macro names if these names is not used with external library...
Definition: asserts.hh:346
std::size_t dof_handler_hash() const
static constexpr bool value
Definition: json.hpp:87
void set_field_units(std::string unit_string)
bool is_actual(double time, std::string field_name)
Check if cache stored actual data.
VTKValueType
Types of VTK value.
virtual void read_ascii_data(Tokenizer &tok, unsigned int n_components, unsigned int i_row)=0
std::string field_input_name_
name of field stored in cache
virtual void get_min_max_range(double &min, double &max)=0
VTKValueType vtk_type_
Type of stored data.
std::size_t dof_handler_hash_
Hash of DOF handler (attribute of native VTK data)
virtual void print_ascii_all(ostream &out_stream)=0
virtual void read_binary_data(std::istream &data_stream, unsigned int n_components, unsigned int i_row)=0
virtual void print_all_yaml(ostream &out_stream, unsigned int precision)=0