Flow123d  release_2.1.0-84-g6a13a75
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, bool print_data_size)
44 {
45  if (print_data_size) {
46  // write size of data
47  unsigned long long int data_byte_size = data_.size() * sizeof(T);
48  out_stream.write(reinterpret_cast<const char*>(&data_byte_size), sizeof(unsigned long long int));
49  }
50  // write data
51  for(auto &d : data_)
52  out_stream.write(reinterpret_cast<const char*>(&d), sizeof(T));
53 }
54 
55 
56 /// Prints the whole data vector into stream.
57 template <class T>
58 void MeshData<T>::print_all_yaml(std::ostream& out_stream, unsigned int precision)
59 {
60  ASSERT(false).error("Unsupported output of the mesh data to YAML format.");
61 }
62 
63 
64 template <class T>
65 void MeshData<T>::get_min_max_range(double &min, double &max)
66 {
67  min = std::numeric_limits<double>::max();
68  max = std::numeric_limits<double>::min();
69  for(auto &d : data_) {
70  if ((double)d < min) min = (double)d;
71  if ((double)d > max) max = (double)d;
72  }
73 }
74 
75 
76 /// Access i-th element in the data vector.
77 template <class T>
78 T& MeshData<T>::operator[](unsigned int i)
79 {
80  ASSERT_DBG(i < data_.size());
81  return data_[i];
82 }
83 
84 template class MeshData<unsigned int>;
85 template class MeshData<double>;
86 
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.
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 print_binary_all(ostream &out_stream, bool print_data_size=true) override
Prints the whole data vector into stream.
void get_min_max_range(double &min, double &max) override