Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Tempus_UnitTest_TimeStepControl.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 #include "Teuchos_XMLParameterListHelpers.hpp"
11 #include "Teuchos_TimeMonitor.hpp"
12 #include "Teuchos_DefaultComm.hpp"
13 
14 #include "Thyra_VectorStdOps.hpp"
15 
16 #include "Tempus_TimeStepControl.hpp"
17 
18 #include "../TestUtils/Tempus_ConvergenceTestUtils.hpp"
19 
20 #include <fstream>
21 #include <vector>
22 
23 namespace Tempus_Unit_Test {
24 
25 using Teuchos::RCP;
26 using Teuchos::rcp;
27 using Teuchos::rcp_const_cast;
28 using Teuchos::rcp_dynamic_cast;
29 using Teuchos::ParameterList;
30 using Teuchos::sublist;
31 using Teuchos::getParametersFromXmlFile;
32 
33 
34 // ************************************************************
35 // ************************************************************
36 TEUCHOS_UNIT_TEST(TimeStepControl, setOutputTimes)
37 {
38  auto tsc = rcp(new Tempus::TimeStepControl<double>());
39 
40  //auto tscPL = tsc->getParameterList();
41  //std::cout << "tscPL = \n" << *tscPL << std::endl;
42 
43  std::vector<double> times_in;
44  //std::cout << "Test 1" << std::endl;
45  times_in.push_back(0.0000000000000000e-11);
46  times_in.push_back(0.1001384570000000e-11);
47  times_in.push_back(0.2002769140000000e-11);
48  times_in.push_back(0.3004153710000000e-11);
49  times_in.push_back(0.4005538280000000e-11);
50  times_in.push_back(0.5006922850000000e-11);
51  times_in.push_back(0.6008307420000000e-11);
52  times_in.push_back(0.7009691990000000e-11);
53  times_in.push_back(0.8011076560000000e-11);
54  times_in.push_back(0.9012461130000000e-11);
55  times_in.push_back(1.0013845700000000e-11);
56 
57  tsc->setOutputTimes(times_in);
58  tsc->initialize();
59  auto times_out = tsc->getOutputTimes();
60  double maxDiff = 0.0;
61 
62  //std::cout << "\n times_in, times_out = " << std::endl;
63  for (size_t i=0; i < times_in.size(); ++i) {
64  //std::cout << std::setw(25) << std::setprecision(16) << times_in[i] << ","
65  // << std::setw(25) << std::setprecision(16) << times_out[i]
66  // << std::endl;
67  maxDiff = std::max(std::abs(times_in[i] - times_out[i]), maxDiff);
68  }
69  //std::cout << " maxDiff = " << maxDiff << std::endl;
70 
71  TEST_COMPARE(maxDiff, <, 1.0e-25);
72 
73 
74  //std::cout << "Test 2" << std::endl;
75  times_in.clear();
76  times_in.push_back(0.00000000000000000000000000000000);
77  times_in.push_back(0.00000000000100138457000000009381);
78  times_in.push_back(0.00000000000200276914000000018762);
79  times_in.push_back(0.00000000000300415371000000007949);
80  times_in.push_back(0.00000000000400553828000000037525);
81  times_in.push_back(0.00000000000500692284999999986321);
82  times_in.push_back(0.00000000000600830742000000015898);
83  times_in.push_back(0.00000000000700969198999999964694);
84  times_in.push_back(0.00000000000801107656000000075050);
85  times_in.push_back(0.00000000000901246112999999943067);
86  times_in.push_back(0.00000000001001384569999999972643);
87 
88  tsc->setOutputTimes(times_in);
89  tsc->initialize();
90  times_out = tsc->getOutputTimes();
91  maxDiff = 0.0;
92 
93  //std::cout << "\n times_in, times_out = " << std::endl;
94  for (size_t i=0; i < times_in.size(); ++i) {
95  //std::cout << std::setw(30) << std::setprecision(20) << times_in[i] << ","
96  // << std::setw(30) << std::setprecision(20) << times_out[i]
97  // << std::endl;
98  maxDiff = std::max(std::abs(times_in[i] - times_out[i]), maxDiff);
99  }
100  //std::cout << " maxDiff = " << maxDiff << std::endl;
101 
102  TEST_COMPARE(maxDiff, <, 1.0e-25);
103 
104  //tscPL = tsc->getParameterList();
105  //std::cout << "tscPL = \n" << *tscPL << std::endl;
106 }
107 
108 
109 // ************************************************************
110 // ************************************************************
111 TEUCHOS_UNIT_TEST(TimeStepControl, getOutputIndicesandIntervals){
112  auto tsc = rcp(new Tempus::TimeStepControl<double>());
113  int setOutputTimeIndex = 17;
114  double setOutputTimeInterval = 1.101001000100001e-7;
115 
116  tsc->setOutputIndexInterval(setOutputTimeIndex);
117  tsc->setOutputTimeInterval(setOutputTimeInterval);
118 
119  int getOutputTimeIndex = tsc->getOutputIndexInterval();
120  double getOutputTimeInterval = tsc->getOutputTimeInterval();
121  TEST_COMPARE(getOutputTimeInterval, ==, setOutputTimeInterval);
122  TEST_COMPARE(getOutputTimeIndex, ==, setOutputTimeIndex);
123 }
124 
125 
126 } // namespace Tempus_Test
TEUCHOS_UNIT_TEST(BackwardEuler, Default_Construction)
TimeStepControl manages the time step size. There several mechanicisms that effect the time step size...