|
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_DECL_H 00030 #define RYTHMOS_TIME_RANGE_DECL_H 00031 00032 #include "Rythmos_ConfigDefs.h" 00033 00034 namespace Rythmos { 00035 00036 00061 template<class TimeType> 00062 int compareTimeValues( const TimeType &t1, const TimeType &t2 ); 00063 00071 template<class TimeType> 00072 class TimeRange 00073 { 00074 public: 00076 TimeRange() 00077 : lower_(0.0), upper_(-1.0) 00078 {} 00080 TimeRange( const TimeType &my_lower, const TimeType &my_upper ) 00081 : lower_(my_lower), upper_(my_upper) 00082 { 00083 } 00085 TimeRange( const TimeRange<TimeType>& tr ) 00086 : lower_(tr.lower()), upper_(tr.upper()) 00087 { 00088 } 00090 virtual ~TimeRange() {} 00092 bool isValid() const { return (lower_ <= upper_); } 00094 TimeType lower() const { return lower_; } 00096 TimeType upper() const { return upper_; } 00098 TimeType length() const { return (upper_ - lower_); } 00100 virtual bool isInRange ( const TimeType &t ) const 00101 { 00102 return ( 00103 compareTimeValues(t,lower_) >= 0 00104 && compareTimeValues(t,upper_) <= 0 00105 ); 00106 } 00108 TimeRange<TimeType> copyAndScale( const TimeType &scale ) const 00109 { 00110 TimeRange<TimeType> newRange = *this; 00111 if (!newRange.isValid()) 00112 return newRange; 00113 newRange.lower_ *= scale; 00114 newRange.upper_ *= scale; 00115 return newRange; 00116 } 00117 00118 private: 00119 TimeType lower_; 00120 TimeType upper_; 00121 }; 00122 00127 template<class TimeType> 00128 TimeRange<TimeType> timeRange(const TimeType my_lower, const TimeType my_upper); 00129 00130 00135 template<class TimeType> 00136 TimeRange<TimeType> invalidTimeRange(); 00137 00138 00143 template<class TimeType> 00144 std::ostream& operator<<( std::ostream& out, const TimeRange<TimeType>& range ); 00145 00146 00150 template<class TimeType> 00151 void asssertInTimeRange( const TimeRange<TimeType> &timeRange, 00152 const TimeType &time ); 00153 00154 00161 template<class TimeType> 00162 bool isInRange_cc(const TimeRange<TimeType> &tr, const TimeType &p); 00163 00164 00171 template<class TimeType> 00172 bool isInRange_oc(const TimeRange<TimeType> &tr, const TimeType &p); 00173 00174 00181 template<class TimeType> 00182 bool isInRange_co(const TimeRange<TimeType> &tr, const TimeType &p); 00183 00184 00191 template<class TimeType> 00192 bool isInRange_oo(const TimeRange<TimeType> &tr, const TimeType &p); 00193 00194 template<class TimeType> 00195 class TimeRange_cc : virtual public TimeRange<TimeType> 00196 { 00197 public: 00198 TimeRange_cc(const TimeRange<TimeType>& tr) 00199 :TimeRange<TimeType>(tr) 00200 { 00201 } 00202 TimeRange_cc( const TimeType &my_lower, const TimeType &my_upper ) 00203 :TimeRange<TimeType>(my_lower,my_upper) 00204 { 00205 } 00206 bool isInRange ( const TimeType &t ) const 00207 { 00208 return ( isInRange_cc<TimeType>(*this,t) ); 00209 } 00210 }; 00211 00212 template<class TimeType> 00213 class TimeRange_co : virtual public TimeRange<TimeType> 00214 { 00215 public: 00216 TimeRange_co(const TimeRange<TimeType>& tr) 00217 :TimeRange<TimeType>(tr) 00218 { 00219 } 00220 TimeRange_co( const TimeType &my_lower, const TimeType &my_upper ) 00221 :TimeRange<TimeType>(my_lower,my_upper) 00222 { 00223 } 00224 bool isInRange ( const TimeType &t ) const 00225 { 00226 return ( isInRange_co<TimeType>(*this,t) ); 00227 } 00228 }; 00229 00230 template<class TimeType> 00231 class TimeRange_oo : virtual public TimeRange<TimeType> 00232 { 00233 public: 00234 TimeRange_oo(const TimeRange<TimeType>& tr) 00235 :TimeRange<TimeType>(tr) 00236 { 00237 } 00238 TimeRange_oo( const TimeType &my_lower, const TimeType &my_upper ) 00239 :TimeRange<TimeType>(my_lower,my_upper) 00240 { 00241 } 00242 bool isInRange ( const TimeType &t ) const 00243 { 00244 return ( isInRange_oo<TimeType>(*this,t) ); 00245 } 00246 }; 00247 00248 template<class TimeType> 00249 class TimeRange_oc : virtual public TimeRange<TimeType> 00250 { 00251 public: 00252 TimeRange_oc(const TimeRange<TimeType>& tr) 00253 :TimeRange<TimeType>(tr) 00254 { 00255 } 00256 TimeRange_oc( const TimeType &my_lower, const TimeType &my_upper ) 00257 :TimeRange<TimeType>(my_lower,my_upper) 00258 { 00259 } 00260 bool isInRange ( const TimeType &t ) const 00261 { 00262 return ( isInRange_oc<TimeType>(*this,t) ); 00263 } 00264 }; 00265 00266 00267 } // namespace Rythmos 00268 00269 00270 #endif //RYTHMOS_TIME_RANGE_DECL_H
1.7.6.1