Git reference: Tutorial example 04-bc-dirichlet.
We will keep the equation from example 03-poisson
(1)-\mbox{div}(\lambda \nabla u) - C_{src} = 0,
but the boundary conditions will be modified to
u(x, y) = Ax + By + C
where A, B and C are real constants.
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);
The output for the parameters C_{src} = 6000, \lambda_{Al} = 236, \lambda_{Cu} = 386, A = 1, B = 1 and C = 20 is shown below: