Tempus Version of the Day
Time Integration
Loading...
Searching...
No Matches
Tutorial_Regression_Tester.hpp
Go to the documentation of this file.
1
2#include <iostream>
3#include <cmath>
4
5#include "Teuchos_RCP.hpp"
6#include "Teuchos_as.hpp"
7
8#include "Thyra_VectorBase.hpp"
9#include "Thyra_VectorStdOps.hpp"
10#include "Thyra_DefaultSpmdVectorSpace.hpp"
11#include "Thyra_DetachedVectorView.hpp"
12
13#include "Tempus_SolutionState.hpp"
14
84 const Teuchos::RCP<Thyra::VectorBase<double> >& x_n,
85 std::ostream& out = std::cout,
86 const double relTol = Teuchos::as<double>(1.0e-8))
87{
88 out << std::scientific;
89 auto x_regress = x_n->clone_v();
90 {
91 Thyra::DetachedVectorView<double> x_regress_view(*x_regress);
92 x_regress_view[0] = Teuchos::as<double>(-1.59496108218721311);
93 x_regress_view[1] = Teuchos::as<double>( 0.96359412806611255);
94 }
95
96 auto x_error = x_n->clone_v();
97 Thyra::V_VmV(x_error.ptr(), *x_n, *x_regress);
98
99 const double x_L2norm_error = Thyra::norm_2(*x_error);
100 const double x_L2norm_regress = Thyra::norm_2(*x_regress);
101 const double relError = x_L2norm_error / x_L2norm_regress;
102
103 out << "Relative L2 Norm of the error (regression) = "
104 << relError << std::endl;
105
106 if (x_L2norm_error > relTol * x_L2norm_regress) {
107 out << "FAILED regression constraint!" << std::endl;
108 return false;
109 }
110
111 return true;
112}
113
126 const Teuchos::RCP<Tempus::SolutionState<double> >& solState,
127 std::ostream& out = std::cout,
128 const double relTol = Teuchos::as<double>(1.0e-8))
129{
130 return tutorialRegressionTest(solState->getX(), out, relTol);
131}
132
148template<int N>
150 const double (&x_n)[N],
151 std::ostream& out = std::cout,
152 const double relTol = Teuchos::as<double>(1.0e-8))
153{
154 Teuchos::RCP<const Thyra::VectorSpaceBase<double> > xSpace =
155 Thyra::defaultSpmdVectorSpace<double>(N);
156 Teuchos::RCP<Thyra::VectorBase<double> > x_vec = Thyra::createMember(xSpace);
157 {
158 Thyra::DetachedVectorView<double> x_view(*x_vec);
159 for (int i = 0; i < N; ++i)
160 x_view[i] = x_n[i];
161 }
162
163 return tutorialRegressionTest(x_vec, out, relTol);
164}
bool tutorialRegressionTest(const Teuchos::RCP< Thyra::VectorBase< double > > &x_n, std::ostream &out=std::cout, const double relTol=Teuchos::as< double >(1.0e-8))
Regression check for the Tempus tutorial van der Pol examples.
Solution state for integrators and steppers.