9 #ifndef Tempus_TimeEventList_impl_hpp
10 #define Tempus_TimeEventList_impl_hpp
15 template<
class Scalar>
18 this->setName(
"TimeEventList");
21 setLandOnExactly(
true);
25 template<
class Scalar>
27 std::string name, std::vector<Scalar> timeList,
28 Scalar relTol,
bool landOnExactly)
33 setLandOnExactly(landOnExactly);
34 setTimeList(timeList);
38 template<
class Scalar>
41 if (timeList_.size() == 0) {
42 timeScale_ = std::abs(this->getDefaultTime());
43 absTol_ = relTol_*timeScale_;
47 timeScale_ = std::max(std::abs(timeList_.front()),
48 std::abs(timeList_.back()));
49 absTol_ = relTol_*timeScale_;
52 if ((-absTol_ <= timeScale_ ) && (timeScale_ <= absTol_)) {
54 absTol_ = relTol_*timeScale_;
59 template<
class Scalar>
62 for(
auto it = std::begin(timeList); it != std::end(timeList); ++it)
67 template<
class Scalar>
70 if (timeList_.size() == 0) {
71 timeList_.push_back(time);
76 auto it = std::upper_bound(timeList_.begin(), timeList_.end(), time);
77 if (timeList_.size() == 1) {
79 if (std::abs(timeList_.front()-time) >= absTol_)
80 timeList_.insert(it, time);
86 if (it == timeList_.begin()) {
87 if (std::abs(timeList_.front()-time) >= absTol_)
88 timeList_.insert(it, time);
89 }
else if (it == timeList_.end()) {
90 if (std::abs(timeList_.back()-time) >= absTol_)
91 timeList_.insert(it, time);
92 }
else if (std::abs(*(it-1) - time) >= absTol_ &&
93 std::abs(*(it ) - time) >= absTol_) {
94 timeList_.insert(it, time);
100 template<
class Scalar>
103 relTol_ = std::abs(relTol);
108 template<
class Scalar>
111 return (std::abs(timeToNextEvent(time)) <= absTol_);
115 template<
class Scalar>
118 return timeOfNextEvent(time) - time;
122 template<
class Scalar>
125 if (timeList_.size() == 0)
return this->getDefaultTime();
128 if (timeList_.front() >= time-absTol_)
return timeList_.front();
131 if (timeList_.back() <= time+absTol_)
return timeList_.back();
133 typename std::vector<Scalar>::const_iterator it =
134 std::upper_bound(timeList_.begin(), timeList_.end(), time);
137 const Scalar timeOfLeftEvent = *(it-1);
138 if (timeOfLeftEvent > time-absTol_ &&
139 timeOfLeftEvent < time+absTol_)
return timeOfLeftEvent;
146 template<
class Scalar>
148 Scalar time1, Scalar time2)
const
156 if (timeList_.size() == 0)
return false;
159 if (time2+absTol_ < timeList_.front() ||
160 timeList_.back() < time1-absTol_)
return false;
162 Scalar timeEvent1 = timeOfNextEvent(time1);
163 Scalar timeEvent2 = timeOfNextEvent(time2);
165 if (timeEvent1 != timeEvent2)
return true;
168 if (time1-absTol_ <= timeEvent1 && timeEvent1 <= time2+absTol_)
return true;
174 template<
class Scalar>
177 Teuchos::RCP<Teuchos::FancyOStream> out =
178 Teuchos::VerboseObjectBase::getDefaultOStream();
179 *out <<
"TimeEventList:" <<
"\n"
180 <<
"name = " << this->getName() <<
"\n"
181 <<
"timeScale_ = " << timeScale_ <<
"\n"
182 <<
"relTol_ = " << relTol_ <<
"\n"
183 <<
"absTol_ = " << absTol_ <<
"\n"
184 <<
"landOnExactly_ = " << landOnExactly_ <<
"\n"
185 <<
"timeList_ = " << std::endl;
186 for (
auto it = timeList_.begin(); it != timeList_.end()-1; ++it)
188 *out << *(timeList_.end()-1) <<
"\n";
193 #endif // Tempus_TimeEventList_impl_hpp
virtual void setTimeList(std::vector< Scalar > timeList)
virtual bool isTime(Scalar time) const
Test if time is near a TimeEvent (within tolerance).
virtual void addTime(Scalar time)
virtual Scalar timeOfNextEvent(Scalar time) const
Time of the next event. Negative indicating the last event is in the past.
virtual bool eventInRange(Scalar time1, Scalar time2) const
Test if an event occurs within the time range.
virtual void setTimeScale()
virtual void describe() const
Describe member data.
virtual void setRelTol(Scalar relTol)
TimeEventList()
Default constructor.
virtual Scalar timeToNextEvent(Scalar time) const
How much time until the next event. Negative indicating the last event is in the past.