Skip to content

Commit

Permalink
solver: option to keep logfile
Browse files Browse the repository at this point in the history
  • Loading branch information
jwallwork23 committed Apr 5, 2022
1 parent 0935850 commit 21e5d69
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions thetis/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class FlowSolver(FrozenClass):
@unfrozen
@PETSc.Log.EventDecorator("thetis.FlowSolver.__init__")
def __init__(self, mesh2d, bathymetry_2d, n_layers,
options=None, extrude_options=None):
options=None, extrude_options=None, keep_log=False):
"""
:arg mesh2d: :class:`Mesh` object of the 2D mesh
:arg bathymetry_2d: Bathymetry of the domain. Bathymetry stands for
Expand All @@ -90,6 +90,7 @@ def __init__(self, mesh2d, bathymetry_2d, n_layers,
:kwarg options: Model options (optional). Model options can also be
changed directly via the :attr:`.options` class property.
:type options: :class:`.ModelOptions3d` instance
:kwarg bool keep_log: append to an existing log file, or overwrite it?
"""
self._initialized = False

Expand Down Expand Up @@ -156,6 +157,7 @@ def __init__(self, mesh2d, bathymetry_2d, n_layers,
"""Do export initial state. False if continuing a simulation"""

self._simulation_continued = False
self.keep_log = keep_log
self._field_preproc_funcs = {}

def compute_dx_factor(self):
Expand Down Expand Up @@ -474,7 +476,8 @@ def create_fields(self):
self.create_function_spaces()

if self.options.log_output and not self.options.no_exports:
set_log_directory(self.options.output_directory)
mode = "a" if self.keep_log else "w"
set_log_directory(self.options.output_directory, mode=mode)

# mesh velocity etc fields must be in the same space as 3D coordinates
coord_is_dg = element_continuity(self.mesh2d.coordinates.function_space().ufl_element()).horizontal == 'dg'
Expand Down Expand Up @@ -652,7 +655,8 @@ def create_equations(self):

if self.options.log_output and not self.options.no_exports:
logfile = os.path.join(create_directory(self.options.output_directory), 'log')
filehandler = logging.logging.FileHandler(logfile, mode='w')
mode = "a" if self.keep_log else "w"
filehandler = logging.logging.FileHandler(logfile, mode=mode)
filehandler.setFormatter(logging.logging.Formatter('%(message)s'))
output_logger.addHandler(filehandler)

Expand Down

0 comments on commit 21e5d69

Please sign in to comment.