:py:mod:`symfem.functions` ========================== .. py:module:: symfem.functions .. autoapi-nested-parse:: Basis function classes. Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: symfem.functions.AnyFunction symfem.functions.ScalarFunction symfem.functions.VectorFunction symfem.functions.MatrixFunction Functions ~~~~~~~~~ .. autoapisummary:: symfem.functions._to_sympy_format symfem.functions._check_equal symfem.functions.parse_function_input symfem.functions.parse_function_list_input Attributes ~~~~~~~~~~ .. autoapisummary:: symfem.functions.SingleSympyFormat symfem.functions.SympyFormat symfem.functions._ValuesToSubstitute symfem.functions.ValuesToSubstitute symfem.functions.FunctionInput .. py:data:: SingleSympyFormat .. py:data:: SympyFormat .. py:data:: _ValuesToSubstitute .. py:function:: _to_sympy_format(item: Any) -> SympyFormat Convert to Sympy format used by these functions. :param item: The input item :returns: The item in Sympy format expected by functions .. py:function:: _check_equal(first: SympyFormat, second: SympyFormat) -> bool Check if two items are equal. :param first: The first item :param second: The second item :returns: Are the two items equal? .. py:class:: AnyFunction(scalar: bool = False, vector: bool = False, matrix: bool = False) Bases: :py:obj:`abc.ABC` A function. .. py:property:: shape :type: Tuple[int, Ellipsis] Get the value shape of the function. :returns: The value shape .. py:method:: __add__(other: Any) :abstractmethod: Add. .. py:method:: __radd__(other: Any) :abstractmethod: Add. .. py:method:: __sub__(other: Any) :abstractmethod: Subtract. .. py:method:: __rsub__(other: Any) :abstractmethod: Subtract. .. py:method:: __neg__() :abstractmethod: Negate. .. py:method:: __truediv__(other: Any) :abstractmethod: Divide. .. py:method:: __rtruediv__(other: Any) :abstractmethod: Divide. .. py:method:: __mul__(other: Any) :abstractmethod: Multiply. .. py:method:: __rmul__(other: Any) :abstractmethod: Multiply. .. py:method:: __matmul__(other: Any) :abstractmethod: Multiply. .. py:method:: __rmatmul__(other: Any) :abstractmethod: Multiply. .. py:method:: __pow__(other: Any) :abstractmethod: Raise to a power. .. py:method:: as_sympy() -> SympyFormat :abstractmethod: Convert to a Sympy expression. :returns: A Sympy expression .. py:method:: as_tex() -> str :abstractmethod: Convert to a TeX expression. :returns: A TeX string .. py:method:: subs(vars: symfem.symbols.AxisVariables, values: Union[AnyFunction, _ValuesToSubstitute]) :abstractmethod: Substitute values into the function. :param vars: The variables to substitute out :param values: The value to substitute in :returns: The substituted function .. py:method:: diff(variable: sympy.core.symbol.Symbol) :abstractmethod: Differentiate the function. :param variable: The variable to differentiate with respect to :returns: The differentiated function .. py:method:: directional_derivative(direction: symfem.geometry.PointType) :abstractmethod: Compute a directional derivative. :param direction: The diection :returns: The directional differentiate .. py:method:: jacobian_component(component: Tuple[int, int]) :abstractmethod: Compute a component of the jacobian. :param component: The component :returns: The component of the jacobian .. py:method:: jacobian(dim: int) :abstractmethod: Compute the jacobian. :param dim: The topological dimension of the cell :returns: The jacobian .. py:method:: dot(other_in: FunctionInput) :abstractmethod: Compute the dot product with another function. :param other_in: The function to multiply with :returns: The product .. py:method:: cross(other_in: FunctionInput) :abstractmethod: Compute the cross product with another function. :param other_in: The function to multiply with :returns: The cross product .. py:method:: div() :abstractmethod: Compute the div of the function. :returns: The divergence .. py:method:: grad(dim: int) :abstractmethod: Compute the grad of the function. :returns: The gradient .. py:method:: curl() :abstractmethod: Compute the curl of the function. :returns: The curl .. py:method:: norm() :abstractmethod: Compute the norm of the function. :returns: The norm .. py:method:: integral(domain: symfem.references.Reference, vars: symfem.symbols.AxisVariablesNotSingle = x, dummy_vars: symfem.symbols.AxisVariablesNotSingle = t) -> ScalarFunction :abstractmethod: Compute the integral of the function. :param domain: The domain of the integral :param vars: The variables to integrate with respect to :param dummy_vars: The dummy variables to use inside the integral :returns: The integral .. py:method:: with_floats() -> AnyFunction :abstractmethod: Return a version the function with floats as coefficients. :returns: A version the function with floats as coefficients .. py:method:: maximum_degree(cell: symfem.references.Reference) -> int :abstractmethod: 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. :param cell: The cell :returns: A version the function with floats as coefficients .. py:method:: __iter__() -> Iterator[AnyFunction] Iterate through components of vector function. .. py:method:: integrate(*limits: Tuple[sympy.core.symbol.Symbol, Union[int, sympy.core.expr.Expr], Union[int, sympy.core.expr.Expr]]) Integrate the function. :param limits: The variables and limits :returns: The integral .. py:method:: det() Compute the determinant. :returns: The deteminant .. py:method:: transpose() Compute the transpose. :returns: The transpose .. py:method:: plot(reference: symfem.references.Reference, filename: Union[str, List[str]], dof_point: Optional[symfem.geometry.PointType] = None, dof_direction: Optional[symfem.geometry.PointType] = None, dof_entity: Optional[Tuple[int, int]] = None, dof_n: Optional[int] = None, value_scale: sympy.core.expr.Expr = sympy.Integer(1), plot_options: Dict[str, Any] = {}, **kwargs: Any) Plot the function. :param reference: The reference cell :param filename: The file name :param dof_point: The DOF point :param dof_direction: The direction of the DOF :param dof_entity: The entity the DOF is associated with :param dof_n: The number of the DOF :param value_scale: The scale factor for the function values :param plot_options: Options for the plot :param kwargs: Keyword arguments .. py:method:: 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. :param reference: The reference cell :param img: The image to plot on :param value_scale: The scale factor for the function values :param n: The number of points per side for plotting .. py:method:: __len__() Compute the determinant. .. py:method:: __getitem__(key) -> AnyFunction Get a component or slice of the function. .. py:method:: _sympy_() -> SympyFormat Convert to Sympy format. .. py:method:: __float__() -> float Convert to a float. .. py:method:: __lt__(other: Any) -> bool Check inequality. .. py:method:: __le__(other: Any) -> bool Check inequality. .. py:method:: __gt__(other: Any) -> bool Check inequality. .. py:method:: __ge__(other: Any) -> bool Check inequality. .. py:method:: __repr__() -> str Representation. .. py:method:: __eq__(other: Any) -> bool Check if two functions are equal. .. py:method:: __ne__(other: Any) -> bool Check if two functions are not equal. .. py:data:: ValuesToSubstitute .. py:class:: ScalarFunction(f: Union[int, sympy.core.expr.Expr]) Bases: :py:obj:`AnyFunction` A scalar-valued function. .. py:attribute:: _f :type: sympy.core.expr.Expr .. py:method:: __add__(other: Any) -> ScalarFunction Add. .. py:method:: __radd__(other: Any) -> ScalarFunction Add. .. py:method:: __sub__(other: Any) -> ScalarFunction Subtract. .. py:method:: __rsub__(other: Any) -> ScalarFunction Subtract. .. py:method:: __truediv__(other: Any) -> ScalarFunction Divide. .. py:method:: __rtruediv__(other: Any) -> ScalarFunction Divide. .. py:method:: __mul__(other: Any) -> ScalarFunction Multiply. .. py:method:: __rmul__(other: Any) -> ScalarFunction Multiply. .. py:method:: __matmul__(other: Any) Multiply. .. py:method:: __rmatmul__(other: Any) Multiply. .. py:method:: __pow__(other: Any) -> ScalarFunction Raise to a power. .. py:method:: __neg__() -> ScalarFunction Negate. .. py:method:: as_sympy() -> SympyFormat Convert to a sympy expression. :returns: A Sympy expression .. py:method:: as_tex() -> str Convert to a TeX expression. :returns: A TeX string .. py:method:: subs(vars: symfem.symbols.AxisVariables, values: ValuesToSubstitute) -> ScalarFunction Substitute values into the function. :param vars: The variables to substitute out :param values: The value to substitute in :returns: The substituted function .. py:method:: diff(variable: sympy.core.symbol.Symbol) -> ScalarFunction Differentiate the function. :param variable: The variable to differentiate with respect to :returns: The differentiated function .. py:method:: directional_derivative(direction: symfem.geometry.PointType) -> ScalarFunction Compute a directional derivative. :param direction: The diection :returns: The directional derivatve .. py:method:: jacobian_component(component: Tuple[int, int]) -> ScalarFunction Compute a component of the jacobian. :param component: The component :returns: The component of the jacobian .. py:method:: jacobian(dim: int) -> MatrixFunction Compute the jacobian. :param dim: The topological dimension of the cell :returns: The jacobian .. py:method:: dot(other_in: FunctionInput) -> ScalarFunction Compute the dot product with another function. :param other_in: The function to multiply with :returns: The product .. py:method:: cross(other_in: FunctionInput) Compute the cross product with another function. :param other_in: The function to multiply with :returns: The cross product .. py:method:: div() Compute the div of the function. :returns: The divergence .. py:method:: grad(dim: int) -> VectorFunction Compute the grad of the function. :returns: The gradient .. py:method:: curl() Compute the curl of the function. :returns: The curl .. py:method:: norm() -> ScalarFunction Compute the norm of the function. :returns: The norm .. py:method:: integral(domain: symfem.references.Reference, vars: symfem.symbols.AxisVariablesNotSingle = x, dummy_vars: symfem.symbols.AxisVariablesNotSingle = t) -> ScalarFunction Compute the integral of the function. :param domain: The domain of the integral :param vars: The variables to integrate with respect to :param dummy_vars: The dummy variables to use inside the integral :returns: The integral .. py:method:: integrate(*limits: Tuple[sympy.core.symbol.Symbol, Union[int, sympy.core.expr.Expr], Union[int, sympy.core.expr.Expr]]) Integrate the function. :param limits: The variables and limits :returns: The integral .. py:method:: 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. :param reference: The reference cell :param img: The image to plot on :param value_scale: The scale factor for the function values :param n: The number of points per side for plotting .. py:method:: with_floats() -> AnyFunction Return a version the function with floats as coefficients. :returns: A version the function with floats as coefficients .. py:method:: 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. :param cell: The cell :returns: A version the function with floats as coefficients .. py:class:: VectorFunction(vec: Union[Tuple[Union[AnyFunction, int, sympy.core.expr.Expr], Ellipsis], List[Union[AnyFunction, int, sympy.core.expr.Expr]]]) Bases: :py:obj:`AnyFunction` A vector-valued function. .. py:property:: shape :type: Tuple[int, Ellipsis] Get the value shape of the function. :returns: The value shape .. py:attribute:: _vec :type: tuple[ScalarFunction, Ellipsis] .. py:method:: __len__() Get the length of the vector. .. py:method:: __getitem__(key) -> Union[ScalarFunction, VectorFunction] Get a component or slice of the function. .. py:method:: __add__(other: Any) -> VectorFunction Add. .. py:method:: __radd__(other: Any) -> VectorFunction Add. .. py:method:: __sub__(other: Any) -> VectorFunction Subtract. .. py:method:: __rsub__(other: Any) -> VectorFunction Subtract. .. py:method:: __neg__() -> VectorFunction Negate. .. py:method:: __truediv__(other: Any) -> VectorFunction Divide. .. py:method:: __rtruediv__(other: Any) -> VectorFunction Divide. .. py:method:: __mul__(other: Any) -> VectorFunction Multiply. .. py:method:: __rmul__(other: Any) -> VectorFunction Multiply. .. py:method:: __matmul__(other: Any) -> VectorFunction Multiply. .. py:method:: __rmatmul__(other: Any) -> VectorFunction Multiply. .. py:method:: __pow__(other: Any) -> VectorFunction Raise to a power. .. py:method:: as_sympy() -> SympyFormat Convert to a sympy expression. :returns: A Sympy expression .. py:method:: as_tex() -> str Convert to a TeX expression. :returns: A TeX string .. py:method:: subs(vars: symfem.symbols.AxisVariables, values: ValuesToSubstitute) -> VectorFunction Substitute values into the function. :param vars: The variables to substitute out :param values: The value to substitute in :returns: The substituted function .. py:method:: diff(variable: sympy.core.symbol.Symbol) -> VectorFunction Differentiate the function. :param variable: The variable to differentiate with respect to :returns: The differentiated function .. py:method:: directional_derivative(direction: symfem.geometry.PointType) :abstractmethod: Compute a directional derivative. :param direction: The diection :returns: The directional derivatve .. py:method:: jacobian_component(component: Tuple[int, int]) :abstractmethod: Compute a component of the jacobian. :param component: The component :returns: The component of the jacobian .. py:method:: jacobian(dim: int) -> MatrixFunction :abstractmethod: Compute the jacobian. :param dim: The topological dimension of the cell :returns: The jacobian .. py:method:: dot(other_in: FunctionInput) -> ScalarFunction Compute the dot product with another function. :param other_in: The function to multiply with :returns: The product .. py:method:: cross(other_in: FunctionInput) -> Union[VectorFunction, ScalarFunction] Compute the cross product with another function. :param other_in: The function to multiply with :returns: The cross product .. py:method:: div() -> ScalarFunction Compute the div of the function. :returns: The divergence .. py:method:: grad() Compute the grad of the function. :returns: The gradient .. py:method:: curl() -> VectorFunction Compute the curl of the function. :returns: The curl .. py:method:: norm() -> ScalarFunction Compute the norm of the function. :returns: The norm .. py:method:: integral(domain: symfem.references.Reference, vars: symfem.symbols.AxisVariablesNotSingle = x, dummy_vars: symfem.symbols.AxisVariablesNotSingle = t) -> ScalarFunction :abstractmethod: Compute the integral of the function. :param domain: The domain of the integral :param vars: The variables to integrate with respect to :param dummy_vars: The dummy variables to use inside the integral :returns: The integral .. py:method:: __iter__() Get iterable. .. py:method:: __next__() Get next item. .. py:method:: 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. :param reference: The reference cell :param img: The image to plot on :param value_scale: The scale factor for the function values :param n: The number of points per side for plotting .. py:method:: with_floats() -> AnyFunction Return a version the function with floats as coefficients. :returns: A version the function with floats as coefficients .. py:method:: 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. :param cell: The cell :returns: A version the function with floats as coefficients .. py:class:: MatrixFunction(mat: Union[Tuple[Tuple[Union[AnyFunction, int, sympy.core.expr.Expr], Ellipsis], Ellipsis], Tuple[List[Union[AnyFunction, int, sympy.core.expr.Expr]], Ellipsis], List[Tuple[Union[AnyFunction, int, sympy.core.expr.Expr], Ellipsis]], List[List[Union[AnyFunction, int, sympy.core.expr.Expr]]], sympy.matrices.dense.MutableDenseMatrix]) Bases: :py:obj:`AnyFunction` A matrix-valued function. .. py:property:: shape :type: Tuple[int, Ellipsis] Get the value shape of the function. :returns: The value shape .. py:attribute:: _mat :type: Tuple[Tuple[ScalarFunction, Ellipsis], Ellipsis] .. py:method:: __getitem__(key) -> Union[ScalarFunction, VectorFunction] Get a component or slice of the function. .. py:method:: row(n: int) -> VectorFunction Get a row of the matrix. :param n: The row number :returns: The row of the matrix .. py:method:: col(n: int) -> VectorFunction Get a colunm of the matrix. :param n: The column number :returns: The column of the matrix .. py:method:: __add__(other: Any) -> MatrixFunction Add. .. py:method:: __radd__(other: Any) -> MatrixFunction Add. .. py:method:: __sub__(other: Any) -> MatrixFunction Subtract. .. py:method:: __rsub__(other: Any) -> MatrixFunction Subtract. .. py:method:: __neg__() -> MatrixFunction Negate. .. py:method:: __truediv__(other: Any) -> MatrixFunction Divide. .. py:method:: __rtruediv__(other: Any) -> MatrixFunction Divide. .. py:method:: __mul__(other: Any) -> MatrixFunction Multiply. .. py:method:: __rmul__(other: Any) -> MatrixFunction Multiply. .. py:method:: __matmul__(other: Any) -> MatrixFunction Multiply. .. py:method:: __rmatmul__(other: Any) -> MatrixFunction Multiply. .. py:method:: __pow__(other: Any) -> MatrixFunction Raise to a power. .. py:method:: as_sympy() -> SympyFormat Convert to a sympy expression. :returns: A Sympy expression .. py:method:: as_tex() -> str Convert to a TeX expression. :returns: A TeX string .. py:method:: subs(vars: symfem.symbols.AxisVariables, values: ValuesToSubstitute) -> MatrixFunction Substitute values into the function. :param vars: The variables to substitute out :param values: The value to substitute in :returns: The substituted function .. py:method:: diff(variable: sympy.core.symbol.Symbol) -> MatrixFunction Differentiate the function. :param variable: The variable to differentiate with respect to :returns: The differentiated function .. py:method:: directional_derivative(direction: symfem.geometry.PointType) :abstractmethod: Compute a directional derivative. :param direction: The diection :returns: The directional derivatve .. py:method:: jacobian_component(component: Tuple[int, int]) :abstractmethod: Compute a component of the jacobian. :param component: The component :returns: The component of the jacobian .. py:method:: jacobian(dim: int) :abstractmethod: Compute the jacobian. :param dim: The topological dimension of the cell :returns: The jacobian .. py:method:: dot(other_in: FunctionInput) -> ScalarFunction Compute the dot product with another function. :param other_in: The function to multiply with :returns: The product .. py:method:: cross(other_in: FunctionInput) Compute the cross product with another function. :param other_in: The function to multiply with :returns: The cross product .. py:method:: div() Compute the div of the function. :returns: The divergence .. py:method:: grad() Compute the grad of the function. :returns: The gradient .. py:method:: curl() Compute the curl of the function. :returns: The curl .. py:method:: norm() -> ScalarFunction :abstractmethod: Compute the norm of the function. :returns: The norm .. py:method:: integral(domain: symfem.references.Reference, vars: symfem.symbols.AxisVariablesNotSingle = x, dummy_vars: symfem.symbols.AxisVariablesNotSingle = t) -> ScalarFunction :abstractmethod: Compute the integral of the function. :param domain: The domain of the integral :param vars: The variables to integrate with respect to :param dummy_vars: The dummy variables to use inside the integral :returns: The integral .. py:method:: det() -> ScalarFunction Compute the determinant. :returns: The deteminant .. py:method:: transpose() -> MatrixFunction Compute the transpose. :returns: The transpose .. py:method:: with_floats() -> AnyFunction Return a version the function with floats as coefficients. :returns: A version the function with floats as coefficients .. py:method:: 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. :param cell: The cell :returns: A version the function with floats as coefficients .. py:data:: FunctionInput .. py:function:: parse_function_input(f: FunctionInput) -> AnyFunction Parse a function. :param f: A function :returns: The function as a Symfem function .. py:function:: parse_function_list_input(functions: Union[List[FunctionInput], Tuple[FunctionInput, Ellipsis]]) -> List[AnyFunction] Parse a list of functions. :param functions: The functions :returns: The functions as Symfem functions