Problem Interface (i_problem)

class pypint.problems.i_problem.IProblem(*args, **kwargs)[source]

Bases: builtins.object

Basic interface for all problems of type \(u'(t,\phi(t))=F(t,\phi(t))\)

__init__(*args, **kwargs)[source]
Parameters:
  • rhs_function_wrt_time (callable) – Function describing the right hand side of the problem equation. Two arguments are required, the first being the time point \(t\) and the second the time-dependent value \(\phi(t)\).
  • time_start (float) – Start of the time interval to integrate over.
  • time_end (float) – End of the time interval to integrate over.
  • dim (tuple) – Number of spacial dimensions, i.e. number of degrees of freedom including shape of spacial points. The first elements denote the number of spacial dimensions (default=``1``) and the last the number of degrees of freedom (variables) at each spacial point. Defaults to (1, 1).
  • strings (dict) –

    (optional) String representation of problem for logging output.

    rhs_wrt_time : str
    string representation of the right hand side w.r.t. time

Examples

>>> # default Problem
>>> prob = IProblem()
>>> prob.dim
(1, 1)
>>> # Problem with two spacial dimensions and one variable at each point
>>> prob = IProblem(dim=(2, 3, 1))
>>> prob.dim
(2, 3, 1)
>>> prob.spacial_dim
(2, 3)
>>> prob.num_spacial_points
6
>>> prob.dofs_per_point
1
evaluate_wrt_time(time, phi_of_time, **kwargs)[source]

Evaluates given right hand side at given time and with given time-dependent value.

Parameters:
  • time (float) – Time point \(t\)
  • phi_of_time (numpy.ndarray) – Time-dependent data.
  • partial (str or None) – (optional) Specifying whether only a certain part of the problem function should be evaluated. E.g. useful for semi-implicit SDC where the imaginary part of the function is explicitly evaluated and the real part of the function implicitly. Usually it is one of None, impl or expl.
Returns:

rhs_value

Return type:

numpy.ndarray

Raises:

ValueError – if time or phi_of_time are not of correct type.

implicit_solve(next_x, func, method='hybr', **kwargs)[source]

A solver for implicit equations.

Finds the implicitly defined \(x_{i+1}\) for the given right hand side function \(f(x_{i+1})\), such that \(x_{i+1}=f(x_{i+1})\).

Parameters:
  • next_x (numpy.ndarray) – A starting guess for the implicitly defined value.
  • rhs_call (callable) – The right hand side function depending on the implicitly defined new value.
  • method (str) – (optional, default=``hybr``) Method fo the root finding algorithm. See scipy.optimize.root <http://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.root.html#scipy.optimize.root> for details.
Returns:

next_x – The calculated new value.

Return type:

numpy.ndarray

Raises:
  • ValueError
    • if next_x is not a numpy.ndarray of shape IProblem.dim
    • if fun is not callable
    • if computed solution is not a :py:class:`numpy.ndarray
  • UserWarning – If the implicit solver did not converged, i.e. the solution object’s success is not True.
__weakref__

list of weak references to the object (if defined)

dim[source]

Read-only accessor for the spacial degrees of freedom of the problem

Returns:dofs – First elements denotes shape of spacial points; the last element the number degrees of freedom (i.e. variables) at each spacial point.
Return type:tuple
dim_for_time_solver[source]

Dimension of array for Time Solvers

This shape is used for the arrays of time solvers, which do not need to know the spacial shape of the spacial points.

Returns:dim_for_time_solver – First element is the total number of spacial points (num_spacial_points) and the second element the number of variables per spacial point (dofs_per_point).
Return type:tuple
dofs_per_point[source]

Variables / Degrees of Freedom at each spacial point

dofs_per_point : int

num_spacial_points[source]

Total number of spacial points

Returns:num_spacial_points – product of the elements of spacial_dim
Return type:int
numeric_type[source]

Accessor for the numerical type of the problem values.

Parameters:numeric_type (numpy.dtype) – Usually it is numpy.float64 or numpy.complex16
Returns:numeric_type
Return type:numpy.dtype
Raises:ValueError – If numeric_type is not a numpy.dtype.
rhs_function_wrt_time[source]

Accessor for the right hand side function.

Parameters:function (callable) – Function of the right hand side of \(u'(t,x)=F(t,\phi_t)\)
Returns:rhs_function – Function of the right hand side.
Return type:callable
spacial_dim[source]

Shape of spacial points

Returns:spacial_dim
Return type:tuple