Skip to content

Refactor adapter for clearer control flow #33

@BenjaminRodenberg

Description

@BenjaminRodenberg

# continue FEniCS computation from checkpoint
u_n.assign(self._u_cp) # set u_n to value of checkpoint
t = self._t_cp
n = self._n_cp
self._interface.fulfilled_action(precice.action_read_iteration_checkpoint())

--> Create Function restore_solver_state_from_checkpoint


u_n.assign(u_np1)
t = new_t = t + dt # todo the variables new_t, new_n could be saved, by just using t and n below, however I think it improved readability.
n = new_n = n + 1

--> Create Function advance_solver_state


# continue FEniCS computation with u_np1
# update checkpoint
self._u_cp.assign(u_np1)
self._t_cp = new_t
self._n_cp = new_n
self._interface.fulfilled_action(precice.action_write_iteration_checkpoint())
precice_step_complete = True

--> Create Function save_solver_state_to_checkpoint


if self._interface.is_action_required(precice.action_write_iteration_checkpoint()):

--> add assertion after this line assert(not solver_state_has_been_restored_before), since this control flow is invalid.


self._interface.write_block_scalar_data(self._write_data_id, self._n_vertices, self._vertex_ids, self._write_data)

--> add if is_read_data_available():


self._interface.read_block_scalar_data(self._read_data_id, self._n_vertices, self._vertex_ids, self._read_data)

--> add if is_write_data_required():


if self._interface.is_read_data_available():
self._interface.read_block_scalar_data(self._read_data_id, self._n_vertices, self._vertex_ids, self._read_data)
if self._interface.is_action_required(precice.action_write_iteration_checkpoint()):
self._u_cp = u_n.copy(deepcopy=True)
self._t_cp = t
self._n_cp = n
self._interface.fulfilled_action(precice.action_write_iteration_checkpoint())

is code duplication of

self._interface.read_block_scalar_data(self._read_data_id, self._n_vertices, self._vertex_ids, self._read_data)

if self._interface.is_action_required(precice.action_write_iteration_checkpoint()):
# continue FEniCS computation with u_np1
# update checkpoint
self._u_cp.assign(u_np1)
self._t_cp = new_t
self._n_cp = new_n
self._interface.fulfilled_action(precice.action_write_iteration_checkpoint())
precice_step_complete = True

Metadata

Metadata

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions