www.cemf.ir
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 #include "systemControl.hpp"
22 #include "Lists.hpp"
23 #include "error.hpp"
24 #include "iOstream.hpp"
25 #include "types.hpp"
26 #include "vocabs.hpp"
27 
29 {
30  if (dict.containsDataEntry("includeObjects"))
31  {
32  wordList incld = dict.getVal<wordList>("includeObjects");
33  for (auto& nm : incld)
34  {
35  includeList_.insert(nm);
36  }
37  }
38 
39  if (dict.containsDataEntry("excludeObjects"))
40  {
41  wordList excld = dict.getVal<wordList>("excludeObjects");
42  for (auto& nm : excld)
43  {
44  excludeList_.insert(nm);
45  }
46  }
47  return true;
48 }
49 
51 {
52  // gets the canonical form of path
53  word wPath = path.canonical().wordPath() + "/";
54 
55  auto first = wPath.find_first_of('/');
56  auto last = wPath.find_last_of('/');
57 
58  if (first == word::npos)
59  {
60  fatalErrorInFunction << "path is empty \n";
61  fatalExit;
62  }
63 
64  if (last == wPath.size() - 1)
65  {
66  wPath = wPath.substr(0, last);
67  last = wPath.find_last_of('/');
68  }
69 
70  word rName = wPath.substr(last + 1);
71 
72  return rName;
73 }
74 
76 {
77  // gets the canonical form of path
78  word wPath = path.canonical().wordPath();
79 
80  auto first = wPath.find_first_of('/');
81  auto last = wPath.find_last_of('/');
82 
83  if (first == word::npos)
84  {
85  fatalErrorInFunction << "path is empty \n";
86  fatalExit;
87  }
88 
89  if (last == wPath.size() - 1)
90  {
91  wPath = wPath.substr(0, last);
92  last = wPath.find_last_of('/');
93  }
94 
95  word tFolder = wPath.substr(0, last);
96 
97  return tFolder;
98 }
99 
101  : repository(
102  "systemControl",
103  path, // local path
104  nullptr // no owner
105  ),
106  runName_(getRunName(path)),
107  topLevelFolder_(getTopFolder(path)),
108  settingsDict_(makeUnique<fileDictionary>(
109  objectFile(
112  objectFile::READ_ALWAYS,
113  objectFile::WRITE_NEVER
114  ),
115  this
116  )),
117  Time_(this, settingsDict_()),
118  settings_(
120  ),
121  caseSetup_(
123  ),
124 
125  libs_(settingsDict_()),
126  outFilePrecision_(
127  settingsDict_().getValOrSet("outFilePrecision", static_cast<uint64>(6))
128  ),
129  timers_(runName_),
130  timersReport_(settingsDict_().getValOrSet("timersReport", Logical("Yes"))),
131  writeToFileTimer_("Write to file", &timers_)
132 {
134 }
135 
137  const real startTime,
138  const real endTime,
139  const real saveInterval,
140  const word startTimeName,
141  const fileSystem path
142 )
143  : repository(
144  "systemControl",
145  path, // local path
146  nullptr // no owner
147  ),
148  runName_(getRunName(path)),
149  topLevelFolder_(getTopFolder(path)),
150  settingsDict_(makeUnique<fileDictionary>(
151  objectFile(
154  objectFile::READ_ALWAYS,
155  objectFile::WRITE_NEVER
156  ),
157  this
158  )),
159  Time_(
160  this,
161  settingsDict_(),
162  startTime,
163  endTime,
164  saveInterval,
165  startTimeName
166  ),
167  settings_(
169  ),
170  caseSetup_(
172  ),
173  libs_(settingsDict_()),
174  externalTimeControl_(true),
175  timers_(runName_),
176  timersReport_(settingsDict_->getValOrSet("timersReport", Logical("Yes"))),
177  writeToFileTimer_("Write to file", &timers_)
178 {
180 }
181 
183 {
184  auto toContinue = time()++;
185 
186  if (toContinue)
187  {
188  writeToFileTimer_.start();
189  // if(time().currentIter() != 0 )
190  {
191  //- save the results to file
192  if (!time().write())
193  {
195  return false;
196  }
197  }
198  writeToFileTimer_.end();
199 
200  if (time().timersReportTime() && timersReport())
201  {
202  timers_.write(mOutput, true);
203  }
204  }
205  else if (time().finalTime())
206  {
207  writeToFileTimer_.start();
208  if (!time().write())
209  {
211  return false;
212  }
213  writeToFileTimer_.end();
214 
215  timers_.write(mOutput, true);
216  }
217 
218  return toContinue;
219 }
pFlow::List< word >
pFlow::fileSystem::canonical
fileSystem canonical() const
Canonical path of this (it should exist)
Definition: fileSystem.cpp:149
pFlow::real
float real
Definition: builtinTypes.hpp:45
Lists.hpp
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
pFlow::mOutput
masterOstream mOutput
types.hpp
systemControl.hpp
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
pFlow::systemControl::readIncludeExclue
bool readIncludeExclue(const dictionary &dict)
Definition: systemControl.cpp:28
pFlow::caseSetupRepository__
const char *const caseSetupRepository__
Definition: vocabs.hpp:31
pFlow::settingsFolder__
const char *const settingsFolder__
Definition: vocabs.hpp:28
pFlow::systemControl::settingsDict_
uniquePtr< fileDictionary > settingsDict_
settingsDict fileDictionary
Definition: systemControl.hpp:54
pFlow::dictionary::containsDataEntry
bool containsDataEntry(const word &name) const
check if a data entry exist
Definition: dictionary.cpp:761
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::systemControl::getTopFolder
static word getTopFolder(const fileSystem &path)
Definition: systemControl.cpp:75
pFlow::systemControl::systemControl
systemControl(const fileSystem path=CWD())
Definition: systemControl.cpp:100
pFlow::systemControl::getRunName
static word getRunName(const fileSystem &path)
Definition: systemControl.cpp:50
pFlow::objectFile
Definition: objectFile.hpp:30
pFlow::makeUnique
uniquePtr< T > makeUnique(Args &&... args)
Definition: uniquePtr.hpp:99
pFlow::dictionary::getVal
T getVal(const word &keyword) const
get the value of data entry
Definition: dictionary.hpp:379
pFlow::systemControl::operator++
bool operator++(int)
Definition: systemControl.cpp:182
pFlow::Logical
Holds a bool value and converts strings to bool.
Definition: Logical.hpp:39
pFlow::caseSetupFolder__
const char *const caseSetupFolder__
Definition: vocabs.hpp:30
pFlow::fileDictionary
Definition: fileDictionary.hpp:29
pFlow::uint64
unsigned long long int uint64
Definition: builtinTypes.hpp:58
pFlow::systemControl::includeList_
wordSet includeList_
Definition: systemControl.hpp:82
pFlow::repository
Definition: repository.hpp:34
pFlow::systemControl::excludeList_
wordSet excludeList_
Definition: systemControl.hpp:84
iOstream.hpp
pFlow::fileSystem::wordPath
word wordPath() const
Path in word type.
Definition: fileSystem.hpp:160
pFlow::settingsRepository__
const char *const settingsRepository__
Definition: vocabs.hpp:29
vocabs.hpp
pFlow::settingsFile__
const char *const settingsFile__
Definition: vocabs.hpp:38
pFlow::dictionary
Dictionary holds a set of data entries or sub-dictionaries that are enclosed in a curely braces or ar...
Definition: dictionary.hpp:67
error.hpp