9#ifndef Tempus_TimeEventRangeIndex_impl_hpp
10#define Tempus_TimeEventRangeIndex_impl_hpp
17 : start_(0), stop_(0), stride_(1), numEvents_(1)
20 std::ostringstream oss;
29 int start,
int stop,
int stride, std::string name)
30 : start_(0), stop_(0), stride_(1), numEvents_(1)
34 std::ostringstream oss;
35 oss <<
"TimeEventRangeIndex (" << start <<
"; " << stop <<
"; " << stride <<
")";
74 }
else if (stride_ > (stop_ - start_)) {
75 stride_ = stop_ - start_;
84 if (stride_ == 0 || start_ == stop_)
87 numEvents_ = int((stop_ - start_) / stride_) + 1;
94 const int indexOfLast = start_ + (numEvents_-1) * stride_;
95 if (index < start_ || index > indexOfLast)
return false;
96 if ((index - start_) % stride_ == 0)
return true;
102template<
class Scalar>
105 return indexOfNextEvent(index) - index;
109template<
class Scalar>
113 if (index < start_)
return start_;
115 const int indexOfLast = start_ + (numEvents_-1) * stride_;
117 if (index >= indexOfLast)
return this->getDefaultIndex();
120 if (isIndex(index))
return index+stride_;
122 const int numStrides = (index - start_) / stride_ + 1;
123 const Scalar indexOfNext = start_ + numStrides * stride_;
128template<
class Scalar>
131 if (index1 > index2) {
138 const Scalar indexOfLast = start_ + (numEvents_-1) * stride_;
139 if (index2 < start_ || indexOfLast < index1)
return false;
141 const int strideJustBeforeIndex1 = std::min(
int(numEvents_-1),
142 std::max(
int(0),
int((index1 - start_) / stride_)));
144 const int strideJustAfterIndex2 = std::max(
int(0), std::min(
int(numEvents_-1),
145 int((index2 - start_) / stride_)));
147 for (
int i = strideJustBeforeIndex1; i <= strideJustAfterIndex2; i++ ) {
148 const int indexEvent = start_ + i * stride_;
149 if (index1 < indexEvent && indexEvent <= index2)
return true;
156template<
class Scalar>
158 const Teuchos::EVerbosityLevel verbLevel)
const
160 auto l_out = Teuchos::fancyOStream( out.getOStream() );
161 Teuchos::OSTab ostab(*l_out, 2,
"TimeEventRangeIndex");
162 l_out->setOutputToRootOnly(0);
164 *l_out <<
"TimeEventRangeIndex:" <<
"\n"
165 <<
" name = " << this->getName() <<
"\n"
166 <<
" Type = " << this->getType() <<
"\n"
167 <<
" start_ = " << start_ <<
"\n"
168 <<
" stop_ = " << stop_ <<
"\n"
169 <<
" stride_ = " << stride_ <<
"\n"
170 <<
" numEvents_ = " << numEvents_ << std::endl;
174template<
class Scalar>
175Teuchos::RCP<const Teuchos::ParameterList>
178 Teuchos::RCP<Teuchos::ParameterList> pl =
179 Teuchos::parameterList(
"Time Event Range Index");
181 pl->setName(this->getName());
182 pl->set(
"Name", this->getName());
183 pl->set(
"Type",
"Range Index");
185 pl->set(
"Start Index", getIndexStart(),
"Start of Index range");
186 pl->set(
"Stop Index", getIndexStop(),
"Stop of Index range");
187 pl->set(
"Stride Index", getIndexStride(),
"Stride of Index range");
196template<
class Scalar>
198 Teuchos::RCP<Teuchos::ParameterList> pl)
200 auto teri = Teuchos::rcp(
new TimeEventRangeIndex<Scalar>());
201 if (pl == Teuchos::null)
return teri;
203 TEUCHOS_TEST_FOR_EXCEPTION(
204 pl->get<std::string>(
"Type",
"Range Index") !=
"Range Index",
206 "Error - Time Event Type != 'Range Index'. (='"
207 + pl->get<std::string>(
"Type")+
"')\n");
209 pl->validateParametersAndSetDefaults(*teri->getValidParameters());
211 teri->setName (pl->get(
"Name",
"From createTimeEventRangeIndex"));
212 teri->setIndexStart (pl->get(
"Start Index", teri->getIndexStart()));
213 teri->setIndexStop (pl->get(
"Stop Index", teri->getIndexStop()));
214 teri->setIndexStride (pl->get(
"Stride Index", teri->getIndexStride()));
virtual void setType(std::string s)
virtual void setName(std::string name)
Set the name of the TimeEvent.
virtual bool isIndex(int index) const
Test if index is a time event.
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
Describe member data.
int stop_
Stop of index range.
virtual void setIndexStop(int stop)
Set the stop of the index range.
virtual int indexOfNextEvent(int index) const
Return the index of the next event following the input index.
TimeEventRangeIndex()
Default constructor.
int stride_
Stride of index range.
virtual void setIndexRange(int start, int stop, int stride)
Set the range of event indices.
virtual bool eventInRangeIndex(int index1, int index2) const
Test if an event occurs within the index range.
virtual void setIndexStart(int start)
Set the start of the index range.
virtual void setNumEvents()
Set the number of events from start_, stop_ and stride_.
virtual int indexToNextEvent(int index) const
How many indices until the next event.
int start_
Start of index range.
virtual void setIndexStride(int stride)
Set the stride of the index range.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Return a valid ParameterList with current settings.
Teuchos::RCP< TimeEventRangeIndex< Scalar > > createTimeEventRangeIndex(Teuchos::RCP< Teuchos::ParameterList > pList)
Nonmember Constructor via ParameterList.