Hi
I have troubles to define the boundary condition correctly when I import a geometry from gmsh.
Can someone help me? I looked for hours, but I have no idea how to do it correctly…
I think I mixed somethings I should only use when I create a geometry directly in fenics and something I should use when I import geometries…
I added some parts of the code:
#Defnie Mesh
msh = meshio.read("./beam.msh")
for cell in msh.cells:
if cell.type == "triangle":
triangle_cells = cell.data
elif cell.type == "tetra":
tetra_cells = cell.data
for key in msh.cell_data_dict["gmsh:physical"].keys():
if key == "triangle":
triangle_data = msh.cell_data_dict["gmsh:physical"][key]
elif key == "tetra":
tetra_data = msh.cell_data_dict["gmsh:physical"][key]
tetra_mesh = meshio.Mesh(points=msh.points, cells={"tetra": tetra_cells})
triangle_mesh =meshio.Mesh(points=msh.points,
cells=[("triangle", triangle_cells)],
cell_data={"name_to_read":[triangle_data]})
meshio.write("mesh.xdmf", tetra_mesh)
meshio.write("mf.xdmf", triangle_mesh)
# Create mesh
mesh = Mesh()
with XDMFFile("mesh.xdmf") as infile:
infile.read(mesh)
File("beam_mesh.pvd").write(mesh)
mvc = MeshValueCollection("size_t", mesh, 1)
with XDMFFile("mf.xdmf") as infile:
infile.read(mvc, "name_to_read")
mf = cpp.mesh.MeshFunctionSizet(mesh, mvc)
File("beam_facets.pvd").write(mf)
Boundary Conditions:
# Create mesh function over the cell facets
boundary_subdomains = MeshFunction("size_t", mesh, mesh.topology().dim() - 1)
#boundary_subdomains.set_all(0)
#force_boundary = AutoSubDomain(right)
#force_boundary.mark(boundary_subdomains, 3)
#Define measure for boundary condition integral
dss = ds(subdomain_data = boundary_subdomains)
#Set up boudary condition at left end
zero = Constant((0.0, 0.0, 0.0))
bc = DirichletBC(V, zero, mf, 1)
Load:
# Work of external forces
def Wext(u_):
return dot(u_, p)*dss(2)