9 #ifndef Tempus_TimeEventRangeIndex_impl_hpp
10 #define Tempus_TimeEventRangeIndex_impl_hpp
15 template<
class Scalar>
17 : start_(0), stop_(0), stride_(1), numEvents_(1)
20 std::ostringstream oss;
27 template<
class Scalar>
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 <<
")";
45 template<
class Scalar>
56 template<
class Scalar>
68 template<
class Scalar>
74 }
else if (stride_ > (stop_ - start_)) {
75 stride_ = stop_ - start_;
81 template<
class Scalar>
84 if (stride_ == 0 || start_ == stop_)
87 numEvents_ = int((stop_ - start_) / stride_) + 1;
91 template<
class Scalar>
94 const int indexOfLast = start_ + (numEvents_-1) * stride_;
95 if (index < start_ || index > indexOfLast)
return false;
96 if ((index - start_) % stride_ == 0)
return true;
102 template<
class Scalar>
105 return indexOfNextEvent(index) - index;
109 template<
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_;
128 template<
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;
156 template<
class Scalar>
160 auto l_out = Teuchos::fancyOStream( out.
getOStream() );
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;
174 template<
class Scalar>
179 Teuchos::parameterList(
"Time Event Range Index");
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");
196 template<
class Scalar>
201 if (pl == Teuchos::null)
return teri;
204 pl->
get<std::string>(
"Type",
"Range Index") !=
"Range Index",
206 "Error - Time Event Type != 'Range Index'. (='"
207 + pl->
get<std::string>(
"Type")+
"')\n");
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()));
221 #endif // Tempus_TimeEventRangeIndex_impl_hpp
virtual void setIndexStart(int start)
Set the start of the index range.
TimeEventRangeIndex specifies a start, stop and stride index.
virtual void setType(std::string s)
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
Describe member data.
virtual void setName(std::string name)
Set the name of the TimeEvent.
T & get(const std::string &name, T def_value)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
int start_
Start of index range.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
int stride_
Stride of index range.
virtual int indexToNextEvent(int index) const
How many indices until the next event.
void validateParametersAndSetDefaults(ParameterList const &validParamList, int const depth=1000)
virtual void setIndexStride(int stride)
Set the stride of the index range.
virtual void setNumEvents()
Set the number of events from start_, stop_ and stride_.
virtual void setIndexStop(int stop)
Set the stop of the index range.
int stop_
Stop of index range.
RCP< std::basic_ostream< char_type, traits_type > > getOStream()
TimeEventRangeIndex()
Default constructor.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Return a valid ParameterList with current settings.
ParameterList & setName(const std::string &name)
virtual bool eventInRangeIndex(int index1, int index2) const
Test if an event occurs within the index range.
virtual int indexOfNextEvent(int index) const
Return the index of the next event following the input index.
virtual bool isIndex(int index) const
Test if index is a time event.
Teuchos::RCP< TimeEventRangeIndex< Scalar > > createTimeEventRangeIndex(Teuchos::RCP< Teuchos::ParameterList > pList)
Nonmember Constructor via ParameterList.
virtual void setIndexRange(int start, int stop, int stride)
Set the range of event indices.