readControlDict.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 #include "readControlDict.hpp"
21 #include "iFstream.hpp"
22 #include "timeFolder.hpp"
23 
25  const real t,
26  const int32 precision)const
27 {
28  std::ostringstream buf;
29  if( formatType_ == "general")
30  buf.setf(ios_base::fmtflags(0), ios_base::floatfield);
31  else if(formatType_ == "scientific")
32  buf.setf(ios_base::fmtflags(ios_base::scientific), ios_base::floatfield);
33  else if(formatType_ == "fixed")
34  buf.setf(ios_base::fmtflags(ios_base::fixed), ios_base::floatfield);
35  else
36  {
37  fatalErrorInFunction<<"the timeFormat is not correct, it should be "
38  " (genral, scientific, fixe) but you supplied "<< formatType_<<endl;
39  fatalExit;
40  }
41 
42  buf.precision(precision);
43  buf << t;
44  return buf.str();
45 }
46 
48 {
49 
50  iFstream cdFile(cdPath_);
51 
52  word startFrom;
53 
54  if( !cdFile.findTokenAndNextSilent("startFrom", startFrom))
55  {
56  startFrom = "latestTime";
57  }
58 
59  if(startFrom == "startTime")
60  {
61  if(!cdFile.findKeywordAndVal("startTime", startTime_ ))
62  {
63  fatalErrorInFunction<<"Could not read startTime from file "<< cdPath_<<endl;
64  return false;
65  }
66  }
67  else
68  {
69  timeFolder folders(rootPath_);
70  if(startFrom == "firstTime")
71  {
72  startTime_ = folders.startTime();
73  }
74  else if( startFrom == "latestTime")
75  {
76  startTime_ = folders.endTime();
77  }
78  else
79  {
81  "expected firstTime, latestTime, or startTime in front of StartFrom, "<<endl<<
82  "but found "<<startFrom<<endl;
83  return false;
84  }
85  }
86 
87 
88  if(!cdFile.findKeywordAndVal("endTime", endTime_ ))
89  {
91  "Could not read endTime from file "<< cdPath_<<endl;
92  return false;
93  }
94 
95  if(!cdFile.findKeywordAndVal("writeInterval", saveInterval_))
96  {
98  "Could not read writeInterval from file "<< cdPath_<<endl;
99  return false;
100  }
101 
102  formatType_ = cdFile.lookupDataOrSet<word>("timeFormat", "general");
103 
104  precision_ = cdFile.lookupDataOrSet("timePrecision", 6);
105 
106  return true;
107 }
108 
110  const fileSystem& rootPath,
111  const fileSystem& cdPath)
112 :
113  rootPath_(rootPath),
114  cdPath_(cdPath)
115 {
116 
117  if(!read())
118  {
119  fatalExit;
120  }
121 }
pFlow::fixed
IOstream & fixed(IOstream &io)
Definition: IOstream.hpp:293
pFlow::iIstream::findTokenAndNextSilent
virtual bool findTokenAndNextSilent(const word &w, word &nextW, int32 limitLine=100)
Definition: iIstream.cpp:168
pFlow::scientific
IOstream & scientific(IOstream &io)
Definition: IOstream.hpp:299
pFlow::iIstream::lookupDataOrSet
T lookupDataOrSet(const word &keyword, const T &setVal)
Definition: iIstreamI.hpp:68
pFlow::real
float real
Definition: builtinTypes.hpp:46
fatalExit
#define fatalExit
Definition: error.hpp:57
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
pFlow::endl
iOstream & endl(iOstream &os)
Definition: iOstream.hpp:312
pFlow::iIstream::findKeywordAndVal
bool findKeywordAndVal(const word &keyword, T &val, bool checkEndStatement=true)
Definition: iIstreamI.hpp:24
pFlow::iFstream
Definition: iFstream.hpp:35
pFlow::timeFolder::startTime
real startTime() const
Definition: timeFolder.hpp:105
pFlow::fileSystem
Definition: fileSystem.hpp:63
fatalErrorInFunction
#define fatalErrorInFunction
Definition: error.hpp:42
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
pFlow::readControlDict::formatType_
word formatType_
Definition: readControlDict.hpp:45
pFlow::timeFolder::endTime
real endTime() const
Definition: timeFolder.hpp:111
readControlDict.hpp
iFstream.hpp
pFlow::readControlDict::read
bool read()
Definition: readControlDict.cpp:47
pFlow::readControlDict::readControlDict
readControlDict(const fileSystem &rootPath=defaultRootPath, const fileSystem &cdPath=defaultCDPath)
Definition: readControlDict.cpp:109
pFlow::readControlDict::convertTimeToName
word convertTimeToName(const real t, const int32 precision) const
Definition: readControlDict.cpp:24
timeFolder.hpp
pFlow::timeFolder
Definition: timeFolder.hpp:32