Wiki

Clone wiki

lifev-release / tutorial / Creation_of_BCHandler

Go back


Creation of BCHandler

BCHandler is the class that handles the list of boundary conditions. This object is a container of BCBase objects. To create an object of class BCHandler, we need to:

  1. include the header file that contains the definitions of the class BCHandler;
  2. initialise the objects of type BCFunctionBase, defining the user-defined boundary functions data;
  3. feed the BCHandler with objects of class BCBase.

First of all, we add the following header file:

    // ...

    // Header for theBCHandler
    #include <lifev/core/fem/BCHandler.hpp>

    // ...

Inside the namespace LifeV, we create the user-defined functions of type f (t,x,y,z) that specify the boundary functions data. In order to be used as input argument to the BCFunctionBase constructor, each one of the user-defined functions should be declared as follows:

    namespace LifeV
    {

    // ...

    Real udFunctionName(Real t, Real x, Real y, Real z, ID i);

    // ...

    }

For example, if we want to define the scalar functions fZero = 0, fOne = 1 and the vectorial function fOneCompX = [1, 0, 0]^T, we write:

    Real fZero( Real /*t*/, Real /*x*/, Real /*y*/, Real /*z*/, ID /*i*/ )
    {
        return 0.0;
    }

    Real fOne( Real /*t*/, Real /*x*/, Real /*y*/, Real /*z*/, ID /*i*/ )
    {
        return 1.0;
    }

    Real fOneCompX(  Real /*t*/, Real /*x*/, Real /*y*/, Real /*z*/, ID i )
    {
        if ( i == 0 )
            return 1.0;

       return 0.0;
    }

Notice that we comment ( with /* */ ) all the unused variables in the function declaration. The user-defined functions can be created outside the main or also in separate files (ud_function.hpp and ud_function.cpp). In the latter case, the header (ud_function.hpp) should be properly included in the main file:

    // ...

    // Header for the user-defined functions file
    #include "ud_function.hpp"
    // ...

Inside the main function, we create the object of class BCFunctionBase, handling the user-defined functions data, e.g.:

    // ...

    int main ( Int argc, char** argv )
    {
        // ...

    BCFunctionBase bcfZero (fZero);
    BCFunctionBase bcfOne (fOne);
    BCFunctionBase bcfOneCompX (fOneCompX);
    }

Inside the main function, we also create an object of class BCHandler using the empty constructor:

    // ...

    int main ( Int argc, char** argv )
    {
        // ...

        BCHandler bcH;
    }

For each one of the conditions we aim at imposing, we call the method addBC of the BCHandler object. The input arguments of method addBC are the same input arguments of the constructor of the class BCBase. Here is some examples:

  • Scalar field u, Dirichlet condition u = 1 = fOne on the mesh surface with flag e.g. 100:

    bcH.addBC("BC1", 100, Essential, Scalar, bcfOne, 1);

  • Scalar field u, Neumann condition \Nabla u \cdot n = 0 = fZero on the mesh surface with flag e.g. 200:

    bcH.addBC("BC2", 200, Natural, Scalar, bcfZero, 1);

  • Vector field u, \mathbb u = [1, 0, 0]\^T = fOneCompX on the mesh surface with flag e.g. 300:

    bcH.addBC("BC3", 300, Essential, Full, bcfOneCompX, 3);

We remark that, instead of analytical function, it is possible to use finite element vectors to set the boundary conditions by using the class BCVectorBase. We refer to the doxygen for further details.

Updated