1. Mean value of a function

Let \(f\) a bounded function on domain \(\Omega\). You can evaluate the mean value of a function thanks to the mean() function :

\[\bar{f}=\frac{1}{|\Omega|}\int_\Omega f=\frac{1}{\int_\Omega 1}\int_\Omega f\]

1.1. Interface

  mean( _range, _expr, _quad, _geomap );

Required parameters:

  • _range = domain of integration

  • _expr = mesurable function

Optional parameters:

  • _quad = quadrature to use.

    • Default = integer corresponding to the quadrature order, see integrate.

  • _geomap = type of geometric mapping.

    • Default = GEOMAP_OPT

1.2. Example

Stokes example using mean
int main(int argc, char**argv )
{
    Environment env( _argc=argc, _argv=argv,
                     _about=about(_name="mystokes",
                                  _author="Feel++ Consortium",
                                  _email="feelpp-devel@feelpp.org"));

    // create the mesh
    auto mesh = loadMesh(_mesh=new Mesh<Simplex< 2 > > );


    // function space
    auto Vh = THch<2>( mesh );

    // element U=(u,p) in Vh
    auto U = Vh->element();
    auto u = U.element<0>();
    auto p = U.element<1>();

    // left hand side
    auto a = form2( _trial=Vh, _test=Vh );
    a = integrate(_range=elements(mesh),
                  _expr=trace(gradt(u)*trans(grad(u))) );

    a+= integrate(_range=elements(mesh),
                  _expr=-div(u)*idt(p)-divt(u)*id(p));

    auto syms = symbols<2>();
    auto u1 = parse( option(_name="functions.alpha").as<std::string>(), syms );
    auto u2 = parse( option(_name="functions.beta").as<std::string>(), syms );
    matrix u_exact = matrix(2,1);
    u_exact = u1,u2;
    auto p_exact = parse( option(_name="functions.gamma").as<std::string>(), syms );
	auto f = -laplacian( u_exact, syms ) + grad( p_exact, syms ).transpose();
    LOG(INFO) << "rhs : " << f;

    // right hand side
    auto l = form1( _test=Vh );
    l = integrate(_range=elements(mesh),
                  _expr=trans(expr<2,1,5>( f, syms ))*id(u));
    a+=on(_range=boundaryfaces(mesh), _rhs=l, _element=u,
          _expr=expr<2,1,5>(u_exact,syms));

    // solve a(u,v)=l(v)
    a.solve(_rhs=l,_solution=U);

    double mean_p = mean(_range=elements(mesh),_expr=idv(p))(0,0);
    double mean_p_exact = mean(_range=elements(mesh),_expr=expr(p_exact,syms))(0,0);
    double l2error_u = normL2( _range=elements(mesh), _expr=idv(u)-expr<2,1,5>( u_exact, syms ) );
    double l2error_p = normL2( _range=elements(mesh), _expr=idv(p)-mean_p-(expr( p_exact, syms )-mean_p_exact) );
    LOG(INFO) << "L2 error norm u: " << l2error_u;
    LOG(INFO) << "L2 error norm p: " << l2error_p;

    // save results
    auto e = exporter( _mesh=mesh );
    e->add( "u", u );
    e->add( "p", p );
    e->save();
}