Hi there
I am really new to fenics, but i worked the tutorials through. Now I am trying to do some more stuff to get into fenics.
https://1drv.ms/u/s!AocekCrLgWbAihmCF7NaIQBNEIit?e=HEuUJC
As you can see in the attached image, I try to simulate a pulling force on a physical surface (2) of a geometry. The second geometry is fixed at its left and right physical planes (1 + 3).
The code I created works but I do not know how to define a specific Force on the surface 2. In addition I have not found any contact body model. Can someone help me to get this to bodies connected?
I found this: https://comet-fenics.readthedocs.io/en/latest/demo/contact/penalty.html but I am not sure how to implement this in my code.
I will upload the .geo code in separat code.
Thank you very much.
import meshio
import matplotlib.pyplot as plt
import numpy as np
from fenics import *
from ufl import nabla_div
from dolfin import Mesh, XDMFFile, File, MeshValueCollection, cpp, Measure,
DirichletBC, FunctionSpace, Constant, TrialFunction,
TestFunction, dot, grad, dx, Function, solve
msh = meshio.read("./winkel.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)
Scaled variables
E = 210000000000
nu = 0.3
mu, lambda_ = Constant(E/(2*(1 + nu))), Constant(Enu/((1 + nu)(1 - 2nu)))
#mu = 80769200000
rho = 7800
load = 0 #beachte Vorzeichen
F = load #Kraft auf Objekt (eventuell muss hier force per volume gewählt werden)
gamma = -9.81 #beachte Vorzeichen*
#beta = 121154000000
#lambda_ = beta
g = gamma
Create mesh and define function space
mesh = Mesh()
with XDMFFile(âmesh.xdmfâ) as infile:
infile.read(mesh)
File(âwinkel_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(âwinkel_facets.pvdâ).write(mf)
V = VectorFunctionSpace(mesh, âPâ, 1)
Define boundary condition
bcl = DirichletBC(V, Constant((0, 0, 0)), mf, 1)
bcr = DirichletBC(V, Constant((0, 0, 0)), mf, 3)
bcup = DirichletBC(V, Constant((0, 200, 0)), mf, 2)
###bcup is displacement? how do I get a Force to this physical surface?
bcs = [bcl, bcr, bcup]
Define strain and stress
def epsilon(u):
return 0.5*(nabla_grad(u) + nabla_grad(u).T)
#return sym(nabla_grad(u))
def sigma(u):
return lambda_nabla_div(u)Identity(d) + 2muepsilon(u)
Define variational problem
u = TrialFunction(V)
d = u.geometric_dimension() # space dimension
v = TestFunction(V)
f = Constant((0, rho*g+F, 0))
T = Constant((0, 0, 0)) #traction force
#Z = Constant((0, 100, 0)) #force on physical plane
a = inner(sigma(u), epsilon(v))*dx
L = dot(f, v)*dx + dot(T, v)*ds #+ dot(Z, v)*ds
Compute solution
u = Function(V)
solve(a == L, u, bcs)
Plot stress
s = sigma(u) - (1./3)*tr(sigma(u))Identity(d) # deviatoric stress
von_Mises = sqrt(3./2inner(s, s))
V = FunctionSpace(mesh, âPâ, 1)
von_Mises = project(von_Mises, V)
Compute magnitude of displacement
u_magnitude = sqrt(dot(u, u))
u_magnitude = project(u_magnitude, V)
print(âmin/max u:â,
u_magnitude.vector().get_local().min(),
u_magnitude.vector().get_local().max())
Save solution to file in VTK format
File(âwinkel/displacement_fenics.pvdâ) << u
File(âwinkel/von_mises_fenics.pvdâ) << von_Mises
File(âwinkel/magnitude_fenics.pvdâ) << u_magnitude