Skip to content

Commit

Permalink
Add a docstring to Element
Browse files Browse the repository at this point in the history
  • Loading branch information
adtzlr committed Jan 3, 2025
1 parent 3d7944d commit f85f581
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
13 changes: 11 additions & 2 deletions docs/felupe/element.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ Element

This module provides classes for the finite element formulations.

**Linear Elements**

.. currentmodule:: felupe

.. autosummary::

Element

**Linear Elements**

.. autosummary::

Line
Expand Down Expand Up @@ -50,6 +54,11 @@ This module provides classes for the finite element formulations.

**Detailed API Reference**

.. autoclass:: felupe.Element
:members:
:undoc-members:
:show-inheritance:

.. autoclass:: felupe.Line
:members:
:undoc-members:
Expand Down
41 changes: 41 additions & 0 deletions src/felupe/element/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,47 @@


class Element:
"""
Base-class for a finite element which provides methods for plotting.
Examples
--------
This example shows how to implement a hexahedron element.
.. pyvista-plot::
:force_static:
>>> import felupe as fem
>>> import numpy as np
>>>
>>> class Hexahedron(fem.Element):
... def __init__(self):
... a = [-1, 1, 1, -1, -1, 1, 1, -1]
... b = [-1, -1, 1, 1, -1, -1, 1, 1]
... c = [-1, -1, -1, -1, 1, 1, 1, 1]
... self.points = np.vstack([a, b, c]).T
...
... # additional attributes for plotting, optional
... self.cells = np.array([[0, 1, 2, 3, 4, 5, 6, 7]])
... self.cell_type = "hexahedron"
...
... def function(self, rst):
... r, s, t = rst
... a, b, c = self.points.T
... ar, bs, ct = 1 + a * r, 1 + b * s, 1 + c * t
... return (ar * bs * ct) / 8
...
... def gradient(self, rst):
... r, s, t = rst
... a, b, c = self.points.T
... ar, bs, ct = 1 + a * r, 1 + b * s, 1 + c * t
... return np.stack([a * bs * ct, ar * b * ct, ar * bs * c], axis=1)
>>>
>>> mesh = fem.Cube(n=6)
>>> element = Hexahedron()
>>> quadrature = fem.GaussLegendre(order=1, dim=3)
>>> region = fem.Region(mesh, element, quadrature)
"""

def view(self, point_data=None, cell_data=None, cell_type=None):
"""View the element with optional given dicts of point- and cell-data items.
Expand Down

0 comments on commit f85f581

Please sign in to comment.