pyoomph.expressions.generic module
- pyoomph.expressions.generic.IntegralTimeSteppingScheme
The schemes
time_derivative_of_integral()actually honours. A different set fromTimeSteppingScheme: the_degrvariants exist only here, and the quadrature-style names of that alias are silently downgraded to"BDF1"by that function, since they are not linear multistep methods. Converselytime_scheme()rejects the_degrnames, so an equation offering both needs two separate arguments.alias of
Literal[‘BDF1’, ‘BDF2’, ‘Newmark2’, ‘BDF2_degr’, ‘Newmark2_degr’]
- pyoomph.expressions.generic.Weak(a, b, *, dimensional_dx=False, coordsys=None)[source]
Shortcut for weak(a,b,dimensional_dx=dimensional_dx,lagrangian=True,coordsys=coordsys).
The argument
coordinate_systemis a deprecated alias forcoordsys.- Return type:
- pyoomph.expressions.generic.avg(f, at_facet=False)[source]
Calculate the average of the given expression for discontinuous Galerkin methods.
- Parameters:
f (
Expression|GiNaC_GlobalParam|int|float) – The expression to calculate the average for.at_facet (
bool) – If True, calculate the average at the facet, i.e. between the values at the facet directly. If you wrap it on a spatial differential operator, you will get the average of e.g. the surface gradient. If False, calculate the average between the two bulk domains. Here, the bulk gradients will be taken when applied with e.g. a grad. Default is False.
- Returns:
The average across the interface. (f_inside + f_outside)/2.
- Return type:
- pyoomph.expressions.generic.contract(a, b)[source]
Contract a and b, i.e. the standard adjacent-index contraction. This is what the
@operator does.If both are scalars, it is just a*b. If both are vectors, it is the dot product. If both are rank-2-tensors/matrices, it is the Frobenius product \(\mathbf{A}:\mathbf{B}=A_{ij}B_{ij}\). If one is a vector and the other a matrix, it is the matrix-vector product, contracting the index of the matrix that faces the other operand:
contract(A,b)[i]is \(A_{ij}b_j\) andcontract(a,B)[i]is \(a_j B_{ji}\). If one is a scalar, it is just the multiplication by a scalar.- Parameters:
a (
Expression|GiNaC_GlobalParam|int|float) – Argument a (scalar, vector or matrix/tensor)b (
Expression|GiNaC_GlobalParam|int|float) – Argument b (scalar, vector or matrix/tensor)
- Returns:
The symbolic contraction of a and b.
- Return type:
Notes
The mixed vector/matrix case is not symmetric, and with
grad()storing \(\partial u_i/\partial x_j\) the order matters: the advection term \(\vec{u}\cdot\nabla\vec{u}\) iscontract(grad(u),u)(equivalentlygrad(u) @ uormatproduct(grad(u),u)), whereascontract(u,grad(u))is \(\nabla(|\vec{u}|^2/2)\).This convention changed: previously the outer index was contracted, so
contract(A,b)was \(A_{ji}b_j\) and the two orders above were interchanged. See the changelog.
- pyoomph.expressions.generic.convected_derivative(A, velocity, alpha=0, ALE='auto', dt_scheme=None, nondim=False, lagrangian=False, dt_factor=1, advection_factor=1, coordsys=None)[source]
Returns the Gordon-Schowalter convected derivative of a rank-2 tensor field \(\mathbf{A}\), i.e. the one-parameter family interpolating between the upper- and the lower-convected derivative:
\[\partial_t \mathbf{A} + \vec{u}\cdot\nabla\mathbf{A} - \mathbf{g}_\alpha\cdot\mathbf{A} - \mathbf{A}\cdot\mathbf{g}_\alpha^\mathrm{T}\]with \(\mathbf{g}_\alpha=\frac{1}{2}[(1+\alpha)\nabla\vec{u}-(1-\alpha)(\nabla\vec{u})^\mathrm{T}]\).
alpha=1reproducesupper_convected_derivative(),alpha=-1gives the lower-convected one, andalpha=0(the default) the co-rotational Jaumann derivative.- Parameters:
A (
Expression|GiNaC_GlobalParam|int|float) – Rank-2 tensor field to be advected.velocity (
Expression|GiNaC_GlobalParam|int|float) – Advection velocity.alpha (
Expression|GiNaC_GlobalParam|int|float) – Slip parameter of the family, see above.ALE (
Union[Literal['auto'],bool]) – Use ALE correction. If set to"auto", it will only be used if the coordinates are degrees of freedom.dt_scheme (
Optional[Literal['BDF1','BDF2','Newmark2','TPZ','MPT','Simpson','Boole','trapezoidal','Kepler','Milne','midpoint']]) – Used time stepping scheme. If set to None, the default time stepping scheme set at problem level will be used.nondim (
bool) – Using non-dimensional time. Defaults to False.lagrangian (
bool) – Using Lagrangian coordinates for the gradient.dt_factor (
Expression|GiNaC_GlobalParam|int|float) – Factor to weight the \(\partial_t \mathbf{A}\) term.advection_factor (
Expression|GiNaC_GlobalParam|int|float) – Factor to weight the advection and stretching terms.coordsys (
CustomCoordinateSystem|None) – Optional coordinate system to use. Defaults to None, meaning the coordinate system at equation level, parent equation level or problem level.
- Return type:
- Returns:
The convected derivative of the tensor field \(\mathbf{A}\) advected by the velocity field \(\vec{u}\).
Notes
Both the advection term and \(\nabla\vec{u}\) are built from
grad(), so on a domain with a co-dimension they are the surface gradient. Usevar("velocity",domain="..")to get the bulk gradient at an interface.
- pyoomph.expressions.generic.delayed_lambda_expansion(func)[source]
Wrapping a callable f, so that it will be evaluated only at the moment of code generation. Can be used to e.g. access potentially changing problem parameters the moment the code is generated.
- Parameters:
func (
Callable[[],Expression]) – The function to be expanded when the code is generated.- Returns:
An expression which you can combine with other expressions, f will be evaluated at code generation time.
- Return type:
- Raises:
RuntimeError – If the input func is not callable.
ValueError – If the result of the expansion cannot be converted into an expression.
- pyoomph.expressions.generic.diff(f, *arg)[source]
Compute the derivative of a given expression with respect to one or more variables.
- Parameters:
f (
Expression|GiNaC_GlobalParam|int|float) – The expression to differentiate.*arg (
Expression) – The variables with respect to which the differentiation is performed.
- Returns:
The resulting expression after differentiation.
- Return type:
- Raises:
ValueError – If no variables are provided for differentiation.
- pyoomph.expressions.generic.directional_derivative(f, direction, nondim=False, lagrangian=False, coordsys=None)[source]
Compute the directional derivative \((\vec{d}\cdot\nabla)f\) of
falongdirection, i.e. the advection operator.fmay be a scalar, a vector or a rank-2 tensor; the rank is detected from the resolved shape and the right operator is used in each case, so for a vector this is \(d_j\,\partial u_i/\partial x_j\) and for a tensor \(d_k\,\partial T_{ij}/\partial x_k\).directionmust be a vector.- Parameters:
f (
Expression|GiNaC_GlobalParam|int|float) – Scalar, vectorial or tensorial expression to differentiate.direction (
Expression|GiNaC_GlobalParam|int|float) – Vector expression giving the direction, e.g. a velocity.nondim (
bool) – Using non-dimensional coordinates. Defaults to False.lagrangian (
bool) – Using Lagrangian coordinates for the gradient.coordsys (
CustomCoordinateSystem|None) – Optional coordinate system to use. Defaults to None, meaning the coordinate system at equation level, parent equation level or problem level.
- Returns:
The directional derivative of
falongdirection, of the same rank asf.
Notes
Built from
grad(), so on a domain with a co-dimension this is the surface gradient: on an interface,directional_derivative(var("c"),u)only differentiates along the surface, even ifcis defined in the bulk. Usevar("c",domain="..")for the bulk gradient.
- pyoomph.expressions.generic.dot(a, b)[source]
Compute the dot product, i.e. the standard adjacent-index contraction.
Between two vectors this is \(a_i b_i\). One operand may also be a rank-2 tensor/matrix, in which case the index facing the other operand is contracted:
dot(A,b)[i]is \(A_{ij}b_j\) (the same asmatproduct(A,b)) anddot(a,B)[i]is \(a_j B_{ji}\) (the same asmatproduct(transpose(B),a)). Two matrices are rejected, since both \(\mathbf{A}\mathbf{B}\) and \(\mathbf{A}:\mathbf{B}\) would be plausible readings - usematproduct()ordouble_dot()to say which.Parameters: a: The first operand. String will be wrapped in a var expression. b: The second operand. String will be wrapped in a var expression.
Returns: Expression: The dot product, a scalar for two vectors and a vector for the mixed case.
- Return type:
Notes
Since
grad()stores \(\partial u_i/\partial x_j\), the advection term \(\vec{u}\cdot\nabla\vec{u}\) isdot(grad(u),u), notdot(u,grad(u)), which is \(\nabla(|\vec{u}|^2/2)\). For a scalar field both orders agree, sincegradof a scalar is a vector.
- pyoomph.expressions.generic.double_dot(A, B)[source]
Compute the double dot product of two expressions A and B.
- Parameters:
A (
Expression) – The first expression.B (
Expression) – The second expression.
- Returns:
The result of the double dot product.
- Return type:
- pyoomph.expressions.generic.dyadic(a, b)[source]
Compute the dyadic product of two expressions.
- Parameters:
a (
Expression) – The first expression.b (
Expression) – The second expression.
- Returns:
The dyadic product of a and b.
- Return type:
- pyoomph.expressions.generic.evaluate_at_midpoint(expr, midpt=0.5, apply_on_integral_dx=False, apply_on_others=True)[source]
Evaluates the given expression by replacing each var by a blending between the history values.
- Parameters:
expr (
Expression|GiNaC_GlobalParam|int|float) – The expression to be evaluated.midpt (
float|int) – The blending at which to evaluate the var statements. Defaults to 0.5, i.e. all variables are evaluated at the average between current and previous time step (midpoint rule)apply_on_integral_dx (
bool) – Whether to apply the evaluation on dx symbols. Defaults to False.apply_on_others (
bool) – Whether the history evaluations also take the normal, the Eulerian element sizes and the Eulerian spatial derivatives in grad/div from the mesh of the corresponding history step. Defaults to True, for the same reason as intime_scheme(). Has no effect unless the mesh moves.
- Return type:
- Returns:
The evaluated expression.
- Raises:
RuntimeError – If the expression is not an Expression.
RuntimeError – If the midpoint is less than 0.
RuntimeError – If the midpoint is a variable fraction (not yet supported).
- pyoomph.expressions.generic.evaluate_in_domain(expr, domain)[source]
Evaluates the given expression within the specified domain. Each var inside the expression will be evaluated in the given domain. Useful to e.g. evaluate the expression in the bulk (domain=”
..”) when at an boundary element, or at the opposite side of the interface (domain=”|.”)- Parameters:
expr (
Expression|GiNaC_GlobalParam|int|float) – The expression to be evaluated.domain (
str|FiniteElementCode|None) – The domain within which the expression should be evaluated. It can be a string representing the domain name or e.g. “..” for the bulk, “|.” for the opposite interface side or “|..” for the opposite bulk side
- Return type:
- Returns:
The evaluated expression within the specified domain.
- pyoomph.expressions.generic.evaluate_in_past(expr, timestep_offset=1, apply_on_integral_dx=False, apply_on_others=False)[source]
Evaluate the given expression in the past at a specified time offset.
- Parameters:
expr (
Expression|GiNaC_GlobalParam|int|float) – The expression to be evaluated.timestep_offset (
int|float) – The time offset in the past. Defaults to 1, i.e. the previously converged solution.apply_on_integral_dx (
bool) – Whether to apply the evaluation on dx symbols. Defaults to False.apply_on_others (
bool) – Whether to also evaluate the remaining mesh-dependent quantities at the old configuration, i.e. the normal, the Eulerian element sizes and the Eulerian spatial derivatives in grad/div. On a moving mesh these depend on where the nodes were, not only on the history of the nodal values, so without this a past gradient mixes old nodal values with the present geometry. Defaults to False.
- Return type:
- Returns:
The evaluated expression in the past.
- Raises:
RuntimeError – If the time offset is negative.
RuntimeError – If the time offset is a variable step.
Note
If the time offset is an integer, the function evaluates the expression at that specific time step. If the time offset is a float, the function linearly interpolates between the results of the two nearest time steps. If the time offset is a variable step, the function raises a RuntimeError.
- pyoomph.expressions.generic.find_subordinate_element_space(*spaces)[source]
The MEET of the given spaces, i.e. the largest space contained in all of them.
The dual of find_dominant_element_space, and it has to be written as a lattice rather than as a position in a list, for the same reason the join above needs its special case: the order is C1 < C1TB < C2TB and C1 < C2 < C2TB, and C1TB and C2 are INCOMPARABLE – a C2 element has no bubble node, a C1TB element has no midside ones. Their join is C2TB (“only space that can hold both”) and their meet is C1.
Getting this wrong is not academic: get_interface_field_connection_space used to walk a total order in which C1TB sat below C2, so a C2 domain coupled to a C1TB one negotiated a C1TB multiplier – a space the C2 element cannot carry at all, whose Nodal_Space_Index_To_Element_Index_Map row is empty. The result was a segfault, not an error. See dev_docs/interface_refinement_coupling.md section 14.5.
- Return type:
Literal['C1','C1TB','C2','C2TB','D1','D1TB','D2','D2TB','DL','D0']
- pyoomph.expressions.generic.get_order_of_space(space)[source]
Get the order of the given finite element space.
- Return type:
int
- pyoomph.expressions.generic.grad(arg, lagrangian=False, nondim=False, coordsys=None, vector=None)[source]
Compute the gradient of the given argument. On surfaces, i.e. with a co-dimension, it is the surface gradient.
Parameters: arg (ExpressionOrNum): The argument for which the gradient is computed. lagrangian (bool, optional): Flag indicating whether the computation is with respect to Lagrangian coordinates. Default is False. nondim (bool, optional): Flag indicating whether the computation is with respect to non-dimensional coordinates. Default is False. coordsys (OptionalCoordinateSystem, optional): The coordinate system in which the gradient is computed. Default is None, which is the coordinate system of the Equation, potential parent equations or given at problem level. vector (Union[None,bool], optional): Flag indicating whether the gradient is a vector. Default is None, meaning it will find out automatically.
Returns: Expression: The computed gradient expression.
- Return type:
Notes
if you calculate grad(u) on a boundary, you will get the surface gradient, even if u is defined in the bulk. To get the bulk gradient at the boundary, use grad(var(“u”,domain=”..”)) instead.
Index order: for a vector field,
grad(u)[i,j]is \(\partial u_i/\partial x_j\), i.e. the Jacobian, with the component as the row and the derivative direction as the column. Many references (in particular in rheology and tensor analysis) instead write \(\nabla\otimes\vec{u}\) with the derivative index first, which is the transpose of this. Consequently the advection term \(\vec{u}\cdot\nabla\vec{u}\) ismatproduct(grad(u),u), equivalentlydot(grad(u),u)orgrad(u) @ u, and notdot(u,grad(u)), which is \(\nabla(|\vec{u}|^2/2)\). See alsodiv(), which contracts the second index accordingly.The argument must be a scalar or a vector: the gradient of a rank-2 tensor would be rank 3, which is not implemented.
Second derivatives of the basis functions are available, so
grad(grad(u)),div(grad(u))andpartial_x(u,2)can be assembled directly. Prefer the integrated-by-parts form-weak(grad(u),grad(v))plus the corresponding surface term anyway wherever you have the choice: on the C0 Lagrange spaces used here the second derivative is discontinuous across element boundaries, so the strong form is an element-wise object and not the distributional Laplacian. The restrictions on the strong form areOnly Eulerian second derivatives.
grad(..., lagrangian=True)cannot be nested.Not available on wedge and pyramid elements, nor on 0d (point/ODE) domains, where it is trivially zero.
On an interface the result is the tangential derivative of the surface gradient. Its trace, i.e.
div(grad(u)), is exactly the Laplace-Beltrami operator, but the full tensorgrad(grad(u))is not symmetric there: it carries a second-fundamental-form part. Second derivatives of a bulk field evaluated on an interface,grad(grad(var("u",domain=".."))), are the ordinary symmetric ones.
- pyoomph.expressions.generic.identity_matrix(dim=-1)[source]
Returns the identity matrix of the specified dimension.
- Parameters:
dim (
int) – The dimension of the identity matrix. If not provided, the dimension is 3.- Returns:
The identity matrix.
- Return type:
- pyoomph.expressions.generic.is_DG_space(space, allow_DL_and_D0=False)[source]
Check if the given space is a discontinuous Galerkin space. By default,
"DL"and"D0"are not considered DG spaces, so that it returnsTruefor"D2TB",``”D2”,”D1TB”`` and"D1"- Parameters:
space (
Literal['C1','C1TB','C2','C2TB','D1','D1TB','D2','D2TB','DL','D0']) – The space to check.allow_DL_and_D0 (
bool) – Flag indicating whether the pure elemental spaces"DL"and"D0"also should return True. Defaults to False.
- Returns:
Whether the space is a discontinuous Galerkin space.
- pyoomph.expressions.generic.is_zero(arg, parameters_to_float=False, tensors=False)[source]
Check if the given argument (Expression or numerical value) is zero.
Parameters: arg (ExpressionOrNum): The argument to be checked. parameters_to_float: Flag indicating whether to convert a global parameter to its float values. Defaults to False, i.e. always False applied on a global parameter. tensors: Flag indicating whether vector- and matrix-valued expressions should be considered as well. By default, these are never zero, not even the zero vector, since a matrix is not the zero expression. With tensors=True, such an expression is zero whenever all of its entries are zero.
Returns: bool: True if the argument is zero, False otherwise.
Raises: ValueError: If the argument cannot be tested for zero.
- Return type:
bool
- pyoomph.expressions.generic.jump(f, at_facet=False)[source]
Calculate the jump of the given expression for discontinuous Galerkin methods.
- Parameters:
f (
Expression|GiNaC_GlobalParam|int|float) – The expression to calculate the jump for.at_facet (
bool) – If True, calculate the jump at the facet, i.e. between the values at the facet directly. If you wrap it on a spatial differential operator, you will get the jump of e.g. the surface gradient. If False, calculate the jump between the two bulk domains. Here, the bulk gradients will be taken when applied with e.g. a grad. Default is False.
- Returns:
The jump across the interface, f_inside - f_outside.
- Return type:
- pyoomph.expressions.generic.largest_facet_space(parent_space, parent_dim)[source]
The largest space a field on a FACET of a bulk domain can use, given the bulk domain’s own space.
A facet does not inherit everything the bulk element has. The bubble spaces are the interesting case, and the rule is not “the parent’s space” but “does the parent element actually own a node there”:
C1TB/C2TB need a bubble node. A C2 element has none – BulkElementTri2dC2’s C1TB row of Nodal_Space_Index_To_Element_Index_Map is literally empty (src/elements_2d.cpp). Asking for a C1TB field on such an interface used to index off the end of that empty row and SEGFAULT (dev_docs/interface_refinement_coupling.md section 14.5).
in 3d the facet is a 2d face, and a C1TB tet carries only a CELL bubble, not a face one. Only a C2TB tet provides the face bubble a C1TB facet field would need.
On the tensor-product families the TB variants are degenerate anyway (a quad’s C1TB node map equals its C1 one), so reducing C1TB to C1 there costs nothing and keeps this rule family-independent.
- Return type:
Literal['C1','C1TB','C2','C2TB','D1','D1TB','D2','D2TB','DL','D0']
- pyoomph.expressions.generic.material_derivative(f, velocity, ALE='auto', dt_scheme=None, nondim=False, lagrangian=False, dt_factor=1, advection_factor=1, coordsys=None)[source]
Compute the material derivative of a function with respect to time, i.e. \(\partial_t f + \nabla f \cdot \vec{u}\). Note that for tensorial quantities, one usually uses the
upper_convected_derivative()instead.- Parameters:
f (
Expression|GiNaC_GlobalParam|int|float|str) – Any scalar, vectorial or tensorial function to be advected.velocity (
Expression|GiNaC_GlobalParam|int|float|str) – Expression for the velocity field.ALE (
Union[Literal['auto'],bool]) – Use ALE correction. If set to"auto", it will only be used if the coordinates are degrees of freedom.dt_scheme (
Optional[Literal['BDF1','BDF2','Newmark2','TPZ','MPT','Simpson','Boole','trapezoidal','Kepler','Milne','midpoint']]) – Used time stepping scheme. If set to None, the default time stepping scheme set at problem level will be used.nondim (
bool) – Using non-dimensional time. Defaults to False.lagrangian (
bool) – Using Lagrangian coordinates for the gradient.dt_factor (
Expression|GiNaC_GlobalParam|int|float) – Factor to weight the \(\partial_t f\) term.advection_factor (
Expression|GiNaC_GlobalParam|int|float) – Factor to weight the advection termcoordsys (
CustomCoordinateSystem|None) – Optional coordinate system to use. Defaults to None, meaning the coordinate system at equation level, parent equation level or problem level.
- Return type:
- Returns:
The material derivative of the expression
fadvected byvelocity.
Notes
The advection term is built from
grad(), so on a domain with a co-dimension it is the surface gradient: on an interface,material_derivative(var("c"),u)advects along the surface only, even ifcis defined in the bulk. Usevar("c",domain="..")to advect with the bulk gradient instead.
- pyoomph.expressions.generic.matproduct(a, b)[source]
Compute the matrix product of two expressions.
Parameters: a (ExpressionOrNum): The first expression. b (ExpressionOrNum): The second expression.
Returns: Expression: The matrix product of a and b.
Note: - If either a or b is not an Expression, it will be converted to one. - If either a or b is zero, the function will return zero. - The matrix product can be computed for matrices as well as vectors.
- Return type:
- pyoomph.expressions.generic.matrix(mlist, fill_to_max_vector_dim=True, fill_identity=False)[source]
Create a GiNaC matrix from a list of lists.
- Parameters:
mlist (
list[list[Expression|GiNaC_GlobalParam|int|float]]) – The input matrix represented as a list of lists.fill_to_max_vector_dim (
bool) – Whether to fill the matrix to the maximum vector dimension 3. Defaults to True.fill_identity (
bool) – Whether to fill the matrix diagonal by 1 when filling to max_vector_dim of 3. Defaults to False.
- Returns:
The matrix expression created from the input.
- Return type:
- Raises:
ValueError – If the number of matrix rows exceeds the maximum vector dimension.
ValueError – If the input matrix is not a valid matrix.
ValueError – If a matrix row exceeds the maximum vector dimension.
- pyoomph.expressions.generic.mesh_velocity(scheme=None, nondim=False)[source]
Get the mesh velocity, i.e. the time derivative of the mesh coordinates without ALE correction.
- Returns:
Just a shorthand for partial_t(var(“mesh”),ALE=False).
- Return type:
- pyoomph.expressions.generic.nondim(arg, tag=[], domain=None, no_jacobian=False, no_hessian=False, only_base_mode=False, only_perturbation_mode=False)[source]
This returns the nondimensional equivalent of a field, i.e. it is the same as var(…)/scale_factor(…).
See var for further details.
- Return type:
Expression|tuple[Expression,...]
- pyoomph.expressions.generic.partial_t(f, order=1, ALE='auto', scheme=None, nondim=False)[source]
Compute the partial derivative of a function with respect to time, i.e. .. \(\partial_t^n f\). With ALE=False, this is evaluated at the nodal values directly, i.e. co-moving with a moving mesh. To correct for it by the mesh velocity \(\dot{\vec{X}}\), use the ALE=True or ALE=”auto”. In the latter case, the correction will only be considered if equations for the moving mesh are present, i.e. if
activate_coordinates_as_dofs()has been called by anyEquationsadded to this or any parent domain.If you want to obtain the mesh velocity, please use it with ALE=False.
- Parameters:
f (
Expression|GiNaC_GlobalParam|int|float|str) – The function to differentiate. It can be an expression or a string representing a variable.order (
int) – The order of the derivative. Defaults to 1, maximum is 2.ALE (
Union[Literal['auto'],bool]) – Flag indicating whether to use Arbitrary Lagrangian-Eulerian (ALE) formulation. Defaults to “auto”. “auto” will activate the ALE correction if you combine it with a moving mesh only.scheme (
Optional[Literal['BDF1','BDF2','Newmark2','TPZ','MPT','Simpson','Boole','trapezoidal','Kepler','Milne','midpoint']]) – The time stepping scheme to use. Defaults to None, meaning the default time stepping scheme set at problem level.nondim (
bool) – Flag indicating whether to use non-dimensional time. Defaults to False.
- Return type:
- Returns:
The partial derivative of the function with respect to time.
Notes
The ALE correction is a
directional_derivative(), hence agrad(), so on a domain with a co-dimension it uses the surface gradient: on an interface,partial_t(var("u"))corrects only with the in-surface part of the mesh motion. Usepartial_t(var("u",domain=".."))if the bulk gradient is wanted.
- pyoomph.expressions.generic.rational_num(numer_or_float_str, denom=1)[source]
Create a rational number expression at full accuracy. Opposed to floats, this will not introduce any rounding errors.
- Parameters:
numer_or_float_str (
int|str) – The numerator of the rational number. If a string is provided, it will be interpreted as a float that should be converted to a rational.denom (
int) – The denominator of the rational number. Defaults to 1.
- Returns:
The rational number expression.
- Return type:
- Raises:
RuntimeError – If numer_or_float_str is a string and denom is not equal to 1.
- pyoomph.expressions.generic.scale_factor(arg, tag=[], domain=None)[source]
Returns the scale factor of an unknown used for nondimensionalization. Will be expanded during code generation. If you pass scale=… as keyword argument to Equations.define_scalar_field, .define_vector_field or .define_ode_variable, this determines the scale factor. If the scale factor is not set there, it will look at parent equations and ultimately at the problem level, where you can set it via Problem.set_scaling. All scales are by default 1.
- Parameters:
arg (
str|tuple[str] |list[str]) – The field names for which to get the scale factors used for nondimensionalizationtag (
list[str]) – Additional tags to associate with the scale factor. Defaults to an empty list.domain (
str|FiniteElementCodeGenerator|None) – The domain for which to compute the scale factor. You might want to get e.g. the scale of a field on the opposite side of the interface via domain=”|.”.
- Returns:
The scale factor(s), will be expanded only during code generation.
- Return type:
Expression|tuple[Expression,...]
- pyoomph.expressions.generic.subexpression(what)[source]
Wraps the expression in a subexpression. This will be calculated and derived in beforehand during the code generation and can speed up the assembly. Also applies to the symbolical Hessian used for bifurcation tracking and normal-mode stability analysis, where it is typically worth the most.
- Parameters:
what (
Expression|GiNaC_GlobalParam|int|float) – What to wrap in a subexpression.- Returns:
A resulting expression where the expression is marked to be calculated in beforehand.
- Return type:
- pyoomph.expressions.generic.symbolic_diff(expr, x, hold_until_codegen=True)[source]
Compute the symbolic differentiation of an expression with respect to a variable. It will be held, i.e. not applied, until code generation by default.
- Parameters:
expr (
Expression|GiNaC_GlobalParam|int|float) – The expression to differentiate.x (
Expression|str) – The variable with respect to which to differentiate.hold_until_codegen (
bool) – Whether to hold the expression until code generation. Defaults to True.
- Returns:
The result of the symbolic differentiation.
- Return type:
- Raises:
RuntimeError – If the differentiation cannot be performed.
- pyoomph.expressions.generic.test_scale_factor(arg, tag=[], domain=None)[source]
Returns the scale factor of a test function or multiple test functions used for nondimensionalization. Will be expanded during code generation. If you pass testscale=… as keyword argument to Equations.define_scalar_field, .define_vector_field or .define_ode_variable, this determines the test scale factor. If the test scale factor is not set there, it will look at parent equations, which gives an additional factor 1/scale_factor(“spatial”) per level, since the integration measure (e.g. dx and dS) is always nondimensional. All test scales are by default 1.
- Parameters:
arg (
str|tuple[str] |list[str]) – The field names for which to get the scale factors used for nondimensionalizationtag (
list[str]) – Additional tags to associate with the scale factor. Defaults to an empty list.domain (
str|FiniteElementCodeGenerator|None) – The domain for which to compute the scale factor. You might want to get e.g. the scale of a field on the opposite side of the interface via domain=”|.”.
- Returns:
The test scale factor(s), will be expanded only during code generation.
- Return type:
Expression|tuple[Expression,...]
- pyoomph.expressions.generic.testfunction(arg, tag=[], domain=None, dimensional=True)[source]
Return the testfunction corresponding to the field(s)
- Parameters:
arg (
str|Expression|tuple[str] |list[str] |tuple[Expression] |list[Expression]) – Select the test function either by by name or by a var expression (or a list thereof).tag (
list[str]) – A list of tags associated with the argument. Default is an empty list, see also the tag argument of the var function.domain (
None|FiniteElementCode|str) – The domain associated with the argument. Default is None, see also the domain argument of the var function.dimensional (
bool) – A boolean flag indicating whether the we should consider the dimensional test_scale of the testfunction. Default is True.
- Return type:
Expression|tuple[Expression,...]- Returns:
The corresponding testfunction(s) as an expression or a tuple of expressions.
- pyoomph.expressions.generic.time_scheme(scheme, expr, only_implicit_terms=False, apply_on_integral_dx=False, apply_on_others=True)[source]
Selects a time stepping scheme for the given expression by replacing all partial_t terms by the corresponding time stepping and expanding all other terms by appropriate evalulations in the past.
- Parameters:
scheme (
Literal['BDF1','BDF2','Newmark2','TPZ','MPT','Simpson','Boole','trapezoidal','Kepler','Milne','midpoint']) – The time stepping scheme to apply (“BDF1”,”BDF2”,”Newmark2”,”TPZ”,”MPT”,”Simpson”,”Boole”)expr (
Expression|GiNaC_GlobalParam|int|float) – The expression to apply the time stepping scheme to.only_implicit_terms (
bool) – Whether to only evaluate the implicit terms (history terms will be not affected). Defaults to False.apply_on_integral_dx (
bool) – Whether to apply the evaluation on dx symbols. Defaults to False.apply_on_others (
bool) – Whether the history evaluations also take the normal, the Eulerian element sizes and the Eulerian spatial derivatives in grad/div from the mesh of the corresponding history step. Defaults to True, since a term evaluated at an earlier time should be evaluated on the mesh of that time throughout. Has no effect unless the mesh moves.
- Return type:
- Returns:
The result of applying the time stepping scheme to the expression.
- Raises:
ValueError – If an unknown time stepping scheme is provided.
- pyoomph.expressions.generic.transpose(A)[source]
Transposes the given matrix.
- Parameters:
A (
Expression) – The matrix expression to be transposed.- Returns:
The transposed matrix.
- Return type:
- pyoomph.expressions.generic.unit_matrix(dim=-1)
Returns the identity matrix of the specified dimension.
- Parameters:
dim (
int) – The dimension of the identity matrix. If not provided, the dimension is 3.- Returns:
The identity matrix.
- Return type:
- pyoomph.expressions.generic.unit_vector(dir)[source]
Returns a unit vector in the specified direction.
- Parameters:
dir (
Union[int,Literal['x','y','z']]) – The direction of the unit vector. Can be either an integer (0, 1, or 2) or a string (“x”, “y”, or “z”).- Returns:
A vector expression representing the unit vector in the specified direction.
- Return type:
- pyoomph.expressions.generic.upper_convected_derivative(A, velocity, ALE='auto', dt_scheme=None, nondim=False, lagrangian=False, dt_factor=1, advection_factor=1, coordsys=None)[source]
Returns the upper-convected derivative of a tensor field \(\mathbf{A}\), i.e. \(\partial_t \mathbf{A} + \vec{u}\cdot\nabla\mathbf{A}-(\nabla \vec{u})\cdot \mathbf{A} - \mathbf{A}\cdot(\nabla\vec{u})^\mathrm{T}\).
Note where the transpose sits: with pyoomph’s convention \((\nabla\vec{u})_{ij}=\partial u_i/\partial x_j\) (see
grad()) the stretching terms are \(-\mathbf{L}\mathbf{A}-\mathbf{A}\mathbf{L}^\mathrm{T}\) with \(\mathbf{L}=\nabla\vec{u}\), which follows from \(\mathbf{C}=\mathbf{F}\mathbf{F}^\mathrm{T}\) and \(\dot{\mathbf{F}}=\mathbf{L}\mathbf{F}\). References written with the opposite gradient convention state the same object with the two transposes interchanged.- Parameters:
A (
Expression|GiNaC_GlobalParam|int|float) – Rank-2 tensor field to be advected.velocity (
Expression|GiNaC_GlobalParam|int|float) – Advection velocityALE (
Union[Literal['auto'],bool]) – Use ALE correction. If set to"auto", it will only be used if the coordinates are degrees of freedom.dt_scheme (
Optional[Literal['BDF1','BDF2','Newmark2','TPZ','MPT','Simpson','Boole','trapezoidal','Kepler','Milne','midpoint']]) – Used time stepping scheme. If set to None, the default time stepping scheme set at problem level will be used.nondim (
bool) – Using non-dimensional time. Defaults to False.lagrangian (
bool) – Using Lagrangian coordinates for the gradient.dt_factor (
Expression|GiNaC_GlobalParam|int|float) – Factor to weight the \(\partial_t \mathbf{A}\) term.advection_factor (
Expression|GiNaC_GlobalParam|int|float) – Factor to weight the advection termcoordsys (
CustomCoordinateSystem|None) – Optional coordinate system to use. Defaults to None, meaning the coordinate system at equation level, parent equation level or problem level.
- Return type:
- Returns:
The upper convected derivative of the tensor field \(\mathbf{A}\) advected by the velocity field \(\vec{u}\).
Notes
Both the advection term and \(\nabla\vec{u}\) are built from
grad(), so on a domain with a co-dimension they are the surface gradient. Usevar("velocity",domain="..")to get the bulk gradient at an interface.
- pyoomph.expressions.generic.var(arg, *, tag=[], domain=None, no_jacobian=False, no_hessian=False, only_base_mode=False, only_perturbation_mode=False)[source]
Binds a variable or a list of variables for usage in an expression by supplying the name(s)
- Parameters:
arg (
str|tuple[str] |list[str]) – A single variable name or a sequence of variable names.tag (
list[str]) – A list of tags to associate with the variable(s). Defaults to [].domain (
str|FiniteElementCodeGenerator|None) – The domain of the variable(s). Defaults to None, meaning the current domain. To get the bulk domain, use"..", for the opposite side of the interface, use"|.", for the opposite bulk domain use"|..".no_jacobian (
bool) – Flag indicating whether derivatives in Jacobian should be ignored. Defaults to False.no_hessian (
bool) – Flag indicating whether derivatives in the Hessian should be ignored. Defaults to False.only_base_mode (
bool) – Flag indicating whether only the axisymmetric base mode of the azimuthal mode expansion should be considered. Defaults to False.only_perturbation_mode (
bool) – Flag indicating whether only the azimuthal perturbation mode should be considered. Defaults to False.
- Return type:
Expression|tuple[Expression,...]- Returns:
A single expression or a tuple of expressions representing the variable(s) to be used in expressions.
Notes
- Special variable names are:
"time": Current time"coordinate": indepedent coordinate vector. Time derivatives of this variable are zero"coordinate_x": indepedent x-coordinate. Time derivatives of this variable are zero"coordinate_y": indepedent y-coordinate. Time derivatives of this variable are zero"coordinate_z": indepedent z-coordinate. Time derivatives of this variable are zero"mesh": mesh coordinate vector, similar to"coordinate", but the time derivative gives the mesh velocity"mesh_x": mesh x-coordinate, similar to"coordinate_x", but the time derivative gives the mesh x-velocity"mesh_y": mesh y-coordinate, similar to"coordinate_y", but the time derivative gives the mesh y-velocity"mesh_z": mesh z-coordinate, similar to"coordinate_z", but the time derivative gives the mesh z-velocity"lagrangian": Lagrangian coordinate vector. By default, initialized with the initial Eulerian"coordinate""lagrangian_x": Lagrangian x-coordinate"lagrangian_y": Lagrangian y-coordinate"lagrangian_z": Lagrangian z-coordinate"normal": Normal vector. To be used at elements with co-dimension, i.e. interface elements"normal_x": x-component of the normal"normal_y": y-component of the normal"normal_z": z-component of the normal"dx": Can be used like in FEniCS to expressweak(a,b)asa*b*var("dx"). It does not respect the functional determinant of the coordinate system, though."dX": Same as"dx", but for Lagrangian integrals"element_size_Eulerian": Eulerian integration of the volume/area/length of the current element. Uses the coordinate system of the element, i.e. considers e.g. \(2\\pi\:r\) in axisymmetry"cartesian_element_size_Eulerian": Same as above, but does not consider the coordinate system"element_size_Lagrangian": Same as “element_size_Eulerian”, but by Lagrangian integration"cartesian_element_size_Lagrangian": Same as"cartesian_element_size_Eulerian", but by Lagrangian integration"element_length_h": Typical length scale of the element, calculated by taking"element_size_Eulerian"to the power of one over the element dimension"cartesian_element_length_h": Typical length scale of the element, but calculated in a Cartesian coordinate system
- pyoomph.expressions.generic.vector(*args)[source]
Create a vector expression from the given components.
- Parameters:
*args (
Expression|GiNaC_GlobalParam|int|float|Sequence[Expression|GiNaC_GlobalParam|int|float]) – Variable number of arguments representing the vector components. Each component can be either an Expression, float, or int. If a single list is provided as the first argument, it is treated as the list of vector components.- Returns:
The vector expression created from the given components.
- Return type:
- Raises:
RuntimeError – If the arguments are not provided correctly.
ValueError – If the vector has too many components or no components at all.
- pyoomph.expressions.generic.weak(a, b, *, dimensional_dx=False, lagrangian=False, coordsys=None)[source]
Construct a term of a weak form, i.e. (a,b)=integral_Omega a*b dOmega where Omega is the domain. a is usually an expression depending on unknowns and b is usually a test function or spatial differentiations thereof.
- Parameters:
a (
Expression|GiNaC_GlobalParam|int|float) – An expression, usually a expression depending on unknowns.b (
Expression|GiNaC_GlobalParam|int|float) – A testfunction or any linear function/operator applied on a testfunction.dimensional_dx (
bool) – Flag indicating whether consider spatial integration units (e.g. m, m^2, m^3). Defaults to False.lagrangian (
bool) – Flag indicating whether to integrate with respect to the Lagrangian coordinates and domain. Defaults to False.coordsys (
CustomCoordinateSystem|None) – The coordinate system to use. Defaults to None, meaning the coordinate system at equation level, parent equation level or problem level. The former namecoordinate_systemis deprecated, but still accepted.
- Returns:
A weak form that can be further used in expressions or added to the residuals of equations by the method add_residual.
- Return type: