Nonzero Dirichlet BC (04-bc-dirichlet)

Git reference: Tutorial example 04-bc-dirichlet.

Suppose that we would like to modify the boundary conditions for example 03-poisson as follows:

u(x, y) = Ax + By + C

where A, B and C are real constants.

Subclassing EssentialBoundaryCondition

This is done by defining a descendant of the EssentialBoundaryCondition class (see definitions.h):

class CustomDirichletCondition : public EssentialBoundaryCondition {
public:
  CustomDirichletCondition(Hermes::vector<std::string> markers, double A, double B, double C);

  virtual EssentialBoundaryCondition::EssentialBCValueType get_value_type() const;

  virtual scalar value(double x, double y, double n_x, double n_y, double t_x, double t_y) const;

  protected:
    double A, B, C;
};

The methods are defined in definitions.cpp as follows:

CustomDirichletCondition::CustomDirichletCondition(Hermes::vector<std::string> markers,
                                                   double A, double B, double C)
  : EssentialBoundaryCondition(markers), A(A), B(B), C(C) { }

EssentialBoundaryCondition::EssentialBCValueType CustomDirichletCondition::get_value_type() const
{
  return EssentialBoundaryCondition::BC_FUNCTION;
}

scalar CustomDirichletCondition::value(double x, double y, double n_x, double n_y,
                                       double t_x, double t_y) const
{
  return A*x + B*y + C;
}

The custom boundary condition class is used in main.cpp as follows:

// Initialize boundary conditions.
CustomDirichletCondition bc_essential(Hermes::vector<std::string>("Bottom", "Inner", "Outer", "Left"),
                                      BDY_A_PARAM, BDY_B_PARAM, BDY_C_PARAM);
EssentialBCs bcs(&bc_essential);

Sample results

The output for the parameters A = 1.0, B = 1,0 and C = 20.0 is shown below:

Solution of the Dirichlet problem.

Table Of Contents

Previous topic

Essential and Natural Boundary Conditions

Next topic

Neumann BC (05-bc-neumann)