Shapefunctions

The shapefunctions module contains generic shapefunctions that can be used to approximate distributed systems without giving any information about the systems themselves. This is achieved by projecting them on generic, piecewise smooth functions.

class ShapeFunction(*args, **kwargs)[source]

Base class for approximation functions with compact support.

When a continuous variable of e.g. space and time x(z,t) is decomposed in a series \tilde x = \sum\limits_{i=1}^{\infty} \varphi_i(z) c_i(t) the \varphi_i(z) denote the shape functions.

classmethod cure_interval(interval, **kwargs)[source]

Create a network or set of functions from this class and return an approximation base (Base) on the given interval.

The kwargs may hold the order of approximation or the amount of functions to use. Use them in your child class as needed.

If you don’t need to now from which class this method is called, overwrite the @classmethod decorator in the child class with the @staticmethod decorator.

Short reference: Inside a @staticmethod you know nothing about the class from which it is called and you can just play with the given parameters. Inside a @classmethod you can additionally operate on the class, since the first parameter is always the class itself.

Parameters:
  • interval (Domain) – Interval to cure.
  • **kwargs – Various arguments, depending on the implementation.
Returns:

Approximation base, generated by the created shape functions.

Return type:

Base

Shapefunction Types

class LagrangeFirstOrder(start, top, end, **kwargs)[source]

Bases: pyinduct.shapefunctions.ShapeFunction

Lagrangian shape functions of order 1.

Parameters:
  • start – Start node
  • top – Top node, where f(x) = 1
  • end – End node
Keyword Arguments:
 
  • half
  • right_border
  • left_border

Example plot of the functions funcs generated with

>>> nodes, funcs = cure_interval(LagrangeFirstOrder, (0, 1), node_count=7)
../_images/lag1st_order.png
static cure_interval(domain, **kwargs)[source]

Cure the given interval with LagrangeFirstOrder shape functions.

Parameters:domain (Domain) – Domain to be cured, the points specify the nodes which will be used.
Returns:Base, generated by a set of LagrangeFirstOrder shapefunctions.
Return type:pi.Base
class LagrangeSecondOrder(start, mid, end, **kwargs)[source]

Bases: pyinduct.shapefunctions.ShapeFunction

Lagrangian shape functions of order 2.

Parameters:
  • start – start node
  • mid – middle node, where f(x) = 1
  • end – end node
Keyword Arguments:
 
  • curvature (str) – “concave” or “convex”
  • half (str) – Generate only “left” or “right” half.
  • domain (tuple) – Domain on which the function is defined.

Example plot of the functions funcs generated with

>>> nodes, funcs = cure_interval(LagrangeSecondOrder, (0, 1), node_count=7)
../_images/lag2nd_order.png
static cure_interval(domain, **kwargs)[source]

Hint function that will cure the given interval with LagrangeSecondOrder.

Parameters:domain (Domain) – domain to be cured
Returns:(domain, funcs), where funcs is set of LagrangeSecondOrder shapefunctions.
Return type:tuple
class LagrangeNthOrder(order, nodes, left=False, right=False, mid_num=None, boundary=None, domain=(-inf, inf))[source]

Bases: pyinduct.shapefunctions.ShapeFunction

Lagrangian shape functions of order n.

Note

The polynomials between the boundary-polynomials and the peak-polynomials, respectively between peak-polynomials and peak-polynomials, are called mid-polynomials.

Parameters:
  • order (int) – Order of the lagrangian polynomials.
  • nodes (numpy.array) – Nodes on which the piecewise defined functions have to be one/zero. Length of nodes must be either order * 2 + 1 (for peak-polynomials, see notes) or ‘order +1’ (for boundary- and mid-polynomials).
  • left (bool) – State the first node (nodes[0]) to be the left boundary of the considered domain.
  • right (bool) – State the last node (nodes[-1]) to be the right boundary of the considered domain.
  • mid_num (int) – Local number of mid-polynomials (see notes) to use (only used for order >= 2). \text{mid\_num} \in \{ 1, ..., \text{order} - 1 \}
  • boundary (str) – provide “left” or “right” to instantiate the according boundary-polynomial.
  • domain (tuple) – Domain of the function.

Example plot of the functions funcs generated with

>>> nodes, funcs = pi.cure_interval(sh.LagrangeNthOrder, (0, 1), node_count=9, order=4)
../_images/lag4th_order.png
static cure_interval(domain, **kwargs)[source]

Hint function that will cure the given interval with LagrangeNthOrder. Length of the domain argument L must satisfy the condition

L = 1 + (1 + n) order \quad \forall n \in \mathbb N.

E.g. n - order = 1 -> L \in \{2, 3, 4, 5, ...\} - order = 2 -> L \in \{3, 5, 7, 9, ...\} - order = 3 -> L \in \{4, 7, 10, 13, ...\} - and so on.

Parameters:
  • domain (Domain) – Domain to be cured.
  • order (int) – Order of the lagrange polynomials.
Returns:

Base, generated by the created shapefunctions.

Return type:

Base

Curing an Interval

All classes contained in this module can easily be used to cure a given interval. For example let’s approximate the interval from z=0 to z=1 with 3 piecewise linear functions:

>>> from pyinduct import Domain, LagrangeFirstOder
>>> nodes = Domain(bounds0(0, 1), num=3)
>>> list(nodes)
[0.0, 0.5, 1.0]
>>> funcs = LagrangeFirstOrder.cure_interval(nodes)
cure_interval(shapefunction_class, interval, node_count=None, node_distance=None, **kwargs)[source]

Use shape functions to cure an interval with either node_count nodes or nodes with node_distance .

Warning

This function is now deprecated and will be removed in future versions.
Use ShapeFunction.cure_interval() instead.
Parameters:
  • shapefunction_class (class) – Class to cure the interval (e.g. LagrangeFirstOrder). The given class has to provide a method called cure_interval().
  • interval (tuple) – Limits that constrain the interval.
  • node_count (int) – Amount of nodes to use.
  • node_distance (numbers.Number) – Distance of nodes.
  • **kwargs – Various arguments that are passed to cure_interval() of the given class.

Note

Either node_count or node_node_distance can be specified. If both are given and are not consistent, an exception will be raised by Domain.

Raises:
  • TypeError – If given class does not provide a static
  • cure_hint() method.
Returns:

(domain, funcs): Where domain is a Domain instance and funcs is a list of (e.g. LagrangeFirstOrder) shapefunctions.

Return type:

tuple