Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/porepy/models/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -1020,10 +1020,11 @@ def save_data_time_step(self) -> None:
* `list`: Export if time is in the list. If the list is empty, then no
times are exported.

In addition, save the solver statistics to file if the option is set.

"""

def save_statistics(self) -> None:
"""Save the solver statistics to file if the option is set."""

def initialize_data_saving(self) -> None:
"""Initialize data saving.

Expand Down
6 changes: 5 additions & 1 deletion src/porepy/models/solution_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,18 +485,22 @@ def after_time_step_convergence(self) -> None:

1. Call :meth:`update_time_step_solution`.
2. Call :meth:`save_data_time_step`.
3. Call :meth:`save_statistics`.

"""
self.update_time_step_solution()
self.save_data_time_step()
self.save_statistics()

def after_time_step_failure(self) -> None:
"""Called after a time step has failed to converge.

The base method reverts the trial time step being executed.
It also calls :meth:`save_statistics`.

"""
self.revert_trial_time_step_solution()
self.save_statistics()

def reset_state_from_file(self) -> None:
"""Reset states but through a restart from file.
Expand Down Expand Up @@ -777,7 +781,7 @@ def revert_trial_time_step_solution(self) -> None:

def after_simulation(self) -> None:
"""Run at the end of simulation. Can be used for cleanup etc."""
pass
self.save_statistics()

def assemble_linear_system(self) -> solvers.LinearSystem:
"""Assemble and return the linearized system.
Expand Down
3 changes: 1 addition & 2 deletions src/porepy/numerics/solvers/nonlinear_solvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,8 +536,7 @@ def check_convergence(
"""Check convergence and divergence based on passed criteria.

Parameters:
model: The model instance specifying the problem to be solved, knowing
of its metrics for measuring states and residuals.
model: The model instance specifying the problem to be solved.
nonlinear_increment: Newly obtained solution increment vector.

Returns:
Expand Down
7 changes: 4 additions & 3 deletions src/porepy/viz/data_saving_model_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ def save_data_time_step(self) -> None:
if do_export:
self.write_pvd_and_vtu()

# Save solver statistics to file.
self.nonlinear_solver_statistics.save()

# Collecting and storing data in runtime for analysis. If default value of None
# is returned, nothing is stored to not burden memory.
if not self._is_time_dependent():
Expand All @@ -75,6 +72,10 @@ def save_data_time_step(self) -> None:
if collected_data is not None:
self.results.append(collected_data)

def save_statistics(self):
"""Save solver statistics to file."""
self.nonlinear_solver_statistics.save()

def collect_data(self) -> Any:
"""Collect relevant simulation data to be stored in attr:`results`.

Expand Down
3 changes: 3 additions & 0 deletions tests/viz/test_solver_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,9 @@ def test_solver_statistics_save_in_model(path, exists):
model = DummyModel(params)
model.prepare_simulation()

# Save the solver statistics explicitly.
model.save_statistics()

# Check whether file was saved and has correct suffix.
if exists:
assert model.nonlinear_solver_statistics.path.exists()
Expand Down
Loading