Rythmos - Transient Integration for Differential Equations Version of the Day
Loading...
Searching...
No Matches
Rythmos_TimeRange_decl.hpp
1//@HEADER
2// ***********************************************************************
3//
4// Rythmos Package
5// Copyright (2006) Sandia Corporation
6//
7// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8// license for use of this work by or on behalf of the U.S. Government.
9//
10// This library is free software; you can redistribute it and/or modify
11// it under the terms of the GNU Lesser General Public License as
12// published by the Free Software Foundation; either version 2.1 of the
13// License, or (at your option) any later version.
14//
15// This library is distributed in the hope that it will be useful, but
16// 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
21// License along with this library; if not, write to the Free Software
22// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
23// USA
24// Questions? Contact Todd S. Coffey (tscoffe@sandia.gov)
25//
26// ***********************************************************************
27//@HEADER
28
29#ifndef RYTHMOS_TIME_RANGE_DECL_H
30#define RYTHMOS_TIME_RANGE_DECL_H
31
32#include "Rythmos_ConfigDefs.h"
33
34namespace Rythmos {
35
36
61template<class TimeType>
62int compareTimeValues( const TimeType &t1, const TimeType &t2 );
63
71template<class TimeType>
73{
74public:
77 : lower_(0.0), upper_(-1.0)
78 {}
80 TimeRange( const TimeType &my_lower, const TimeType &my_upper )
81 : lower_(my_lower), upper_(my_upper)
82 {
83 }
86 : lower_(tr.lower()), upper_(tr.upper())
87 {
88 }
90 virtual ~TimeRange() {}
92 bool isValid() const { return (lower_ <= upper_); }
94 TimeType lower() const { return lower_; }
96 TimeType upper() const { return upper_; }
98 TimeType length() const { return (upper_ - lower_); }
100 virtual bool isInRange ( const TimeType &t ) const
101 {
102 return (
103 compareTimeValues(t,lower_) >= 0
104 && compareTimeValues(t,upper_) <= 0
105 );
106 }
108 TimeRange<TimeType> copyAndScale( const TimeType &scale ) const
109 {
110 TimeRange<TimeType> newRange = *this;
111 if (!newRange.isValid())
112 return newRange;
113 newRange.lower_ *= scale;
114 newRange.upper_ *= scale;
115 return newRange;
116 }
117
118private:
119 TimeType lower_;
120 TimeType upper_;
121};
122
127template<class TimeType>
128TimeRange<TimeType> timeRange(const TimeType my_lower, const TimeType my_upper);
129
130
135template<class TimeType>
137
138
143template<class TimeType>
144std::ostream& operator<<( std::ostream& out, const TimeRange<TimeType>& range );
145
146
150template<class TimeType>
151void asssertInTimeRange( const TimeRange<TimeType> &timeRange,
152 const TimeType &time );
153
154
161template<class TimeType>
162bool isInRange_cc(const TimeRange<TimeType> &tr, const TimeType &p);
163
164
171template<class TimeType>
172bool isInRange_oc(const TimeRange<TimeType> &tr, const TimeType &p);
173
174
181template<class TimeType>
182bool isInRange_co(const TimeRange<TimeType> &tr, const TimeType &p);
183
184
191template<class TimeType>
192bool isInRange_oo(const TimeRange<TimeType> &tr, const TimeType &p);
193
194template<class TimeType>
195class TimeRange_cc : virtual public TimeRange<TimeType>
196{
197public:
198 TimeRange_cc(const TimeRange<TimeType>& tr)
199 :TimeRange<TimeType>(tr)
200 {
201 }
202 TimeRange_cc( const TimeType &my_lower, const TimeType &my_upper )
203 :TimeRange<TimeType>(my_lower,my_upper)
204 {
205 }
206 bool isInRange ( const TimeType &t ) const
207 {
208 return ( isInRange_cc<TimeType>(*this,t) );
209 }
210};
211
212template<class TimeType>
213class TimeRange_co : virtual public TimeRange<TimeType>
214{
215public:
216 TimeRange_co(const TimeRange<TimeType>& tr)
217 :TimeRange<TimeType>(tr)
218 {
219 }
220 TimeRange_co( const TimeType &my_lower, const TimeType &my_upper )
221 :TimeRange<TimeType>(my_lower,my_upper)
222 {
223 }
224 bool isInRange ( const TimeType &t ) const
225 {
226 return ( isInRange_co<TimeType>(*this,t) );
227 }
228};
229
230template<class TimeType>
231class TimeRange_oo : virtual public TimeRange<TimeType>
232{
233public:
234 TimeRange_oo(const TimeRange<TimeType>& tr)
235 :TimeRange<TimeType>(tr)
236 {
237 }
238 TimeRange_oo( const TimeType &my_lower, const TimeType &my_upper )
239 :TimeRange<TimeType>(my_lower,my_upper)
240 {
241 }
242 bool isInRange ( const TimeType &t ) const
243 {
244 return ( isInRange_oo<TimeType>(*this,t) );
245 }
246};
247
248template<class TimeType>
249class TimeRange_oc : virtual public TimeRange<TimeType>
250{
251public:
252 TimeRange_oc(const TimeRange<TimeType>& tr)
253 :TimeRange<TimeType>(tr)
254 {
255 }
256 TimeRange_oc( const TimeType &my_lower, const TimeType &my_upper )
257 :TimeRange<TimeType>(my_lower,my_upper)
258 {
259 }
260 bool isInRange ( const TimeType &t ) const
261 {
262 return ( isInRange_oc<TimeType>(*this,t) );
263 }
264};
265
266
267} // namespace Rythmos
268
269
270#endif //RYTHMOS_TIME_RANGE_DECL_H
Represent a time range.
TimeRange(const TimeRange< TimeType > &tr)
Copy constructor.
std::ostream & operator<<(std::ostream &out, const TimeRange< TimeType > &range)
Output operator.
int compareTimeValues(const TimeType &t1, const TimeType &t2)
Compare two times taking into account floating point errors.
TimeRange< TimeType > invalidTimeRange()
Nonmember constructor.
bool isInRange_oo(const TimeRange< TimeType > &tr, const TimeType &p)
Nonmember isInRange function (open, open).
TimeRange< TimeType > copyAndScale(const TimeType &scale) const
bool isInRange_co(const TimeRange< TimeType > &tr, const TimeType &p)
Nonmember isInRange function [closed, open).
virtual bool isInRange(const TimeType &t) const
TimeRange(const TimeType &my_lower, const TimeType &my_upper)
Construct a valid range.
bool isInRange_cc(const TimeRange< TimeType > &tr, const TimeType &p)
Nonmember isInRange function [closed, closed].
bool isInRange_oc(const TimeRange< TimeType > &tr, const TimeType &p)
Nonmember isInRange function (open, closed].
TimeRange()
Construct an invalid range.
TimeRange< TimeType > timeRange(const TimeType my_lower, const TimeType my_upper)
Nonmember constructor.