Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Tempus_UnitTest_ERK_General.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 
12 
13 #include "../TestModels/SinCosModel.hpp"
14 
15 
16 namespace Tempus_Unit_Test {
17 
18 using Teuchos::RCP;
19 using Teuchos::rcp;
20 using Teuchos::rcp_const_cast;
21 using Teuchos::rcp_dynamic_cast;
22 
23 
24 // ************************************************************
25 // ************************************************************
26 TEUCHOS_UNIT_TEST(ERK_General, Default_Construction)
27 {
28  auto model = rcp(new Tempus_Test::SinCosModel<double>());
29 
30  // Default construction.
31  auto stepper = rcp(new Tempus::StepperERK_General<double>());
32  stepper->setModel(model);
33  stepper->initialize();
34  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
35 
36  // Default values for construction.
37  auto modifier = rcp(new Tempus::StepperRKModifierDefault<double>());
38  auto modifierX = rcp(new Tempus::StepperRKModifierXDefault<double>());
39  auto observer = rcp(new Tempus::StepperRKObserverDefault<double>());
40  bool useFSAL = stepper->getUseFSAL();
41  std::string ICConsistency = stepper->getICConsistency();
42  bool ICConsistencyCheck = stepper->getICConsistencyCheck();
43  bool useEmbedded = stepper->getUseEmbedded();
44 
45  int NumStages = 4;
46  Teuchos::SerialDenseMatrix<int,double> A(NumStages,NumStages);
50 
51  // Fill A:
52  A(0,0) = 0.0; A(0,1) = 0.0; A(0,2) = 0.0; A(0,3) = 0.0;
53  A(1,0) = 0.5; A(1,1) = 0.0; A(1,2) = 0.0; A(1,3) = 0.0;
54  A(2,0) = 0.0; A(2,1) = 0.5; A(2,2) = 0.0; A(2,3) = 0.0;
55  A(3,0) = 0.0; A(3,1) = 0.0; A(3,2) = 1.0; A(3,3) = 0.0;
56 
57  // Fill b:
58  b(0) = 1.0/6.0; b(1) = 1.0/3.0; b(2) = 1.0/3.0; b(3) = 1.0/6.0;
59 
60  // fill c:
61  c(0) = 0.0; c(1) = 0.5; c(2) = 0.5; c(3) = 1.0;
62 
63  int order = 4;
64 
65 
66  // Test the set functions.
67  stepper->setAppAction(modifier); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
68  stepper->setAppAction(modifierX); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
69  stepper->setAppAction(observer); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
70  stepper->setUseFSAL(useFSAL); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
71  stepper->setICConsistency(ICConsistency); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
72  stepper->setICConsistencyCheck(ICConsistencyCheck); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
73  stepper->setUseEmbedded(useEmbedded); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
74 
75  stepper->setTableau(A, b, c, order, order, order); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
76 
77 
78  // Full argument list construction.
80  model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
81  A, b, c, order, order, order, bstar, modifier));
82  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
83 
84  // Test stepper properties.
85  TEUCHOS_ASSERT(stepper->getOrder() == 4);
86 }
87 
88 
89 // ************************************************************
90 // ************************************************************
91 TEUCHOS_UNIT_TEST(ERK_General, StepperFactory_Construction)
92 {
93  auto model = rcp(new Tempus_Test::SinCosModel<double>());
94  testFactoryConstruction("General ERK", model);
95 }
96 
97 
98 // ************************************************************
99 // ************************************************************
100 TEUCHOS_UNIT_TEST(ERK_General, AppAction)
101 {
102  auto stepper = rcp(new Tempus::StepperERK_General<double>());
103  auto model = rcp(new Tempus_Test::SinCosModel<double>());
104  testRKAppAction(stepper, model, out, success);
105 }
106 
107 
108 } // namespace Tempus_Test
void testRKAppAction(const Teuchos::RCP< Tempus::StepperRKBase< double > > &stepper, const Teuchos::RCP< const Thyra::ModelEvaluator< double > > &model, Teuchos::FancyOStream &out, bool &success)
Unit test utility for Stepper RK AppAction.
void testFactoryConstruction(std::string stepperType, const Teuchos::RCP< const Thyra::ModelEvaluator< double > > &model)
Unit test utility for Stepper construction through StepperFactory.
General Explicit Runge-Kutta Butcher Tableau.
Sine-Cosine model problem from Rythmos. This is a canonical Sine-Cosine differential equation with a...
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
TEUCHOS_UNIT_TEST(BackwardEuler, Default_Construction)
#define TEUCHOS_ASSERT(assertion_test)
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)