Flow123d  last_with_con_2.0.0-663-gd0e2296
output_mesh_data.cc
Go to the documentation of this file.
1 /*
2  * output_mesh_data.cc
3  *
4  * Created on: Jul 8, 2016
5  * Author: jb
6  */
7 
8 #include "io/output_mesh_data.hh"
9 
10 
11 /// Constructor. @p name is the possible name of the output vector.
12 template <class T>
13 MeshData<T>::MeshData(std::string name, NumCompValueType n_elem)
14 {
15  this->set_vtk_type<T>();
16  output_field_name = name;
17  n_elem_ = n_elem;
18 }
19 
20 template <class T>
22 {};
23 
24 /// Prints @p idx element of data vector into stream.
25 template <class T>
26 void MeshData<T>::print_ascii(std::ostream& out_stream, unsigned int idx)
27 {
28  ASSERT_LT(idx, this->n_values);
29  out_stream << data_[idx] ;
30 }
31 
32 /// Prints the whole data vector into stream.
33 template <class T>
34 void MeshData<T>::print_ascii_all(std::ostream& out_stream)
35 {
36  for(auto &d : data_)
37  out_stream << d << " ";
38 }
39 
40 
41 /// Prints the whole data vector into stream.
42 template <class T>
43 void MeshData<T>::print_binary_all(ostream &out_stream)
44 {
45  // write size of data
46  unsigned long long int data_byte_size = data_.size() * sizeof(T);
47  out_stream.write(reinterpret_cast<const char*>(&data_byte_size), sizeof(unsigned long long int));
48  // write data
49  for(auto &d : data_)
50  out_stream.write(reinterpret_cast<const char*>(&d), sizeof(T));
51 }
52 
53 
54 /// Prints the whole data vector into stream.
55 template <class T>
56 void MeshData<T>::print_all_yaml(std::ostream& out_stream, unsigned int precision)
57 {
58  ASSERT(false).error("Unsupported output of the mesh data to YAML format.");
59 }
60 
61 
62 template <class T>
63 void MeshData<T>::get_min_max_range(double &min, double &max)
64 {
65  min = std::numeric_limits<double>::max();
66  max = std::numeric_limits<double>::min();
67  for(auto &d : data_) {
68  if ((double)d < min) min = (double)d;
69  if ((double)d > max) max = (double)d;
70  }
71 }
72 
73 
74 /// Access i-th element in the data vector.
75 template <class T>
76 T& MeshData<T>::operator[](unsigned int i)
77 {
78  ASSERT_DBG(i < data_.size());
79  return data_[i];
80 }
81 
82 template class MeshData<unsigned int>;
83 template class MeshData<double>;
84 
void print_ascii(std::ostream &out_stream, unsigned int idx) override
Prints idx element of data vector into stream.
#define ASSERT(expr)
Allow use shorter versions of macro names if these names is not used with external library...
Definition: asserts.hh:347
void print_ascii_all(std::ostream &out_stream) override
Prints the whole data vector into stream.
MeshData(std::string name, NumCompValueType n_elem=N_SCALAR)
Constructor. name is the possible name of the output vector.
void print_binary_all(ostream &out_stream) override
Prints the whole data vector into stream.
T & operator[](unsigned int i)
Access i-th element in the data vector.
#define ASSERT_LT(a, b)
Definition of comparative assert macro (Less Than)
Definition: asserts.hh:296
#define ASSERT_DBG(expr)
Definition: asserts.hh:350
~MeshData() override
void print_all_yaml(std::ostream &out_stream, unsigned int precision) override
Prints the whole data vector into stream. UNSUPPORTED.
void get_min_max_range(double &min, double &max) override