This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Implementing Boundary Condition

0 votes

Hi,

I have a xml mesh and also I have some .dat file in which I have the node numbers that they are on the boundary. I like to implement Dirichlet boundary conditions at these points (zero displacement). How can i do that?

asked Feb 19, 2016 by Abi FEniCS Novice (270 points)

Please post short but complete example code. It's easier for someone to respond by showing you how to modify your code.

1 Answer

0 votes

Here is my code. In this code since my mesh has complex geometry the MeshFunction does not work properly and do not satisfy boundary conditions well especially this line:
"bc0_2 = DirichletBC(W.sub(0), Constant((0.0, 0.0, 0.0)), facet_domains,4) #noslip"

I am looking for something rather than MeshFunction and if is possible to use the node numbers for implementing boundary conditions. It should be noted my mesh contains about 1 million element. I use this script for other geometries and works very well but for this complex one does not.

from future import print_function

from dolfin import *

Solves Stokes eqn

stablized = True

mu = Constant(1.32) #Constant(1320.0) #Constant(1.32) #viscossity

Load mesh and subdomains

mesh_filename = '/global/home/users/volume_mesh.h5'
mesh = Mesh()
mesh_in = HDF5File(mpi_comm_world(), mesh_filename, 'r')
mesh_in.read(mesh, 'mesh', False)
mesh_in.close()

Define function spaces

P2 = VectorElement("Lagrange", mesh.ufl_cell(), 2)

P1 = FiniteElement("Lagrange", mesh.ufl_cell(), 1)

TH = P2 * P1

W = FunctionSpace(mesh, TH)

V = VectorFunctionSpace(mesh, "CG", 1)
P = FunctionSpace(mesh, "CG", 1)
W = MixedFunctionSpace([V, P]) #Taylor-Hood

U_in = -100 #0.372105 #mm/s #372.105 for micron/s unit
results_dir = '/global/home/users/stokes_flow/'

BC

if MPI.rank(mpi_comm_world()) == 0:
print "Setting BC..."

bc_file = '/global/home/users/arzani/Microchannel/simple/advdif/mesh/BCnodeFacets.h5'

bc_file = '/global/home/users/BCnodeFacets.h5'
facet_domains = MeshFunction('size_t', mesh)
facet_domains_in = HDF5File(mpi_comm_world(), bc_file, 'r')
facet_domains_in.read(facet_domains, 'mesh_function')
facet_domains_in.close()

inflow = Expression((" -5(2020-x[1]x[1]-x[2]x[2])", "0.0", "0.0"))
bc0_1 = DirichletBC(W.sub(0), Constant((0.0, 0.0, 0.0)) , facet_domains,3) #noslip
bc0_2 = DirichletBC(W.sub(0), Constant((0.0, 0.0, 0.0)), facet_domains,4) #noslip
bc1_1 = DirichletBC(W.sub(0), inflow, facet_domains,1) #inlet for u

Collect boundary conditions

bcs = [bc1_1,bc0_1, bc0_2]

answered Feb 23, 2016 by Abi FEniCS Novice (270 points)
...