CppNoddy  0.90
Public Member Functions | List of all members
CppNoddy::PDE_double_IBVP< _Type > Class Template Reference

A templated object for real/complex vector system of unsteady equations. More...

#include <PDE_double_IBVP.h>

Inheritance diagram for CppNoddy::PDE_double_IBVP< _Type >:
CppNoddy::Uncopyable

Public Member Functions

 PDE_double_IBVP (Equation_3matrix< _Type > *equation_ptr, const DenseVector< double > &xnodes, const DenseVector< double > &ynodes, Residual_with_coords< _Type > *ptr_to_bottom_residual, Residual_with_coords< _Type > *ptr_to_top_residual)
 The class is defined by a vector function for the system. More...
 
 ~PDE_double_IBVP ()
 Destructor. More...
 
void update_previous_solution ()
 Copy the current solution to the previous solution. More...
 
void step2 (const double &dt)
 A Crank-Nicolson 'time' stepper. More...
 
double & t ()
 Return a reference to the current value of the 'timelike' coordinate. More...
 
double & tolerance ()
 Return a reference to the convergence tolerance. More...
 
TwoD_Node_Mesh< _Type > & solution ()
 

Detailed Description

template<typename _Type>
class CppNoddy::PDE_double_IBVP< _Type >

A templated object for real/complex vector system of unsteady equations.

Definition at line 45 of file PDE_double_IBVP.h.

Constructor & Destructor Documentation

template<typename _Type >
CppNoddy::PDE_double_IBVP< _Type >::PDE_double_IBVP ( Equation_3matrix< _Type > *  equation_ptr,
const DenseVector< double > &  xnodes,
const DenseVector< double > &  ynodes,
Residual_with_coords< _Type > *  ptr_to_bottom_residual,
Residual_with_coords< _Type > *  ptr_to_top_residual 
)

The class is defined by a vector function for the system.

Parameters
equation_ptrA pointer to an inherited Equation object.
xnodesA vector that defines the nodal x-positions.
ynodesA vector that defines the nodal y-positions.
ptr_to_bottom_residualA pointer to a residual object that defines the y=y1 boundary conditions.
ptr_to_top_residualA pointer to a residual object that defines the y=y2 boundary conditions.

Definition at line 19 of file PDE_double_IBVP.cpp.

24  :
25  TOL( 1.e-8 ),
26  T( 0.0 ),
27  MAX_ITERATIONS( 20 ),
28  p_EQUATION( ptr_to_equation ),
29  p_BOTTOM_RESIDUAL( ptr_to_bottom_residual ),
30  p_TOP_RESIDUAL( ptr_to_top_residual ),
31  UPDATED( false )
32  {
33  // create the 2D mesh for the current time level and previous time level
34  SOLN = TwoD_Node_Mesh<_Type>( xnodes, ynodes, p_EQUATION -> get_order() );
35  // copy construct the previous solution's storage
36  PREV_SOLN = SOLN;
37  // initialise the eqn object
38  // "x"
39  p_EQUATION -> coord(2) = xnodes[0];
40 #ifdef TIME
41  // timers
42  T_ASSEMBLE = Timer( "Assembling of the matrix (incl. equation updates):" );
43  T_SOLVE = Timer( "Solving of the matrix:" );
44 #endif
45  }
template<typename _Type >
CppNoddy::PDE_double_IBVP< _Type >::~PDE_double_IBVP ( )

Destructor.

Definition at line 48 of file PDE_double_IBVP.cpp.

49  {
50 #ifdef TIME
51  std::cout << "\n";
52  T_ASSEMBLE.stop();
53  T_ASSEMBLE.print();
54  T_SOLVE.stop();
55  T_SOLVE.print();
56 #endif
57  }

Member Function Documentation

template<typename _Type >
TwoD_Node_Mesh< _Type > & CppNoddy::PDE_double_IBVP< _Type >::solution ( )
inline
Returns
A handle to the solution mesh

Definition at line 127 of file PDE_double_IBVP.h.

Referenced by main(), and CppNoddy::PDE_double_IBVP< _Type >::tolerance().

128  {
129  return SOLN;
130  }
template<typename _Type >
void CppNoddy::PDE_double_IBVP< _Type >::step2 ( const double &  dt)

A Crank-Nicolson 'time' stepper.

Definition at line 60 of file PDE_double_IBVP.cpp.

References CppNoddy::BandedMatrix< _Type >::assign(), CppNoddy::Utility::dot(), CppNoddy::BandedMatrix< _Type >::get_elt_iter(), CppNoddy::DenseVector< _Type >::inf_norm(), CppNoddy::BandedMatrix< _Type >::noffdiag(), and CppNoddy::BandedLinearSystem< _Type >::solve().

Referenced by main(), and CppNoddy::PDE_double_IBVP< _Type >::update_previous_solution().

61  {
62  DT = dt;
63  if ( !UPDATED )
64  {
65  std::string problem;
66  problem = " You have called the PDE_double_IBVP::step2 method without calling\n";
67  problem += " the PDE_double_IBVP::update_previous_solution method first. This\n";
68  problem += " method is required to copy/store the previous time level's solution\n";
69  problem += " and then allow you to specify/alter the x-initial condition by\n";
70  problem += " for the current time level.";
71  throw ExceptionRuntime( problem );
72  }
73  // the order of the problem
74  unsigned order( p_EQUATION -> get_order() );
75  // get the number of nodes in the mesh
76  // -- this may have been refined by the user since the last call.
77  unsigned nx( SOLN.get_nnodes().first );
78  unsigned ny( SOLN.get_nnodes().second );
79  // measure of maximum residual
80  double max_residual( 1.0 );
81  // the current solution moves to the previous solution
82  // ANY LARGE STORAGE USED IN THE MAIN LOOP IS
83  // DEFINED HERE TO AVOID REPEATED CONSTRUCTION.
84  // Note we blank the A matrix after every iteration.
85  //
86  // Banded LHS matrix - max obove diagonal band wTidth is
87  // from first variable at node i to last variable at node i+1
88  BandedMatrix<_Type> a( ny * order, 2 * order - 1, 0.0 );
89  // RHS
90  DenseVector<_Type> b( ny * order, 0.0 );
91  // linear solver definition
92 #ifdef LAPACK
93  BandedLinearSystem<_Type> system( &a, &b, "lapack" );
94 #else
95  BandedLinearSystem<_Type> system( &a, &b, "native" );
96 #endif
97  for ( std::size_t j = 0; j < nx - 1; ++j )
98  {
99  //// next x-soln guess is the previous x-soln
100  //for ( std::size_t var = 0; var < order; ++var )
101  //{
102  //for ( std::size_t i = 0; i < ny; ++i )
103  //{
104  //SOLN( j + 1, i, var ) = SOLN( j, i, var );
105  //}
106  //}
107  //
108  // iteration counter
109  int counter = 0;
110  // loop until converged or too many iterations
111  do
112  {
113  // iteration counter
114  ++counter;
115  // time the assemble phase
116 #ifdef TIME
117  T_ASSEMBLE.start();
118 #endif
119  assemble_matrix_problem( a, b, j );
120  max_residual = b.inf_norm();
121 #ifdef DEBUG
122  std::cout.precision( 12 );
123  std::cout << " PDE_double_IBVP.step2 : x_j = " << SOLN.coord(j,0).first << " Residual_max = " << max_residual << " tol = " << TOL << " counter = " << counter << "\n";
124 #endif
125 #ifdef TIME
126  T_ASSEMBLE.stop();
127  T_SOLVE.start();
128 #endif
129  // linear solver
130  system.solve();
131  // keep the solution in a OneD_GenMesh object
132  for ( std::size_t i = 0; i < ny; ++i )
133  {
134  for ( std::size_t var = 0; var < order; ++var )
135  {
136  SOLN( j + 1, i, var ) += b[ i * order + var ];
137  }
138  }
139 #ifdef TIME
140  T_SOLVE.stop();
141 #endif
142  }
143  while ( ( max_residual > TOL ) && ( counter < MAX_ITERATIONS ) );
144  if ( counter >= MAX_ITERATIONS )
145  {
146  std::string problem( "\n The PDE_double_IBVP.step2 method took too many iterations. \n" );
147  throw ExceptionItn( problem, counter, max_residual );
148  }
149  }
150  // set the time to the updated level
151  T += DT;
152 #ifdef DEBUG
153  std::cout << "[DEBUG] solved at t = " << T << "\n";
154 #endif
155  UPDATED = false;
156  }
template<typename _Type >
double & CppNoddy::PDE_double_IBVP< _Type >::t ( )
inline

Return a reference to the current value of the 'timelike' coordinate.

Returns
A handle to the current timelinke coordinate stored in the object

Definition at line 133 of file PDE_double_IBVP.h.

Referenced by main(), and CppNoddy::PDE_double_IBVP< _Type >::update_previous_solution().

134  {
135  return T;
136  }
template<typename _Type>
double& CppNoddy::PDE_double_IBVP< _Type >::tolerance ( )
inline

Return a reference to the convergence tolerance.

Definition at line 79 of file PDE_double_IBVP.h.

References CppNoddy::PDE_double_IBVP< _Type >::solution().

80  {
81  return TOL;
82  }
template<typename _Type>
void CppNoddy::PDE_double_IBVP< _Type >::update_previous_solution ( )
inline

Copy the current solution to the previous solution.

Definition at line 65 of file PDE_double_IBVP.h.

References CppNoddy::PDE_double_IBVP< _Type >::step2(), and CppNoddy::PDE_double_IBVP< _Type >::t().

Referenced by main().

66  {
67  PREV_SOLN = SOLN;
68  UPDATED = true;
69  }

The documentation for this class was generated from the following files:

© 2012

R.E. Hewitt