symfem.functions

Basis function classes.

Module Contents

Classes

AnyFunction

A function.

ScalarFunction

A scalar-valued function.

VectorFunction

A vector-valued function.

MatrixFunction

A matrix-valued function.

Functions

_to_sympy_format(→ SympyFormat)

Convert to Sympy format used by these functions.

_check_equal(→ bool)

Check if two items are equal.

parse_function_input(→ AnyFunction)

Parse a function.

parse_function_list_input(→ List[AnyFunction])

Parse a list of functions.

Attributes

SingleSympyFormat

SympyFormat

_ValuesToSubstitute

ValuesToSubstitute

FunctionInput

symfem.functions.SingleSympyFormat
symfem.functions.SympyFormat
symfem.functions._ValuesToSubstitute
symfem.functions._to_sympy_format(item: Any) SympyFormat

Convert to Sympy format used by these functions.

Parameters:

item – The input item

Returns:

The item in Sympy format expected by functions

symfem.functions._check_equal(first: SympyFormat, second: SympyFormat) bool

Check if two items are equal.

Parameters:
  • first – The first item

  • second – The second item

Returns:

Are the two items equal?

class symfem.functions.AnyFunction(scalar: bool = False, vector: bool = False, matrix: bool = False)

Bases: abc.ABC

A function.

property shape: Tuple[int, Ellipsis]

Get the value shape of the function.

Returns:

The value shape

abstract __add__(other: Any)

Add.

abstract __radd__(other: Any)

Add.

abstract __sub__(other: Any)

Subtract.

abstract __rsub__(other: Any)

Subtract.

abstract __neg__()

Negate.

abstract __truediv__(other: Any)

Divide.

abstract __rtruediv__(other: Any)

Divide.

abstract __mul__(other: Any)

Multiply.

abstract __rmul__(other: Any)

Multiply.

abstract __matmul__(other: Any)

Multiply.

abstract __rmatmul__(other: Any)

Multiply.

abstract __pow__(other: Any)

Raise to a power.

abstract as_sympy() SympyFormat

Convert to a Sympy expression.

Returns:

A Sympy expression

abstract as_tex() str

Convert to a TeX expression.

Returns:

A TeX string

abstract subs(vars: symfem.symbols.AxisVariables, values: AnyFunction | _ValuesToSubstitute)

Substitute values into the function.

Parameters:
  • vars – The variables to substitute out

  • values – The value to substitute in

Returns:

The substituted function

abstract diff(variable: sympy.core.symbol.Symbol)

Differentiate the function.

Parameters:

variable – The variable to differentiate with respect to

Returns:

The differentiated function

abstract directional_derivative(direction: symfem.geometry.PointType)

Compute a directional derivative.

Parameters:

direction – The diection

Returns:

The directional differentiate

abstract jacobian_component(component: Tuple[int, int])

Compute a component of the jacobian.

Parameters:

component – The component

Returns:

The component of the jacobian

abstract jacobian(dim: int)

Compute the jacobian.

Parameters:

dim – The topological dimension of the cell

Returns:

The jacobian

abstract dot(other_in: FunctionInput)

Compute the dot product with another function.

Parameters:

other_in – The function to multiply with

Returns:

The product

abstract cross(other_in: FunctionInput)

Compute the cross product with another function.

Parameters:

other_in – The function to multiply with

Returns:

The cross product

abstract div()

Compute the div of the function.

Returns:

The divergence

abstract grad(dim: int)

Compute the grad of the function.

Returns:

The gradient

abstract curl()

Compute the curl of the function.

Returns:

The curl

abstract norm()

Compute the norm of the function.

Returns:

The norm

abstract integral(domain: symfem.references.Reference, vars: symfem.symbols.AxisVariablesNotSingle = x, dummy_vars: symfem.symbols.AxisVariablesNotSingle = t) ScalarFunction

Compute the integral of the function.

Parameters:
  • domain – The domain of the integral

  • vars – The variables to integrate with respect to

  • dummy_vars – The dummy variables to use inside the integral

Returns:

The integral

abstract with_floats() AnyFunction

Return a version the function with floats as coefficients.

Returns:

A version the function with floats as coefficients

abstract maximum_degree(cell: symfem.references.Reference) int

Return the maximum degree of the function on a reference cell.

This function returns the order of the lowerst order Lagrange space on the input cell that includes this function.

Parameters:

cell – The cell

Returns:

A version the function with floats as coefficients

__iter__() Iterator[AnyFunction]

Iterate through components of vector function.

integrate(*limits: Tuple[sympy.core.symbol.Symbol, int | sympy.core.expr.Expr, int | sympy.core.expr.Expr])

Integrate the function.

Parameters:

limits – The variables and limits

Returns:

The integral

det()

Compute the determinant.

Returns:

The deteminant

transpose()

Compute the transpose.

Returns:

The transpose

plot(reference: symfem.references.Reference, filename: str | List[str], dof_point: symfem.geometry.PointType | None = None, dof_direction: symfem.geometry.PointType | None = None, dof_entity: Tuple[int, int] | None = None, dof_n: int | None = None, value_scale: sympy.core.expr.Expr = sympy.Integer(1), plot_options: Dict[str, Any] = {}, **kwargs: Any)

Plot the function.

Parameters:
  • reference – The reference cell

  • filename – The file name

  • dof_point – The DOF point

  • dof_direction – The direction of the DOF

  • dof_entity – The entity the DOF is associated with

  • dof_n – The number of the DOF

  • value_scale – The scale factor for the function values

  • plot_options – Options for the plot

  • kwargs – Keyword arguments

plot_values(reference: symfem.references.Reference, img: Any, value_scale: sympy.core.expr.Expr = sympy.Integer(1), n: int = 6)

Plot the function’s values.

Parameters:
  • reference – The reference cell

  • img – The image to plot on

  • value_scale – The scale factor for the function values

  • n – The number of points per side for plotting

__len__()

Compute the determinant.

__getitem__(key) AnyFunction

Get a component or slice of the function.

_sympy_() SympyFormat

Convert to Sympy format.

__float__() float

Convert to a float.

__lt__(other: Any) bool

Check inequality.

__le__(other: Any) bool

Check inequality.

__gt__(other: Any) bool

Check inequality.

__ge__(other: Any) bool

Check inequality.

__repr__() str

Representation.

__eq__(other: Any) bool

Check if two functions are equal.

__ne__(other: Any) bool

Check if two functions are not equal.

symfem.functions.ValuesToSubstitute
class symfem.functions.ScalarFunction(f: int | sympy.core.expr.Expr)

Bases: AnyFunction

A scalar-valued function.

_f: sympy.core.expr.Expr
__add__(other: Any) ScalarFunction

Add.

__radd__(other: Any) ScalarFunction

Add.

__sub__(other: Any) ScalarFunction

Subtract.

__rsub__(other: Any) ScalarFunction

Subtract.

__truediv__(other: Any) ScalarFunction

Divide.

__rtruediv__(other: Any) ScalarFunction

Divide.

__mul__(other: Any) ScalarFunction

Multiply.

__rmul__(other: Any) ScalarFunction

Multiply.

__matmul__(other: Any)

Multiply.

__rmatmul__(other: Any)

Multiply.

__pow__(other: Any) ScalarFunction

Raise to a power.

__neg__() ScalarFunction

Negate.

as_sympy() SympyFormat

Convert to a sympy expression.

Returns:

A Sympy expression

as_tex() str

Convert to a TeX expression.

Returns:

A TeX string

subs(vars: symfem.symbols.AxisVariables, values: ValuesToSubstitute) ScalarFunction

Substitute values into the function.

Parameters:
  • vars – The variables to substitute out

  • values – The value to substitute in

Returns:

The substituted function

diff(variable: sympy.core.symbol.Symbol) ScalarFunction

Differentiate the function.

Parameters:

variable – The variable to differentiate with respect to

Returns:

The differentiated function

directional_derivative(direction: symfem.geometry.PointType) ScalarFunction

Compute a directional derivative.

Parameters:

direction – The diection

Returns:

The directional derivatve

jacobian_component(component: Tuple[int, int]) ScalarFunction

Compute a component of the jacobian.

Parameters:

component – The component

Returns:

The component of the jacobian

jacobian(dim: int) MatrixFunction

Compute the jacobian.

Parameters:

dim – The topological dimension of the cell

Returns:

The jacobian

dot(other_in: FunctionInput) ScalarFunction

Compute the dot product with another function.

Parameters:

other_in – The function to multiply with

Returns:

The product

cross(other_in: FunctionInput)

Compute the cross product with another function.

Parameters:

other_in – The function to multiply with

Returns:

The cross product

div()

Compute the div of the function.

Returns:

The divergence

grad(dim: int) VectorFunction

Compute the grad of the function.

Returns:

The gradient

curl()

Compute the curl of the function.

Returns:

The curl

norm() ScalarFunction

Compute the norm of the function.

Returns:

The norm

integral(domain: symfem.references.Reference, vars: symfem.symbols.AxisVariablesNotSingle = x, dummy_vars: symfem.symbols.AxisVariablesNotSingle = t) ScalarFunction

Compute the integral of the function.

Parameters:
  • domain – The domain of the integral

  • vars – The variables to integrate with respect to

  • dummy_vars – The dummy variables to use inside the integral

Returns:

The integral

integrate(*limits: Tuple[sympy.core.symbol.Symbol, int | sympy.core.expr.Expr, int | sympy.core.expr.Expr])

Integrate the function.

Parameters:

limits – The variables and limits

Returns:

The integral

plot_values(reference: symfem.references.Reference, img: Any, value_scale: sympy.core.expr.Expr = sympy.Integer(1), n: int = 6)

Plot the function’s values.

Parameters:
  • reference – The reference cell

  • img – The image to plot on

  • value_scale – The scale factor for the function values

  • n – The number of points per side for plotting

with_floats() AnyFunction

Return a version the function with floats as coefficients.

Returns:

A version the function with floats as coefficients

maximum_degree(cell: symfem.references.Reference) int

Return the maximum degree of the function on a reference cell.

This function returns the order of the lowerst order Lagrange space on the input cell that includes this function.

Parameters:

cell – The cell

Returns:

A version the function with floats as coefficients

class symfem.functions.VectorFunction(vec: Tuple[AnyFunction | int | sympy.core.expr.Expr, Ellipsis] | List[AnyFunction | int | sympy.core.expr.Expr])

Bases: AnyFunction

A vector-valued function.

property shape: Tuple[int, Ellipsis]

Get the value shape of the function.

Returns:

The value shape

_vec: tuple[ScalarFunction, Ellipsis]
__len__()

Get the length of the vector.

__getitem__(key) ScalarFunction | VectorFunction

Get a component or slice of the function.

__add__(other: Any) VectorFunction

Add.

__radd__(other: Any) VectorFunction

Add.

__sub__(other: Any) VectorFunction

Subtract.

__rsub__(other: Any) VectorFunction

Subtract.

__neg__() VectorFunction

Negate.

__truediv__(other: Any) VectorFunction

Divide.

__rtruediv__(other: Any) VectorFunction

Divide.

__mul__(other: Any) VectorFunction

Multiply.

__rmul__(other: Any) VectorFunction

Multiply.

__matmul__(other: Any) VectorFunction

Multiply.

__rmatmul__(other: Any) VectorFunction

Multiply.

__pow__(other: Any) VectorFunction

Raise to a power.

as_sympy() SympyFormat

Convert to a sympy expression.

Returns:

A Sympy expression

as_tex() str

Convert to a TeX expression.

Returns:

A TeX string

subs(vars: symfem.symbols.AxisVariables, values: ValuesToSubstitute) VectorFunction

Substitute values into the function.

Parameters:
  • vars – The variables to substitute out

  • values – The value to substitute in

Returns:

The substituted function

diff(variable: sympy.core.symbol.Symbol) VectorFunction

Differentiate the function.

Parameters:

variable – The variable to differentiate with respect to

Returns:

The differentiated function

abstract directional_derivative(direction: symfem.geometry.PointType)

Compute a directional derivative.

Parameters:

direction – The diection

Returns:

The directional derivatve

abstract jacobian_component(component: Tuple[int, int])

Compute a component of the jacobian.

Parameters:

component – The component

Returns:

The component of the jacobian

abstract jacobian(dim: int) MatrixFunction

Compute the jacobian.

Parameters:

dim – The topological dimension of the cell

Returns:

The jacobian

dot(other_in: FunctionInput) ScalarFunction

Compute the dot product with another function.

Parameters:

other_in – The function to multiply with

Returns:

The product

cross(other_in: FunctionInput) VectorFunction | ScalarFunction

Compute the cross product with another function.

Parameters:

other_in – The function to multiply with

Returns:

The cross product

div() ScalarFunction

Compute the div of the function.

Returns:

The divergence

grad()

Compute the grad of the function.

Returns:

The gradient

curl() VectorFunction

Compute the curl of the function.

Returns:

The curl

norm() ScalarFunction

Compute the norm of the function.

Returns:

The norm

abstract integral(domain: symfem.references.Reference, vars: symfem.symbols.AxisVariablesNotSingle = x, dummy_vars: symfem.symbols.AxisVariablesNotSingle = t) ScalarFunction

Compute the integral of the function.

Parameters:
  • domain – The domain of the integral

  • vars – The variables to integrate with respect to

  • dummy_vars – The dummy variables to use inside the integral

Returns:

The integral

__iter__()

Get iterable.

__next__()

Get next item.

plot_values(reference: symfem.references.Reference, img: Any, value_scale: sympy.core.expr.Expr = sympy.Integer(1), n: int = 6)

Plot the function’s values.

Parameters:
  • reference – The reference cell

  • img – The image to plot on

  • value_scale – The scale factor for the function values

  • n – The number of points per side for plotting

with_floats() AnyFunction

Return a version the function with floats as coefficients.

Returns:

A version the function with floats as coefficients

maximum_degree(cell: symfem.references.Reference) int

Return the maximum degree of the function on a reference cell.

This function returns the order of the lowerst order Lagrange space on the input cell that includes this function.

Parameters:

cell – The cell

Returns:

A version the function with floats as coefficients

class symfem.functions.MatrixFunction(mat: Tuple[Tuple[AnyFunction | int | sympy.core.expr.Expr, Ellipsis], Ellipsis] | Tuple[List[AnyFunction | int | sympy.core.expr.Expr], Ellipsis] | List[Tuple[AnyFunction | int | sympy.core.expr.Expr, Ellipsis]] | List[List[AnyFunction | int | sympy.core.expr.Expr]] | sympy.matrices.dense.MutableDenseMatrix)

Bases: AnyFunction

A matrix-valued function.

property shape: Tuple[int, Ellipsis]

Get the value shape of the function.

Returns:

The value shape

_mat: Tuple[Tuple[ScalarFunction, Ellipsis], Ellipsis]
__getitem__(key) ScalarFunction | VectorFunction

Get a component or slice of the function.

row(n: int) VectorFunction

Get a row of the matrix.

Parameters:

n – The row number

Returns:

The row of the matrix

col(n: int) VectorFunction

Get a colunm of the matrix.

Parameters:

n – The column number

Returns:

The column of the matrix

__add__(other: Any) MatrixFunction

Add.

__radd__(other: Any) MatrixFunction

Add.

__sub__(other: Any) MatrixFunction

Subtract.

__rsub__(other: Any) MatrixFunction

Subtract.

__neg__() MatrixFunction

Negate.

__truediv__(other: Any) MatrixFunction

Divide.

__rtruediv__(other: Any) MatrixFunction

Divide.

__mul__(other: Any) MatrixFunction

Multiply.

__rmul__(other: Any) MatrixFunction

Multiply.

__matmul__(other: Any) MatrixFunction

Multiply.

__rmatmul__(other: Any) MatrixFunction

Multiply.

__pow__(other: Any) MatrixFunction

Raise to a power.

as_sympy() SympyFormat

Convert to a sympy expression.

Returns:

A Sympy expression

as_tex() str

Convert to a TeX expression.

Returns:

A TeX string

subs(vars: symfem.symbols.AxisVariables, values: ValuesToSubstitute) MatrixFunction

Substitute values into the function.

Parameters:
  • vars – The variables to substitute out

  • values – The value to substitute in

Returns:

The substituted function

diff(variable: sympy.core.symbol.Symbol) MatrixFunction

Differentiate the function.

Parameters:

variable – The variable to differentiate with respect to

Returns:

The differentiated function

abstract directional_derivative(direction: symfem.geometry.PointType)

Compute a directional derivative.

Parameters:

direction – The diection

Returns:

The directional derivatve

abstract jacobian_component(component: Tuple[int, int])

Compute a component of the jacobian.

Parameters:

component – The component

Returns:

The component of the jacobian

abstract jacobian(dim: int)

Compute the jacobian.

Parameters:

dim – The topological dimension of the cell

Returns:

The jacobian

dot(other_in: FunctionInput) ScalarFunction

Compute the dot product with another function.

Parameters:

other_in – The function to multiply with

Returns:

The product

cross(other_in: FunctionInput)

Compute the cross product with another function.

Parameters:

other_in – The function to multiply with

Returns:

The cross product

div()

Compute the div of the function.

Returns:

The divergence

grad()

Compute the grad of the function.

Returns:

The gradient

curl()

Compute the curl of the function.

Returns:

The curl

abstract norm() ScalarFunction

Compute the norm of the function.

Returns:

The norm

abstract integral(domain: symfem.references.Reference, vars: symfem.symbols.AxisVariablesNotSingle = x, dummy_vars: symfem.symbols.AxisVariablesNotSingle = t) ScalarFunction

Compute the integral of the function.

Parameters:
  • domain – The domain of the integral

  • vars – The variables to integrate with respect to

  • dummy_vars – The dummy variables to use inside the integral

Returns:

The integral

det() ScalarFunction

Compute the determinant.

Returns:

The deteminant

transpose() MatrixFunction

Compute the transpose.

Returns:

The transpose

with_floats() AnyFunction

Return a version the function with floats as coefficients.

Returns:

A version the function with floats as coefficients

maximum_degree(cell: symfem.references.Reference) int

Return the maximum degree of the function on a reference cell.

This function returns the order of the lowerst order Lagrange space on the input cell that includes this function.

Parameters:

cell – The cell

Returns:

A version the function with floats as coefficients

symfem.functions.FunctionInput
symfem.functions.parse_function_input(f: FunctionInput) AnyFunction

Parse a function.

Parameters:

f – A function

Returns:

The function as a Symfem function

symfem.functions.parse_function_list_input(functions: List[FunctionInput] | Tuple[FunctionInput, Ellipsis]) List[AnyFunction]

Parse a list of functions.

Parameters:

functions – The functions

Returns:

The functions as Symfem functions