29#ifndef RYTHMOS_TIME_RANGE_DEF_H
30#define RYTHMOS_TIME_RANGE_DEF_H
32#include "Rythmos_TimeRange_decl.hpp"
33#include "Teuchos_Assert.hpp"
34#include "Teuchos_ScalarTraits.hpp"
37template<
class TimeType>
38int Rythmos::compareTimeValues(
const TimeType &t1,
const TimeType &t2 )
41 const TimeType epsMore = 10.0*std::numeric_limits<TimeType>::epsilon();
42 const TimeType t1Mag = Teuchos::ScalarTraits<TimeType>::magnitude(t1);
43 const TimeType t1Tol = t1Mag*epsMore;
44 if ( t2 - t1Tol <= t1 && t1 <= t2 + t1Tol )
46 else if ( t1 > t2 + t1Tol )
53template<
class TimeType>
54Rythmos::TimeRange<TimeType>
55Rythmos::timeRange(
const TimeType lower,
const TimeType upper)
57 return TimeRange<TimeType>(lower,upper);
61template<
class TimeType>
62Rythmos::TimeRange<TimeType>
63Rythmos::invalidTimeRange()
65 return TimeRange<TimeType>();
69template<
class TimeType>
71Rythmos::operator<<( std::ostream& out,
const TimeRange<TimeType>& range )
74 if (range.isValid()) {
75 out << range.lower() <<
"," << range.upper();
85template<
class TimeType>
86void Rythmos::asssertInTimeRange(
const TimeRange<TimeType> &timeRange,
87 const TimeType &time )
89 TEUCHOS_TEST_FOR_EXCEPTION( !timeRange.isInRange(time), std::out_of_range,
90 "Error, the time = " << time
91 <<
" is out of the range = " << timeRange <<
"!"
96template<
class TimeType>
97bool Rythmos::isInRange_cc(
const TimeRange<TimeType> &tr,
const TimeType &p)
100 compareTimeValues(p,tr.lower()) >= 0
101 && compareTimeValues(p,tr.upper()) <= 0
106template<
class TimeType>
107bool Rythmos::isInRange_oc(
const TimeRange<TimeType> &tr,
const TimeType &p)
110 compareTimeValues(p,tr.lower()) > 0
111 && compareTimeValues(p,tr.upper()) <= 0
116template<
class TimeType>
117bool Rythmos::isInRange_co(
const TimeRange<TimeType> &tr,
const TimeType &p)
120 compareTimeValues(p,tr.lower()) >= 0
121 && compareTimeValues(p,tr.upper()) < 0
126template<
class TimeType>
127bool Rythmos::isInRange_oo(
const TimeRange<TimeType> &tr,
const TimeType &p)
130 compareTimeValues(p,tr.lower()) > 0
131 && compareTimeValues(p,tr.upper()) < 0
136#define RYTHMOS_TIME_RANGE_INSTANT(SCALAR) \
138 template class TimeRange< SCALAR >; \
140 template int compareTimeValues( const SCALAR &t1, const SCALAR &t2 ); \
141 template TimeRange< SCALAR > timeRange(const SCALAR lower, const SCALAR upper); \
142 template TimeRange< SCALAR > invalidTimeRange(); \
143 template std::ostream& operator<<( std::ostream& out, const TimeRange< SCALAR >& range ); \
144 template void asssertInTimeRange( const TimeRange<SCALAR > &timeRange, const SCALAR &time ); \
145 template bool isInRange_cc(const TimeRange< SCALAR > &tr, const SCALAR &p); \
146 template bool isInRange_oc(const TimeRange< SCALAR > &tr, const SCALAR &p); \
147 template bool isInRange_co(const TimeRange< SCALAR > &tr, const SCALAR &p); \
148 template bool isInRange_oo(const TimeRange< SCALAR > &tr, const SCALAR &p); \
149 template class TimeRange_cc< SCALAR >; \
150 template class TimeRange_co< SCALAR >; \
151 template class TimeRange_oo< SCALAR >; \
152 template class TimeRange_oc< SCALAR >;