CppNoddy  0.85
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Groups Pages
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.
void solve ()
 Direct solver for the whole 2D domain.
void assemble_LHS ()
 Assemble the LHS of the linear Poisson matrix problem.
- 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.
virtual ~Poisson_base ()
virtual void dump ()
 A dump function for data output.

Additional Inherited Members

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

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().

:
Poisson_base( left, right, bottom, top, Nx, Ny, source_ptr )
{
#ifdef LAPACK
p_SYSTEM = new BandedLinearSystem<double>( &A, &B, "lapack" );
// since the LHS of the problem is fixed, we can LU decompose
// here in the constructor for a zero RHS, then any actual solve is
// done just done as a re_solve using the decomposition
// this is obviously much faster! This requires the LAPACK solver
// since the native solver does not do LU.
#else
p_SYSTEM = new BandedLinearSystem<double>( &A, &B, "native" );
#endif
}

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().

{
const double inv_dx2 = 1 / ( DX * DX );
const double inv_dy2 = 1 / ( DY * DY );
// clear the matrix
Utility::fill( A, 0.0 );
// top & bottom Dirichlet
for ( unsigned i = 0; i < NX; ++i )
{
A( i, i ) = 1.0;
A( ( NY - 1 ) * NX + i, ( NY - 1 ) * NX + i ) = 1.0;
}
// left & right Dirichlet
for ( unsigned j = 0; j < NY; ++j )
{
A( j * NX, j * NX ) = 1.0;
A( j * NX + NX - 1, j * NX + NX - 1 ) = 1.0;
}
// interior points
for ( unsigned i = 1; i < NX - 1; ++i )
{
for ( unsigned j = 1; j < NY - 1; ++j )
{
A( j * NX + i, j * NX + i ) = -2 * ( inv_dx2 + inv_dy2 );
A( j * NX + i, j * NX + i - 1 ) = inv_dx2;
A( j * NX + i, j * NX + i + 1 ) = inv_dx2;
A( j * NX + i, j * NX + i - NX ) = inv_dy2;
A( j * NX + i, j * NX + i + NX ) = inv_dy2;
}
}
}
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().

{
// top & bottom
for ( unsigned i = 0; i < NX; ++i )
{
B[ i ] = p_SOURCE -> get( i, 0 );
B[ ( NY - 1 ) * NX + i ] = p_SOURCE -> get( i, NY - 1 );
}
// left & right
for ( unsigned j = 0; j < NY; ++j )
{
B[ j * NX ] = p_SOURCE -> get( 0, j );
B[ j * NX + NX - 1 ] = p_SOURCE -> get( NX - 1, j );
}
// interior points
for ( unsigned i = 1; i < NX - 1; ++i )
{
for ( unsigned j = 1; j < NY - 1; ++j )
{
B[ j * NX + i ] = p_SOURCE -> get( i, j );
}
}
#ifdef LAPACK
// if we have LAPACK, use the existing LU decomposition
p_SYSTEM -> re_solve_lapack();
#else
// native solver sets up the whole linear system from scratch & solves
#endif
for ( unsigned i = 0; i < NX; ++i )
{
for ( unsigned j = 0; j < NY; ++j )
{
p_SOURCE -> set( i, j ) = B[ j * NX + i ];
}
}
}

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

© 2012

R.E. Hewitt