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: Copyright (2017) Sandia Corporation
4 //
5 // Distributed under BSD 3-clause license (See accompanying file Copyright.txt)
6 // ****************************************************************************
7 // @HEADER
8 
10 
11 #include "Tempus_TimeEventBase.hpp"
12 
13 namespace Tempus_Unit_Test {
14 
15 using Teuchos::RCP;
16 using Teuchos::rcp;
17 using Teuchos::rcp_const_cast;
18 using Teuchos::rcp_dynamic_cast;
19 
20 // ************************************************************
21 // ************************************************************
22 TEUCHOS_UNIT_TEST(TimeEventBase, Default_Construction)
23 {
24  auto te = rcp(new Tempus::TimeEventBase<double>());
25 
26  TEST_COMPARE(te->getType(), ==, "Base");
27 
28  TEST_COMPARE(te->getName(), ==, "TimeEventBase");
29  te->setName("TestName");
30  TEST_COMPARE(te->getName(), ==, "TestName");
31 
32  TEST_COMPARE(te->isTime(0.0), ==, false);
34  te->getAbsTol(), std::numeric_limits<double>::epsilon() * 100.0, 1.0e-14);
35  TEST_FLOATING_EQUALITY(te->timeToNextEvent(0.0), te->getDefaultTime(),
36  1.0e-14);
37  TEST_FLOATING_EQUALITY(te->timeOfNextEvent(0.0), te->getDefaultTime(),
38  1.0e-14);
39  TEST_FLOATING_EQUALITY(te->getDefaultTol(), te->getAbsTol(), 1.0e-14);
40  TEST_COMPARE(te->eventInRange(0.0, 1.0), ==, false);
41 
42  TEST_COMPARE(te->isIndex(0), ==, false);
43  TEST_COMPARE(te->indexToNextEvent(0), ==, te->getDefaultIndex());
44  TEST_COMPARE(te->indexOfNextEvent(0), ==, te->getDefaultIndex());
45  TEST_COMPARE(te->eventInRange(0, 10), ==, false);
46 
47  // Check base class defaults.
48  TEST_COMPARE(te->isIndex(1), ==, false);
49  TEST_COMPARE(te->indexToNextEvent(1), ==, te->getDefaultIndex());
50  TEST_COMPARE(te->indexOfNextEvent(1), ==, te->getDefaultIndex());
51  TEST_COMPARE(te->eventInRangeIndex(1, 4), ==, false);
52 }
53 
54 // ************************************************************
55 // ************************************************************
56 TEUCHOS_UNIT_TEST(TimeEventBase, getValidParameters)
57 {
58  auto teb = rcp(new Tempus::TimeEventBase<double>());
59 
60  auto pl = teb->getValidParameters();
61 
62  TEST_COMPARE(pl->get<std::string>("Type"), ==, "Base");
63  TEST_COMPARE(pl->get<std::string>("Name"), ==, "TimeEventBase");
64 
65  { // Ensure that parameters are "used", excluding sublists.
66  std::ostringstream unusedParameters;
67  pl->unused(unusedParameters);
68  TEST_COMPARE(unusedParameters.str(), ==, "");
69  }
70 }
71 
72 } // 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.