Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F107165508
demo_hyperelasticity.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Apr 5, 13:12
Size
3 KB
Mime Type
text/x-python
Expires
Mon, Apr 7, 13:12 (2 d)
Engine
blob
Format
Raw Data
Handle
25346211
Attached To
R9239 model_development_fenics
demo_hyperelasticity.py
View Options
""" This demo program solves a hyperelastic problem. It is implemented
in Python by Johan Hake following the C++ demo by Harish Narayanan"""
# Copyright (C) 2008-2010 Johan Hake and Garth N. Wells
#
# This file is part of DOLFIN.
#
# DOLFIN is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# DOLFIN is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
#
# Modified by Harish Narayanan 2009
# Modified by Anders Logg 2011
#
# First added: 2009-10-11
# Last changed: 2012-11-12
# Begin demo
from
dolfin
import
*
# Optimization options for the form compiler
parameters
[
"form_compiler"
][
"cpp_optimize"
]
=
True
# ffc_options = {"optimize": True, \
# "eliminate_zeros": True, \
# %"precompute_basis_const": True, \
# "precompute_ip_const": True}
# Create mesh and define function space
mesh
=
UnitCubeMesh
(
24
,
16
,
16
)
V
=
VectorFunctionSpace
(
mesh
,
"Lagrange"
,
1
)
# Mark boundary subdomians
left
=
CompiledSubDomain
(
"near(x[0], side) && on_boundary"
,
side
=
0.0
)
right
=
CompiledSubDomain
(
"near(x[0], side) && on_boundary"
,
side
=
1.0
)
# Define Dirichlet boundary (x = 0 or x = 1)
c
=
Expression
((
"0.0"
,
"0.0"
,
"0.0"
),
element
=
V
.
ufl_element
())
r
=
Expression
((
"scale*0.0"
,
"scale*(y0 + (x[1] - y0)*cos(theta) - (x[2] - z0)*sin(theta) - x[1])"
,
"scale*(z0 + (x[1] - y0)*sin(theta) + (x[2] - z0)*cos(theta) - x[2])"
),
scale
=
0.5
,
y0
=
0.5
,
z0
=
0.5
,
theta
=
pi
/
3
,
element
=
V
.
ufl_element
())
bcl
=
DirichletBC
(
V
,
c
,
left
)
bcr
=
DirichletBC
(
V
,
r
,
right
)
bcs
=
[
bcl
,
bcr
]
# Define functions
du
=
TrialFunction
(
V
)
# Incremental displacement
v
=
TestFunction
(
V
)
# Test function
u
=
Function
(
V
)
# Displacement from previous iteration
B
=
Constant
((
0.0
,
-
0.5
,
0.0
))
# Body force per unit volume
T
=
Constant
((
0.1
,
0.0
,
0.0
))
# Traction force on the boundary
# Kinematics
d
=
u
.
geometric_dimension
()
I
=
Identity
(
d
)
# Identity tensor
F
=
I
+
grad
(
u
)
# Deformation gradient
C
=
F
.
T
*
F
# Right Cauchy-Green tensor
# Invariants of deformation tensors
Ic
=
tr
(
C
)
J
=
det
(
F
)
# Elasticity parameters
E
,
nu
=
10.0
,
0.3
mu
,
lmbda
=
Constant
(
E
/
(
2
*
(
1
+
nu
))),
Constant
(
E
*
nu
/
((
1
+
nu
)
*
(
1
-
2
*
nu
)))
# Stored strain energy density (compressible neo-Hookean model)
psi
=
(
mu
/
2
)
*
(
Ic
-
3
)
-
mu
*
ln
(
J
)
+
(
lmbda
/
2
)
*
(
ln
(
J
))
**
2
# Total potential energy
Pi
=
psi
*
dx
-
dot
(
B
,
u
)
*
dx
-
dot
(
T
,
u
)
*
ds
# Compute first variation of Pi (directional derivative about u in the direction of v)
F
=
derivative
(
Pi
,
u
,
v
)
# Compute Jacobian of F
J
=
derivative
(
F
,
u
,
du
)
# Solve variational problem
solve
(
F
==
0
,
u
,
bcs
,
J
=
J
)
# Save solution in VTK format
file
=
File
(
"displacement.pvd"
);
file
<<
u
;
# Plot and hold solution
plot
(
u
,
mode
=
"displacement"
,
interactive
=
True
)
Event Timeline
Log In to Comment