timeControl.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 "timeControl.hpp"
23 #include "dictionary.hpp"
24 
25 
27 {
29 }
30 
32 (
33  const dictionary& dict
34 )
35 :
36  dt_
37  (
38  dict.getVal<real>("dt")
39  ),
40  startTime_
41  (
42  dict.getVal<real>("startTime")
43  ),
44  endTime_
45  (
46  dict.getVal<real>("endTime")
47  ),
48  stopAt_(endTime_),
49  currentTime_(startTime_),
50  saveInterval_
51  (
52  dict.getVal<real>("saveInterval")
53  ),
54  lastSaved_(startTime_),
55  currentIter_(0),
56  timePrecision_
57  (
58  dict.getValOrSet("timePrecision", 4)
59  ),
60  timersReportInterval_
61  (
62  startTime_,
63  dict.getValOrSet("timersReportInterval", 0.04)
64  ),
65  performSorting_
66  (
67  dict.getValOrSet("performSorting", Logical("No"))
68  ),
69  sortingInterval_
70  (
71  startTime_,
72  dict.getValOrSet("sortingInterval", static_cast<real>(1.0))
73  )
74 {
75  checkForOutputToFile();
76 }
77 
79  dictionary& dict,
80  real startTime,
81  real endTime,
82  real saveInterval,
83  word startTimeName)
84 :
85  dt_
86  (
87  dict.getVal<real>("dt")
88  ),
89  startTime_(startTime),
90  endTime_(endTime),
91  stopAt_(endTime_),
92  currentTime_(startTime_),
93  saveInterval_(saveInterval),
94  lastSaved_(startTime_),
95  currentIter_(0),
96  timePrecision_
97  (
98  dict.getValOrSet("timePrecision", 4)
99  ),
100  managedExternaly_(true),
101  timeName_(startTimeName),
102  timersReportInterval_
103  (
104  startTime_,
105  dict.getValOrSet("timersReportInterval", 0.04)
106  ),
107  performSorting_
108  (
109  dict.getValOrSet("performSorting", Logical("No"))
110  ),
111  sortingInterval_
112  (
113  startTime_,
114  dict.getValOrSet("sortingInterval", static_cast<real>(1.0))
115  )
116 {
118 }
119 
121 {
122  if(managedExternaly_)
123  return timeName_;
124  else
125  return currentTimeWord();
126 }
127 
129 {
130  if( currentTime_ >= endTime_ ) return true;
131  if( abs(currentTime_-endTime_) < 0.5*dt_ )return true;
132  return false;
133 }
134 
136 {
137  if( currentTime_ >= stopAt_ ) return true;
138  if( abs(currentTime_-stopAt_) < 0.5*dt_ )return true;
139  return false;
140 }
141 
143 {
144 
145  bool save = false;
146  if(managedExternaly_)
147  {
148  if( abs(currentTime_-writeTime_) < 0.5*dt_)
149  {
150  save = true;
151  lastSaved_ = currentTime_;
152  }
153  }
154  else
155  {
156  if ( abs(currentTime_ - lastSaved_ - saveInterval_) < 0.5 * dt_ )
157  {
158  lastSaved_ = currentTime_;
159  save = true;
160  }
161  else if( abs(currentTime_ - lastSaved_) < min( pow(10.0,-1.0*timePrecision_), 0.5 *dt_) )
162  {
163  lastSaved_ = currentTime_;
164  save = true;
165  }
166 
167  }
168 
169  outputToFile_ = save;
170 
171 
172 }
173 
175 {
176  if(currentIter_<=1)return false;
177  return timersReportInterval_.isMember(currentTime_, dt_);
178 }
179 
181 {
182  return performSorting_()&&sortingInterval_.isMember(currentTime_,dt_);
183 }
184 
186  bool saveToFile,
187  const word& timeName)
188 {
189  if(managedExternaly_)
190  {
191  outputToFile_ = saveToFile;
192  timeName_ = timeName;
193  }
194 }
195 
197 {
198 
199  if( reachedStopAt() ) return false;
200  // increament iteration number
201  currentIter_++;
202 
203  currentTime_ += dt_;
204  if(screenReport() && !managedExternaly_)
205  {
206  REPORT(0)<<"Time (s): "<<cyanText( currentTimeWord() )<<endREPORT;
207  }
208  // switch outputToFile_ on/off
209  checkForOutputToFile();
210 
211  return true;
212 }
endREPORT
#define endREPORT
Definition: streams.hpp:41
pFlow::dictionary::getValOrSet
T getValOrSet(const word &keyword, const T &setVal) const
Definition: dictionary.hpp:325
pFlow::timeControl::timersReportTime
bool timersReportTime() const
Definition: timeControl.cpp:174
pFlow::real
float real
Definition: builtinTypes.hpp:46
REPORT
#define REPORT(n)
Definition: streams.hpp:40
pFlow::timeControl::operator++
bool operator++(int)
Definition: timeControl.cpp:196
pFlow::timeControl::sortTime
bool sortTime() const
Definition: timeControl.cpp:180
cyanText
#define cyanText(text)
Definition: streams.hpp:34
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
pFlow::timeControl::timeName
word timeName() const
Definition: timeControl.cpp:120
timeControl.hpp
pFlow::pow
Vector< T, Allocator > pow(const Vector< T, Allocator > &v, T e)
Definition: VectorMath.hpp:109
dictionary.hpp
pFlow::timeControl::screenReportInterval_
int32StridedRagne screenReportInterval_
Definition: timeControl.hpp:83
pFlow::abs
INLINE_FUNCTION_HD real abs(real x)
Definition: math.hpp:43
pFlow::timeControl::screenReport
bool screenReport() const
Definition: timeControl.cpp:26
pFlow::timeControl::checkForOutputToFile
void checkForOutputToFile()
Definition: timeControl.cpp:142
pFlow::timeControl::finalTime
bool finalTime() const
Definition: timeControl.cpp:128
pFlow::dictionary::getVal
T getVal(const word &keyword) const
Definition: dictionary.hpp:309
pFlow::Logical
Definition: Logical.hpp:35
pFlow::timeControl::timeControl
timeControl(const dictionary &dict)
Definition: timeControl.cpp:32
pFlow::timeControl::currentIter_
int32 currentIter_
Definition: timeControl.hpp:66
pFlow::stridedRange::isMember
bool isMember(T val, T epsilon=0) const
Definition: stridedRange.hpp:100
pFlow::timeControl::setSaveTimeFolder
void setSaveTimeFolder(bool saveToFile, const word &timeName="wrongTimeFolder")
Definition: timeControl.cpp:185
pFlow::min
T min(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:138
pFlow::dictionary
Definition: dictionary.hpp:38
pFlow::timeControl::reachedStopAt
bool reachedStopAt() const
Definition: timeControl.cpp:135