pyoomph.expressions package

Submodules

Module contents

This module provides the core functionality to formulate mathematical expressions in the pyoomph library.

pyoomph.expressions.absolute(x)[source]

Compute the absolute of the input expression or number.

Parameters:

x (ExpressionOrNum) – The input expression or number.

Returns:

The absolute of the input.

Return type:

Expression

pyoomph.expressions.acos(x)[source]

Compute the inverse cosine of the input expression or number.

Parameters:

x (ExpressionOrNum) – The input expression or number.

Returns:

The inverse cosine of the input.

Return type:

Expression

pyoomph.expressions.asin(x)[source]

Compute the inverse sine of the input expression or number.

Parameters:

x (ExpressionOrNum) – The input expression or number.

Returns:

The inverse sine of the input.

Return type:

Expression

pyoomph.expressions.atan(x)[source]

Compute the inverse tangent of the input expression or number.

Parameters:

x (ExpressionOrNum) – The input expression or number.

Returns:

The inverse tangent of the input.

Return type:

Expression

pyoomph.expressions.atan2(y, x)[source]

Compute atan2(y,x) of the input expression or number.

Parameters:
  • y (ExpressionOrNum) – First argument, expression or number.

  • x (ExpressionOrNum) – Second argument. expression or number.

Returns:

atan2(y,x), i.e. atan(y/x) with case distinction.

Return type:

Expression

pyoomph.expressions.cos(x)[source]

Compute the cosine of the input expression or number.

Parameters:

x (ExpressionOrNum) – The input expression or number.

Returns:

The cosine of the input.

Return type:

Expression

pyoomph.expressions.cosh(x)[source]

Compute the hyperbolic cosine of the input expression or number.

Parameters:

x (ExpressionOrNum) – The input expression or number.

Returns:

The hyperbolic cosine of the input.

Return type:

Expression

pyoomph.expressions.determinant(M, n=0)[source]

Compute the determinant of a matrix expression.

Parameters:
  • M (Expression) – The matrix expression for which to compute the determinant.

  • n (int) – Range of the matrix to consider for the determinant. Default is 0 (extract nonzero block), <0 means full matrix, >0 upper left matrix of n x n.

Returns:

The determinant of the matrix expression.

Return type:

Expression

pyoomph.expressions.div(arg, lagrangian=False, matrix=None, nondim=False, coordsys=None)[source]

Compute the divergence of the given argument. On surfaces, i.e. with a co-dimension, it is the surface divergence.

Parameters: arg (ExpressionOrNum): The argument for which the divergence is computed. lagrangian (bool, optional): Flag indicating whether the computation is with respect to Lagrangian coordinates. Defaults to False. matrix (bool, optional): Flag indicating whether the computation is for a matrix expression. Defaults to None, i.e. auto-select. nondim (bool, optional): Flag indicating whether the computation is with respect to non-dimensional coordinates. Defaults to False. coordsys (BaseCoordinateSystem, optional): The coordinate system in which the computation is performed. Defaults to None, i.e. the coordinate system of either the current or parent equations or the problem.

Returns: Expression: The computed divergence expression.

Return type:

Expression

Notes

if you calculate div(u) on a boundary, you will get the surface divergence, even if u is defined in the bulk. To get the bulk divergence at the boundary, use div(var(“u”,domain=”..”)) instead.

pyoomph.expressions.exp(x)[source]

Compute the exponential of the input expression or number.

Parameters:

x (ExpressionOrNum) – The input expression or number.

Returns:

The exponential of the input.

Return type:

Expression

pyoomph.expressions.heaviside(x)[source]

Returns a piecewise function that evaluates to iftrue when cond is greater than or equal to zero, and evaluates to iffalse otherwise.

Parameters:
  • cond (ExpressionOrNum) – The condition to check.

  • iftrue (ExpressionOrNum) – The value to return if cond is greater than or equal to zero.

  • iffalse (ExpressionOrNum) – The value to return if cond is less than zero.

Returns:

The resulting piecewise function.

Return type:

Expression

pyoomph.expressions.imag_part(x)[source]

Compute the imaginary part of the input expression or number.

Parameters:

x (ExpressionOrNum) – The input expression or number.

Returns:

The imaginary part of the input.

Return type:

Expression

pyoomph.expressions.imaginary_i()[source]

Return the imaginary unit i.

Returns:

The imaginary unit i.

Return type:

Expression

pyoomph.expressions.inverse_matrix(M, n=0, use_subexpression_for_det=True, fill_to_vector_dim_3=False, skip_empty_rows_and_cols=False)[source]

Compute the inverse of a matrix expression.

Parameters:
  • M (Expression) – The matrix expression for which to compute the determinant.

  • n (int) – Range of the matrix to consider for the inverse. Default is 0 (extract nonzero block), <0 means full matrix, >0 upper left matrix of n x n.

  • use_subexpression_for_det (bool) – Flag indicating whether to use a subexpression for the determinant. Default is True.

  • skip_empty_rows_and_cols (bool) – Analyze the input and skip empty rows and columns. These empty rows and columns will be added to the result as zero rows and columns of the inverse. Default is False.

Returns:

The symbolical inverse of the matrix expression.

Return type:

Expression

pyoomph.expressions.log(x)[source]

Compute the logarithm of the input expression or number.

Parameters:

x (ExpressionOrNum) – The input expression or number.

Returns:

The logarithm of the input.

Return type:

Expression

pyoomph.expressions.maximum(x, y)[source]

Compute the maximum of both input expressions or numbers.

Parameters:
  • x (ExpressionOrNum) – First argument, expression or number.

  • y (ExpressionOrNum) – Second argument. expression or number.

Returns:

max(x,y).

Return type:

Expression

pyoomph.expressions.minimum(x, y)[source]

Compute the minimum of both input expressions or numbers.

Parameters:
  • x (ExpressionOrNum) – First argument, expression or number.

  • y (ExpressionOrNum) – Second argument. expression or number.

Returns:

min(x,y).

Return type:

Expression

pyoomph.expressions.partial_x(f, order=1)[source]

Compute the partial derivative of a given expression with respect to the x-coordinate.

Parameters:
  • f (ExpressionOrNum) – The expression to differentiate.

  • order (int) – The order of differentiation (default is 1).

Returns:

The resulting expression after differentiation.

Return type:

Expression

pyoomph.expressions.partial_y(f, order=1)[source]

Compute the partial derivative of a given expression with respect to the y-coordinate.

Parameters:
  • f (ExpressionOrNum) – The expression to differentiate.

  • order (int) – The order of differentiation (default is 1).

Returns:

The resulting expression after differentiation.

Return type:

Expression

pyoomph.expressions.partial_z(f, order=1)[source]

Compute the partial derivative of a given expression with respect to the y-coordinate.

Parameters:
  • f (ExpressionOrNum) – The expression to differentiate.

  • order (int) – The order of differentiation (default is 1).

Returns:

The resulting expression after differentiation.

Return type:

Expression

pyoomph.expressions.piecewise_geq0(cond, iftrue, iffalse)[source]

Returns a piecewise function that evaluates to iftrue when cond is greater than or equal to zero, and evaluates to iffalse otherwise.

Parameters:
  • cond (ExpressionOrNum) – The condition to check.

  • iftrue (ExpressionOrNum) – The value to return if cond is greater than or equal to zero.

  • iffalse (ExpressionOrNum) – The value to return if cond is less than zero.

Returns:

The resulting piecewise function.

Return type:

Expression

pyoomph.expressions.real_part(x)[source]

Compute the real part of the input expression or number.

Parameters:

x (ExpressionOrNum) – The input expression or number.

Returns:

The real part of the input.

Return type:

Expression

pyoomph.expressions.signum(x)[source]

Compute the signum of the input expression or number.

Parameters:

x (ExpressionOrNum) – The input expression or number.

Returns:

The signum of the input.

Return type:

Expression

pyoomph.expressions.sin(x)[source]

Compute the sine of the input expression or number.

Parameters:

x (ExpressionOrNum) – The input expression or number.

Returns:

The sine of the input.

Return type:

Expression

pyoomph.expressions.sinh(x)[source]

Compute the hyperbolic sine of the input expression or number.

Parameters:

x (ExpressionOrNum) – The input expression or number.

Returns:

The hyperbolic sine of the input.

Return type:

Expression

pyoomph.expressions.square_root(what, order=2)[source]

Calculates the square root of the given expression or number.

Parameters:
  • what (ExpressionOrNum) – The expression or number to calculate the square root of.

  • order (int) – The order of the square root. Default is 2.

Returns:

The square root of the given expression or number.

Return type:

Expression

pyoomph.expressions.sym(a)[source]

Calculate the symmetric part of a given matrix.

Parameters:

a (Expression) – The input matrix expression.

Returns:

The symmetric part of the matrix.

Return type:

Expression

pyoomph.expressions.tan(x)[source]

Compute the tangent of the input expression or number.

Parameters:

x (ExpressionOrNum) – The input expression or number.

Returns:

The tangent of the input.

Return type:

Expression

pyoomph.expressions.tanh(x)[source]

Compute the hyperbolic tangent of the input expression or number.

Parameters:

x (ExpressionOrNum) – The input expression or number.

Returns:

The hyperbolic tangent of the input.

Return type:

Expression

pyoomph.expressions.trace(M)[source]

Compute the trace of a matrix expression.

Parameters: M (Expression): The matrix expression for which to compute the trace.

Returns: Expression: The trace of the matrix expression.

Return type:

Expression

pyoomph.expressions.var_and_test(n, tag=[], domain=None)[source]

Bind a variable of an unknown field the corresponding test function for a given name.

Parameters:
  • n (str) – The name of the unkown.

  • tag (List[str], optional) – List of tags for the variable and test function. Defaults to [], see var()

  • domain (Union[None, str, "FiniteElementCodeGenerator"], optional) – The domain of the variable and test function. Defaults to None, see var()

Returns:

A tuple containing the field and test function as expressions.

Return type:

Tuple[Expression, Expression]