timeFolder.hpp
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 #ifndef __timeFolder_hpp__
22 #define __timeFolder_hpp__
23 
24 
25 #include "systemControl.hpp"
26 
27 namespace pFlow
28 {
29 
30 Map<real, fileSystem> getTimeFolders(const fileSystem& path);
31 
33 {
35 protected:
36 
38 
40 
41 
42 public:
43 
44  timeFolder(const systemControl& control )
45  :
46  timeFolder(control.path())
47  {}
48 
49  timeFolder(const fileSystem& path)
50  :
51  folders_(getTimeFolders(path)),
52  currentFolder_(folders_.begin())
53  {
54 
55  }
56 
57  real time()const
58  {
59  return currentFolder_->first;
60  }
61 
63  {
64  return currentFolder_->second;
65  }
66 
67  word timeName()const
68  {
69  auto tName = tailName(folder().wordPath(), '/');
70  return tName;
71  }
72 
74  {
75  return fileSystem(timeName());
76  }
77 
78  bool operator ++(int)
79  {
80  if(!finished()) currentFolder_++;
81  return !finished();
82  }
83 
84  explicit operator bool()const
85  {
86  return !finished();
87  }
88 
89  bool operator !()const
90  {
91  return finished();
92  }
93 
94  void rewind()
95  {
96  currentFolder_ = folders_.begin();
97  }
98 
99  bool finished()const
100  {
101  if(currentFolder_ == folders_.end()) return true;
102  return false;
103  }
104 
106  {
107  auto [t,f] = *folders_.begin();
108  return t;
109  }
110 
111  real endTime()const
112  {
113  auto [t,f] = *(--folders_.end());
114  return t;
115  }
116 };
117 
118 inline
120 {
121  Map<real, fileSystem> tFolders;
122 
123  auto subDirs = subDirectories(path);
124 
125  for(auto& subD: subDirs)
126  {
127  auto timeName = tailName(subD.wordPath(), '/');
128  real TIME;
129  if( auto success = readReal(timeName, TIME); success)
130  {
131  if(!tFolders.insertIf(TIME, subD))
132  {
134  " duplicate time folder! time = " << TIME <<endl;
135  fatalExit;
136  }
137  }
138  }
139 
140  return tFolders;
141 }
142 
143 
144 
145 } // pFlow
146 
147 
148 #endif // __Control_hpp__
pFlow::tailName
word tailName(const word &w, char sep='.')
Definition: bTypesFunctions.cpp:168
pFlow::timeFolder::timeFolder
timeFolder(const systemControl &control)
Definition: timeFolder.hpp:44
pFlow::timeFolder::time
real time() const
Definition: timeFolder.hpp:57
pFlow::Map< real, fileSystem >::iterator
typename mapType::iterator iterator
Definition: Map.hpp:46
pFlow::real
float real
Definition: builtinTypes.hpp:46
fatalExit
#define fatalExit
Definition: error.hpp:57
pFlow::timeFolder::operator!
bool operator!() const
Definition: timeFolder.hpp:89
pFlow::timeFolder::finished
bool finished() const
Definition: timeFolder.hpp:99
pFlow::timeFolder::folders_
timeList folders_
Definition: timeFolder.hpp:37
systemControl.hpp
pFlow::timeFolder::rewind
void rewind()
Definition: timeFolder.hpp:94
pFlow::readReal
bool readReal(const word &w, real &val)
Definition: bTypesFunctions.cpp:335
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
pFlow::systemControl
Definition: systemControl.hpp:41
pFlow::timeFolder::timeName
word timeName() const
Definition: timeFolder.hpp:67
pFlow::endl
iOstream & endl(iOstream &os)
Definition: iOstream.hpp:312
pFlow
Definition: demComponent.hpp:28
pFlow::timeFolder::startTime
real startTime() const
Definition: timeFolder.hpp:105
pFlow::fileSystem
Definition: fileSystem.hpp:63
pFlow::subDirectories
fileSystemList subDirectories(const fileSystem &path)
Definition: fileSystem.cpp:313
pFlow::timeFolder::timeFolder
timeFolder(const fileSystem &path)
Definition: timeFolder.hpp:49
pFlow::timeFolder::localFolder
fileSystem localFolder() const
Definition: timeFolder.hpp:73
fatalErrorInFunction
#define fatalErrorInFunction
Definition: error.hpp:42
pFlow::Map::insertIf
bool insertIf(const keyType &k, const mappedType &v)
Definition: MapI.hpp:23
pFlow::timeFolder::currentFolder_
timeList::iterator currentFolder_
Definition: timeFolder.hpp:39
pFlow::getTimeFolders
Map< real, fileSystem > getTimeFolders(const fileSystem &path)
Definition: timeFolder.hpp:119
pFlow::Map< real, fileSystem >
pFlow::timeFolder::endTime
real endTime() const
Definition: timeFolder.hpp:111
pFlow::timeFolder::operator++
bool operator++(int)
Definition: timeFolder.hpp:78
pFlow::timeFolder::folder
fileSystem folder() const
Definition: timeFolder.hpp:62
pFlow::timeFolder
Definition: timeFolder.hpp:32