Skip to content
Snippets Groups Projects
Commit 04e25d26 authored by EXT Jean-Matthieu Etancelin's avatar EXT Jean-Matthieu Etancelin
Browse files

improve iterative simulation config

parent 8abd0860
No related branches found
No related tags found
1 merge request!16MPI operators
...@@ -4,7 +4,7 @@ from hysop import Simulation, Problem ...@@ -4,7 +4,7 @@ from hysop import Simulation, Problem
from hysop.parameters.scalar_parameter import ScalarParameter from hysop.parameters.scalar_parameter import ScalarParameter
from hysop.tools.contexts import Timer from hysop.tools.contexts import Timer
from hysop import dprint, vprint from hysop import dprint, vprint
from hysop.tools.decorators import debug from hysop.tools.decorators import debug
from hysop.core.graph.graph import ready from hysop.core.graph.graph import ready
from hysop.constants import HYSOP_REAL, HYSOP_INTEGER from hysop.constants import HYSOP_REAL, HYSOP_INTEGER
from hysop.simulation import eps from hysop.simulation import eps
...@@ -13,6 +13,7 @@ from hysop.core.mpi import main_rank, main_size, main_comm ...@@ -13,6 +13,7 @@ from hysop.core.mpi import main_rank, main_size, main_comm
import numpy as np import numpy as np
import datetime import datetime
class PseudoSimulation(Simulation): class PseudoSimulation(Simulation):
"""Pseudo time-iterations for iterative method""" """Pseudo time-iterations for iterative method"""
...@@ -80,8 +81,9 @@ class IterativeMethod(Problem): ...@@ -80,8 +81,9 @@ class IterativeMethod(Problem):
override Problem class in a proper way. Here only a pseudo-timestep is override Problem class in a proper way. Here only a pseudo-timestep is
used together with a maximal number of iteration to compute a pseudo-final time. used together with a maximal number of iteration to compute a pseudo-final time.
""" """
def __init__(self, stop_criteria, tolerance=1e-8, state_print=100, max_iter=10000, def __init__(self, stop_criteria, tolerance=1e-8, state_print=100, max_iter=10000,
dt0=None, dt=None, **kwargs): dt0=None, dt=None, configsimu=None, **kwargs):
super(IterativeMethod, self).__init__(**kwargs) super(IterativeMethod, self).__init__(**kwargs)
self.stop_criteria, self.tolerance = stop_criteria, tolerance self.stop_criteria, self.tolerance = stop_criteria, tolerance
...@@ -104,9 +106,16 @@ class IterativeMethod(Problem): ...@@ -104,9 +106,16 @@ class IterativeMethod(Problem):
dtype=self.stop_criteria.dtype) dtype=self.stop_criteria.dtype)
self._stop_criteria_reset[...] = 1e10 self._stop_criteria_reset[...] = 1e10
self.configsimu = self._default_configsimu
if not configsimu is None:
self.configsimu = configsimu
def _default_configsimu(self, l, s):
pass
@debug @debug
@ready @ready
def apply(self, simulation, configsimu=lambda l:None, report_freq=100, **kwds): def apply(self, simulation, report_freq=0, **kwds):
vprint('=== Entering iterative method...') vprint('=== Entering iterative method...')
self.stop_criteria.value = self._stop_criteria_reset self.stop_criteria.value = self._stop_criteria_reset
...@@ -119,8 +128,9 @@ class IterativeMethod(Problem): ...@@ -119,8 +128,9 @@ class IterativeMethod(Problem):
dt0=self.dt0, dt=self.dt, dt0=self.dt0, dt=self.dt,
t=ScalarParameter(name='dummy-t', t=ScalarParameter(name='dummy-t',
dtype=HYSOP_REAL, dtype=HYSOP_REAL,
quiet=True)) quiet=True),
configsimu(loop) mpi_params=self.mpi_params)
self.configsimu(loop, simulation)
# Usual initialize-loop-finalize sequence : # Usual initialize-loop-finalize sequence :
loop.initialize() loop.initialize()
with Timer() as tm: with Timer() as tm:
...@@ -140,8 +150,8 @@ class IterativeMethod(Problem): ...@@ -140,8 +150,8 @@ class IterativeMethod(Problem):
formatter={'float_kind': lambda x: '{:8.8f}'.format(x)}), formatter={'float_kind': lambda x: '{:8.8f}'.format(x)}),
datetime.timedelta(seconds=round(avg_time)), datetime.timedelta(seconds=round(avg_time)),
avg_time, avg_time,
'' if main_size==1 else ', averaged over {} ranks. '.format(main_size))) '' if main_size == 1 else ', averaged over {} ranks. '.format(main_size)))
self.it_num.value = loop.current_iteration self.it_num.value = loop.current_iteration
loop.finalize() loop.finalize()
self.final_report() self.final_report()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment