Hi
I am solving a nonlinear problem on a cube (Single element). Here is my minimal work:
from dolfin import *
n = 1
mesh = BoxMesh(Point(0, 0, 0), Point(1, 1, 1), n,n,n)
#mesh = UnitCubeMesh.create(n,n,n,CellType.Type.hexahedron)
# Define boundary
class Left(SubDomain):
def inside(self, x, on_boundary):
return abs(x[0] - 0.0) < DOLFIN_EPS and on_boundary
class Right(SubDomain):
def inside(self, x, on_boundary):
return abs(x[0] - 1.0) < DOLFIN_EPS and on_boundary
#element for pressure field
Element1 = FiniteElement("CG", mesh.ufl_cell(), 1)
#element for displacement field
Element2 = VectorElement("CG", mesh.ufl_cell(), 2)
# Defining the mixed function space
W_elem = MixedElement([Element1, Element2])
W = FunctionSpace(mesh, W_elem)
left = Left()
right = Right()
boundaries = MeshFunction('size_t', mesh, mesh.topology().dim()-1)
subdomains = MeshFunction('size_t', mesh, mesh.topology().dim())
boundaries.set_all(0)
left.mark(boundaries, 1)
right.mark(boundaries, 2)
dx = Measure('dx', domain=mesh, subdomain_data=subdomains, metadata={'quadrature_degree': 2})
ds = Measure('ds', domain=mesh, subdomain_data=boundaries, metadata={'quadrature_degree': 2})
n = FacetNormal(mesh)
# Fixed boundary condition at the left face
u_0 = Constant((0.0,0.0,0.0))
bc_left = DirichletBC(W.sub(1), u_0, boundaries, 1)
dw = TrialFunction(W)
v = TestFunction(W)
w = Function(W)
p,u = split(w)
d = u.geometric_dimension()
I = Identity(d) # Identity tensor
F = I + grad(u) # Deformation gradient
C = F.T*F
Ic = tr(C)
J = det(F)
force = Constant((1000, 0.0, 0.0))
# Total potential energy
psi = 0.4e6*(Ic - 3.)*dx - p*(J - 1)*dx - dot(force, u)*ds(2)
F1 = derivative(psi, w, TestFunction(W))
Jacob = derivative(F1, w, TrialFunction(W))
problem = NonlinearVariationalProblem(F1, w, bc_left, Jacob)
solver = NonlinearVariationalSolver(problem)
solver.solve()
(p, u) = w.split(True)
file = File("displacement.pvd")
file << u
The question is when I change the element type to hexahedron by using:
mesh = UnitCubeMesh.create(n,n,n,CellType.Type.hexahedron)
I get strange results that seems wrong. Here is a figure showing how the results are different:
Any idea what is wrong with the hexahedron element?
Thanks!