www.cemf.ir
vtkFile.cpp
Go to the documentation of this file.
1 /*------------------------------- phasicFlow ---------------------------------
2  O C enter of
3  O O E ngineering and
4  O O M ultiscale modeling of
5  OOOOOOO F luid flow
6 ------------------------------------------------------------------------------
7  Copyright (C): www.cemf.ir
8  email: hamid.r.norouzi AT gmail.com
9 ------------------------------------------------------------------------------
10 Licence:
11  This file is part of phasicFlow code. It is a free software for simulating
12  granular and multiphase flows. You can redistribute it and/or modify it under
13  the terms of GNU General Public License v3 or any other later versions.
14 
15  phasicFlow is distributed to help others in their research in the field of
16  granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
17  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 
19 -----------------------------------------------------------------------------*/
20 
21 
22 #include "vtkFile.hpp"
23 
24 bool pFlow::vtkFile::openStream(bool wHeader)
25 {
26  oStream_ = makeUnique<oFstream>( fileName(), binary_, append_ );
27  if( !oStream_ )return false;
28  if(wHeader)
29  return writeHeader();
30  else
31  return true;
32 }
33 
34 bool pFlow::vtkFile::vtkFile::writeHeader()
35 {
36 
37  if(!oStream_) return false;
38 
39  oStream_() << "# vtk DataFile Version 3.0" << endl;
40 
41  oStream_() << "vtk file for time : " << time_ << endl;
42  if(binary_)
43  oStream_() << "BINARY" << endl;
44  else
45  oStream_() << "ASCII" << endl;
46 
47  if( oStream_().fail() ) return false;
48 
49  return true;
50 
51 }
52 
54 (
55  const fileSystem dir,
56  const word& bName,
57  real time,
58  bool bnry,
59  bool append
60 )
61 :
62  binary_(bnry),
63  append_(append),
64  time_(time),
65  dirPath_(dir),
66  baseName_(bName)
67 {
68 
69  if(!openStream(!append))
70  {
72  " error in creating vtkFile "<<fileName()<<endl;
73  fatalExit;
74  }
75 
76 }
77 
78 
80 {
81  word fName = baseName_ +"-" + int322Word(10000*time_) + ".vtk";
82  return dirPath_ +fName;
83 }
84 
pFlow::real
float real
Definition: builtinTypes.hpp:45
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
pFlow::vtkFile::fileName
virtual fileSystem fileName() const
Definition: vtkFile.cpp:79
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
pFlow::vtkFile::binary_
bool binary_
Definition: vtkFile.hpp:39
pFlow::vtkFile::vtkFile
vtkFile(const fileSystem dir, const word &bName, real time, bool bnry, bool append=false)
Definition: vtkFile.cpp:54
pFlow::vtkFile::writeHeader
virtual bool writeHeader()
pFlow::endl
iOstream & endl(iOstream &os)
Add newline and flush stream.
Definition: iOstream.hpp:341
pFlow::fileSystem
Manages file pathes, manupulate and combines them.
Definition: fileSystem.hpp:71
fatalErrorInFunction
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
Definition: error.hpp:77
pFlow::vtkFile::openStream
bool openStream(bool wHeader)
Definition: vtkFile.cpp:24
pFlow::vtkFile::append_
bool append_
Definition: vtkFile.hpp:41
pFlow::int322Word
word int322Word(const int32 &v)
Convert int32 to word.
Definition: bTypesFunctions.cpp:110
pFlow::vtkFile::oStream_
uniquePtr< oFstream > oStream_
Definition: vtkFile.hpp:37
vtkFile.hpp