9 #ifndef Tempus_TimeEventListIndex_impl_hpp
10 #define Tempus_TimeEventListIndex_impl_hpp
15 template<
class Scalar>
18 this->setName(
"TimeEventListIndex");
22 template<
class Scalar>
24 std::string name, std::vector<int> indexList)
27 this->setIndexList(indexList);
31 template<
class Scalar>
34 indexList_ = indexList;
36 std::sort(indexList_.begin(), indexList_.end());
37 indexList_.erase(std::unique(
38 indexList_.begin(), indexList_.end()), indexList_.end());
43 template<
class Scalar>
46 if (indexList_.size() == 0) {
47 indexList_.push_back(index);
51 std::vector<int>::iterator it;
52 it = std::find(indexList_.begin(), indexList_.end(), index);
54 if (it != indexList_.end())
return;
56 it = std::upper_bound(indexList_.begin(), indexList_.end(), index);
57 indexList_.insert(it, index);
61 template<
class Scalar>
64 return (indexToNextEvent(index) == 0);
68 template<
class Scalar>
71 return indexOfNextEvent(index) - index;
75 template<
class Scalar>
78 if (indexList_.size() == 0)
return this->getDefaultIndex();
81 if (indexList_.front() >= index)
return indexList_.front();
84 if (indexList_.back() <= index)
return indexList_.back();
86 std::vector<int>::const_iterator it =
87 std::upper_bound(indexList_.begin(), indexList_.end(), index);
90 const Scalar indexOfLeftEvent = *(it-1);
91 if (indexOfLeftEvent == index)
return indexOfLeftEvent;
98 template<
class Scalar>
101 if (index1 > index2) {
107 if (indexList_.size() == 0)
return false;
110 if (index2 < indexList_.front() || indexList_.back() < index1)
return false;
112 Scalar indexEvent1 = indexOfNextEvent(index1);
113 Scalar indexEvent2 = indexOfNextEvent(index2);
115 if (indexEvent1 != indexEvent2)
return true;
118 if (index1 <= indexEvent1 && indexEvent1 <= index2)
return true;
124 template<
class Scalar>
127 Teuchos::RCP<Teuchos::FancyOStream> out =
128 Teuchos::VerboseObjectBase::getDefaultOStream();
129 *out <<
"TimeEventListIndex:" <<
"\n"
130 <<
"name = " << this->getName() <<
"\n"
131 <<
"IndexList_ = " << std::endl;
132 for (
auto it = indexList_.begin(); it != indexList_.end()-1; ++it)
134 *out << *(indexList_.end()-1) <<
"\n";
139 #endif // Tempus_TimeEventListIndex_impl_hpp
TimeEventListIndex()
Default constructor.
virtual int indexToNextEvent(int index) const
How many indices until the next event. Negative indicating the last event is in the past...
virtual bool isIndex(int index) const
Test if index is near a index event (within tolerance).
virtual int indexOfNextEvent(int index) const
Index of the next event. Negative indicating the last event is in the past.
virtual void addIndex(int index)
virtual void describe() const
Describe member data.
virtual bool eventInRangeIndex(int index1, int index2) const
Test if an event occurs within the index range.
virtual void setIndexList(std::vector< int > indexList, bool sort=true)