9 #ifndef Tempus_TimeEventRange_impl_hpp
10 #define Tempus_TimeEventRange_impl_hpp
15 template<
class Scalar>
17 : start_(this->getDefaultTime()),
18 stop_ (this->getDefaultTime()),
26 this->
setName(
"TimeEventRange");
31 template<
class Scalar>
33 std::string name, Scalar start, Scalar stop, Scalar stride,
34 Scalar relTol,
bool landOnExactly)
38 numEvents_(std::abs(stop-start)/stride+1),
41 absTol_(relTol*start),
42 landOnExactly_(landOnExactly)
49 template<
class Scalar>
51 std::string name, Scalar start, Scalar stop,
int numEvents,
52 Scalar relTol,
bool landOnExactly)
55 stride_(std::abs(stop-start)/(numEvents-1)),
56 numEvents_(numEvents),
59 absTol_(relTol*start),
60 landOnExactly_(landOnExactly)
69 template<
class Scalar>
73 if (stop_ < start_) stop_ = start_;
74 setTimeStride(stride_);
79 template<
class Scalar>
83 if (start_ > stop_) start_ = stop_;
84 setTimeStride(stride_);
89 template<
class Scalar>
92 timeScale_ = std::max(std::abs(start_), std::abs(stop_));
93 absTol_ = relTol_*timeScale_;
96 if ((-absTol_ <= timeScale_ ) && (timeScale_ <= absTol_)) {
98 absTol_ = relTol_*timeScale_;
103 template<
class Scalar>
107 if ((start_ >= stop_-absTol_) && (start_ <= stop_+absTol_)) {
113 if ((stride_ > stop_ - start_) || (stride_ < 2*absTol_)) {
114 stride_ = stop_ - start_;
117 numEvents_ = int((stop_+absTol_ - start_) / stride_) + 1;
121 template<
class Scalar>
124 numEvents_ = numEvents;
125 if (numEvents_ < 1) numEvents_ = 1;
126 stride_ = (stop_ - start_)/Scalar(numEvents_-1);
128 if (stride_ < 2 * absTol_) {
129 setTimeStride(2*absTol_);
134 template<
class Scalar>
137 relTol_ = std::abs(relTol);
138 absTol_ = relTol_*timeScale_;
142 template<
class Scalar>
145 return (std::abs(timeToNextEvent(time)) <= absTol_);
149 template<
class Scalar>
152 return timeOfNextEvent(time) - time;
156 template<
class Scalar>
160 if (start_ >= time-absTol_)
return start_;
162 const Scalar timeOfLast = start_ + (numEvents_-1) * stride_;
164 if (timeOfLast <= time+absTol_)
return timeOfLast;
166 const int numStrides = (time - start_) / stride_;
167 const Scalar timeOfNext = start_ + numStrides * stride_;
170 if (timeOfNext > time-absTol_ &&
171 timeOfNext < time+absTol_)
return timeOfNext;
174 return timeOfNext + stride_;
178 template<
class Scalar>
187 const Scalar timeOfLast = start_ + (numEvents_-1) * stride_;
189 if (time2+absTol_ < start_ || timeOfLast < time1-absTol_)
return false;
191 Scalar timeEvent1 = timeOfNextEvent(time1);
192 Scalar timeEvent2 = timeOfNextEvent(time2);
194 if (timeEvent1 != timeEvent2)
return true;
197 if (time1-absTol_ <= timeEvent1 && timeEvent1 <= time2+absTol_)
return true;
203 template<
class Scalar>
206 Teuchos::RCP<Teuchos::FancyOStream> out =
207 Teuchos::VerboseObjectBase::getDefaultOStream();
208 *out <<
"TimeEventRange:" <<
"\n"
209 <<
"name = " << this->getName() <<
"\n"
210 <<
"start_ = " << start_ <<
"\n"
211 <<
"stop_ = " << stop_ <<
"\n"
212 <<
"stride_ = " << stride_ <<
"\n"
213 <<
"numEvents_ = " << numEvents_ <<
"\n"
214 <<
"timeScale_ = " << timeScale_ <<
"\n"
215 <<
"relTol_ = " << relTol_ <<
"\n"
216 <<
"absTol_ = " << absTol_ <<
"\n"
217 <<
"landOnExactly_ = " << landOnExactly_ << std::endl;
222 #endif // Tempus_TimeEventRange_impl_hpp
virtual void describe() const
Describe member data.
virtual void setRelTol(Scalar relTol)
Scalar stride_
Stride of time range.
virtual void setNumEvents(int numEvents)
virtual void setName(std::string name)
virtual void setLandOnExactly(bool LOE)
Scalar start_
Start of time range.
virtual bool eventInRange(Scalar time1, Scalar time2) const
Test if an event occurs within the time range.
virtual Scalar timeToNextEvent(Scalar time) const
How much time until the next event. Negative indicating the last event is in the past.
virtual void setTimeStop(Scalar stop)
virtual void setTimeScale()
virtual void setTimeRange(Scalar start, Scalar stop, Scalar stride)
virtual void setTimeStart(Scalar start)
Scalar stop_
Stop of time range.
virtual void setTimeStride(Scalar stride)
virtual bool isTime(Scalar time) const
Test if time is near a TimeEvent (within tolerance).
TimeEventRange()
Default constructor.
virtual Scalar timeOfNextEvent(Scalar time) const
Time of the next event. Negative indicating the last event is in the past.