-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #96 from chrhansk/feature-step-control-refactor
Refactor step controllers
- Loading branch information
Showing
22 changed files
with
120 additions
and
74 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,19 @@ | ||
from pygradflow.params import Params | ||
from pygradflow.problem import Problem | ||
from pygradflow.step.step_control import StepController, StepControlResult | ||
from pygradflow.step.newton_control import NewtonController | ||
from pygradflow.step.step_control import StepControlResult | ||
|
||
|
||
class FixedStepSizeController(StepController): | ||
class FixedStepSizeController(NewtonController): | ||
def __init__(self, problem: Problem, params: Params) -> None: | ||
super().__init__(problem, params) | ||
self.lamb = params.lamb_init | ||
|
||
def step(self, iterate, rho, dt, next_steps, display, timer): | ||
def step(self, iterate, rho, dt, display, timer): | ||
assert dt > 0.0 | ||
|
||
next_steps = self.newton_steps(iterate, rho, dt) | ||
|
||
step = next(next_steps) | ||
|
||
return StepControlResult.from_step_result(step, self.lamb, True) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from typing import Iterator, Optional | ||
|
||
from pygradflow.iterate import Iterate | ||
from pygradflow.newton import newton_method | ||
from pygradflow.params import Params | ||
from pygradflow.problem import Problem | ||
from pygradflow.step.solver.step_solver import StepResult | ||
from pygradflow.step.step_control import StepController | ||
|
||
|
||
class NewtonController(StepController): | ||
""" | ||
Step controller working by solving the implicit Euler | ||
equations using a semi-smooth Newton method | ||
""" | ||
|
||
def __init__(self, problem: Problem, params: Params) -> None: | ||
super().__init__(problem, params) | ||
|
||
def newton_steps( | ||
self, | ||
iterate: Iterate, | ||
rho: float, | ||
dt: float, | ||
initial_iterate: Optional[Iterate] = None, | ||
) -> Iterator[StepResult]: | ||
problem = self.problem | ||
params = self.params | ||
|
||
self.method = newton_method(problem, params, iterate, dt, rho) | ||
|
||
if initial_iterate is not None: | ||
curr_iterate = initial_iterate | ||
else: | ||
curr_iterate = iterate | ||
|
||
while True: | ||
next_step = self.method.step(curr_iterate) | ||
yield next_step | ||
curr_iterate = next_step.iterate |
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
11 changes: 6 additions & 5 deletions
11
pygradflow/step/__init__.py → pygradflow/step/solver/__init__.py
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
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
Oops, something went wrong.