core.problem module¶
Description¶
Module containing the base Problem class for pySDC
- class Problem(init: Any)[source]¶
Bases:
RegisterParamsPrototype class for problems, just defines the attributes essential to get started.
- Parameters:
- logger¶
custom logger for problem-related logging.
- Type:
logging.Logger
- dtype_f: Type[Any] | None = None¶
- dtype_u: Type[Any] | None = None¶
- property f_init: Any¶
Generate a data variable for RHS
- generate_scipy_reference_solution(eval_rhs: Callable, t: float, u_init: Any | None = None, t_init: float | None = None, **kwargs: Any) Any[source]¶
Compute a reference solution using scipy.solve_ivp with very small tolerances. Keep in mind that scipy needs the solution to be a one dimensional array. If you are solving something higher dimensional, you need to make sure the function eval_rhs takes a flattened one-dimensional version as an input and output, but reshapes to whatever the problem needs for evaluation.
The keyword arguments will be passed to scipy.solve_ivp. You should consider passing method=’BDF’ for stiff problems and to accelerate that you can pass a function that evaluates the Jacobian with arguments jac(t, u) as jac=jac.
- Parameters:
eval_rhs (function) – Function evaluate the full right hand side. Must have signature eval_rhs(float: t, numpy.1darray: u)
t (float) – current time
u_init (pySDC.implementations.problem_classes.Lorenz.dtype_u) – initial conditions for getting the exact solution
t_init (float) – the starting time
- Returns:
Reference solution
- Return type:
numpy.ndarray
- get_fig() Any[source]¶
Get a figure suitable to plot the solution of this problem
- Returns:
self.fig
- Return type:
matplotlib.pyplot.figure.Figure
- logger: Logger = <Logger problem (WARNING)>¶
- plot(u: Any, t: float | None = None, fig: Any | None = None) None[source]¶
Plot the solution. Please supply a figure with the same structure as returned by
self.get_fig.- Parameters:
u (dtype_u) – Solution to be plotted
t (float) – Time to display at the top of the figure
fig (matplotlib.pyplot.figure.Figure) – Figure with the correct structure
- Return type:
None
- solve_jacobian(rhs: Any, dt: float, u: Any | None = None, u0: Any | None = None, t: float = 0, **kwargs: Any) Any[source]¶
Solve the Jacobian for an Euler step, linearized around u. This defaults to an Euler step to accommodate linear problems.
- Parameters:
rhs – Right hand side for the Euler step
dt (float) – Step size for the Euler step
u – Solution to linearize around
u0 – Initial guess
t (float) – Current time
- Returns:
Solution
- solve_system(rhs: Any, dt: float, u0: Any, t: float) Any[source]¶
Perform an Euler step.
- Parameters:
rhs – Right hand side for the Euler step
dt (float) – Step size for the Euler step
u0 – Initial guess
t (float) – Current time
- Returns:
solution to the Euler step
- property u_init: Any¶
Generate a data variable for u
- class WorkCounter[source]¶
Bases:
objectUtility class for counting iterations.
Contains one attribute niter initialized to zero during instantiation, which can be incremented by calling object as a function, e.g
>>> count = WorkCounter() # => niter = 0 >>> count() # => niter = 1 >>> count() # => niter = 2
- niter: int¶