9 #ifndef Tempus_TimeEventComposite_decl_hpp
10 #define Tempus_TimeEventComposite_decl_hpp
13 #include "Teuchos_Time.hpp"
27 template<
class Scalar>
35 this->
setName(
"TimeEventComposite");
44 virtual bool isTime(Scalar time)
const
48 if (e->isTime(time)) {
65 std::vector< std::pair<Scalar, Scalar> > timeAbs;
67 timeAbs.push_back(std::make_pair(e->timeOfNextEvent(time), e->getAbsTol()));
68 std::sort(timeAbs.begin(), timeAbs.end());
73 if (timeAbs.front().first >= time-timeAbs.front().second)
74 return timeAbs.front().first;
77 if (timeAbs.back().first <= time+timeAbs.front().second)
78 return timeAbs.back().first;
80 typename std::vector< std::pair<Scalar, Scalar> >::const_iterator it =
81 std::upper_bound(timeAbs.begin(), timeAbs.end(), std::make_pair(time, 0.0));
84 const Scalar timeOfLeftEvent = (*(it-1)).first;
85 const Scalar absTolOfLeftEvent = (*(it-1)).second;
86 if (timeOfLeftEvent > time - absTolOfLeftEvent &&
87 timeOfLeftEvent < time + absTolOfLeftEvent)
88 return timeOfLeftEvent;
99 if (e->eventInRange(time1, time2)) {
110 bool is_index =
false;
112 if (e->isIndex(index)) {
129 std::vector<int> indexList;
131 indexList.push_back(e->indexOfNextEvent(index));
133 std::sort(indexList.begin(), indexList.end());
134 indexList.erase(std::unique(
135 indexList.begin(), indexList.end()), indexList.end());
140 if (indexList.front() >= index)
return indexList.front();
143 if (indexList.back() <= index)
return indexList.back();
145 std::vector<int>::const_iterator it =
146 std::upper_bound(indexList.begin(), indexList.end(), index);
149 const Scalar indexOfLeftEvent = *(it-1);
150 if (indexOfLeftEvent == index)
return indexOfLeftEvent;
160 bool inRange =
false;
162 if (e->eventInRangeIndex(index1, index2)) {
188 Teuchos::RCP<Teuchos::FancyOStream> out =
189 Teuchos::VerboseObjectBase::getDefaultOStream();
190 *out <<
"TimeEventComposite:" <<
"\n"
191 <<
"name = " << this->
getName() <<
"\n"
192 <<
"Number of TimeEvents = " <<
timeEvents_.size() << std::endl;
193 *out <<
"--------------------------------------------" << std::endl;
196 *out <<
"--------------------------------------------" << std::endl;
210 #endif // Tempus_TimeEventComposite_decl_hpp
virtual Scalar getDefaultTime() const
virtual bool isIndex(int index) const
Test if index is a time event.TimeEventBase.
TimeEventComposite()
Constructor.
virtual void setName(std::string name)
virtual bool isTime(Scalar time) const
Test if time is near a TimeEvent (within tolerance).
std::vector< Teuchos::RCP< TimeEventBase< Scalar > > > timeEvents_
virtual int getDefaultIndex() const
virtual bool eventInRange(Scalar time1, Scalar time2) const
Test if an event occurs within the time range.
virtual void describe() const
Describe member data.
virtual Scalar timeToNextEvent(Scalar time) const
How much time until the next event. Negative indicating the last event is in the past.
This composite TimeEvent loops over added TimeEvents.
std::size_t getSize() const
virtual bool eventInRangeIndex(int index1, int index2) const
Test if an event occurs within the time range.
virtual int indexToNextEvent(int index) const
How many indices until the next event. Negative indicating the last event is in the past...
virtual int indexOfNextEvent(int index) const
Index of the next event. Negative indicating the last event is in the past.
This class defines time events which can be used to "trigger" an action. Time events are points in ti...
virtual std::string getName() const
virtual Scalar timeOfNextEvent(Scalar time) const
Time of the next event. Negative indicating the last event is in the past.
virtual ~TimeEventComposite()
Destructor.
void addTimeEvent(Teuchos::RCP< TimeEventBase< Scalar > > timeEvent)