Core¶
In the Core module you can find all basic classes and functions which form the backbone of the toolbox.
-
class
BaseFraction(members)[source]¶ Bases:
objectAbstract base class representing a basis that can be used to describe functions of several variables.
-
derive(order)[source]¶ Basic implementation of derive function. Empty implementation, overwrite to add more functionality.
Parameters: order ( numbers.Number) – derivative orderReturns: derived object Return type: BaseFraction
-
get_member(idx)[source]¶ Getter function to access members.
Note
Empty function, overwrite to implement custom functionality.
Parameters: idx – member index
-
scalar_product_hint()[source]¶ Empty Hint that can return steps for scalar product calculation.
In detail this means a list object containing function calls to fill with (first, second) parameters that will calculate the scalar product when summed up.
Note
Overwrite to implement custom functionality.
-
scale(factor)[source]¶ Factory method to obtain instances of this base fraction, scaled by the given factor. Empty function, overwrite to implement custom functionality.
Parameters: factor – Factor to scale the vector.
-
transformation_hint(info, target)[source]¶ Method that provides a information about how to transform weights from one
BaseFractioninto another.In Detail this function has to return a callable, which will take the weights of the source- and return the weights of the target system. It may have keyword arguments for other data which is required to perform the transformation. Information about these extra keyword arguments should be provided in form of a dictionary whose keys are keyword arguments of the returned transformation handle.
Note
This implementation covers the most basic case, where the two
BaseFractions are of same type. For any other case it will raise an exception. Overwrite this Method in your implementation to support conversion between bases that differ from yours.Parameters: - info –
TransformationInfo - target –
TransformationInfo
Raises: NotImplementedErrorReturns: Transformation handle
- info –
-
-
class
ComposedFunctionVector(functions, scalars)[source]¶ Bases:
pyinduct.core.BaseFractionImplementation of composite function vector
.
-
class
Function(eval_handle, domain=(-inf, inf), nonzero=(-inf, inf), derivative_handles=None)[source]¶ Bases:
pyinduct.core.BaseFractionMost common instance of a
BaseFraction. This class handles all tasks concerning derivation and evaluation of functions. It is used broad across the toolbox and therefore incorporates some very specific attributes. For example, to ensure the accurateness of numerical handling functions may only evaluated in areas where they provide nonzero return values. Also their domain has to be taken into account. Therefore the attributes domain and nonzero are provided.To save implementation time, ready to go version like
pyinduct.shapefunctions.LagrangeFirstOrderare provided in thepyinduct.simulationmodule.For the implementation of new shape functions subclass this implementation or directly provide a callable eval_handle and callable derivative_handles if spatial derivatives are required for the application.
Parameters: - eval_handle – Callable object that can be evaluated.
- domain – Domain on which the eval_handle is defined.
- nonzero – Region in which the eval_handle will give nonzero output.
- derivative_handles (list) – List of callable(s) that contain derivatives of eval_handle
-
derivative_handles¶
-
derive(order=1)[source]¶ Spatially derive this
Function.This is done by neglecting order derivative handles and to select handle
as the new
evaluation_handle.Parameters: order (int) – the amount of derivations to perform
Raises: TypeError– If order is not of type int.ValueError– If the requested derivative order is higher than the provided one.
Returns: Functionthe derived function.
-
evaluation_hint(values)[source]¶ If evaluation can be accelerated by using special properties of a function, this function can be overwritten to performs that computation. It gets passed an array of places where the caller wants to evaluate the function and should return an array of the same length, containing the results.
Note
This implementation just calls the normal evaluation hook.
Parameters: values – places to be evaluated at Returns: Evaluation results. Return type: numpy.ndarray
-
function_handle¶
-
get_member(idx)[source]¶ Implementation of the abstract parent method.
Since the
Functionhas only one member (itself) the parameter idx is ignored and self is returned.Parameters: idx – ignored. Returns: self
-
raise_to(power)[source]¶ Raises the function to the given power.
Warning
Derivatives are lost after this action is performed.
Parameters: power ( numbers.Number) – power to raise the function toReturns: raised function
-
scalar_product_hint()[source]¶ Return the hint that the
pyinduct.core.dot_product_l2()has to calculated to gain the scalar product.
-
scale(factor)[source]¶ Factory method to scale a
pyinduct.core.Function.Parameters: factor – numbers.Numberor a callable.
-
transformation_hint(info, target)[source]¶ If info.src_base is a subclass of Function, use default strategy.
Note
If a different behaviour is desired, overwrite this method.
Parameters: - info (
TransformationInfo) – Information about the requested transformation. - target (bool) – Is the called object the target of the transformation? If False, source and target in info will be swapped.
Returns: transformation handle
- info (
-
class
TransformationInfo[source]¶ Bases:
objectStructure that holds information about transformations between different bases.
This class serves as an easy to use structure to aggregate information, describing transformations between different
BaseFractions. It can be tested for equality to check the equity of transformations and is hashable which makes it usable as dictionary key to cache different transformations.-
src_lbl¶ str – label of source basis
-
dst_lbl¶ str – label destination basis
-
src_base¶ numpy.ndarray– source basis in form of an array of the source Fractions
-
dst_base¶ numpy.ndarray– destination basis in form of an array of the destination Fractions
-
src_order¶ available temporal derivative order of source weights
-
dst_order¶ needed temporal derivative order for destination weights
-
-
back_project_from_base(weights, base)[source]¶ Build evaluation handle for a distributed variable that was approximated as a set of weights om a certain base.
Parameters: - weights (numpy.ndarray) – Weight vector.
- base (numpy.ndarray) – Vector that generates the base.
Returns: evaluation handle
-
calculate_base_transformation_matrix(src_base, dst_base)[source]¶ Calculates the transformation matrix
, so that the a set of weights, describing a function in the
src_base will express the same function in the dst_base, while minimizing the reprojection error.
An quadratic error is used as the error-norm for this case.Warning
This method assumes that all members of the given bases have the same type and that their
BaseFractions, define compatible scalar products.Raises: TypeError– If given bases do not provide anscalar_product_hint()method.Parameters: - dst_base (
BaseFraction) – New projection base. - src_base (
BaseFraction) – Current projection base.
Returns: Transformation matrix
.Return type: numpy.ndarray- dst_base (
-
calculate_expanded_base_transformation_matrix(src_base, dst_base, src_order, dst_order, use_eye=False)[source]¶ Constructs a transformation matrix
from basis given by src_base to basis given
by dst_base that also transforms all temporal derivatives of the given weights.- See:
calculate_base_transformation_matrix()for further details.
Parameters: - dst_base (
BaseFraction) – New projection base. - src_base (
BaseFraction) – Current projection base. - src_order – Temporal derivative order available in src_base.
- dst_order – Temporal derivative order needed in dst_base.
- use_eye (bool) – Use identity as base transformation matrix. (For selection of derivatives in the same base)
Raises: ValueError– If destination needs a higher derivative order than source can provide.Returns: Transformation matrix
Return type: numpy.ndarray
-
calculate_scalar_matrix(values_a, values_b)[source]¶ Convenience version of py:function:calculate_scalar_product_matrix with
numpy.multiply()hardcoded as scalar_product_handle.Parameters: - values_a (numbers.Number or numpy.ndarray) – (array of) value(s) for rows
- values_b (numbers.Number or numpy.ndarray) – (array of) value(s) for columns
Returns: Matrix containing the pairwise products of the elements from values_a and values_b.
Return type: numpy.ndarray
-
calculate_scalar_product_matrix(scalar_product_handle, base_a, base_b, optimize=False)[source]¶ Calculates a matrix
, whose elements are the scalar products of each element from base_a and base_b,
so that
.Parameters: - scalar_product_handle (callable) – function handle that is called to calculate the scalar product. This function has to be able to cope with (1d) vectorial input.
- base_a (numpy.ndarray) – array of
BaseFraction - base_b (numpy.ndarray) – array of
BaseFraction - optimize (bool) – switch to turn on the symmetry based speed up. For development purposes only.
Returns: matrix 
Return type: numpy.ndarray
-
change_projection_base(src_weights, src_base, dst_base)[source]¶ Converts given weights that form an approximation using src_base to the best possible fit using dst_base. Bases can be given as
BaseFractionarray.Parameters: - src_weights (numpy.ndarray) – Vector of numbers.
- src_base (numpy.ndarray) – Vector of
BaseFractions that generate the source basis - dst_base (numpy.ndarray) – Vector of
BaseFractions that generate the target basis
Returns: target weights
Return type: numpy.ndarray
-
complex_quadrature(func, a, b, **kwargs)[source]¶ Wraps the scipy qaudpack routines to handle complex valued functions.
Parameters: - func (callable) – function
- a (
numbers.Number) – lower limit - b (
numbers.Number) – upper limit - **kwargs – Arbitrary keyword arguments for desired scipy qaudpack routine.
Returns: (real part, imaginary part)
Return type: tuple
-
domain_intersection(first, second)[source]¶ Calculate intersection(s) of two domains.
Parameters: - first (
pyinduct.simulation.Domain) – first domain - second (
pyinduct.simulation.Domain) – second domain
Returns: intersection(s) given by (start, end) tuples.
Return type: list
- first (
-
dot_product(first, second)[source]¶ Calculates the inner product of two vectors.
Parameters: - first (
numpy.ndarray) – first vector - second (
numpy.ndarray) – second vector
Returns: inner product
- first (
-
dot_product_l2(first, second)[source]¶ Vectorized version of dot_product.
Parameters: - first (callable or
numpy.ndarray) – (1d array of) callable(s) - second (callable or
numpy.ndarray) – (1d array of) callable(s)
Returns: array of inner products
Return type: numpy.ndarray
- first (callable or
-
get_weight_transformation(info)[source]¶ Create a handle that will transform weights from info.src_base into weights for info-dst_base while paying respect to the given derivative orders.
This is accomplished by recursively iterating through source and destination bases and evaluating their
transformation_hints.Parameters: info (py:class:TransformationInfo) – information about the requested transformation. Returns: transformation function handle Return type: callable
-
integrate_function(function, interval)[source]¶ Integrates the given function over the interval using
complex_quadrature().Parameters: - function (callable) – Function to integrate.
- interval (Tuple) – (start, end) values of the Interval to integrate on.
Returns: (Result of the Integration, errors that occurred during the integration).
Return type: tuple
-
normalize_base(b1, b2=None)[source]¶ Takes two arrays of
BaseFractions
and
and normalizes them so
that
.
If only one base is given,
is set to
.Parameters: - b1 (np.array of
BaseFraction) –
- b2 (np.array of
BaseFraction) –
Raises: ValueError– If
and
are orthogonal.Returns: - if b2 is None,
otherwise: Tuple of 2
BaseFractionarrays.
Return type: np.array of
BaseFraction- b1 (np.array of
-
project_on_base(function, base)[source]¶ Projects a function on a basis given by base.
Parameters: Returns: Weight vector in the given base
Return type: numpy.ndarray
-
project_weights(projection_matrix, src_weights)[source]¶ Project src_weights on new basis using the provided projection_matrix.
Parameters: - projection_matrix (
numpy.ndarray) – projection between the source and the target basis; dimension (m, n) - src_weights (
numpy.ndarray) – weights in the source basis; dimension (1, m)
Returns: weights in the target basis; dimension (1, n)
Return type: numpy.ndarray- projection_matrix (