Skip to main content

Dirichlet boundary condition

To apply boundary condition in FEM computation, EASIFEM, provides a class called DirichletBC_.

info

DirichletBC_ is a subclass of AbstractBC.

To understand how DirichletBC works, lets consider an example of linear elasticity. Let's say we want to apply the following boundary condition.

u=U0, on Γ\mathbf{u} = \mathbf{U}_{0}, \text{ on } \Gamma

Now, we may think that there is only one boundary condition. But in easifem this is not the case. Actually, u\mathbf{u}, has three components in 3D (and two components in 2D). Therefore, the above boundary condition is actually boundary condition for uxu_x, uyu_y, and uzu_z. So, we have three boundary condition on a given boundary Γ\Gamma.

The second point, which is quite obvious, is that every boundary condition has two things:

  • The boundary
  • The value (condition)

To define the boundary EASIFEM employs the MeshSelection class. The value can be specified in several ways as mentioned below in this section.

note

Several instances of DirichletBC can have same boundary but different condition.

Learn from example:

Let's consider the following example, in which we will specify the constant boundary condition.

Click here to see the example
PROGRAM main
USE easifemBase
USE easifemClasses
IMPLICIT NONE

TYPE(DirichletBC_) :: obj
TYPE(MeshSelection_) :: boundary
TYPE(ParameterList_) :: param
TYPE(Domain_) :: dom
TYPE(HDF5File_) :: domainfile
CHARACTER(*), PARAMETER :: domainfilename = "./mesh3D.h5"
INTEGER(I4B) :: bottom = 1, top = 2, left = 3, right = 4, &
& front = 5, behind = 6, nsd
INTEGER(I4B), ALLOCATABLE :: nodeNum(:)
REAL(DFP), ALLOCATABLE :: nodalValue(:, :)

CALL FPL_Init; CALL param%Initiate()
CALL domainfile%Initiate(filename=domainfilename, mode="READ")
CALL domainfile%OPEN()
CALL dom%Initiate(domainfile, group="")

nsd = dom%GetNSD()

! We call Set SetAbstractBCParam to set the parameter for boundary condition
CALL SetAbstractBCParam(param=param, prefix=obj%GetPrefix(), &
& name="ZeroBC", idof=1, nodalValueType=Constant)

! We call SetMeshSelectionParam to set the parameter for boundary condition
CALL SetMeshSelectionParam(param=param, prefix=boundary%GetPrefix(), &
& isSelectionByMeshID=.TRUE.)

CALL boundary%Initiate(param)

CALL boundary%Add(dom=dom, dim=nsd - 1, meshID=[top])
CALL boundary%Set()

CALL obj%Initiate(param=param, boundary=boundary, dom=dom)

CALL obj%Set(constantNodalValue=0.0_DFP)

CALL obj%Get(nodeNum=nodeNum, nodalValue=nodalValue)

CALL Display(nodeNum, "nodeNum", advance="NO")
CALL Display(nodalValue, "nodalValue", advance="YES")

CALL domainfile%DEALLOCATE()
CALL dom%DEALLOCATE()
CALL param%DEALLOCATE(); CALL FPL_Finalize
END PROGRAM main

In the above code, to define the boundary condition, we follow the steps given below.

Step 1: Set the properties of the DirichletBC

We set the properties of DirichletBC_ by using the method called SetAbstractBCParam.

CALL SetAbstractBCParam(param=param, prefix=obj%GetPrefix(),  &
& name="ZeroBC", idof=1, nodalValueType=Constant)
note

Because we are setting constant boundary condition, we used nodalValueType=Constant.

You can learn more about this method here.

Step 2: Define a boundary

To define a boundary we will use the MeshSelection. In the above code, we select the boundary by specifing the meshID.

CALL SetMeshSelectionParam(param=param, prefix=boundary%GetPrefix(),  &
& isSelectionByMeshID=.TRUE.)

After setting the boundary parameter we call Initiate method.

CALL boundary%Initiate(param)

Subsequently, we call Add method to add the information of meshID.

CALL boundary%Add(dom=dom, dim=nsd - 1, meshID=[top])
CALL boundary%Set()
info

After adding the information of meshID we should call Set method, which means that we are done adding information to the boundary.

You can learn more about SetMeshSelectionParam here

Step 3: Initiate instance of DirichletBC

After initiating the boundary, call Initiate. To initiate an instance of DirichletBC_ we need to pass the boundary, paramters, and domain.

CALL obj%Initiate(param=param, boundary=boundary, dom=dom)

Step 4: Set the boundary condition

After initiating an instance of DirichletBC_, next step is to set the boundary condition. To do so, we will use the method Set.

While setting the value we should respect the configuration used while calling SetAbstractBCParam. For example, in the above example we configure boundary condition for nodalValueType=Constant. Therefore, we should set the constantNodalValue while calling the set method.

CALL obj%Set(constantNodalValue=0.0_DFP)

Step 5: Get the value of boundary condition

To get the boundary condition we will use the method Get. The Get function can take two arguments nodeNum(:) and nodalValue(:,:). The nodeNum(:) is compulsory, whereas nodalValue can be optional.

CALL obj%Get(nodeNum=nodeNum, nodalValue=nodalValue)
note

On return, the size of nodeNum and SIZE(nodalValue, 1) is same.

The columns in nodalValue denotes the boundary condition at different times. You can read more about this subroutine here.

Further reading

There is more to DirichletBC_, and you can learn about them from following pages. (Here DBC stands for DirichletBC_)