gel.kinematics

Interface to reading displacements from files, continuum mechanics.

The most useful aspect of this submodule is the class Kinematics which contains definitions of various fields in continuum mechanics, useful for defining material models in gel.mechanics. It also contains the proper functionality for allowing differentiating through such relationships to obtain stress tensors and for projecting $J$ into an appropriate element-wise basis.

 1r"""Interface to reading displacements from files, continuum mechanics.
 2
 3The most useful aspect of this submodule is the class `Kinematics`
 4which contains definitions of various fields in continuum mechanics,
 5useful for defining material models in `gel.mechanics`. It also contains
 6the proper functionality for allowing differentiating through such
 7relationships to obtain stress tensors and for projecting $J$ into an
 8appropriate element-wise basis.
 9"""
10from .header import *
11from .helper import *
12 
13
14class Kinematics:
15
16    def __init__(self, geo, u=None, differentiable_F=False):
17        """
18        Object that stores variables concerning the kinematics of the problem.
19
20        Needs a geometry geo that all this movement is happening with, and may
21        optionally provide a displacement u to impose. Otherwise, its u will
22        be computed from scratch.
23
24        In order to be able to differentiate computed quantities wrt. F, set
25        differentiable_F=True , ie. for computing stress tensors.
26        """
27        self.geo = geo
28        """`gel.geometry.Geometry` on which displacements are defined"""
29
30        self.u = None
31        r"""FEniCS function displacement field $\mathbf{u}$"""
32        if u is None:
33            self.u = Function(geo.V)
34        else:
35            self.u = u
36
37        I = Identity(self.u.geometric_dimension())
38
39        self.F = I + grad(self.u) 
40        r"""$\mathbf{F}=\mathbf{I}+\nabla\mathbf{u}$"""
41
42        self.differentiable_F = differentiable_F
43        r"""bool indicating if `F` is equipped for being the argument
44        that another form is differentiated with respect to
45        """
46        if differentiable_F:
47            # Be able to use it as argument of differentiation
48            self.F = variable(self.F)
49
50        self.C = self.F.T*self.F # Right Cauchy-Green
51        r"""$\mathbf{C}=\mathbf{F}^T\mathbf{F}$"""
52
53        self.Ic = tr(self.C)
54        r"""$I_1=\text{tr}\left(\mathbf{C}\right)$"""
55
56        self.Ju = det(self.F)
57        r"""$J=\det\left(\mathbf{F}\right)$"""
58
59    @property
60    def projected_J(self):
61        r"""Element-wise-DoF $J$ FEniCS function"""
62        return project(self.Ju, self.geo.DG0)
63
64
65def kinematics_from_file(geo, filename, *args, **kwargs):
66    """Returns `Kinematics` object from displacements "u" in xdmf `filename`.
67
68    * `geo`: `gel.geometry.Geometry` object with underlying meshes
69    matching that for the displacements in `filename`
70    * `filename`: str path to full-shape/checkpoing .xdmf file with
71    displacement data "U"
72    * `args`, `kwargs`: other arguments for the `Kinematics` constructor
73
74    Note that this will only read "u" at the first timestep.
75    """
76    u = load_shape(geo.V, filename, "u")
77
78    return Kinematics(geo, *args, u=u, **kwargs)
class Kinematics:
15class Kinematics:
16
17    def __init__(self, geo, u=None, differentiable_F=False):
18        """
19        Object that stores variables concerning the kinematics of the problem.
20
21        Needs a geometry geo that all this movement is happening with, and may
22        optionally provide a displacement u to impose. Otherwise, its u will
23        be computed from scratch.
24
25        In order to be able to differentiate computed quantities wrt. F, set
26        differentiable_F=True , ie. for computing stress tensors.
27        """
28        self.geo = geo
29        """`gel.geometry.Geometry` on which displacements are defined"""
30
31        self.u = None
32        r"""FEniCS function displacement field $\mathbf{u}$"""
33        if u is None:
34            self.u = Function(geo.V)
35        else:
36            self.u = u
37
38        I = Identity(self.u.geometric_dimension())
39
40        self.F = I + grad(self.u) 
41        r"""$\mathbf{F}=\mathbf{I}+\nabla\mathbf{u}$"""
42
43        self.differentiable_F = differentiable_F
44        r"""bool indicating if `F` is equipped for being the argument
45        that another form is differentiated with respect to
46        """
47        if differentiable_F:
48            # Be able to use it as argument of differentiation
49            self.F = variable(self.F)
50
51        self.C = self.F.T*self.F # Right Cauchy-Green
52        r"""$\mathbf{C}=\mathbf{F}^T\mathbf{F}$"""
53
54        self.Ic = tr(self.C)
55        r"""$I_1=\text{tr}\left(\mathbf{C}\right)$"""
56
57        self.Ju = det(self.F)
58        r"""$J=\det\left(\mathbf{F}\right)$"""
59
60    @property
61    def projected_J(self):
62        r"""Element-wise-DoF $J$ FEniCS function"""
63        return project(self.Ju, self.geo.DG0)
Kinematics(geo, u=None, differentiable_F=False)
17    def __init__(self, geo, u=None, differentiable_F=False):
18        """
19        Object that stores variables concerning the kinematics of the problem.
20
21        Needs a geometry geo that all this movement is happening with, and may
22        optionally provide a displacement u to impose. Otherwise, its u will
23        be computed from scratch.
24
25        In order to be able to differentiate computed quantities wrt. F, set
26        differentiable_F=True , ie. for computing stress tensors.
27        """
28        self.geo = geo
29        """`gel.geometry.Geometry` on which displacements are defined"""
30
31        self.u = None
32        r"""FEniCS function displacement field $\mathbf{u}$"""
33        if u is None:
34            self.u = Function(geo.V)
35        else:
36            self.u = u
37
38        I = Identity(self.u.geometric_dimension())
39
40        self.F = I + grad(self.u) 
41        r"""$\mathbf{F}=\mathbf{I}+\nabla\mathbf{u}$"""
42
43        self.differentiable_F = differentiable_F
44        r"""bool indicating if `F` is equipped for being the argument
45        that another form is differentiated with respect to
46        """
47        if differentiable_F:
48            # Be able to use it as argument of differentiation
49            self.F = variable(self.F)
50
51        self.C = self.F.T*self.F # Right Cauchy-Green
52        r"""$\mathbf{C}=\mathbf{F}^T\mathbf{F}$"""
53
54        self.Ic = tr(self.C)
55        r"""$I_1=\text{tr}\left(\mathbf{C}\right)$"""
56
57        self.Ju = det(self.F)
58        r"""$J=\det\left(\mathbf{F}\right)$"""

Object that stores variables concerning the kinematics of the problem.

Needs a geometry geo that all this movement is happening with, and may optionally provide a displacement u to impose. Otherwise, its u will be computed from scratch.

In order to be able to differentiate computed quantities wrt. F, set differentiable_F=True , ie. for computing stress tensors.

geo

gel.geometry.Geometry on which displacements are defined

u

FEniCS function displacement field $\mathbf{u}$

F

$\mathbf{F}=\mathbf{I}+\nabla\mathbf{u}$

differentiable_F

bool indicating if F is equipped for being the argument that another form is differentiated with respect to

C

$\mathbf{C}=\mathbf{F}^T\mathbf{F}$

Ic

$I_1=\text{tr}\left(\mathbf{C}\right)$

Ju

$J=\det\left(\mathbf{F}\right)$

projected_J
60    @property
61    def projected_J(self):
62        r"""Element-wise-DoF $J$ FEniCS function"""
63        return project(self.Ju, self.geo.DG0)

Element-wise-DoF $J$ FEniCS function

def kinematics_from_file(geo, filename, *args, **kwargs):
66def kinematics_from_file(geo, filename, *args, **kwargs):
67    """Returns `Kinematics` object from displacements "u" in xdmf `filename`.
68
69    * `geo`: `gel.geometry.Geometry` object with underlying meshes
70    matching that for the displacements in `filename`
71    * `filename`: str path to full-shape/checkpoing .xdmf file with
72    displacement data "U"
73    * `args`, `kwargs`: other arguments for the `Kinematics` constructor
74
75    Note that this will only read "u" at the first timestep.
76    """
77    u = load_shape(geo.V, filename, "u")
78
79    return Kinematics(geo, *args, u=u, **kwargs)

Returns Kinematics object from displacements "u" in xdmf filename.

  • geo: gel.geometry.Geometry object with underlying meshes matching that for the displacements in filename
  • filename: str path to full-shape/checkpoing .xdmf file with displacement data "U"
  • args, kwargs: other arguments for the Kinematics constructor

Note that this will only read "u" at the first timestep.