Regarding the Boundarg conditions (DirichletBC)

Hello Everyone,

I am importing the indexed facet region of mesh in Fenics and want to apply Dirichlet conditions as shown in the code below.

from fenics import *       
from mshr import *

mesh = Mesh("mesh.xml")

boundaries_GB = MeshFunction("size_t", mesh, "mesh_facet_region.xml")

V_GB = FunctionSpace(mesh, 'CG', 1)

bc_GB = [DirichletBC(V_GB, Constant(1.0), boundaries_GB,14),
         DirichletBC(V_GB, Constant(1.0), boundaries_GB,15),
         DirichletBC(V_GB, Constant(1.0), boundaries_GB,157)]      

This code is working for me but I have to apply this boundary condition on many facets.
So, my question is that is there any smart way to apply that instead of writing all the lines in the array i.e. something like using a range or condition.

Thank you,
Manish

E.g.

from fenics import *       
from mshr import *
import numpy as np

mesh = Mesh("mesh.xml")

boundaries_GB = MeshFunction("size_t", mesh, "mesh_facet_region.xml")

V_GB = FunctionSpace(mesh, 'CG', 1)

tags = np.arange(14, 18, 1)
bc_GB = [DirichletBC(V_GB, Constant(1.0), boundaries_GB, i) for i in tags]

Define tags as needed to include all the boundaries where you wish to apply the bc.

1 Like

@conpierce8 Thank you. I was exactly looking for something like this.

Thanks,
Manish