-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added
solve_system
to all DAE problem classes (#371)
* Added solve_system method to all DAE classes * Removed comment * Moved solve_system to generic ProblemDAE class * Used possibility to update documentation :D * Moved work_counters for rhs also to ProblemDAE * Inheritance from generic_implicit
- Loading branch information
Showing
5 changed files
with
143 additions
and
103 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,67 @@ | ||
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 and stored | ||
in work_counters['newton']. The number of each function class of the right-hand side is then stored | ||
in work_counters['rhs'] | ||
""" | ||
|
||
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() | ||
self.work_counters['rhs'] = 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
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