Debian Codegraph @

demo/documented/hyperelasticity/cpp/HyperElasticity.ufl.rst

raw
1 UFL input for hyperleasticity
2 =============================
3
4 The first step is to define the variational problem at hand. We define
5 the variational problem in UFL terms in a separate form file
6 :download:`HyperElasticity.ufl`.
7
8 We are interested in solving for a discrete vector field in three
9 dimensions, so first we need the appropriate finite element space and
10 trial and test functions on this space::
11
12 from ufl_legacy import (Coefficient, derivative, det, ds, dx,
13 FiniteElement, grad, Identity, inner, ln,
14 TestFunction, TrialFunction, tr, tetrahedron,
15 VectorElement)
16
17 # Function spaces
18 element = VectorElement("Lagrange", tetrahedron, 1)
19 R = FiniteElement("Real", tetrahedron, 0)
20
21 # Trial and test functions
22 du = TrialFunction(element) # Incremental displacement
23 v = TestFunction(element) # Test function
24
25 Note that ``VectorElement`` creates a finite element space of vector
26 fields. The dimension of the vector field (the number of components)
27 is assumed to be the same as the spatial dimension (in this case 3),
28 unless otherwise specified.
29
30 Next, we will be needing functions for the boundary source ``B``, the
31 traction ``T`` and the displacement solution itself ``u``::
32
33 # Functions
34 u = Coefficient(element) # Displacement from previous iteration
35 B = Coefficient(element) # Body force per unit volume
36 T = Coefficient(element) # Traction force on the boundary
37
38 Now, we can define the kinematic quantities involved in the model::
39
40 # Kinematics
41 d = len(u)
42 I = Identity(d) # Identity tensor
43 F = I + grad(u) # Deformation gradient
44 C = F.T*F # Right Cauchy-Green tensor
45
46 # Invariants of deformation tensors
47 Ic = tr(C)
48 J = det(F)
49
50 Before defining the energy density and thus the total potential
51 energy, it only remains to specify constants for the elasticity
52 parameters::
53
54 # Elasticity parameters
55 mu = Coefficient(R)
56 lmbda = Coefficient(R)
57
58 Both the first variation of the potential energy, and the Jacobian of
59 the variation, can be automatically computed by a call to
60 ``derivative``::
61
62 # Stored strain energy density (compressible neo-Hookean model)
63 psi = (mu/2)*(Ic - 3) - mu*ln(J) + (lmbda/2)*(ln(J))**2
64
65 # Total potential energy
66 Pi = psi*dx - inner(B, u)*dx - inner(T, u)*ds
67
68 # First variation of Pi (directional derivative about u in the direction of v)
69 F = derivative(Pi, u, v)
70
71 # Compute Jacobian of F
72 J = derivative(F, u, du)
73
74 Note that ``derivative`` is here used with three arguments: the form
75 to be differentiated, the variable (function) we are supposed to
76 differentiate with respect too, and the direction the derivative is
77 taken in.
78
79 Before the form file can be used in the C++ program, it must be
80 compiled using FFC by running (on the command-line):
81
82 .. code-block:: sh
83
84 ffc -l dolfin HyperElasticity.ufl
85
86 Note the flag ``-l dolfin`` which tells FFC to generate
87 DOLFIN-specific wrappers that make it easy to access the generated
88 code from within DOLFIN.