9 #ifndef Tempus_TimeEventComposite_decl_hpp
10 #define Tempus_TimeEventComposite_decl_hpp
16 #include "Tempus_config.hpp"
28 template<
class Scalar>
36 this->
setName(
"TimeEventComposite");
44 virtual bool isTime(Scalar time)
const
49 if (e->isTime(time)) {
66 std::vector< std::pair<Scalar, Scalar> > timeAbs;
67 for(
auto& e : timeEvents_)
68 timeAbs.push_back(std::make_pair(e->timeOfNextEvent(time), e->getAbsTol()));
69 std::sort(timeAbs.begin(), timeAbs.end());
74 if (timeAbs.front().first >= time-timeAbs.front().second)
75 return timeAbs.front().first;
78 if (timeAbs.back().first <= time+timeAbs.front().second)
79 return timeAbs.back().first;
81 typename std::vector< std::pair<Scalar, Scalar> >::const_iterator it =
82 std::upper_bound(timeAbs.begin(), timeAbs.end(), std::make_pair(time, 0.0));
85 const Scalar timeOfLeftEvent = (*(it-1)).first;
86 const Scalar absTolOfLeftEvent = (*(it-1)).second;
87 if (timeOfLeftEvent > time - absTolOfLeftEvent &&
88 timeOfLeftEvent < time + absTolOfLeftEvent)
89 return timeOfLeftEvent;
99 for(
auto& e : timeEvents_) {
100 if (e->eventInRange(time1, time2)) {
111 bool is_index =
false;
112 for(
auto& e : timeEvents_) {
113 if (e->isIndex(index)) {
130 std::vector<int> indexList;
131 for(
auto& e : timeEvents_)
132 indexList.push_back(e->indexOfNextEvent(index));
134 std::sort(indexList.begin(), indexList.end());
135 indexList.erase(std::unique(
136 indexList.begin(), indexList.end()), indexList.end());
141 if (indexList.front() >= index)
return indexList.front();
144 if (indexList.back() <= index)
return indexList.back();
146 std::vector<int>::const_iterator it =
147 std::upper_bound(indexList.begin(), indexList.end(), index);
150 const Scalar indexOfLeftEvent = *(it-1);
151 if (indexOfLeftEvent == index)
return indexOfLeftEvent;
161 bool inRange =
false;
162 for(
auto& e : timeEvents_) {
163 if (e->eventInRangeIndex(index1, index2)) {
176 timeEvents_.push_back(timeEvent);
181 { timeEvents_.clear(); }
184 std::size_t
getSize()
const {
return timeEvents_.size(); }
191 *out <<
"TimeEventComposite:" <<
"\n"
192 <<
"name = " << this->
getName() <<
"\n"
193 <<
"Number of TimeEvents = " << timeEvents_.size() << std::endl;
194 *out <<
"--------------------------------------------" << std::endl;
195 for(
auto& e : timeEvents_) {
197 *out <<
"--------------------------------------------" << std::endl;
211 #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.
static RCP< FancyOStream > getDefaultOStream()
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)