10#ifndef Tempus_TimeEventList_impl_hpp
11#define Tempus_TimeEventList_impl_hpp
17template <
class Scalar>
31template <
class Scalar>
33 std::string name,
bool landOnExactly,
48template <
class Scalar>
68template <
class Scalar>
79template <
class Scalar>
106 else if (std::abs(*(it - 1) - time) >=
absTol_ &&
107 std::abs(*(it)-time) >=
absTol_) {
113template <
class Scalar>
120template <
class Scalar>
129template <
class Scalar>
135template <
class Scalar>
145 return std::numeric_limits<Scalar>::max();
147 typename std::vector<Scalar>::const_iterator it =
149 const Scalar timeEvent = *it;
157template <
class Scalar>
174template <
class Scalar>
176 Teuchos::FancyOStream &out,
const Teuchos::EVerbosityLevel )
const
178 auto l_out = Teuchos::fancyOStream(out.getOStream());
179 Teuchos::OSTab ostab(*l_out, 2,
"TimeEventList");
180 l_out->setOutputToRootOnly(0);
182 *l_out <<
"TimeEventList:"
184 <<
" name = " << this->
getName() <<
"\n"
185 <<
" Type = " << this->
getType() <<
"\n"
187 <<
" relTol_ = " <<
relTol_ <<
"\n"
188 <<
" absTol_ = " <<
absTol_ <<
"\n"
193 *l_out << *it <<
", ";
194 *l_out << *(
timeList_.end() - 1) << std::endl;
197 *l_out <<
"<empty>" << std::endl;
201template <
class Scalar>
202Teuchos::RCP<const Teuchos::ParameterList>
205 Teuchos::RCP<Teuchos::ParameterList> pl =
206 Teuchos::parameterList(
"Time Event List");
209 pl->set(
"Name", this->
getName());
210 pl->set(
"Type", this->
getType());
212 pl->set(
"Relative Tolerance", this->
getRelTol(),
213 "Relative time tolerance for matching time events.");
216 "Should these time events be landed on exactly, i.e, adjust the "
217 "timestep to hit time event, versus stepping over and keeping the "
218 "time step unchanged.");
221 std::ostringstream list;
222 if (!times.empty()) {
223 for (std::size_t i = 0; i < times.size() - 1; ++i) list << times[i] <<
", ";
224 list << times[times.size() - 1];
226 pl->set<std::string>(
"Time List", list.str(),
227 "Comma deliminated list of times");
235template <
class Scalar>
237 Teuchos::RCP<Teuchos::ParameterList> pl)
240 if (pl == Teuchos::null)
return tel;
242 TEUCHOS_TEST_FOR_EXCEPTION(pl->get<std::string>(
"Type",
"List") !=
"List",
244 "Error - Time Event Type != 'List'. (='" +
245 pl->get<std::string>(
"Type") +
"')\n");
247 pl->validateParametersAndSetDefaults(*tel->getValidParameters());
249 tel->setName(pl->get(
"Name",
"From createTimeEventList"));
250 tel->setRelTol(pl->get(
"Relative Tolerance", tel->getRelTol()));
251 tel->setLandOnExactly(pl->get(
"Land On Exactly", tel->getLandOnExactly()));
253 std::vector<Scalar> timeList;
254 std::string str = pl->get<std::string>(
"Time List");
255 std::string delimiters(
",");
257 std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
259 std::string::size_type pos = str.find_first_of(delimiters, lastPos);
260 while ((pos != std::string::npos) || (lastPos != std::string::npos)) {
262 std::string token = str.substr(lastPos, pos - lastPos);
263 timeList.push_back(Scalar(std::stod(token)));
264 if (pos == std::string::npos)
break;
266 lastPos = str.find_first_not_of(delimiters, pos);
267 pos = str.find_first_of(delimiters, lastPos);
269 tel->setTimeList(timeList);
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 getDefaultTime() const
Return the default time used for TimeEvents.
virtual Scalar getDefaultTol() const
Return the default tolerance used by TimeEvents.
TimeEventList specifies a list of time events.
virtual Scalar timeToNextEvent(Scalar time) const
How much time until the next event.
std::vector< Scalar > timeList_
Sorted and unique list of time events.
virtual Scalar timeOfNextEvent(Scalar time) const
Return the time of the next event following the input time.
virtual bool isTime(Scalar time) const
Test if time is near an event (within tolerance).
virtual Scalar getRelTol() const
Return the relative tolerance.
Scalar timeScale_
A reference time scale.
TimeEventList()
Default constructor.
virtual void setTimeScale()
Set the time scale for the time events.
virtual std::vector< Scalar > getTimeList() const
Return the list of time events.
virtual void addTime(Scalar time)
Add the time to event vector.
virtual bool eventInRange(Scalar time1, Scalar time2) const
Test if an event occurs within 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 setLandOnExactly(bool LOE)
Set if the time event should be landed on exactly.
virtual void setTimeList(std::vector< Scalar > timeList, bool sort=true)
Set the list of time events.
virtual bool getLandOnExactly() const
Return if the time events need to be landed on exactly.
Scalar absTol_
Absolute time tolerance, relTol_*timeScale_.
Scalar relTol_
Relative time tolerance for matching time events.
bool approxZero(Scalar value, Scalar tol=Teuchos::ScalarTraits< Scalar >::sfmin())
Test if value is approximately zero within tolerance.
bool approxEqualAbsTol(Scalar a, Scalar b, Scalar absTol)
Test if values are approximately equal within the absolute tolerance.
Teuchos::RCP< TimeEventList< Scalar > > createTimeEventList(Teuchos::RCP< Teuchos::ParameterList > pList)
Nonmember Constructor via ParameterList.