www.cemf.ir
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 #include "math.hpp"
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  real tmp = currentTime_;
123  currentTime_ = t;
124  lastSaved_ = t;
125  checkForOutputToFile();
126  return tmp;
127 }
128 
130 {
131  if(managedExternaly_)
132  return timeName_;
133  else
134  return currentTimeWord();
135 }
136 
138 {
139  if( currentTime_ >= endTime_ ) return true;
140  if( std::abs(currentTime_-endTime_) < 0.5*dt_ )return true;
141  return false;
142 }
143 
145 {
146  if( currentTime_ >= stopAt_ ) return true;
147  if( std::abs(currentTime_-stopAt_) < 0.5*dt_ )return true;
148  return false;
149 }
150 
152 {
153 
154  bool save = false;
155  if(managedExternaly_)
156  {
157  if( std::abs(currentTime_-writeTime_) < 0.5*dt_)
158  {
159  save = true;
160  lastSaved_ = currentTime_;
161  }
162  }
163  else
164  {
165  if ( std::abs(currentTime_ - lastSaved_ - saveInterval_) < 0.5 * dt_ )
166  {
167  lastSaved_ = currentTime_;
168  save = true;
169  }
170  else if( std::abs(currentTime_ - lastSaved_) < std::min( pow(10.0,-1.0*timePrecision_), 0.5 *dt_) )
171  {
172  lastSaved_ = currentTime_;
173  save = true;
174  }
175 
176  }
177 
178  outputToFile_ = save;
179 }
180 
182 {
183  if(currentIter_<=1)return false;
184  return timersReportInterval_.isMember(currentTime_, 0.55*dt_);
185 }
186 
188 {
189  return performSorting_()&&sortingInterval_.isMember(currentTime_,dt_);
190 }
191 
193  bool saveToFile,
194  const word& timeName)
195 {
196  if(managedExternaly_)
197  {
198  outputToFile_ = saveToFile;
199  timeName_ = timeName;
200  }
201 }
202 
204 {
205 
206  if( reachedStopAt() ) return false;
207  // increament iteration number
208  currentIter_++;
209 
210  currentTime_ += dt_;
211  if(screenReport() && !managedExternaly_)
212  {
213  REPORT(0)<<"Time (s): "<<Cyan_Text( currentTimeWord() )<<END_REPORT;
214  }
215  // switch outputToFile_ on/off
216  checkForOutputToFile();
217 
218  return true;
219 }
pFlow::dictionary::getValOrSet
T getValOrSet(const word &keyword, const T &setVal) const
get the value of data entry or if not found, set the value to setVal
Definition: dictionary.hpp:415
pFlow::timeControl::timersReportTime
bool timersReportTime() const
Definition: timeControl.cpp:181
pFlow::real
float real
Definition: builtinTypes.hpp:45
Cyan_Text
#define Cyan_Text(text)
Definition: iOstream.hpp:44
REPORT
#define REPORT(n)
Definition: streams.hpp:39
pFlow::timeControl::operator++
bool operator++(int)
Definition: timeControl.cpp:203
pFlow::timeControl::sortTime
bool sortTime() const
Definition: timeControl.cpp:187
pFlow::pow
Vector< T, Allocator > pow(const Vector< T, Allocator > &v1, const Vector< T, Allocator > &v2)
Definition: VectorMath.hpp:89
pFlow::algorithms::KOKKOS::min
INLINE_FUNCTION_H Type min(const Type *first, int32 numElems)
Definition: kokkosAlgorithms.hpp:124
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
pFlow::timeControl::timeName
word timeName() const
Definition: timeControl.cpp:129
pFlow::timeControl::setTime
real setTime(real t)
Definition: timeControl.cpp:120
timeControl.hpp
dictionary.hpp
pFlow::timeControl::screenReportInterval_
int32StridedRagne screenReportInterval_
Definition: timeControl.hpp:83
pFlow::timeControl::screenReport
bool screenReport() const
Definition: timeControl.cpp:26
pFlow::timeControl::checkForOutputToFile
void checkForOutputToFile()
Definition: timeControl.cpp:151
pFlow::abs
Vector< T, Allocator > abs(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:84
END_REPORT
#define END_REPORT
Definition: streams.hpp:40
pFlow::timeControl::finalTime
bool finalTime() const
Definition: timeControl.cpp:137
pFlow::dictionary::getVal
T getVal(const word &keyword) const
get the value of data entry
Definition: dictionary.hpp:379
pFlow::Logical
Holds a bool value and converts strings to bool.
Definition: Logical.hpp:39
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:110
pFlow::timeControl::setSaveTimeFolder
void setSaveTimeFolder(bool saveToFile, const word &timeName="wrongTimeFolder")
Definition: timeControl.cpp:192
math.hpp
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
pFlow::timeControl::reachedStopAt
bool reachedStopAt() const
Definition: timeControl.cpp:144