Skip to content

Commit 71da182

Browse files
committed
Changing checkpointing handling and minor editing
1 parent 635142c commit 71da182

File tree

3 files changed

+8
-89
lines changed

3 files changed

+8
-89
lines changed

fenicsadapter/checkpointing.py

-31
This file was deleted.

fenicsadapter/fenicsadapter.py

+8-38
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import numpy as np
66
from .config import Config
7-
from .checkpointing import Checkpoint
87
import logging
98
import precice
109
from precice import action_write_initial_data, action_write_iteration_checkpoint, action_read_iteration_checkpoint
@@ -64,11 +63,8 @@ def __init__(self, adapter_config_filename='precice-adapter-config.json'):
6463
# Temporarily hard-coding interpolation strategy. Need to provide user with the appropriate choice
6564
self._my_expression = None
6665

67-
# checkpointing
68-
self._checkpoint = Checkpoint()
69-
7066
# Solver state used by the Adapter internally to handle checkpointing
71-
self._state = None
67+
self._checkpoint = None
7268

7369
# function space
7470
self._function_space = None
@@ -154,17 +150,14 @@ def write(self, write_function):
154150
else:
155151
raise Exception("Rank of function space is neither 0 nor 1")
156152

157-
def initialize(self, coupling_subdomain, mesh, u_n, read_function, write_function, dimension=2, t=0, n=0):
153+
def initialize(self, coupling_subdomain, mesh, read_function, write_function, dimension=2):
158154
"""Initializes remaining attributes. Called once, from the solver.
159155
160156
:param write_function: FEniCS function for data to be written by this instance of coupling
161157
:param read_function: FEniCS function for data to be read by this instance of coupling
162158
:param coupling_subdomain: domain where coupling takes place
163159
:param mesh: fenics mesh
164-
:param u_n: initial data for solution
165160
:param dimension: problem dimension
166-
:param t: starting time
167-
:param n: time step n
168161
"""
169162

170163
self._fenics_dimensions = dimension
@@ -194,10 +187,8 @@ def initialize(self, coupling_subdomain, mesh, u_n, read_function, write_functio
194187

195188
self._interface.initialize_data()
196189

197-
#if self._interface.is_read_data_available():
198-
# self._read_data = self.read()
199-
200-
self.initialize_solver_state(u_n, t, n)
190+
if self._interface.is_read_data_available():
191+
self.read()
201192

202193
return self._precice_tau
203194

@@ -255,41 +246,20 @@ def update_boundary_condition(self, coupling_bc_expression):
255246
else:
256247
coupling_bc_expression.update_boundary_data(self._read_data, x_vert, y_vert)
257248

258-
def initialize_solver_state(self, u_n, t, n):
259-
"""Initalizes the solver state before coupling starts in each iteration
260-
:param u_n:
261-
:param t:
262-
:param n:
263-
"""
264-
self._state = SolverState(u_n, t, n)
265-
logger.debug("Solver state is initialized")
266-
267-
def store_checkpoint(self):
249+
def store_checkpoint(self, u, t, n):
268250
"""Stores the current solver state to a checkpoint.
269251
"""
270-
logger.debug("Save solver state")
271-
self._checkpoint.write(self._state)
252+
logger.debug("Store checkpoint")
253+
self._checkpoint = SolverState(u, t, n)
272254
self._interface.fulfilled_action(self.action_write_checkpoint())
273255

274256
def retrieve_checkpoint(self):
275257
"""Resets the solver's state to the checkpoint's state.
276258
"""
277259
assert (not self._interface.is_timestep_complete()) # avoids invalid control flow
278260
logger.debug("Restore solver state")
279-
self._state.update(self._checkpoint.get_state())
280261
self._interface.fulfilled_action(self.action_read_checkpoint())
281-
282-
def end_timestep(self, u_np1, dt):
283-
"""Advances the solver's state by one timestep. Also advances coupling state
284-
:param state: old state
285-
:param u_np1: new value
286-
:param dt: timestep size
287-
:return: maximum time step value recommended by preCICE
288-
"""
289-
logger.debug("Advance solver state")
290-
logger.debug("old state: t={time}".format(time=self._state.t))
291-
self._state.update(SolverState(u_np1, self._state.t + dt, self._state.n + 1))
292-
logger.debug("new state: t={time}".format(time=self._state.t))
262+
return self._checkpoint.get_state()
293263

294264
def advance(self, dt):
295265
max_dt = self._interface.advance(dt)

fenicsadapter/solverstate.py

-20
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,6 @@ def get_state(self):
1717
"""
1818
return self.u, self.t, self.n
1919

20-
def update(self, other_state):
21-
"""
22-
updates the state using FEniCS assign function. self.u is updated.
23-
This may also have an effect outside of this object! Compare to SolverState.copy(other_state).
24-
:param other_state:
25-
"""
26-
self.u.assign(other_state.u)
27-
self.t = other_state.t
28-
self.n = other_state.n
29-
30-
def copy(self, other_state):
31-
"""
32-
copies a state using FEniCS copy function. self.u is overwritten.
33-
This does not have an effect outside of this object! Compare to SolverState.update(other_state).
34-
:param other_state:
35-
"""
36-
self.u = other_state.u.copy()
37-
self.t = other_state.t
38-
self.n = other_state.n
39-
4020
def print_state(self):
4121
u, t, n = self.get_state()
4222
return "u={u}, t={t}, n={n}".format(u=u, t=t, n=n)

0 commit comments

Comments
 (0)