Logo
Finite Element Embedded Library and Language in C++
Feel++ Feel++ on Github Feel++ on Travis-CI Feel++ on Twitter Feel++ on YouTube Feel++ community
 All Classes Files Functions Variables Typedefs Pages
Constructing a function space

The next step is to construct a function space over the mesh. The source code is available in myfunctionspace.cpp.

#include <feel/feel.hpp>
using namespace Feel;
int main( int argc, char** argv )
{
//Initialize Feel++ Environment
Environment env( _argc=argc, _argv=argv,
_about=about( _name="myfunctionspace",
_author="Feel++ Consortium",
_email="feelpp-devel@feelpp.org" ) );
// create the mesh
auto mesh = loadMesh(_mesh=new Mesh<Simplex<2>>);
// function space \f$ X_h \f$ using order 2 Lagrange basis functions
auto Xh = Pch<2>( mesh );
auto g = expr<4>( soption(_name="functions.g"));
auto gradg = grad<3>(g);
// elements of \f$ u,w \in X_h \f$
auto u = Xh->element( "u" );
auto w = Xh->element( "w" );
// build the interpolant of u
u.on( _range=elements( mesh ), _expr=g );
// build the interpolant of the interpolation error
w.on( _range=elements( mesh ), _expr=idv( u )-g );
// compute L2 norms
double L2g = normL2( elements( mesh ), g );
double H1g = normL2( elements( mesh ), _expr=g,_grad_expr=gradg );
double L2uerror = normL2( elements( mesh ), ( idv( u )-g ) );
double H1uerror = normH1( elements( mesh ), _expr=( idv( u )-g ),
_grad_expr=( gradv( u )-gradg ) );
if ( Environment::isMasterRank() )
{
std::cout << "||u-g||_0 = " << L2uerror/L2g << std::endl;
std::cout << "||u-g||_1 = " << H1uerror/H1g << std::endl;
}
// export for post-processing
auto e = exporter( _mesh=mesh );
// save interpolant
e->add( "g", u );
// save interpolant of interpolation error
e->add( "u-g", w );
e->save();
}
Loading a Mesh in 2D
// create the mesh
auto mesh = loadMesh(_mesh=new Mesh<Simplex<2>>);
Constructing a function space
// function space \f$ X_h \f$ using order 2 Lagrange basis functions
auto Xh = Pch<2>( mesh );
Defining an expression
auto g = expr<4>( soption(_name="functions.g"));
auto gradg = grad<3>(g);
Building and checking the interpolant
// elements of \f$ u,w \in X_h \f$
auto u = Xh->element( "u" );
auto w = Xh->element( "w" );
// build the interpolant of u
u.on( _range=elements( mesh ), _expr=g );
// build the interpolant of the interpolation error
w.on( _range=elements( mesh ), _expr=idv( u )-g );
// compute L2 norms
double L2g = normL2( elements( mesh ), g );
double H1g = normL2( elements( mesh ), _expr=g,_grad_expr=gradg );
double L2uerror = normL2( elements( mesh ), ( idv( u )-g ) );
double H1uerror = normH1( elements( mesh ), _expr=( idv( u )-g ),
_grad_expr=( gradv( u )-gradg ) );
if ( Environment::isMasterRank() )
{
std::cout << "||u-g||_0 = " << L2uerror/L2g << std::endl;
std::cout << "||u-g||_1 = " << H1uerror/H1g << std::endl;
}