diff --git a/conmech/plotting/drawer.py b/conmech/plotting/drawer.py index 9586099a..1094e56a 100644 --- a/conmech/plotting/drawer.py +++ b/conmech/plotting/drawer.py @@ -4,6 +4,7 @@ @author: MichaƂ Jureczka @author: Piotr Bartman """ +import time import matplotlib.pyplot as plt import networkx as nx @@ -245,7 +246,7 @@ def draw_stress(self, axes): def get_output_path(config, format_, name): output_dir = config.output_dir or str(config.timestamp) directory = f"{config.outputs_path}/{output_dir}" - name = name if name else config.timestamp + name = name if name else time.time_ns() path = f"{directory}/{name}.{format_}" return path diff --git a/conmech/solvers/optimization/optimization.py b/conmech/solvers/optimization/optimization.py index 1e5c4eae..34a5275f 100644 --- a/conmech/solvers/optimization/optimization.py +++ b/conmech/solvers/optimization/optimization.py @@ -122,10 +122,19 @@ def _solve_impl( "quasi secant method limited memory", "qsm", "qsmlm", + ): + # pylint: disable=import-outside-toplevel,import-error) + from kosopt import qsmlm + solution = qsmlm.minimize( + self.loss, solution, args=args, maxiter=maxiter + ) + elif method.lower() in ( # TODO + "discontinuous gradient", + "discontinuous gradient method", + "dg", ): # pylint: disable=import-outside-toplevel,import-error) from kosopt import qsmlmi - solution = qsmlmi.minimize( self.loss, solution, args=args, maxiter=maxiter ) diff --git a/conmech/solvers/solver.py b/conmech/solvers/solver.py index 9408330b..7d0c1e02 100644 --- a/conmech/solvers/solver.py +++ b/conmech/solvers/solver.py @@ -4,6 +4,7 @@ from typing import Callable, Optional import numpy as np +import time from conmech.dynamics.statement import Statement, Variables from conmech.scenarios.problems import ContactLaw @@ -46,6 +47,8 @@ def __init__( ) ) + self.last_timing = None + def __str__(self) -> str: raise NotImplementedError() @@ -58,6 +61,7 @@ def _solve_impl( raise NotImplementedError() def solve(self, initial_guess: np.ndarray, **kwargs) -> np.ndarray: + start = time.time() solution = self._solve_impl( initial_guess, velocity=self.v_vector, displacement=self.u_vector, **kwargs ) @@ -70,4 +74,6 @@ def solve(self, initial_guess: np.ndarray, **kwargs) -> np.ndarray: ): solution[i] = c[j] + self.last_timing = time.time() - start + return solution diff --git a/examples/Bagirov_Bartman_Ochal_2023.py b/examples/Bagirov_Bartman_Ochal_2023.py index a09bf002..2db00671 100644 --- a/examples/Bagirov_Bartman_Ochal_2023.py +++ b/examples/Bagirov_Bartman_Ochal_2023.py @@ -108,7 +108,7 @@ def main(config: Config): setup = StaticSetup(mesh_descr=mesh_descr) - for method in ("Powell", "BFGS", "CG", "qsm")[3:]: + for method in ("Powell", "BFGS", "CG", "qsm", "dg")[:]: for force in ( np.asarray([23e3 * kN, 26.2e3 * kN, 27e3 * kN, 30e3 * kN]) * surface ): @@ -130,7 +130,12 @@ def outer_forces(x, t=None): ) drawer = Drawer(state=state, config=config) drawer.colorful = True - drawer.draw(show=config.show, save=config.save, title=f"{method}: {force}") + drawer.draw( + show=config.show, + save=config.save, + title=f"{method}: {force}, " + f"time: {runner.step_solver.last_timing}" + ) if __name__ == "__main__": @@ -142,4 +147,4 @@ def outer_forces(x, t=None): Y[i] = MMLV99.potential_normal_direction(X[i]) plt.plot(X, Y) plt.show() - main(Config().init()) + main(Config(save=True, show=False).init())