-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved solve_system to generic ProblemDAE class
- Loading branch information
Showing
4 changed files
with
56 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,64 @@ | ||
import numpy as np | ||
from scipy.optimize import root | ||
|
||
from pySDC.core.Problem import ptype | ||
from pySDC.core.Problem import ptype, WorkCounter | ||
from pySDC.implementations.datatype_classes.mesh import mesh | ||
|
||
|
||
class ptype_dae(ptype): | ||
""" | ||
Interface class for DAE problems. Ensures that all parameters are passed that are needed by DAE sweepers | ||
r""" | ||
This class implements a generic DAE class and illustrates the interface class for DAE problems. | ||
It ensures that all parameters are passed that are needed by DAE sweepers. | ||
Parameters | ||
---------- | ||
nvars : int | ||
Number of unknowns of the problem class. | ||
newton_tol : float | ||
Tolerance for the nonlinear solver. | ||
Attributes | ||
---------- | ||
work_counters : WorkCounter | ||
Counts the work, here the number of function calls during the nonlinear solve is logged. | ||
""" | ||
|
||
dtype_u = mesh | ||
dtype_f = mesh | ||
|
||
def __init__(self, nvars, newton_tol): | ||
""" | ||
Initialization routine | ||
Args: | ||
problem_params (dict): custom parameters for the example | ||
dtype_u: mesh data type (will be passed parent class) | ||
dtype_f: mesh data type (will be passed parent class) | ||
""" | ||
"""Initialization routine""" | ||
super().__init__((nvars, None, np.dtype('float64'))) | ||
self._makeAttributeAndRegister('nvars', 'newton_tol', localVars=locals(), readOnly=True) | ||
|
||
self.work_counters['newton'] = WorkCounter() | ||
|
||
def solve_system(self, impl_sys, u0, t): | ||
r""" | ||
Solver for nonlinear implicit system (defined in sweeper). | ||
Parameters | ||
---------- | ||
impl_sys : callable | ||
Implicit system to be solved. | ||
u0 : dtype_u | ||
Initial guess for solver. | ||
t : float | ||
Current time :math:`t`. | ||
Returns | ||
------- | ||
me : dtype_u | ||
Numerical solution. | ||
""" | ||
|
||
me = self.dtype_u(self.init) | ||
opt = root( | ||
impl_sys, | ||
u0, | ||
method='hybr', | ||
tol=self.newton_tol, | ||
) | ||
me[:] = opt.x | ||
self.work_counters['newton'].niter += opt.nfev | ||
return me |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.