Hello, I am currently stuck at defining appropriate boundary conditions for my dogbone specimen geometry (kindly see the image below). I also went through some posts where the similar error had been occured like this where @dokken introduces a facetfunction where we can also visualize domain in paraview and this where @MiroK marks the facets and applies DBC therefore I modified my code accordingly but still the error persists.
My MWE is:
import meshio
from dolfin import *
import mgis.fenics as mf
import numpy as np
import matplotlib.pyplot as plt
from IPython.display import clear_output
msh = meshio.read("/mnt/d/Research Projects/FEniCS/doggy.msh")
def create_mesh(mesh, cell_type, prune_z=False):
cells = mesh.get_cells_type(cell_type)
points = mesh.points[:, :2] if prune_z else mesh.points
out_mesh = meshio.Mesh(points=points, cells={cell_type: cells})
return out_mesh
triangle_mesh = create_mesh(msh, "triangle", prune_z=True)
meshio.write("doggy.xdmf", triangle_mesh)
# Read the modified mesh with swapped axes
modified_mesh = Mesh()
with XDMFFile("doggy.xdmf") as infile:
infile.read(modified_mesh)
# Get the vertex coordinates of the modified mesh
coordinates = modified_mesh.coordinates()
# Swap the x and y coordinates
modified_coordinates = coordinates[:, ::-1]
# Update the vertex coordinates in the modified mesh
modified_mesh.coordinates()[:, :] = modified_coordinates
# Plot the modified mesh
plot(modified_mesh)
Vu = VectorFunctionSpace(modified_mesh, "CG", 1)
u = Function(Vu, name="Displacement")
class top(SubDomain):
def inside(self, x, on_boundary):
return on_boundary and near(x[1], 31.75)
class bottom(SubDomain):
def inside(self, x, on_boundary):
return on_boundary and (x[1] == -31.75)
boundaries = MeshFunction("size_t", modified_mesh, modified_mesh.geometry().dim()-1)
top().mark(boundaries, 1)
bottom().mark(boundaries, 2)
Uimp = Expression(("0", "t"), t=1, degree=0)
bcu = [DirichletBC(Vu, Constant((0, 0)), boundaries, 2),
DirichletBC(Vu, Uimp, boundaries, 1)]
v = Function(Vu)
bcu[1].apply(v.vector()) #<--!!!This line is giving error specifically!!!
Vd = FunctionSpace(modified_mesh, "CG", 1)
d = Function(Vd, name="Damage")
dold = Function(Vd, name="Previous damage")
bcd = DirichletBC(Vd, Constant(0.), boundaries, 2)
Error:
*** Warning: Found no facets matching domain for boundary condition.
Image of my domain:
I humbly request to kindly suggest me on how to go about this error. I appreciate any inputs regarding the same.
Thank You for the help.