|
4 | 4 |
|
5 | 5 | import numpy as np
|
6 | 6 | from .config import Config
|
7 |
| -from .checkpointing import Checkpoint |
8 | 7 | import logging
|
9 | 8 | import precice
|
10 | 9 | 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'):
|
64 | 63 | # Temporarily hard-coding interpolation strategy. Need to provide user with the appropriate choice
|
65 | 64 | self._my_expression = None
|
66 | 65 |
|
67 |
| - # checkpointing |
68 |
| - self._checkpoint = Checkpoint() |
69 |
| - |
70 | 66 | # Solver state used by the Adapter internally to handle checkpointing
|
71 |
| - self._state = None |
| 67 | + self._checkpoint = None |
72 | 68 |
|
73 | 69 | # function space
|
74 | 70 | self._function_space = None
|
@@ -154,17 +150,14 @@ def write(self, write_function):
|
154 | 150 | else:
|
155 | 151 | raise Exception("Rank of function space is neither 0 nor 1")
|
156 | 152 |
|
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): |
158 | 154 | """Initializes remaining attributes. Called once, from the solver.
|
159 | 155 |
|
160 | 156 | :param write_function: FEniCS function for data to be written by this instance of coupling
|
161 | 157 | :param read_function: FEniCS function for data to be read by this instance of coupling
|
162 | 158 | :param coupling_subdomain: domain where coupling takes place
|
163 | 159 | :param mesh: fenics mesh
|
164 |
| - :param u_n: initial data for solution |
165 | 160 | :param dimension: problem dimension
|
166 |
| - :param t: starting time |
167 |
| - :param n: time step n |
168 | 161 | """
|
169 | 162 |
|
170 | 163 | self._fenics_dimensions = dimension
|
@@ -194,10 +187,8 @@ def initialize(self, coupling_subdomain, mesh, u_n, read_function, write_functio
|
194 | 187 |
|
195 | 188 | self._interface.initialize_data()
|
196 | 189 |
|
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() |
201 | 192 |
|
202 | 193 | return self._precice_tau
|
203 | 194 |
|
@@ -255,41 +246,20 @@ def update_boundary_condition(self, coupling_bc_expression):
|
255 | 246 | else:
|
256 | 247 | coupling_bc_expression.update_boundary_data(self._read_data, x_vert, y_vert)
|
257 | 248 |
|
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): |
268 | 250 | """Stores the current solver state to a checkpoint.
|
269 | 251 | """
|
270 |
| - logger.debug("Save solver state") |
271 |
| - self._checkpoint.write(self._state) |
| 252 | + logger.debug("Store checkpoint") |
| 253 | + self._checkpoint = SolverState(u, t, n) |
272 | 254 | self._interface.fulfilled_action(self.action_write_checkpoint())
|
273 | 255 |
|
274 | 256 | def retrieve_checkpoint(self):
|
275 | 257 | """Resets the solver's state to the checkpoint's state.
|
276 | 258 | """
|
277 | 259 | assert (not self._interface.is_timestep_complete()) # avoids invalid control flow
|
278 | 260 | logger.debug("Restore solver state")
|
279 |
| - self._state.update(self._checkpoint.get_state()) |
280 | 261 | 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() |
293 | 263 |
|
294 | 264 | def advance(self, dt):
|
295 | 265 | max_dt = self._interface.advance(dt)
|
|
0 commit comments