|
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 00059 template<class TimeType> 00060 int compareTimeValues( const TimeType &t1, const TimeType &t2 ); 00061 00069 template<class TimeType> 00070 class TimeRange 00071 { 00072 public: 00074 TimeRange() 00075 : lower_(0.0), upper_(-1.0) 00076 {} 00078 TimeRange( const TimeType &my_lower, const TimeType &my_upper ) 00079 : lower_(my_lower), upper_(my_upper) 00080 { 00081 } 00083 TimeRange( const TimeRange<TimeType>& tr ) 00084 : lower_(tr.lower()), upper_(tr.upper()) 00085 { 00086 } 00088 virtual ~TimeRange() {} 00090 bool isValid() const { return (lower_ <= upper_); } 00092 TimeType lower() const { return lower_; } 00094 TimeType upper() const { return upper_; } 00096 TimeType length() const { return (upper_ - lower_); } 00098 virtual bool isInRange ( const TimeType &t ) const 00099 { 00100 return ( 00101 compareTimeValues(t,lower_) >= 0 00102 && compareTimeValues(t,upper_) <= 0 00103 ); 00104 } 00106 TimeRange<TimeType> copyAndScale( const TimeType &scale ) const 00107 { 00108 TimeRange<TimeType> newRange = *this; 00109 if (!newRange.isValid()) 00110 return newRange; 00111 newRange.lower_ *= scale; 00112 newRange.upper_ *= scale; 00113 return newRange; 00114 } 00115 00116 private: 00117 TimeType lower_; 00118 TimeType upper_; 00119 }; 00120 00125 template<class TimeType> 00126 TimeRange<TimeType> timeRange(const TimeType my_lower, const TimeType my_upper); 00127 00128 00133 template<class TimeType> 00134 TimeRange<TimeType> invalidTimeRange(); 00135 00136 00141 template<class TimeType> 00142 std::ostream& operator<<( std::ostream& out, const TimeRange<TimeType>& range ); 00143 00144 00148 template<class TimeType> 00149 void asssertInTimeRange( const TimeRange<TimeType> &timeRange, 00150 const TimeType &time ); 00151 00152 00159 template<class TimeType> 00160 bool isInRange_cc(const TimeRange<TimeType> &tr, const TimeType &p); 00161 00162 00169 template<class TimeType> 00170 bool isInRange_oc(const TimeRange<TimeType> &tr, const TimeType &p); 00171 00172 00179 template<class TimeType> 00180 bool isInRange_co(const TimeRange<TimeType> &tr, const TimeType &p); 00181 00182 00189 template<class TimeType> 00190 bool isInRange_oo(const TimeRange<TimeType> &tr, const TimeType &p); 00191 00192 template<class TimeType> 00193 class TimeRange_cc : virtual public TimeRange<TimeType> 00194 { 00195 public: 00196 TimeRange_cc(const TimeRange<TimeType>& tr) 00197 :TimeRange<TimeType>(tr) 00198 { 00199 } 00200 TimeRange_cc( const TimeType &my_lower, const TimeType &my_upper ) 00201 :TimeRange<TimeType>(my_lower,my_upper) 00202 { 00203 } 00204 bool isInRange ( const TimeType &t ) const 00205 { 00206 return ( isInRange_cc<TimeType>(*this,t) ); 00207 } 00208 }; 00209 00210 template<class TimeType> 00211 class TimeRange_co : virtual public TimeRange<TimeType> 00212 { 00213 public: 00214 TimeRange_co(const TimeRange<TimeType>& tr) 00215 :TimeRange<TimeType>(tr) 00216 { 00217 } 00218 TimeRange_co( const TimeType &my_lower, const TimeType &my_upper ) 00219 :TimeRange<TimeType>(my_lower,my_upper) 00220 { 00221 } 00222 bool isInRange ( const TimeType &t ) const 00223 { 00224 return ( isInRange_co<TimeType>(*this,t) ); 00225 } 00226 }; 00227 00228 template<class TimeType> 00229 class TimeRange_oo : virtual public TimeRange<TimeType> 00230 { 00231 public: 00232 TimeRange_oo(const TimeRange<TimeType>& tr) 00233 :TimeRange<TimeType>(tr) 00234 { 00235 } 00236 TimeRange_oo( const TimeType &my_lower, const TimeType &my_upper ) 00237 :TimeRange<TimeType>(my_lower,my_upper) 00238 { 00239 } 00240 bool isInRange ( const TimeType &t ) const 00241 { 00242 return ( isInRange_oo<TimeType>(*this,t) ); 00243 } 00244 }; 00245 00246 template<class TimeType> 00247 class TimeRange_oc : virtual public TimeRange<TimeType> 00248 { 00249 public: 00250 TimeRange_oc(const TimeRange<TimeType>& tr) 00251 :TimeRange<TimeType>(tr) 00252 { 00253 } 00254 TimeRange_oc( const TimeType &my_lower, const TimeType &my_upper ) 00255 :TimeRange<TimeType>(my_lower,my_upper) 00256 { 00257 } 00258 bool isInRange ( const TimeType &t ) const 00259 { 00260 return ( isInRange_oc<TimeType>(*this,t) ); 00261 } 00262 }; 00263 00264 00265 } // namespace Rythmos 00266 00267 00268 #endif //RYTHMOS_TIME_RANGE_DECL_H
1.7.4