- Author
- Christophe Prud'homme
Solving Nonlinear Equations
Feel++ allows to solve nonlinear equations thanks to its interface to the interface to the PETSc nonlinear solver library. It requires the implementation of two extra functions in your application that will update the jacobian matrix associated to the tangent problem and the residual.
Consider that you have an application class MyApp
with a backend as data member
#include <feel/feelcore/feel.hpp>
namespace Feel {
class MyApp : public Application
{
public:
typedef Backend<double> backend_type;
typedef boost::shared_ptr<backend_type> backend_ptrtype;
MyApp( int argc, char** argv,
AboutData const& ad, po::options_description const& od )
:
Application( argc, argv, ad, od ),
M_backend( backend_type::build( this->vm() ) ),
{
M_backend->nlSolver()->residual =
boost::bind( &self_type::updateResidual, boost::ref( *this ), _1, _2 );
M_backend->nlSolver()->jacobian =
boost::bind( &self_type::updateJacobian, boost::ref( *this ), _1, _2 );
}
void updateResidual( const vector_ptrtype& X, vector_ptrtype& R )
{
}
void updateJacobian( const vector_ptrtype& X, sparse_matrix_ptrtype& J)
{
}
void run()
{
Xh...
element_type u(Xh);
vector_ptrtype U( M_backend->newVector( u.functionSpace() ) );
*U = u;
vector_ptrtype R( M_backend->newVector( u.functionSpace() ) );
sparse_matrix_ptrtype J;
updateJacobian( U, R );
updateResidual( U, J );
M_backend->nlSolve( J, U, R, 1e-10, 10 );
u = *U;
}
private:
backend_ptrtype M_backend;
};
}
The function updateJacobian
and updateResidual
implement the assmebly of the matrix
(jacobian matrix) and the vector
(residual vector) respectively.
A first nonlinear problem
As a simple example, let
be a subset of
, (i.e.
) with boundary
. Consider now the following equation and boundary condition

where
is a given parameter and
.
- Note
- To be described in this section. For now see
"doc/manual/nonlinear/nonlinearpow.cpp"
for an implementation of this problem.
Simplified combustion problem: Bratu
As a simple example, let
be a subset of
,(i.e.
) with boundary
. Consider now the following equation and boundary condition

where
is a given parameter. This is usually called the Bratu problem and appears in the simplification of nonlinear diffusion process for example in the field of combustion.
- Note
- To be described in this section. For now see
"doc/manual/nonlinear/bratu.cpp"
for an implementation of this problem.