00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef RYTHMOS_TIME_RANGE_DEF_H
00030 #define RYTHMOS_TIME_RANGE_DEF_H
00031
00032 #include "Rythmos_TimeRange_decl.hpp"
00033 #include "Teuchos_Assert.hpp"
00034 #include "Teuchos_ScalarTraits.hpp"
00035
00036
00037 template<class TimeType>
00038 int Rythmos::compareTimeValues( const TimeType &t1, const TimeType &t2 )
00039 {
00040
00041 const TimeType epsMore = 10.0*std::numeric_limits<TimeType>::epsilon();
00042 const TimeType t1Mag = Teuchos::ScalarTraits<TimeType>::magnitude(t1);
00043 const TimeType t1Tol = t1Mag*epsMore;
00044 if ( t2 - t1Tol <= t1 && t1 <= t2 + t1Tol )
00045 return 0;
00046 else if ( t1 > t2 + t1Tol )
00047 return +1;
00048
00049 return -1;
00050 }
00051
00052
00053 template<class TimeType>
00054 Rythmos::TimeRange<TimeType>
00055 Rythmos::timeRange(const TimeType lower, const TimeType upper)
00056 {
00057 return TimeRange<TimeType>(lower,upper);
00058 }
00059
00060
00061 template<class TimeType>
00062 Rythmos::TimeRange<TimeType>
00063 Rythmos::invalidTimeRange()
00064 {
00065 return TimeRange<TimeType>();
00066 }
00067
00068
00069 template<class TimeType>
00070 std::ostream&
00071 Rythmos::operator<<( std::ostream& out, const TimeRange<TimeType>& range )
00072 {
00073 out << "[";
00074 if (range.isValid()) {
00075 out << range.lower() << "," << range.upper();
00076 }
00077 else {
00078 out <<"INVALID";
00079 }
00080 out << "]";
00081 return out;
00082 }
00083
00084
00085 template<class TimeType>
00086 void Rythmos::asssertInTimeRange( const TimeRange<TimeType> &timeRange,
00087 const TimeType &time )
00088 {
00089 TEST_FOR_EXCEPTION( !timeRange.isInRange(time), std::out_of_range,
00090 "Error, the time = " << time
00091 << " is out of the range = " << timeRange << "!"
00092 );
00093 }
00094
00095
00096 template<class TimeType>
00097 bool Rythmos::isInRange_cc(const TimeRange<TimeType> &tr, const TimeType &p)
00098 {
00099 return (
00100 compareTimeValues(p,tr.lower()) >= 0
00101 && compareTimeValues(p,tr.upper()) <= 0
00102 );
00103 }
00104
00105
00106 template<class TimeType>
00107 bool Rythmos::isInRange_oc(const TimeRange<TimeType> &tr, const TimeType &p)
00108 {
00109 return (
00110 compareTimeValues(p,tr.lower()) > 0
00111 && compareTimeValues(p,tr.upper()) <= 0
00112 );
00113 }
00114
00115
00116 template<class TimeType>
00117 bool Rythmos::isInRange_co(const TimeRange<TimeType> &tr, const TimeType &p)
00118 {
00119 return (
00120 compareTimeValues(p,tr.lower()) >= 0
00121 && compareTimeValues(p,tr.upper()) < 0
00122 );
00123 }
00124
00125
00126 template<class TimeType>
00127 bool Rythmos::isInRange_oo(const TimeRange<TimeType> &tr, const TimeType &p)
00128 {
00129 return (
00130 compareTimeValues(p,tr.lower()) > 0
00131 && compareTimeValues(p,tr.upper()) < 0
00132 );
00133 }
00134
00135
00136 #define RYTHMOS_TIME_RANGE_INSTANT(SCALAR) \
00137 \
00138 template class TimeRange< SCALAR >; \
00139 \
00140 template int compareTimeValues( const SCALAR &t1, const SCALAR &t2 ); \
00141 template TimeRange< SCALAR > timeRange(const SCALAR lower, const SCALAR upper); \
00142 template TimeRange< SCALAR > invalidTimeRange(); \
00143 template std::ostream& operator<<( std::ostream& out, const TimeRange< SCALAR >& range ); \
00144 template void asssertInTimeRange( const TimeRange<SCALAR > &timeRange, const SCALAR &time ); \
00145 template bool isInRange_cc(const TimeRange< SCALAR > &tr, const SCALAR &p); \
00146 template bool isInRange_oc(const TimeRange< SCALAR > &tr, const SCALAR &p); \
00147 template bool isInRange_co(const TimeRange< SCALAR > &tr, const SCALAR &p); \
00148 template bool isInRange_oo(const TimeRange< SCALAR > &tr, const SCALAR &p); \
00149 template class TimeRange_cc< SCALAR >; \
00150 template class TimeRange_co< SCALAR >; \
00151 template class TimeRange_oo< SCALAR >; \
00152 template class TimeRange_oc< SCALAR >;
00153
00154
00155 #endif //RYTHMOS_TIME_RANGE_DEF_H