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 
66 {
67  checkForOutputToFile();
68 }
69 
71  dictionary& dict,
72  real startTime,
73  real endTime,
74  real saveInterval,
75  word startTimeName)
76 :
77  dt_
78  (
79  dict.getVal<real>("dt")
80  ),
81  startTime_(startTime),
82  endTime_(endTime),
83  stopAt_(endTime_),
84  currentTime_(startTime_),
85  saveInterval_(saveInterval),
86  lastSaved_(startTime_),
87  currentIter_(0),
88  timePrecision_
89  (
90  dict.getValOrSet("timePrecision", 4)
91  ),
92  managedExternaly_(true),
93  timeName_(startTimeName),
94  timersReportInterval_
95  (
96  startTime_,
97  dict.getValOrSet("timersReportInterval", 0.04)
98  )
99 {
101 }
102 
104 {
105  if(managedExternaly_)
106  return timeName_;
107  else
108  return currentTimeWord();
109 }
110 
112 {
113  if( currentTime_ >= endTime_ ) return true;
114  if( abs(currentTime_-endTime_) < 0.5*dt_ )return true;
115  return false;
116 }
117 
119 {
120  if( currentTime_ >= stopAt_ ) return true;
121  if( abs(currentTime_-stopAt_) < 0.5*dt_ )return true;
122  return false;
123 }
124 
126 {
127 
128  bool save = false;
129  if(managedExternaly_)
130  {
131  if( abs(currentTime_-writeTime_) < 0.5*dt_)
132  {
133  save = true;
134  lastSaved_ = currentTime_;
135  }
136  }
137  else
138  {
139  if ( abs(currentTime_ - lastSaved_ - saveInterval_) < 0.5 * dt_ )
140  {
141  lastSaved_ = currentTime_;
142  save = true;
143  }
144  else if( abs(currentTime_ - lastSaved_) < min( pow(10.0,-1.0*timePrecision_), 0.5 *dt_) )
145  {
146  lastSaved_ = currentTime_;
147  save = true;
148  }
149 
150  }
151 
152  outputToFile_ = save;
153 
154 
155 }
156 
158 {
159  if(currentIter_<=1)return false;
160  return timersReportInterval_.isMember(currentTime_, dt_);
161 }
162 
164  bool saveToFile,
165  const word& timeName)
166 {
167  if(managedExternaly_)
168  {
169  outputToFile_ = saveToFile;
170  timeName_ = timeName;
171  }
172 }
173 
175 {
176 
177  if( reachedStopAt() ) return false;
178  // increament iteration number
179  currentIter_++;
180 
181  currentTime_ += dt_;
182  if(screenReport() && !managedExternaly_)
183  {
184  REPORT(0)<<"Time (s): "<<cyanText( currentTimeWord() )<<endREPORT;
185  }
186  // switch outputToFile_ on/off
187  checkForOutputToFile();
188 
189  return true;
190 }
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:157
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:174
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:103
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:79
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:125
pFlow::timeControl::finalTime
bool finalTime() const
Definition: timeControl.cpp:111
pFlow::dictionary::getVal
T getVal(const word &keyword) const
Definition: dictionary.hpp:309
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:163
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:118