Flow123d  release_2.2.0-23-g01927c6
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 
26 #include "system/tokenizer.hh"
27 #include "system/system.hh"
28 
30 public:
31 
32  /**
33  * Number of components of element data stored in the database.
34  */
36  N_SCALAR = 1,
37  N_VECTOR = 3,
39  };
40 
41  /// Types of VTK value
44  } VTKValueType;
45 
46  /// Constructor.
48  : time_(-std::numeric_limits<double>::infinity()),
49  field_name_("") {}
50 
51  /// Destructor
52  virtual ~ElementDataCacheBase() {}
53 
54  /// Getter for time of cache
55  double get_time()
56  { return time_; }
57 
58  /// Getter for quantity name of cache
59  std::string field_input_name()
60  { return field_input_name_; }
61 
62  /// Check if cache stored actual data
63  bool is_actual(double time, std::string field_name) {
64  return (time_ == time) && (field_input_name_ == field_name);
65  }
66 
67  /**
68  * Read ascii data of given \p i_row from tokenizer
69  */
70  virtual void read_ascii_data(Tokenizer &tok, unsigned int n_components, unsigned int i_row)=0;
71 
72  /**
73  * Read binary data of given \p i_row from data stream
74  */
75  virtual void read_binary_data(std::istream &data_stream, unsigned int n_components, unsigned int i_row)=0;
76 
77  /**
78  * Print one value at given index in ascii format
79  */
80  virtual void print_ascii(ostream &out_stream, unsigned int idx) = 0;
81 
82  /**
83  * Print all data in ascii format at once stored in database
84  */
85  virtual void print_ascii_all(ostream &out_stream) = 0;
86 
87  /**
88  * Print all data in binary format at once stored in database
89  */
90  virtual void print_binary_all(ostream &out_stream, bool print_data_size = true) = 0;
91 
92  /**
93  * Print stored values in the YAML format (using JSON like arrays).
94  * Used for output of observe values.
95  */
96  virtual void print_all_yaml(ostream &out_stream, unsigned int precision) = 0;
97 
98  /**
99  * Find minimal and maximal range of stored data
100  */
101  virtual void get_min_max_range(double &min, double &max) = 0;
102 
103  /**
104  * Set string representation of SI units.
105  */
106  void set_field_units(std::string unit_string) {
107  this->field_units_ = unit_string;
108  }
109 
110  /**
111  * Set string representation of SI units.
112  */
113  void set_n_values(unsigned int n_values) {
114  this->n_values_ = n_values;
115  }
116 
117  /**
118  * Get string representation of SI units.
119  */
120  inline std::string field_units() {
121  return this->field_units_;
122  }
123 
124  /**
125  * Get number of data values.
126  */
127  inline unsigned int n_values() {
128  return this->n_values_;
129  }
130 
131  /**
132  * Get number of data elements per data value.
133  */
135  return this->n_elem_;
136  }
137 
138  /// Get type of stored data
139  inline VTKValueType vtk_type() {
140  return this->vtk_type_;
141  }
142 
143 protected:
144  template <class T>
145  void set_vtk_type() {
150  } else if ( std::is_same<T, int>::value ) {
152  } else {
153  ASSERT(false).error("Unsupported VTK type");
154  }
155  }
156 
157  /// time step stored in cache
158  double time_;
159 
160  /// name of field stored in cache
161  std::string field_input_name_;
162  std::string field_name_;
163 
164  /**
165  * Data copied from Field.
166  */
167  std::string field_units_;
168 
169  /**
170  * Number of data values.
171  */
172  unsigned int n_values_;
173 
174  /**
175  * Number of data elements per data value.
176  */
178 
179  /// Type of stored data
180  VTKValueType vtk_type_;
181 };
182 
183 
184 #endif /* ELEMENT_DATA_CACHE_BASE_HH_ */
double time_
time step stored in cache
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
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.
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