Skip to content

Commit

Permalink
Fix doctests
Browse files Browse the repository at this point in the history
  • Loading branch information
adtzlr committed Apr 19, 2024
1 parent 9800082 commit 682f7e3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 36 deletions.
6 changes: 3 additions & 3 deletions src/felupe/assembly/_integral.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class IntegralForm:
created.
>>> import felupe as fem
>>>
>>> mesh = fem.Cube(n=11)
>>> region = fem.RegionHexahedron(mesh)
>>> displacement = fem.Field(region, dim=3)
Expand All @@ -129,7 +129,7 @@ class IntegralForm:
>>> import numpy as np
>>> from felupe.math import cdya, dya
>>>
>>> mu, lmbda = 1.0, 2.0
>>> I = np.eye(3).reshape(3, 3, 1, 1)
>>> dSdE = 2 * mu * cdya(I, I) + lmbda * dya(I, I)
Expand Down Expand Up @@ -169,7 +169,7 @@ class IntegralForm:
>>> form = fem.IntegralForm([dSdE], v=field, dV=region.dV, u=field)
>>> values = form.integrate(parallel=False)
>>> values.shape
>>> values[0].shape
(8, 3, 8, 3, 1000)
The cell-wise stiffness matrices are re-used to assemble the sparse system stiffness
Expand Down
70 changes: 37 additions & 33 deletions src/felupe/assembly/expression/_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,18 @@ def FormExpressionDecorator(v, u=None, dx=None, kwargs=None, parallel=False):
pre-computed array to be passed. The bilinear form of linear elasticity serves as a
reference example for the demonstration on how to use this feature of FElupe. The
stiffness matrix is assembled for a unit cube out of hexahedrons.
>>> import felupe as fem
>>>
>>> mesh = fem.Cube(n=11)
>>> region = fem.RegionHexahedron(mesh)
>>> displacement = fem.Field(region, dim=3)
>>> field = fem.FieldContainer([displacement])
>>>
>>> boundaries, loadcase = fem.dof.uniaxial(field, move=0.5, clamped=True)
.. pyvista-plot::
:context:
>>> import felupe as fem
>>>
>>> mesh = fem.Cube(n=6)
>>> region = fem.RegionHexahedron(mesh)
>>> displacement = fem.Field(region, dim=3)
>>> field = fem.FieldContainer([displacement])
>>>
>>> boundaries, loadcase = fem.dof.uniaxial(field, move=0.5, clamped=True)
The bilinear form of linear elasticity is defined as
Expand Down Expand Up @@ -107,30 +110,31 @@ def FormExpressionDecorator(v, u=None, dx=None, kwargs=None, parallel=False):
to ``v`` and ``u`` along with the gradient flags for both fields. Arguments as well
as keyword arguments of the weak-form may be defined inside the decorator or as part
of the assembly arguments.
>>> from felupe.math import ddot, trace, sym, grad
>>>
>>> @fem.Form(
>>> v=field, u=field, kwargs={"μ": 1.0, "λ": 2.0}
>>> )
>>> def bilinearform():
>>> "A container for a bilinear form."
>>>
>>> def linear_elasticity(v, u, μ, λ):
>>> "Linear elasticity."
>>>
>>> δε, ε = sym(grad(v)), sym(grad(u))
>>> return 2 * μ * ddot(δε, ε) + λ * trace(δε) * trace(ε)
>>>
>>> return [linear_elasticity,]
>>>
>>> stiffness_matrix = bilinearform.assemble(v=field, u=field, parallel=False)
>>>
>>> system = fem.solve.partition(
>>> field, stiffness_matrix, dof1=loadcase["dof1"], dof0=loadcase["dof0"]
>>> )
>>> field += fem.solve.solve(*system, ext0=loadcase["ext0"])
>>> field.plot("Principal Values of Logarithmic Strain").show()
.. pyvista-plot::
:context:
>>> from felupe.math import ddot, trace, sym, grad
>>>
>>> @fem.Form(v=field, u=field, kwargs={"μ": 1.0, "λ": 2.0})
... def bilinearform():
... "A container for a bilinear form."
...
... def linear_elasticity(v, u, μ, λ):
... "Linear elasticity."
...
... δε, ε = sym(grad(v)), sym(grad(u))
... return 2 * μ * ddot(δε, ε) + λ * trace(δε) * trace(ε)
...
... return [linear_elasticity,]
>>>
>>> stiffness_matrix = bilinearform.assemble(v=field, u=field, parallel=False)
>>>
>>> system = fem.solve.partition(
... field, stiffness_matrix, dof1=loadcase["dof1"], dof0=loadcase["dof0"]
... )
>>> field += fem.solve.solve(*system, ext0=loadcase["ext0"])
>>> field.plot("Principal Values of Logarithmic Strain").show()
"""

Expand Down

0 comments on commit 682f7e3

Please sign in to comment.