systemControl.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 "types.hpp"
23 #include "iOstream.hpp"
24 #include "error.hpp"
25 #include "systemControl.hpp"
26 #include "vocabs.hpp"
27 
28 
30 (
31  const fileSystem& path
32 )
33 {
34 
35  // gets the canonical form of path
36  word wPath = path.canonical().wordPath()+"/";
37 
38  auto first = wPath.find_first_of('/');
39  auto last = wPath.find_last_of('/');
40 
41  if( first == word::npos)
42  {
44  "path is empty \n";
45  fatalExit;
46  }
47 
48  if( last == wPath.size()-1)
49  {
50  wPath = wPath.substr(0,last);
51  last = wPath.find_last_of('/');
52  }
53 
54  word rName = wPath.substr(last+1);
55 
56  return rName;
57 
58 }
59 
61 (
62  const fileSystem& path
63 )
64 {
65 
66  // gets the canonical form of path
67  word wPath = path.canonical().wordPath();
68 
69  auto first = wPath.find_first_of('/');
70  auto last = wPath.find_last_of('/');
71 
72  if( first == word::npos)
73  {
75  "path is empty \n";
76  fatalExit;
77  }
78 
79  if( last == wPath.size()-1)
80  {
81  wPath = wPath.substr(0,last);
82  last = wPath.find_last_of('/');
83  }
84 
85  word tFolder = wPath.substr(0,last);
86 
87  return tFolder;
88 
89 }
90 
91 
93 (
94  const fileSystem path
95 )
96 :
98  (
99  "systemControl",
100  path, // local path
101  nullptr // no owner
102  ),
103  runName_
104  (
105  getRunName(path)
106  ),
107  topLevelFolder_
108  (
109  getTopFolder(path)
110  ),
111  settings_
112  (
115  this
116  ),
117  caseSetup_
118  (
121  this
122  ),
123  settingsDict_
124  (
125  settings().emplaceObject<dictionary>
126  (
127  objectFile
128  (
130  "",
131  objectFile::READ_ALWAYS,
132  objectFile::WRITE_NEVER
133  ),
135  true
136  )
137  ),
138  libs_(settingsDict_),
139  outFilePrecision_(
140  settingsDict_.getValOrSet("outFilePrecision", static_cast<size_t>(6))
141  ),
142  Time_
143  (
144  this,
145  settingsDict_
146  ),
147  g_(
148  settingsDict_.getVal<realx3>("g")
149  ),
150  domain_(
151  settingsDict_.subDict("domain")
152  ),
153  timers_(runName_),
154  timersReport_
155  (
156  settingsDict_.getValOrSet("timersReport", Logical("Yes"))
157  ),
158  writeToFileTimer_("Write to file", &timers_)
159 {}
160 
162  const real startTime,
163  const real endTime,
164  const real saveInterval,
165  const word startTimeName,
166  const fileSystem path)
167 :
168  repository
169  (
170  "systemControl",
171  path, // local path
172  nullptr // no owner
173  ),
174  runName_
175  (
176  getRunName(path)
177  ),
178  topLevelFolder_
179  (
180  getTopFolder(path)
181  ),
182  settings_
183  (
186  this
187  ),
188  caseSetup_
189  (
192  this
193  ),
194  settingsDict_
195  (
196  settings().emplaceObject<dictionary>
197  (
198  objectFile
199  (
201  "",
202  objectFile::READ_ALWAYS,
203  objectFile::WRITE_NEVER
204  ),
206  true
207  )
208  ),
209  libs_(settingsDict_),
210  Time_
211  (
212  this,
213  settingsDict_,
214  startTime,
215  endTime,
216  saveInterval,
217  startTimeName
218  ),
219  externalTimeControl_(true),
220  g_(
221  settingsDict_.getVal<realx3>("g")
222  ),
223  domain_(
224  settingsDict_.subDict("domain")
225  ),
226  timers_(runName_),
227  timersReport_
228  (
229  settingsDict_.getValOrSet("timersReport", Logical("Yes"))
230  ),
231  writeToFileTimer_("Write to file", &timers_)
232 {}
233 
234 
236 {
237 
238  auto toContinue = time()++;
239 
240  if(toContinue)
241  {
242  writeToFileTimer_.start();
243  //if(time().currentIter() != 0 )
244  {
245  //- save the results to file
246  if( !time().write() )
247  {
249  return false;
250  }
251  }
252  writeToFileTimer_.end();
253 
254  if( time().timersReportTime() &&
255  timersReport() )
256  {
257  timers_.write(output, true);
258  }
259 
260  }
261  else if (time().finalTime())
262  {
263  writeToFileTimer_.start();
264  if( !time().write() )
265  {
267  return false;
268  }
269  writeToFileTimer_.end();
270 
271  timers_.write(output, true);
272  }
273 
274  return toContinue;
275 }
276 
277 
pFlow::fileSystem::canonical
fileSystem canonical() const
Definition: fileSystem.cpp:140
pFlow::real
float real
Definition: builtinTypes.hpp:46
fatalExit
#define fatalExit
Definition: error.hpp:57
types.hpp
systemControl.hpp
pFlow::caseSetupFolder__
const char * caseSetupFolder__
Definition: vocabs.hpp:31
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
pFlow::settingsFile__
const char * settingsFile__
Definition: vocabs.hpp:39
pFlow::fileSystem
Definition: fileSystem.hpp:63
pFlow::caseSetupRepository__
const char * caseSetupRepository__
Definition: vocabs.hpp:32
pFlow::settingsFolder__
const char * settingsFolder__
Definition: vocabs.hpp:29
fatalErrorInFunction
#define fatalErrorInFunction
Definition: error.hpp:42
pFlow::systemControl::getTopFolder
static word getTopFolder(const fileSystem &path)
Definition: systemControl.cpp:61
pFlow::systemControl::systemControl
systemControl(const fileSystem path=CWD())
Definition: systemControl.cpp:93
pFlow::output
Ostream output
pFlow::systemControl::getRunName
static word getRunName(const fileSystem &path)
Definition: systemControl.cpp:30
pFlow::objectFile
Definition: objectFile.hpp:33
pFlow::systemControl::operator++
bool operator++(int)
Definition: systemControl.cpp:235
pFlow::settingsRepository__
const char * settingsRepository__
Definition: vocabs.hpp:30
pFlow::Logical
Definition: Logical.hpp:35
pFlow::repository
Definition: repository.hpp:34
iOstream.hpp
pFlow::fileSystem::wordPath
word wordPath() const
Definition: fileSystem.hpp:126
vocabs.hpp
pFlow::triple< real >
pFlow::dictionary
Definition: dictionary.hpp:38
error.hpp