CppNoddy  0.90
Public Member Functions | List of all members
CppNoddy::Poisson_Cartesian Class Reference

An object for Cartesian Poisson problems with Dirichlet boundary conditions. More...

#include <Poisson_Cartesian.h>

Inheritance diagram for CppNoddy::Poisson_Cartesian:
CppNoddy::Poisson_base CppNoddy::Uncopyable

Public Member Functions

 Poisson_Cartesian (const double &left, const double &right, const double &bottom, const double &top, const unsigned &Nx, const unsigned &Ny, DenseMatrix< double > *source_ptr)
 Constructor for a simple Finite Differenced Poisson problem class. More...
 
void solve ()
 Direct solver for the whole 2D domain. More...
 
void assemble_LHS ()
 Assemble the LHS of the linear Poisson matrix problem. More...
 
- Public Member Functions inherited from CppNoddy::Poisson_base
 Poisson_base (const double &left, const double &right, const double &bottom, const double &top, const unsigned &Nx, const unsigned &Ny, DenseMatrix< double > *source_ptr)
 A simple Finite Differenced Poisson problem class. More...
 
virtual ~Poisson_base ()
 
virtual void dump ()
 A dump function for data output. More...
 

Additional Inherited Members

- Protected Attributes inherited from CppNoddy::Poisson_base
unsigned NX
 geometry of the domain/meesh More...
 
unsigned NY
 
double DX
 
double DY
 
double LEFT
 
double RIGHT
 
double TOP
 
double BOTTOM
 
DenseMatrix< double > * p_SOURCE
 pointer to the source matrix More...
 
BandedMatrix< double > A
 The containers for the banded matrix problem. More...
 
DenseVector< double > B
 
BandedLinearSystem< double > * p_SYSTEM
 The banded linear system. More...
 

Detailed Description

An object for Cartesian Poisson problems with Dirichlet boundary conditions.

Definition at line 19 of file Poisson_Cartesian.h.

Constructor & Destructor Documentation

CppNoddy::Poisson_Cartesian::Poisson_Cartesian ( const double &  left,
const double &  right,
const double &  bottom,
const double &  top,
const unsigned &  Nx,
const unsigned &  Ny,
DenseMatrix< double > *  source_ptr 
)

Constructor for a simple Finite Differenced Poisson problem class.

Parameters
leftThe x-position of the left-hand boundary.
rightThe x-position of the right-hand boundary.
bottomThe y-position of the bottom boundary.
topThe y-position of the top boundary.
NxNumber of nodes in x-direction.
NyNumber of nodes in y-direction.
source_ptrA pointer to a DenseMatrix<double> source term.

Definition at line 18 of file Poisson_Cartesian.cpp.

References CppNoddy::Poisson_base::A, assemble_LHS(), CppNoddy::Poisson_base::B, CppNoddy::Poisson_base::p_SYSTEM, and solve().

24  :
25  Poisson_base( left, right, bottom, top, Nx, Ny, source_ptr )
26  {
27 #ifdef LAPACK
28  assemble_LHS();
29  p_SYSTEM = new BandedLinearSystem<double>( &A, &B, "lapack" );
30 
31  // since the LHS of the problem is fixed, we can LU decompose
32  // here in the constructor for a zero RHS, then any actual solve is
33  // done just done as a re_solve using the decomposition
34  // this is obviously much faster! This requires the LAPACK solver
35  // since the native solver does not do LU.
36  p_SYSTEM -> solve();
37 #else
38  p_SYSTEM = new BandedLinearSystem<double>( &A, &B, "native" );
39 #endif
40  }
Poisson_base(const double &left, const double &right, const double &bottom, const double &top, const unsigned &Nx, const unsigned &Ny, DenseMatrix< double > *source_ptr)
A simple Finite Differenced Poisson problem class.
Definition: Poisson_base.h:32
void assemble_LHS()
Assemble the LHS of the linear Poisson matrix problem.
BandedLinearSystem< double > * p_SYSTEM
The banded linear system.
Definition: Poisson_base.h:107
DenseVector< double > B
Definition: Poisson_base.h:105
BandedMatrix< double > A
The containers for the banded matrix problem.
Definition: Poisson_base.h:104
void solve()
Direct solver for the whole 2D domain.

Member Function Documentation

void CppNoddy::Poisson_Cartesian::assemble_LHS ( )
virtual

Assemble the LHS of the linear Poisson matrix problem.

Reimplemented from CppNoddy::Poisson_base.

Definition at line 84 of file Poisson_Cartesian.cpp.

References CppNoddy::Poisson_base::A, CppNoddy::Poisson_base::DX, CppNoddy::Poisson_base::DY, CppNoddy::Utility::fill(), CppNoddy::Poisson_base::NX, and CppNoddy::Poisson_base::NY.

Referenced by Poisson_Cartesian(), and solve().

85  {
86  const double inv_dx2 = 1 / ( DX * DX );
87  const double inv_dy2 = 1 / ( DY * DY );
88  // clear the matrix
89  Utility::fill( A, 0.0 );
90  // top & bottom Dirichlet
91  for ( unsigned i = 0; i < NX; ++i )
92  {
93  A( i, i ) = 1.0;
94  A( ( NY - 1 ) * NX + i, ( NY - 1 ) * NX + i ) = 1.0;
95  }
96  // left & right Dirichlet
97  for ( unsigned j = 0; j < NY; ++j )
98  {
99  A( j * NX, j * NX ) = 1.0;
100  A( j * NX + NX - 1, j * NX + NX - 1 ) = 1.0;
101  }
102  // interior points
103  for ( unsigned i = 1; i < NX - 1; ++i )
104  {
105  for ( unsigned j = 1; j < NY - 1; ++j )
106  {
107  A( j * NX + i, j * NX + i ) = -2 * ( inv_dx2 + inv_dy2 );
108  A( j * NX + i, j * NX + i - 1 ) = inv_dx2;
109  A( j * NX + i, j * NX + i + 1 ) = inv_dx2;
110  A( j * NX + i, j * NX + i - NX ) = inv_dy2;
111  A( j * NX + i, j * NX + i + NX ) = inv_dy2;
112  }
113  }
114  }
unsigned NX
geometry of the domain/meesh
Definition: Poisson_base.h:98
BandedMatrix< double > A
The containers for the banded matrix problem.
Definition: Poisson_base.h:104
void fill(BandedMatrix< _Type > &A, const _Type &value)
Set all elements of a specified BANDED matrix.
Definition: Utility.h:89
void CppNoddy::Poisson_Cartesian::solve ( )
virtual

Direct solver for the whole 2D domain.

Reimplemented from CppNoddy::Poisson_base.

Definition at line 42 of file Poisson_Cartesian.cpp.

References assemble_LHS(), CppNoddy::Poisson_base::B, CppNoddy::Poisson_base::NX, CppNoddy::Poisson_base::NY, CppNoddy::Poisson_base::p_SOURCE, and CppNoddy::Poisson_base::p_SYSTEM.

Referenced by main(), and Poisson_Cartesian().

43  {
44  // top & bottom
45  for ( unsigned i = 0; i < NX; ++i )
46  {
47  B[ i ] = p_SOURCE -> get( i, 0 );
48  B[ ( NY - 1 ) * NX + i ] = p_SOURCE -> get( i, NY - 1 );
49  }
50 
51  // left & right
52  for ( unsigned j = 0; j < NY; ++j )
53  {
54  B[ j * NX ] = p_SOURCE -> get( 0, j );
55  B[ j * NX + NX - 1 ] = p_SOURCE -> get( NX - 1, j );
56  }
57 
58  // interior points
59  for ( unsigned i = 1; i < NX - 1; ++i )
60  {
61  for ( unsigned j = 1; j < NY - 1; ++j )
62  {
63  B[ j * NX + i ] = p_SOURCE -> get( i, j );
64  }
65  }
66 #ifdef LAPACK
67  // if we have LAPACK, use the existing LU decomposition
68  p_SYSTEM -> re_solve_lapack();
69 #else
70  // native solver sets up the whole linear system from scratch & solves
71  assemble_LHS();
72  p_SYSTEM -> solve();
73 #endif
74 
75  for ( unsigned i = 0; i < NX; ++i )
76  {
77  for ( unsigned j = 0; j < NY; ++j )
78  {
79  p_SOURCE -> set( i, j ) = B[ j * NX + i ];
80  }
81  }
82  }
unsigned NX
geometry of the domain/meesh
Definition: Poisson_base.h:98
void assemble_LHS()
Assemble the LHS of the linear Poisson matrix problem.
BandedLinearSystem< double > * p_SYSTEM
The banded linear system.
Definition: Poisson_base.h:107
DenseVector< double > B
Definition: Poisson_base.h:105
DenseMatrix< double > * p_SOURCE
pointer to the source matrix
Definition: Poisson_base.h:102
void solve()
Direct solver for the whole 2D domain.

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

© 2012

R.E. Hewitt