9#ifndef Tempus_TimeEventRange_impl_hpp
10#define Tempus_TimeEventRange_impl_hpp
31 std::ostringstream oss;
39 Scalar start, Scalar stop, Scalar stride,
40 std::string name,
bool landOnExactly, Scalar relTol)
52 std::ostringstream oss;
53 oss <<
"TimeEventRange (" << start <<
"; " << stop <<
"; " << stride <<
")";
66 Scalar start, Scalar stop,
int numEvents,
67 std::string name,
bool landOnExactly, Scalar relTol)
78 std::ostringstream oss;
79 oss <<
"TimeEventRange (" << start <<
"; " << stop <<
"; " << numEvents <<
")";
92 Scalar start, Scalar stop, Scalar stride)
106template<
class Scalar>
108 Scalar start, Scalar stop,
int numEvents)
122template<
class Scalar>
132template<
class Scalar>
142template<
class Scalar>
156template<
class Scalar>
159 stride_ = Teuchos::ScalarTraits<Scalar>::magnitude(stride);
174template<
class Scalar>
197template<
class Scalar>
205template<
class Scalar>
213 if (time > timeOfLast+
absTol_)
return false;
219 numStrides = std::min(std::max(0, numStrides),
int(
numEvents_-1));
227 const Scalar rightBracket = leftBracket +
stride_;
235template<
class Scalar>
242template<
class Scalar>
250 if (time > timeOfLast-
absTol_)
return std::numeric_limits<Scalar>::max();
265template<
class Scalar>
281 const int strideJustBeforeTime1 = std::min(
int(
numEvents_-1),
284 const int strideJustAfterTime2 = std::max(
int(0), std::min(
int(
numEvents_-1),
287 for (
int i = strideJustBeforeTime1; i <= strideJustAfterTime2; i++ ) {
289 if (time1 < timeEvent-
absTol_ && timeEvent-
absTol_ <= time2)
return true;
296template<
class Scalar>
298 const Teuchos::EVerbosityLevel verbLevel)
const
300 auto l_out = Teuchos::fancyOStream( out.getOStream() );
301 Teuchos::OSTab ostab(*l_out, 2,
"TimeEventRange");
302 l_out->setOutputToRootOnly(0);
304 *l_out <<
"TimeEventRange:" <<
"\n"
305 <<
" name = " << this->
getName() <<
"\n"
306 <<
" Type = " << this->
getType() <<
"\n"
307 <<
" start_ = " <<
start_ <<
"\n"
308 <<
" stop_ = " <<
stop_ <<
"\n"
309 <<
" stride_ = " <<
stride_ <<
"\n"
312 <<
" relTol_ = " <<
relTol_ <<
"\n"
313 <<
" absTol_ = " <<
absTol_ <<
"\n"
318template<
class Scalar>
319Teuchos::RCP<const Teuchos::ParameterList>
322 Teuchos::RCP<Teuchos::ParameterList> pl =
323 Teuchos::parameterList(
"Time Event Range");
326 pl->set(
"Name", this->
getName());
327 pl->set(
"Type", this->
getType());
329 pl->set(
"Start Time",
getTimeStart(),
"Start of time range");
330 pl->set(
"Stop Time",
getTimeStop(),
"Stop of time range");
331 pl->set(
"Stride Time",
getTimeStride(),
"Stride of time range");
335 "Number of events in time range. If specified, 'Stride Time' is reset.");
337 pl->set(
"Relative Tolerance",
getRelTol(),
338 "Relative time tolerance for matching time events.");
341 "Should these time events be landed on exactly, i.e, adjust the timestep to hit time event, versus stepping over and keeping the time step unchanged.");
350template<
class Scalar>
352 Teuchos::RCP<Teuchos::ParameterList> pl)
355 if (pl == Teuchos::null)
return ter;
357 TEUCHOS_TEST_FOR_EXCEPTION(
358 pl->get<std::string>(
"Type",
"Range") !=
"Range",
360 "Error - Time Event Type != 'Range'. (='"
361 + pl->get<std::string>(
"Type")+
"')\n");
363 auto validPL = *ter->getValidParameters();
364 bool numEventsFound = pl->isParameter(
"Number of Events");
365 if (!numEventsFound) validPL.remove(
"Number of Events");
367 pl->validateParametersAndSetDefaults(validPL);
369 ter->setName (pl->get(
"Name",
"From createTimeEventRange"));
370 ter->setTimeStart (pl->get(
"Start Time", ter->getTimeStart()));
371 ter->setTimeStop (pl->get(
"Stop Time", ter->getTimeStop()));
372 ter->setTimeStride (pl->get(
"Stride Time", ter->getTimeStride()));
374 ter->setNumEvents (pl->get(
"Number of Events", ter->getNumEvents()));
375 ter->setRelTol (pl->get(
"Relative Tolerance", ter->getRelTol()));
376 ter->setLandOnExactly (pl->get(
"Land On Exactly", ter->getLandOnExactly()));
virtual void setType(std::string s)
virtual std::string getName() const
Return the name of the TimeEvent.
virtual std::string getType() const
Return the type of TimeEvent.
virtual void setName(std::string name)
Set the name of the TimeEvent.
virtual Scalar getDefaultTol() const
Return the default tolerance used by TimeEvents.
TimeEventRange specifies a start, stop and stride time.
virtual Scalar getTimeStride() const
Return the stride of the time range.
virtual Scalar getTimeStart() const
Return the start of the time range.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Return a valid ParameterList with current settings.
virtual void setRelTol(Scalar relTol)
Set the relative tolerance.
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
Describe member data.
virtual void setNumEvents(int numEvents)
Set the number of time events.
virtual void setTimeScale()
Set the time scale for the time events.
virtual void setLandOnExactly(bool LOE)
Set if the time event should be landed on exactly.
bool landOnExactly_
Should these time events be landed on exactly, i.e, adjust the timestep to hit time event,...
virtual void setTimeStop(Scalar stop)
Set the stop of the time range.
virtual void setTimeStride(Scalar stride)
Set the stride of the time range.
virtual bool getLandOnExactly() const
Set if the time events need to be landed on exactly.
Scalar stride_
Stride of time range.
virtual Scalar timeOfNextEvent(Scalar time) const
Return the time of the next event following the input time.
virtual bool eventInRange(Scalar time1, Scalar time2) const
Test if an event occurs within the time range.
Scalar timeScale_
A reference time scale, max(abs(start_,stop_)).
virtual Scalar getAbsTol() const
Return the absolute tolerance.
virtual int getNumEvents() const
Return the number of time events in the time range.
Scalar start_
Start of time range.
unsigned numEvents_
Number of events in time range.
Scalar absTol_
Absolute time tolerance, relTol_*timeScale_.
TimeEventRange()
Default constructor.
virtual void setTimeStart(Scalar start)
Set the start of the time range.
virtual void setTimeRange(Scalar start, Scalar stop, Scalar stride)
Set the range of time events from start, stop and stride.
Scalar relTol_
Relative time tolerance for matching time events.
virtual Scalar getRelTol() const
Return the relative tolerance.
virtual bool isTime(Scalar time) const
Test if time is near an event (within tolerance).
Scalar stop_
Stop of time range.
virtual Scalar timeToNextEvent(Scalar time) const
How much time until the next event.
virtual Scalar getTimeStop() const
Return the stop of the time range.
bool approxZero(Scalar value, Scalar tol=Teuchos::ScalarTraits< Scalar >::sfmin())
Test if value is approximately zero within tolerance.
Teuchos::RCP< TimeEventRange< Scalar > > createTimeEventRange(Teuchos::RCP< Teuchos::ParameterList > pList)
Nonmember Constructor via ParameterList.
bool approxEqualAbsTol(Scalar a, Scalar b, Scalar absTol)
Test if values are approximately equal within the absolute tolerance.