Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros 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 
9 #include "Teuchos_UnitTestHarness.hpp"
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->getUseFSALDefault();
41  std::string ICConsistency = stepper->getICConsistencyDefault();
42  bool ICConsistencyCheck = stepper->getICConsistencyCheckDefault();
43  bool useEmbedded = stepper->getUseEmbeddedDefault();
44 
45  int NumStages = 4;
46  Teuchos::SerialDenseMatrix<int,double> A(NumStages,NumStages);
47  Teuchos::SerialDenseVector<int,double> b(NumStages);
48  Teuchos::SerialDenseVector<int,double> c(NumStages);
49  Teuchos::SerialDenseVector<int,double> bstar(0);
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 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
68  auto obs = rcp(new Tempus::StepperRKObserverComposite<double>());
69  stepper->setObserver(obs); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
70 #endif
71  stepper->setAppAction(modifier); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
72  stepper->setAppAction(modifierX); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
73  stepper->setAppAction(observer); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
74  stepper->setUseFSAL(useFSAL); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
75  stepper->setICConsistency(ICConsistency); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
76  stepper->setICConsistencyCheck(ICConsistencyCheck); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
77  stepper->setUseEmbedded(useEmbedded); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
78 
79  stepper->setTableau(A, b, c, order, order, order); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
80 
81 
82  // Full argument list construction.
83 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
84  stepper = rcp(new Tempus::StepperERK_General<double>(
85  model, obs, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
86  A, b, c, order, order, order, bstar));
87  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
88 #endif
89  stepper = rcp(new Tempus::StepperERK_General<double>(
90  model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
91  A, b, c, order, order, order, bstar, modifier));
92  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
93 
94  // Test stepper properties.
95  TEUCHOS_ASSERT(stepper->getOrder() == 4);
96 }
97 
98 
99 // ************************************************************
100 // ************************************************************
101 TEUCHOS_UNIT_TEST(ERK_General, StepperFactory_Construction)
102 {
103  auto model = rcp(new Tempus_Test::SinCosModel<double>());
104  testFactoryConstruction("General ERK", model);
105 }
106 
107 
108 // ************************************************************
109 // ************************************************************
110 TEUCHOS_UNIT_TEST(ERK_General, AppAction)
111 {
112  auto stepper = rcp(new Tempus::StepperERK_General<double>());
113  auto model = rcp(new Tempus_Test::SinCosModel<double>());
114  testRKAppAction(stepper, model, out, success);
115 }
116 
117 
118 } // 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_UNIT_TEST(BackwardEuler, Default_Construction)