Hello everyone,
In my code, I wanted to implement a displacement boundary constraint on the right bottom corner point as fixed only along y direction in a rectangular domain. Since it is a mixed element function space, I am little unsure about the code. I have checked for some previous posts but still remains unclear.
Could anyone please confirm me that the applied boundary condition for the right bottom corner point of the beam is constrained along y direction? . My code is
import os
from mpi4py import MPI
from petsc4py import PETSc
import dolfinx
import numpy as np
import ufl
from basix.ufl import element
from dolfinx import default_real_type, log, plot
from dolfinx.fem import Function, functionspace,assemble_scalar
from dolfinx.fem.petsc import NonlinearProblem
from dolfinx.io import XDMFFile
from dolfinx.nls.petsc import NewtonSolver
from ufl import dx, grad, inner
from dolfinx import fem, default_scalar_type,mesh
#Creating mesh
msh = mesh.create_rectangle (comm=MPI.COMM_WORLD, points=((0.0, 0.0), (6.0,1.0)), n=(1,1), cell_type=mesh.CellType.quadrilateral)
#Create function space
V = ufl.VectorElement("Lagrange", msh.ufl_cell(),1) #For deformation map
P1 = element("Lagrange", msh.basix_cell(), 1) #For phase field parametrs
#Creating mixed element space for phi,p,mu,lamda1,lamda2
ME = functionspace(msh, ufl.MixedElement([V, P1, P1, P1, P1]))
#Creating Test functions and function
a, q, v, l1, l2 = ufl.TestFunctions(ME)
u = Function(ME) # current solution
u0 = Function(ME) # solution from previous converged step
# Split mixed functions
d, p, mu, lam1, lam2 = ufl.split(u)
d0, p0, mu0, lam01, lam02 = ufl.split(u0)
# Zero u
u.x.array[:] = 0.0
# Interpolate initial condition for the concentration
np.random.seed(30)
u.sub(1).interpolate(lambda x: 0.75 + 0.02 * (0.5 - np.random.rand(x.shape[1])))
u.x.scatter_forward()
#Applying boundary condition to beam
def left_corner(x):
return np.logical_and(np.isclose(x[1],0.0),np.isclose(x[0],0.0))
ME0, _ = ME.sub(0).collapse()
bottom_value1 = fem.Function(ME0)
bottom_value1.x.array[:]= 0
left_corner_vertex = mesh.locate_entities_boundary(msh,0,left_corner)
dofs = fem.locate_dofs_topological((ME.sub(0),ME0),0,left_corner_vertex)
bc_left_corner = fem.dirichletbc(bottom_value1,dofs,ME0)
##########
def right_corner(x):
return np.logical_and(np.isclose(x[1],0.0),np.isclose(x[0],6.0))
bottom_value2 = fem.Function(ME0)
bottom_value2.x.array[:]= 0
right_corner_vertex = mesh.locate_entities_boundary(msh,0,right_corner)
right_dof = fem.locate_dofs_topological ((ME.sub(0),ME0.sub(1)),0,right_corner_vertex) #Having doubt regarding the bc on right corner
#to constrain displacment only along y direction.
bc_right_corner = fem.dirichletbc(bottom_value2, right_dof, ME.sub(0))
##########
Since I need to include boundary condition to only along y direction to subspace of mixed element function space, it is confusing (right_corner function in code). So it will be great help if someone confirm me regarding the implementation.
Thanks for your time and considerations.