|
Rythmos - Transient Integration for Differential Equations
Version of the Day
|
00001 //@HEADER 00002 // *********************************************************************** 00003 // 00004 // Rythmos Package 00005 // Copyright (2006) Sandia Corporation 00006 // 00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00008 // license for use of this work by or on behalf of the U.S. Government. 00009 // 00010 // This library is free software; you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as 00012 // published by the Free Software Foundation; either version 2.1 of the 00013 // License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, but 00016 // WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 00023 // USA 00024 // Questions? Contact Todd S. Coffey (tscoffe@sandia.gov) 00025 // 00026 // *********************************************************************** 00027 //@HEADER 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 // Here we will do the comparison based on the magnitude of t1 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 // t1 < t2 - t1Tol 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 TEUCHOS_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
1.7.6.1