Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Tempus_UnitTest_TimeEventBase.cpp
Go to the documentation of this file.
1 //@HEADER
2 // *****************************************************************************
3 // Tempus: Time Integration and Sensitivity Analysis Package
4 //
5 // Copyright 2017 NTESS and the Tempus contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 //@HEADER
9 
11 
12 #include "Tempus_TimeEventBase.hpp"
13 
14 namespace Tempus_Unit_Test {
15 
16 using Teuchos::RCP;
17 using Teuchos::rcp;
18 using Teuchos::rcp_const_cast;
19 using Teuchos::rcp_dynamic_cast;
20 
21 // ************************************************************
22 // ************************************************************
23 TEUCHOS_UNIT_TEST(TimeEventBase, Default_Construction)
24 {
25  auto te = rcp(new Tempus::TimeEventBase<double>());
26 
27  TEST_COMPARE(te->getType(), ==, "Base");
28 
29  TEST_COMPARE(te->getName(), ==, "TimeEventBase");
30  te->setName("TestName");
31  TEST_COMPARE(te->getName(), ==, "TestName");
32 
33  TEST_COMPARE(te->isTime(0.0), ==, false);
35  te->getAbsTol(), std::numeric_limits<double>::epsilon() * 100.0, 1.0e-14);
36  TEST_FLOATING_EQUALITY(te->timeToNextEvent(0.0), te->getDefaultTime(),
37  1.0e-14);
38  TEST_FLOATING_EQUALITY(te->timeOfNextEvent(0.0), te->getDefaultTime(),
39  1.0e-14);
40  TEST_FLOATING_EQUALITY(te->getDefaultTol(), te->getAbsTol(), 1.0e-14);
41  TEST_COMPARE(te->eventInRange(0.0, 1.0), ==, false);
42 
43  TEST_COMPARE(te->isIndex(0), ==, false);
44  TEST_COMPARE(te->indexToNextEvent(0), ==, te->getDefaultIndex());
45  TEST_COMPARE(te->indexOfNextEvent(0), ==, te->getDefaultIndex());
46  TEST_COMPARE(te->eventInRange(0, 10), ==, false);
47 
48  // Check base class defaults.
49  TEST_COMPARE(te->isIndex(1), ==, false);
50  TEST_COMPARE(te->indexToNextEvent(1), ==, te->getDefaultIndex());
51  TEST_COMPARE(te->indexOfNextEvent(1), ==, te->getDefaultIndex());
52  TEST_COMPARE(te->eventInRangeIndex(1, 4), ==, false);
53 }
54 
55 // ************************************************************
56 // ************************************************************
57 TEUCHOS_UNIT_TEST(TimeEventBase, getValidParameters)
58 {
59  auto teb = rcp(new Tempus::TimeEventBase<double>());
60 
61  auto pl = teb->getValidParameters();
62 
63  TEST_COMPARE(pl->get<std::string>("Type"), ==, "Base");
64  TEST_COMPARE(pl->get<std::string>("Name"), ==, "TimeEventBase");
65 
66  { // Ensure that parameters are "used", excluding sublists.
67  std::ostringstream unusedParameters;
68  pl->unused(unusedParameters);
69  TEST_COMPARE(unusedParameters.str(), ==, "");
70  }
71 }
72 
73 } // namespace Tempus_Unit_Test
#define TEST_COMPARE(v1, comp, v2)
#define TEST_FLOATING_EQUALITY(v1, v2, tol)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
TEUCHOS_UNIT_TEST(BackwardEuler, Default_Construction)
This class defines time events which can be used to &quot;trigger&quot; an action.