BinaryLogger.cpp
1 #include "BinaryLogger.hpp"
2 
3 using namespace std;
4 
5 BinaryLogger::BinaryLogger(string const& filename):filename_(filename){}
6 
8 
9 void BinaryLogger::Log(Tessellation3D const& tess)const
10 {
11  ofstream file_handle(filename_.c_str(),ios::binary);
12  if(!file_handle.good())
13  throw UniversalError("Error opening BinaryLogger file!!");
14 
15  size_t N=tess.GetPointNo();
16  binary_write_single_size_t(N,file_handle);
17 
18  // Write the points
19  for(size_t i=0;i<N;++i)
20  {
21  Vector3D temp=tess.GetMeshPoint(i);
22  binary_write_single_double(temp.x,file_handle);
23  binary_write_single_double(temp.y,file_handle);
24  binary_write_single_double(temp.z,file_handle);
25  }
26 
27  // Write the faces
28  size_t nfaces=tess.GetTotalFacesNumber();
29  binary_write_single_size_t(nfaces,file_handle);
30  for(size_t i=0;i<nfaces;++i)
31  {
32  Face const& f=tess.GetFace(i);
33  // write neighbors
34  binary_write_single_size_t(f.neighbors.first,file_handle);
35  binary_write_single_size_t(f.neighbors.second,file_handle);
36  // write the vertices
37  binary_write_single_size_t(f.vertices.size(),file_handle);
38  for(size_t j=0;j<f.vertices.size();++j)
39  {
40  binary_write_single_double(f.vertices[j].x,file_handle);
41  binary_write_single_double(f.vertices[j].y,file_handle);
42  binary_write_single_double(f.vertices[j].z,file_handle);
43  }
44  }
45  // write which faces each cell has
46  for(size_t i=0;i<N;++i)
47  {
48  vector<size_t> temp=tess.GetCellFaces(i);
49  binary_write_single_size_t(temp.size(),file_handle);
50  for(size_t j=0;j<temp.size();++j)
51  binary_write_single_size_t(temp[j],file_handle);
52  }
53  file_handle.close();
54 }
double z
Component in the z direction.
Definition: Vector3D.hpp:50
std::pair< size_t, size_t > neighbors
Neighboring cells.
Definition: Face.hpp:23
BinaryLogger(string const &filename)
Class constructor.
Definition: BinaryLogger.cpp:5
Abstract class for tessellation in 3D.
~BinaryLogger(void)
class destructor
Definition: BinaryLogger.cpp:7
Container for error reports.
void binary_write_single_double(double d, ofstream &fh)
Writes a double to a binary file.
Definition: simple_io.cpp:80
Class for a logger for the tessellation in 3D that outputs a binary file. The output is as follows: 1...
virtual Vector3D GetMeshPoint(size_t index) const =0
Returns Position of mesh generating point.
std::vector< Vector3D > vertices
Points at the ends of the edge.
Definition: Face.hpp:20
void Log(Tessellation3D const &tess) const
Creates a log file of the tessellation.
Definition: BinaryLogger.cpp:9
3D Mathematical vector
Definition: Vector3D.hpp:15
double y
Component in the y direction.
Definition: Vector3D.hpp:47
void binary_write_single_size_t(size_t n, ofstream &fh)
Writes a single size_t to a binary file.
Definition: simple_io.cpp:85
virtual Face const & GetFace(size_t index) const =0
Returns Face (interface between cells)
virtual size_t GetPointNo(void) const =0
Get Total number of mesh generating points.
virtual size_t GetTotalFacesNumber(void) const =0
Returns the total number of faces.
double x
Component in the x direction.
Definition: Vector3D.hpp:44
Interface between two cells.
Definition: Face.hpp:15
virtual vector< size_t > const & GetCellFaces(size_t index) const =0
Returns the indeces of a cell&#39;s Faces.