libMesh
first_order_unsteady_solver_test.C
Go to the documentation of this file.
1 // Ignore unused parameter warnings coming from cppunit headers
2 #include <libmesh/ignore_warnings.h>
3 #include <cppunit/extensions/HelperMacros.h>
4 #include <cppunit/TestCase.h>
5 #include <libmesh/restore_warnings.h>
6 
7 #include <libmesh/equation_systems.h>
8 #include <libmesh/mesh.h>
9 #include <libmesh/mesh_generation.h>
10 #include <libmesh/quadrature.h>
11 #include <libmesh/diff_solver.h>
12 #include <libmesh/euler_solver.h>
13 #include <libmesh/euler2_solver.h>
14 
15 #include "test_comm.h"
16 
18 
19 // THE CPPUNIT_TEST_SUITE_END macro expands to code that involves
20 // std::auto_ptr, which in turn produces -Wdeprecated-declarations
21 // warnings. These can be ignored in GCC as long as we wrap the
22 // offending code in appropriate pragmas. We can't get away with a
23 // single ignore_warnings.h inclusion at the beginning of this file,
24 // since the libmesh headers pull in a restore_warnings.h at some
25 // point. We also don't bother restoring warnings at the end of this
26 // file since it's not a header.
27 #include <libmesh/ignore_warnings.h>
28 
29 
32 {
33 public:
34  ConstantFirstOrderODE(EquationSystems & es,
35  const std::string & name_in,
36  const unsigned int number_in)
37  : FirstOrderScalarSystemBase(es, name_in, number_in)
38  {}
39 
40  virtual Number F( FEMContext & /*context*/, unsigned int /*qp*/ )
41  { return 5.0; }
42 
43  virtual Number M( FEMContext & /*context*/, unsigned int /*qp*/ )
44  { return 2.1; }
45 
46  virtual Number u( Real t )
47  { return 5.0/2.1*t; }
48 };
49 
52 {
53 public:
54  LinearTimeFirstOrderODE(EquationSystems & es,
55  const std::string & name_in,
56  const unsigned int number_in)
57  : FirstOrderScalarSystemBase(es, name_in, number_in)
58  {}
59 
60  virtual Number F( FEMContext & context, unsigned int /*qp*/ )
61  { return 2.0*context.get_time(); }
62 
63  virtual Number M( FEMContext & /*context*/, unsigned int /*qp*/ )
64  { return 5.0; }
65 
66  virtual Number u( Real t )
67  { return 1.0/5.0*t*t; }
68 };
69 
70 template<typename TimeSolverType>
71 class ThetaSolverTestBase : public TimeSolverTestImplementation<TimeSolverType>
72 {
73 public:
75  : TimeSolverTestImplementation<TimeSolverType>(),
76  _theta(1.0)
77  {}
78 
79 protected:
80 
81  virtual void aux_time_solver_init( TimeSolverType & time_solver )
82  { time_solver.theta = _theta; }
83 
84  void set_theta( Real theta )
85  { _theta = theta; }
86 
88 };
89 
90 class EulerSolverTest : public CppUnit::TestCase,
91  public ThetaSolverTestBase<EulerSolver>
92 {
93 public:
94  CPPUNIT_TEST_SUITE( EulerSolverTest );
95 
96  CPPUNIT_TEST( testEulerSolverConstantFirstOrderODE );
97  CPPUNIT_TEST( testEulerSolverLinearTimeFirstOrderODE );
98 
99  CPPUNIT_TEST_SUITE_END();
100 
101 public:
102 
104  {
105  this->set_theta(1.0);
106  this->run_test_with_exact_soln<ConstantFirstOrderODE>(0.5,10);
107 
108  this->set_theta(0.5);
109  this->run_test_with_exact_soln<ConstantFirstOrderODE>(0.5,10);
110  }
111 
113  {
114  // Need \theta = 0.5 since this has t in F.
115  this->set_theta(0.5);
116  this->run_test_with_exact_soln<LinearTimeFirstOrderODE>(0.5,10);
117  }
118 
119 };
120 
121 class Euler2SolverTest : public CppUnit::TestCase,
122  public ThetaSolverTestBase<Euler2Solver>
123 {
124 public:
125  CPPUNIT_TEST_SUITE( Euler2SolverTest );
126 
127  CPPUNIT_TEST( testEuler2SolverConstantFirstOrderODE );
128  CPPUNIT_TEST( testEuler2SolverLinearTimeFirstOrderODE );
129 
130  CPPUNIT_TEST_SUITE_END();
131 
132 public:
134  {
135  this->set_theta(1.0);
136  this->run_test_with_exact_soln<ConstantFirstOrderODE>(0.5,10);
137 
138  this->set_theta(0.5);
139  this->run_test_with_exact_soln<ConstantFirstOrderODE>(0.5,10);
140  }
141 
143  {
144  // Need \theta = 0.5 since this has t in F.
145  this->set_theta(0.5);
146  this->run_test_with_exact_soln<LinearTimeFirstOrderODE>(0.5,10);
147  }
148 };
149 
UniquePtr< TimeSolver > time_solver
A pointer to the solver object we&#39;re going to use.
Definition: diff_system.h:221
virtual Number M(FEMContext &, unsigned int)
CPPUNIT_TEST_SUITE_REGISTRATION(EulerSolverTest)
virtual Number F(FEMContext &context, unsigned int)
virtual Number u(Real t)
Exact solution as a function of time t.
virtual Number F(FEMContext &, unsigned int)
LinearTimeFirstOrderODE(EquationSystems &es, const std::string &name_in, const unsigned int number_in)
FEMSystem-based class for testing of TimeSolvers using first order SCALARs.
virtual Number M(FEMContext &, unsigned int)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual Number u(Real t)
Exact solution as a function of time t.
virtual void aux_time_solver_init(TimeSolverType &time_solver)
ConstantFirstOrderODE(EquationSystems &es, const std::string &name_in, const unsigned int number_in)