22 #include "boost/lexical_cast.hpp" 42 this->set_vtk_type<T>();
55 "Do not support output of vectors with fixed size >3. Field: %s\n",
78 ASSERT_LT(component_idx,
data_.size()).error(
"Index of component is out of range.\n");
79 return data_[component_idx];
86 for (
unsigned int i=0; i<size_of_cache; ++i) {
88 row_vec->resize(row_vec_size);
89 data_cache[i] = row_vec;
99 for (
unsigned int i_vec=0; i_vec<
data_.size(); ++i_vec) {
100 idx = i_row * n_components;
102 for (
unsigned int i_col=0; i_col < n_components; ++i_col, ++idx) {
103 vec[idx] = boost::lexical_cast<T>(*tok);
110 template <
typename T>
113 for (
unsigned int i_vec=0; i_vec<
data_.size(); ++i_vec) {
114 idx = i_row * n_components;
116 for (
unsigned int i_col=0; i_col < n_components; ++i_col, ++idx) {
117 data_stream.read(reinterpret_cast<char *>(&vec[idx]),
sizeof(T));
129 template <
typename T>
135 out_stream << vec[i] <<
" ";
145 template <
typename T>
149 for(
unsigned int idx = 0; idx < this->
n_values_; idx++) {
151 out_stream << vec[i] <<
" ";
157 template <
typename T>
160 if (print_data_size) {
162 unsigned long long int data_byte_size = this->
n_values_ *
n_elem_ *
sizeof(T);
163 out_stream.write(reinterpret_cast<const char*>(&data_byte_size),
sizeof(
unsigned long long int));
167 for(
unsigned int idx = 0; idx < this->
n_values_; idx++) {
169 out_stream.write(reinterpret_cast<const char*>(&(vec[i])),
sizeof(T));
174 template <
typename T>
179 for(
unsigned int idx = 0; idx < this->
n_values_; idx++) {
180 if (idx != 0) out_stream <<
", ";
181 unsigned int vec_pos =
n_elem_ * idx;
183 case NumCompValueType::N_SCALAR: {
187 case NumCompValueType::N_VECTOR: {
188 typename arma::Col<T>::template fixed<3> vec_val;
189 for (
unsigned int i=0; i<3; ++i, ++vec_pos)
190 vec_val(i) = vec[vec_pos];
194 case NumCompValueType::N_TENSOR: {
195 typename arma::Mat<T>::template fixed<3,3> mat_val;
196 for (
unsigned int i=0; i<3; ++i)
197 for (
unsigned int j=0; j<3; ++j, ++vec_pos)
198 mat_val(i,j) = vec[vec_pos];
208 template <
typename T>
211 min = std::numeric_limits<double>::max();
212 max = std::numeric_limits<double>::min();
214 for(
unsigned int idx = 0; idx < this->
n_values_; idx++) {
216 if (vec[i] < min) min = vec[i];
217 if (vec[i] > max) max = vec[i];
226 template <
typename T>
230 unsigned int vec_idx = idx*this->
n_elem_;
231 for(
unsigned int i = 0; i < this->
n_elem_; i++, vec_idx++) {
232 vec[vec_idx] = value[i];
239 template <
typename T>
243 unsigned int vec_idx = idx*this->
n_elem_;
244 for(
unsigned int i = 0; i < this->
n_elem_; i++, vec_idx++) {
245 vec[vec_idx] += value[i];
252 template <
typename T>
256 unsigned int vec_idx = idx*this->
n_elem_;
257 for(
unsigned int i = 0; i < this->
n_elem_; i++, vec_idx++) {
265 template <
typename T>
269 unsigned int vec_idx = idx*this->
n_elem_;
270 for(
unsigned int i = 0; i < this->
n_elem_; i++, vec_idx++) {
271 vec[vec_idx] /= divisor;
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
void print_ascii(ostream &out_stream, unsigned int idx) override
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.
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 print_all_yaml(ostream &out_stream, unsigned int precision) override
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.
#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.