libMesh
first_order_unsteady_solver_test.C
Go to the documentation of this file.
1 #include <libmesh/equation_systems.h>
2 #include <libmesh/mesh.h>
3 #include <libmesh/mesh_generation.h>
4 #include <libmesh/quadrature.h>
5 #include <libmesh/diff_solver.h>
6 #include <libmesh/euler_solver.h>
7 #include <libmesh/euler2_solver.h>
8 
10 
11 
14 {
15 public:
16  ConstantFirstOrderODE(EquationSystems & es,
17  const std::string & name_in,
18  const unsigned int number_in)
19  : FirstOrderScalarSystemBase(es, name_in, number_in)
20  {}
21 
22  virtual Number F( FEMContext & /*context*/, unsigned int /*qp*/ )
23  { return 5.0; }
24 
25  virtual Number M( FEMContext & /*context*/, unsigned int /*qp*/ )
26  { return Real(21)/10; }
27 
28  virtual Number u( Real t )
29  { return Real(50)/21*t; }
30 };
31 
34 {
35 public:
36  LinearTimeFirstOrderODE(EquationSystems & es,
37  const std::string & name_in,
38  const unsigned int number_in)
39  : FirstOrderScalarSystemBase(es, name_in, number_in)
40  {}
41 
42  virtual Number F( FEMContext & context, unsigned int /*qp*/ )
43  { return 2.0*context.get_time(); }
44 
45  virtual Number M( FEMContext & /*context*/, unsigned int /*qp*/ )
46  { return 5.0; }
47 
48  virtual Number u( Real t )
49  { return 1/Real(5)*t*t; }
50 };
51 
52 template<typename TimeSolverType>
53 class ThetaSolverTestBase : public TimeSolverTestImplementation<TimeSolverType>
54 {
55 public:
57  : TimeSolverTestImplementation<TimeSolverType>(),
58  _theta(1.0)
59  {}
60 
61 protected:
62 
63  virtual void aux_time_solver_init( TimeSolverType & time_solver )
64  { time_solver.theta = _theta; }
65 
66  void set_theta( Real theta )
67  { _theta = theta; }
68 
70 };
71 
72 class EulerSolverTest : public CppUnit::TestCase,
73  public ThetaSolverTestBase<EulerSolver>
74 {
75 public:
77 
78 #ifdef LIBMESH_HAVE_SOLVER
81 #endif
82 
84 
85 public:
86 
88  {
89  LOG_UNIT_TEST;
90 
91  this->set_theta(1.0);
92  this->run_test_with_exact_soln<ConstantFirstOrderODE>(0.5,10);
93 
94  this->set_theta(0.5);
95  this->run_test_with_exact_soln<ConstantFirstOrderODE>(0.5,10);
96  }
97 
99  {
100  LOG_UNIT_TEST;
101 
102  // Need \theta = 0.5 since this has t in F.
103  this->set_theta(0.5);
104  this->run_test_with_exact_soln<LinearTimeFirstOrderODE>(0.5,10);
105  }
106 
107 };
108 
109 class Euler2SolverTest : public CppUnit::TestCase,
110  public ThetaSolverTestBase<Euler2Solver>
111 {
112 public:
114 
115 #ifdef LIBMESH_HAVE_SOLVER
118 #endif
119 
121 
122 public:
124  {
125  LOG_UNIT_TEST;
126 
127  this->set_theta(1.0);
128  this->run_test_with_exact_soln<ConstantFirstOrderODE>(0.5,10);
129 
130  this->set_theta(0.5);
131  this->run_test_with_exact_soln<ConstantFirstOrderODE>(0.5,10);
132  }
133 
135  {
136  LOG_UNIT_TEST;
137 
138  // Need \theta = 0.5 since this has t in F.
139  this->set_theta(0.5);
140  this->run_test_with_exact_soln<LinearTimeFirstOrderODE>(0.5,10);
141  }
142 };
143 
LIBMESH_CPPUNIT_TEST_SUITE(EulerSolverTest)
CPPUNIT_TEST(testEulerSolverConstantFirstOrderODE)
LIBMESH_CPPUNIT_TEST_SUITE(Euler2SolverTest)
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)
CPPUNIT_TEST(testEuler2SolverConstantFirstOrderODE)