26 #include "boost/lexical_cast.hpp" 50 this->set_vtk_type<T>();
63 "Do not support output of vectors with fixed size >3. Field: %s\n",
86 ASSERT_LT(component_idx,
data_.size()).error(
"Index of component is out of range.\n");
87 return data_[component_idx];
94 for (
unsigned int i=0; i<size_of_cache; ++i) {
96 row_vec->resize(row_vec_size, numeric_limits<T>::signaling_NaN());
97 data_cache[i] = row_vec;
104 template <
typename T>
107 for (
unsigned int i_vec=0; i_vec<
data_.size(); ++i_vec) {
108 idx = i_row * n_components;
110 for (
unsigned int i_col=0; i_col < n_components; ++i_col, ++idx) {
111 vec[idx] = boost::lexical_cast<T>(*tok);
118 template <
typename T>
121 for (
unsigned int i_vec=0; i_vec<
data_.size(); ++i_vec) {
122 idx = i_row * n_components;
124 for (
unsigned int i_col=0; i_col < n_components; ++i_col, ++idx) {
125 data_stream.read(reinterpret_cast<char *>(&vec[idx]),
sizeof(T));
137 template <
typename T>
143 out_stream << vec[i] <<
" ";
153 template <
typename T>
157 for(
unsigned int idx = 0; idx < this->
n_values_; idx++) {
159 out_stream << vec[i] <<
" ";
165 template <
typename T>
168 if (print_data_size) {
170 unsigned long long int data_byte_size = this->
n_values_ *
n_elem_ *
sizeof(T);
171 out_stream.write(reinterpret_cast<const char*>(&data_byte_size),
sizeof(
unsigned long long int));
175 for(
unsigned int idx = 0; idx < this->
n_values_; idx++) {
177 out_stream.write(reinterpret_cast<const char*>(&(vec[i])),
sizeof(T));
182 template <
typename T>
187 for(
unsigned int idx = 0; idx < this->
n_values_; idx++) {
188 if (idx != 0) out_stream <<
" , ";
189 unsigned int vec_pos =
n_elem_ * idx;
191 case NumCompValueType::N_SCALAR: {
195 case NumCompValueType::N_VECTOR: {
196 typename arma::Col<T>::template fixed<3> vec_val;
197 for (
unsigned int i=0; i<3; ++i, ++vec_pos)
198 vec_val(i) = vec[vec_pos];
202 case NumCompValueType::N_TENSOR: {
203 typename arma::Mat<T>::template fixed<3,3> mat_val;
204 for (
unsigned int i=0; i<3; ++i)
205 for (
unsigned int j=0; j<3; ++j, ++vec_pos)
206 mat_val(i,j) = vec[vec_pos];
216 template <
typename T>
219 min = std::numeric_limits<double>::max();
220 max = std::numeric_limits<double>::min();
222 for(
unsigned int idx = 0; idx < this->
n_values_; idx++) {
224 if (vec[i] < min) min = vec[i];
225 if (vec[i] > max) max = vec[i];
234 template <
typename T>
238 unsigned int vec_idx = idx*this->
n_elem_;
239 for(
unsigned int i = 0; i < this->
n_elem_; i++, vec_idx++) {
240 vec[vec_idx] = value[i];
247 template <
typename T>
251 unsigned int vec_idx = idx*this->
n_elem_;
252 for(
unsigned int i = 0; i < this->
n_elem_; i++, vec_idx++) {
253 vec[vec_idx] += value[i];
260 template <
typename T>
264 unsigned int vec_idx = idx*this->
n_elem_;
265 for(
unsigned int i = 0; i < this->
n_elem_; i++, vec_idx++) {
273 template <
typename T>
277 unsigned int vec_idx = idx*this->
n_elem_;
278 for(
unsigned int i = 0; i < this->
n_elem_; i++, vec_idx++) {
279 vec[vec_idx] /= divisor;
283 template <
typename T>
288 bool is_nan =
false, out_of_limit =
false;
289 for (
unsigned int j=0; j<
data_.size(); ++j) {
291 for(
unsigned int i=0; i<vec.size(); ++i) {
294 else vec[i] = default_val;
296 if ( (vec[i] < lower_bound) || (vec[i] > upper_bound) ) out_of_limit =
true;
305 template <
typename T>
310 for (
unsigned int j=0; j<
data_.size(); ++j) {
312 for(
unsigned int i=0; i<vec.size(); ++i) {
double time_
time step stored in cache
void read_binary_data(std::istream &data_stream, unsigned int n_components, unsigned int i_row) override
Implements ElementDataCacheBase::read_binary_data.
std::shared_ptr< std::vector< T > > ComponentDataPtr
CheckScaleData
Allow to hold sign, if data in cache is checked and scale (both can be executed only once) ...
void print_ascii(ostream &out_stream, unsigned int idx) override
CheckScaleData check_scale_data_
Sign, if data in cache is checked and scale.
Some value(s) is set to NaN.
void store_value(unsigned int idx, const T *value)
T & operator[](unsigned int i)
Access i-th element in the data vector of 0th component.
void read_ascii_data(Tokenizer &tok, unsigned int n_components, unsigned int i_row) override
Implements ElementDataCacheBase::read_ascii_data.
Some value(s) is out of limits.
static constexpr bool value
ElementDataCache()
Default constructor.
void get_min_max_range(double &min, double &max) override
void add(unsigned int idx, const T *value)
virtual ~ElementDataCache() override
Destructor of ElementDataCache.
static CacheData create_data_cache(unsigned int size_of_cache, unsigned int row_vec_size)
void zero(unsigned int idx)
void scale_data(double coef)
void print_all_yaml(ostream &out_stream, unsigned int precision) override
Data is neither checked nor scaled.
CheckResult
Return type of method that checked data stored in ElementDataCache (NaN values, limits) ...
CheckResult check_values(double default_val, double lower_bound, double upper_bound)
void normalize(unsigned int idx, unsigned int divisor)
void print_binary_all(ostream &out_stream, bool print_data_size=true) override
Print all data stored in output data to appended binary format.
std::string field_input_name_
name of field stored in cache
#define ASSERT_LT(a, b)
Definition of comparative assert macro (Less Than)
ComponentDataPtr get_component_data(unsigned int component_idx)
Return vector of element data for get component.
void print_ascii_all(ostream &out_stream) override
Print all data stored in output data ro ascii format.
All values are not NaN and are in limits.
#define THROW(whole_exception_expr)
Wrapper for throw. Saves the throwing point.
#define ASSERT_LT_DBG(a, b)
Definition of comparative assert macro (Less Than) only for debug mode.