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
Visualizing functions over a mesh

The next step is to visualize function over the mesh. The source code is available in myexporter.cpp.

Loading a Mesh in 2D
Here, we generate a second order mesh,
auto mesh = unitCircle<2>(); // ``order 2'' circle
and one of first order.
auto meshp1 = unitCircle<1>(); // ``order 1'' circle
Constructing a function space
here, we generate a second order function space,
auto Xh = Pch<2>( mesh ); // $\mathbb{p}_2$ space
Defining a (scalar) function over the function space
auto v = project( _space=Xh, _range=elements(mesh),
_expr=sin(pi*Px()));
Exporter
We create now three exporter:
  • once generated on the P1 mesh
  • once generated on the P2 mesh
  • once generated on a P1 mesh extracted from P2 mesh
auto exhi = exporter( _mesh=mesh, _name="exhi" );
auto exlo = exporter( _mesh=meshp1, _name="exlo" );
auto exhilo = exporter( _mesh=lagrangeP1(_space=Xh)->mesh(),_name="exhilo");
Adding function to save
Here we save the function many times. That is here not relevant but you may want to simulate process over time.
int max = 10; double dt = 0.1;
double time = 0;
for (int i = 0; i<max; i++)
{
exhilo->step( time )->add( "vhilo", v );
exlo->step( time )->add( "vlo", v );
exhi->step( time )->add( "vhi", v );
time += dt;
}
Actually saving
exhi->save();
exlo->save();
exhilo->save();

Complete code

The complete code reads as follows

#include <feel/feelcore/environment.hpp>
#include <feel/feeldiscr/pch.hpp>
#include <feel/feeldiscr/operatorlagrangep1.hpp>
#include <feel/feelfilters/unitcircle.hpp>
#include <feel/feelfilters/exporter.hpp>
#include <feel/feelvf/projectors.hpp>
#include <feel/feelvf/operations.hpp>
#include <feel/feelvf/stdmathfunctors.hpp>
#include <feel/feelvf/geometricdata.hpp>
int main(int argc, char**argv )
{
using namespace Feel;
Environment env( _argc=argc, _argv=argv,
_about=about(_name="myexporter",
_author="Christophe Prud'homme",
_email="christophe.prudhomme@feelpp.org"));
auto mesh = unitCircle<2>(); // ``order 2'' circle
auto meshp1 = unitCircle<1>(); // ``order 1'' circle
auto Xh = Pch<2>( mesh ); // $\mathbb{p}_2$ space
auto v = project( _space=Xh, _range=elements(mesh),
_expr=sin(pi*Px()));
auto exhi = exporter( _mesh=mesh, _name="exhi" );
auto exlo = exporter( _mesh=meshp1, _name="exlo" );
auto exhilo = exporter( _mesh=lagrangeP1(_space=Xh)->mesh(),_name="exhilo");
int max = 10; double dt = 0.1;
double time = 0;
for (int i = 0; i<max; i++)
{
exhilo->step( time )->add( "vhilo", v );
exlo->step( time )->add( "vlo", v );
exhi->step( time )->add( "vhi", v );
time += dt;
}
exhi->save();
exlo->save();
exhilo->save();
}

to compile just type

make feelpp_doc_myexporter

to execute just type

./feelpp_doc_myexporter
Reading saved data
You can visualize data via
  • ensight
  • paraview
  • gmsh

The results files are in $HOME/feel/myexporter/np_1.