Hello everyone, I’m trying to adapt Hertzian contact 3D code given here into 2D. I am satisfied with the visualization results but the values are not matching with the theoretical values.
Maximum pressure FEniCS : 0.37048 Hertz: 1.39916
Applied force FEniCS : 0.38579 Hertz: 0.02930
Here is MWE -
from dolfin import *
from mshr import *
import numpy as np
domain = Rectangle(Point(-1, -1),Point(1, 1))
mesh = generate_mesh(domain, 10)
class Top(SubDomain):
def inside(self, x, on_boundary):
return near(x[1], 1) and on_boundary
def bottom(x, on_boundary):
return near(x[1], -1) and on_boundary
facets = MeshFunction("size_t", mesh, 1)
facets.set_all(0)
Top().mark(facets, 1)
ds = Measure('ds', subdomain_data=facets)
R = 0.5
d = 0.02
obstacle = Expression("-d+(pow(x[0],2))/2/R", d=d, R=R, degree=2)
V = VectorFunctionSpace(mesh, "CG", 1)
V2 = FunctionSpace(mesh, "CG", 1)
V0 = FunctionSpace(mesh, "DG", 0)
u = Function(V, name="Displacement")
du = TrialFunction(V)
u_ = TestFunction(V)
gap = Function(V2, name="Gap")
p = Function(V0, name="Contact pressure")
bc =[DirichletBC(V, Constant((0., 0.)), bottom)]
E = Constant(10.)
nu = Constant(0.3)
mu = E/2/(1+nu)
lmbda = E*nu/(1+nu)/(1-2*nu)
def eps(v):
return sym(grad(v))
def sigma(v):
return lmbda*tr(eps(v))*Identity(2) + 2.0*mu*eps(v)
def ppos(x):
return (x+abs(x))/2.
pen = Constant(1e4)
form = inner(sigma(u), eps(u_))*dx + pen*dot(u_[1], ppos(u[1]-obstacle))*ds(1)
J = derivative(form, u, du)
parameters["form_compiler"]["representation"] = 'quadrature'
parameters["form_compiler"]["representation"] = "tsfc"
import warnings
from ffc.quadrature.deprecation import QuadratureRepresentationDeprecationWarning
warnings.simplefilter("ignore", QuadratureRepresentationDeprecationWarning)
solver_parameters = {
"newton_solver": {
"linear_solver": "cg",
"preconditioner" : "ilu",
"relative_tolerance" : 1e-10,
"absolute_tolerance" : 1e-15,
"maximum_iterations" : 30
}
}
form_compiler_parameters = {
"cpp_optimize": True,
"representation": "quadrature",
"quadrature_degree": 2
}
solve(form == 0 , u , bc , J=J , solver_parameters= solver_parameters,form_compiler_parameters= form_compiler_parameters)
p.assign(-project(sigma(u)[1, 1], V0))
gap.assign(project(obstacle-u[1], V2))
a = sqrt(R*d)
F = 4/3.*float(E)/(1-float(nu)**2)*a*d
p0 = 3*F/(2*pi*a**2)
print("Maximum pressure FE: {0:8.5f} Hertz: {1:8.5f}".format(max(np.abs(p.vector().get_local())), p0))
print("Applied force FE: {0:8.5f} Hertz: {1:8.5f}".format(4*assemble(p*ds(1)), F))
Any suggestions would be highly appreciable.
Thanks.