LifeV
TimeData.hpp
Go to the documentation of this file.
1 //@HEADER
2 /*
3 *******************************************************************************
4 
5  Copyright (C) 2004, 2005, 2007 EPFL, Politecnico di Milano, INRIA
6  Copyright (C) 2010 EPFL, Politecnico di Milano, Emory University
7 
8  This file is part of LifeV.
9 
10  LifeV is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  LifeV is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with LifeV. If not, see <http://www.gnu.org/licenses/>.
22 
23 *******************************************************************************
24 */
25 
26 //@HEADER
27 
28 /*!
29  @file
30  @brief File containing a class for handling temporal discretization
31 
32  @author M.A. Fernandez
33  @author Cristiano Malossi <cristiano.malossi@epfl.ch>
34  @date 01-06-2009
35 
36  @contributor Matteo Pozzoli <matteo1.pozzoli@mail.polimi.it>
37 
38  @maintainer Matteo Pozzoli <matteo1.pozzoli@mail.polimi.it>
39  */
40 
41 #ifndef TimeData_H
42 #define TimeData_H 1
43 
44 
45 #include <ostream>
46 
47 
48 
49 #include <lifev/core/filter/GetPot.hpp>
50 #include <lifev/core/LifeV.hpp>
51 
52 namespace LifeV
53 {
54 
55 //! TimeData - Class for handling temporal discretization.
56 /*!
57  * @author Cristiano Malossi
58  *
59  * The class is a data container for the time discretization.
60  */
61 class TimeData
62 {
63 public:
64 
65  //! @name Constructors & Destructor
66  //@{
67 
68  //! Empty Constructor
69  TimeData();
70 
71  //! Constructor
72  /*!
73  * @param dataFile GetPot data file
74  * @param section the section on the data file that contains the information on the time discretization
75  */
76  TimeData ( const GetPot& dataFile, const std::string& section = "time_discretization" );
77 
78  //! Copy constructor
79  /*!
80  * @param TimeData - TimeData class
81  */
82  TimeData ( const TimeData& TimeData);
83 
84  //! Virtual destructor
85  virtual ~TimeData() {}
86 
87  //@}
88 
89 
90  //! @name Methods
91  //@{
92 
93  //! Read the dataFile and set all the internal quantities
94  /*!
95  * @param dataFile data file
96  * @param section section of the file
97  */
98  void setup ( const GetPot& dfile, const std::string& section = "time_discretization" );
99 
100  //! Update the time by a timestep.
101  void updateTime()
102  {
103  M_time += M_timeStep;
105  }
106 
107  //! Return if we can make a new timestep
108  /*!
109  * @return true if time <= endTime, false viceversa
110  */
111  bool canAdvance()
112  {
113  return round ( M_time ) <= round ( M_endTime );
114  }
115 
116  //! Return if it is the initial time step
117  /*!
118  * @return true if time = initial time, false viceversa
119  */
121  {
122  return round ( M_time ) == round ( M_initialTime );
123  }
124 
125  //! Return if it is the last time step
126  /*!
127  * @return true if time + timestep > endTime, false viceversa.
128  */
130  {
131  return round ( M_time + M_timeStep ) > round ( M_endTime );
132  }
133 
134  //! Display general information about the content of the class
135  /*!
136  @param output - specify the output format (std::cout by default)
137  */
138  void showMe ( std::ostream& output = std::cout ) const;
139 
140  //@}
141 
142 
143  //! @name Utility methods
144  //@{
145 
146  Real round ( const Real& n, const Int& decimal = 10 ) const;
147 
148  //@}
149 
150 
151  //! @name Set Methods
152  //@{
153 
154  //! Set the initial time step
155  /*!
156  * @param initialTime initial time step value
157  */
158  void setInitialTime ( const Real& initialTime )
159  {
160  M_initialTime = initialTime;
161  }
162 
163  //! Set the final time step
164  /*!
165  * @param endtime final time step value
166  */
167  void setEndTime ( const Real& endTime )
168  {
169  M_endTime = endTime;
170  }
171 
172  //! Set the present time of the simulation
173  /*!
174  * @param time present time value
175  */
176  void setTime ( const Real& time )
177  {
178  M_time = time;
179  }
180 
181  //! Set the initial time step
182  /*!
183  * @param timeStep initial time step value
184  */
185  void setTimeStep ( const Real& timeStep )
186  {
187  M_timeStep = timeStep;
188  }
189 
190  //! Set the time step number
191  /*!
192  * @param timeStepNumber time step number
193  */
194  void setTimeStepNumber ( const UInt& timeStepNumber )
195  {
196  M_timeStepNumber = timeStepNumber;
197  }
198 
199  //@}
200 
201 
202  //! @name Get Methods
203  //@{
204 
205  //! Get the initial time step
206  /*!
207  * @return initial time step value
208  */
209  const Real& initialTime() const
210  {
211  return M_initialTime;
212  }
213 
214  //! Get the final time step
215  /*!
216  * @return final time step value
217  */
218  const Real& endTime() const
219  {
220  return M_endTime;
221  }
222 
223  //! Get the period
224  /*!
225  * @return period value
226  */
227  const Real& periodTime() const
228  {
229  return M_periodTime;
230  }
231 
232  //! Get the present time
233  /*!
234  * @return time value
235  */
236  const Real& time() const
237  {
238  return M_time;
239  }
240 
241  //! Get the time left
242  /*!
243  * @return time left value
244  */
245  Real leftTime() const
246  {
247  return round ( M_endTime - M_time );
248  }
249 
250  //! Get the elapsed time
251  /*!
252  * @return elapsed time value
253  */
255  {
256  return round ( M_time - M_initialTime );
257  }
258 
259  //! Get the present time shifted inside the first cycle
260  //! (i.e. in the interval (M_initialTime,M_periodTime)).
261  //! Useful for periodic behavior, e.g. BC.
262  /*!
263  * @return time value in first cycle
264  */
266  {
267  return (M_time - static_cast<int> (floor ( (M_time - M_timeStep / 2) / M_periodTime) ) * M_periodTime);
268  }
269 
270  //! Get the previous time
271  /*!
272  * @return previous time value
273  */
275  {
276  return M_time - M_timeStep;
277  }
278 
279  //! Get the next time
280  /*!
281  * @return next time value
282  */
283  Real nextTime() const
284  {
285  return M_time + M_timeStep;
286  }
287 
288  //! Get the time step used for advancing
289  /*!
290  * @return time step value
291  */
292  const Real& timeStep() const
293  {
294  return M_timeStep;
295  }
296 
297  //! Get the number of time step performed
298  /*!
299  * @return time step performed
300  */
301  const UInt& timeStepNumber() const
302  {
303  return M_timeStepNumber;
304  }
305 
306  //@}
307 
308 private:
309 
310  //! initial time
312 
313  //! end time
315 
316  //! period time
318 
319  //! current time
321 
322  //! time step
324 
325  //! iteration number
327 };
328 
329 } // namespace LifeV
330 
331 #endif // TimeData_H
const Real & time() const
Get the present time.
Definition: TimeData.hpp:236
void setTimeStep(const Real &timeStep)
Set the initial time step.
Definition: TimeData.hpp:185
Real M_periodTime
period time
Definition: TimeData.hpp:317
TimeData(const TimeData &TimeData)
Copy constructor.
Definition: TimeData.cpp:62
void setTime(const Real &time)
Set the present time of the simulation.
Definition: TimeData.hpp:176
Real M_endTime
end time
Definition: TimeData.hpp:314
Real M_initialTime
initial time
Definition: TimeData.hpp:311
int32_type Int
Generic integer data.
Definition: LifeV.hpp:188
bool isLastTimeStep()
Return if it is the last time step.
Definition: TimeData.hpp:129
void updateInverseJacobian(const UInt &iQuadPt)
virtual ~TimeData()
Virtual destructor.
Definition: TimeData.hpp:85
const Real & initialTime() const
Get the initial time step.
Definition: TimeData.hpp:209
Real M_timeStep
time step
Definition: TimeData.hpp:323
bool isFirstTimeStep()
Return if it is the initial time step.
Definition: TimeData.hpp:120
Real leftTime() const
Get the time left.
Definition: TimeData.hpp:245
void setTimeStepNumber(const UInt &timeStepNumber)
Set the time step number.
Definition: TimeData.hpp:194
Real M_time
current time
Definition: TimeData.hpp:320
const Real & timeStep() const
Get the time step used for advancing.
Definition: TimeData.hpp:292
UInt M_timeStepNumber
iteration number
Definition: TimeData.hpp:326
const Real & periodTime() const
Get the period.
Definition: TimeData.hpp:227
const Real & endTime() const
Get the final time step.
Definition: TimeData.hpp:218
void updateTime()
Update the time by a timestep.
Definition: TimeData.hpp:101
double Real
Generic real data.
Definition: LifeV.hpp:175
void showMe(std::ostream &output=std::cout) const
Display general information about the content of the class.
Definition: TimeData.cpp:86
void setEndTime(const Real &endTime)
Set the final time step.
Definition: TimeData.hpp:167
Real elapsedTime() const
Get the elapsed time.
Definition: TimeData.hpp:254
Real inCycleTime() const
Get the present time shifted inside the first cycle (i.e.
Definition: TimeData.hpp:265
Real round(const Real &n, const Int &decimal=10) const
Definition: TimeData.cpp:104
TimeData()
Empty Constructor.
Definition: TimeData.cpp:46
bool canAdvance()
Return if we can make a new timestep.
Definition: TimeData.hpp:111
Real previousTime() const
Get the previous time.
Definition: TimeData.hpp:274
void setInitialTime(const Real &initialTime)
Set the initial time step.
Definition: TimeData.hpp:158
const UInt & timeStepNumber() const
Get the number of time step performed.
Definition: TimeData.hpp:301
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191
Real nextTime() const
Get the next time.
Definition: TimeData.hpp:283
TimeData - Class for handling temporal discretization.
Definition: TimeData.hpp:61