read_data = precice.read_data() # Update the coupling expression with the new read data precice.update_coupling_expression(coupling_expression, read_data) dt.assign(np.min([fenics_dt, precice_dt])) # Compute solution u^n+1, use bcs u_D^n+1, u^n and coupling bcs solve(a == L, u_np1, bcs) # Write data to preCICE according to which problem is being solved if problem is ProblemType.DIRICHLET: # Dirichlet problem reads temperature and writes flux on boundary to Neumann problem determine_gradient(V_g, u_np1, flux) precice.write_data(flux) elif problem is ProblemType.NEUMANN: # Neumann problem reads flux and writes temperature on boundary to Dirichlet problem precice.write_data(u_np1) precice_dt = precice.advance(dt(0)) if precice.is_action_required(precice.action_read_iteration_checkpoint() ): # roll back to checkpoint u_cp, t_cp, n_cp = precice.retrieve_checkpoint() u_n.assign(u_cp) t = t_cp n = n_cp else: # update solution u_n.assign(u_np1) t += dt
if precice.is_action_required(precice.action_write_iteration_checkpoint()): # write checkpoint precice.store_checkpoint(u_n, t, n) read_data = precice.read_data() # Update the coupling expression with the new read data precice.update_coupling_expression(coupling_expression, read_data) dt.assign(np.min([fenics_dt, precice_dt])) # Compute solution solve(a == L, u_np1, bcs) # Dirichlet problem obtains flux from solution and sends flux on boundary to Neumann problem fluxes = fluxes_from_temperature_full_domain(F_known_u, V, k) precice.write_data(fluxes) precice_dt = precice.advance(dt(0)) if precice.is_action_required(precice.action_read_iteration_checkpoint()): # roll back to checkpoint u_cp, t_cp, n_cp = precice.retrieve_checkpoint() u_n.assign(u_cp) t = t_cp n = n_cp else: # update solution u_n.assign(u_np1) t += dt n += 1 if precice.is_time_window_complete(): # if abs(t % dt_out) < 10e-5: # output if t is a multiple of dt_out
b_forces = b.copy( ) # b is the same for every iteration, only forces change for ps in Forces_x: ps.apply(b_forces) for ps in Forces_y: ps.apply(b_forces) assert (b is not b_forces) solve(A, u_np1.vector(), b_forces) dt = Constant(np.min([precice_dt, fenics_dt])) # Write new displacements to preCICE u_delta = project(u_np1 - u_ref, V) precice.write_data(u_delta) # Call to advance coupling, also returns the optimum time step value precice_dt = precice.advance(dt(0)) # Either revert to old step if timestep has not converged or move to next timestep if precice.is_action_required(precice.action_read_iteration_checkpoint() ): # roll back to checkpoint u_cp, t_cp, n_cp = precice.retrieve_checkpoint() u_n.assign(u_cp) t = t_cp n = n_cp else: u_n.assign(u_np1) t += float(dt) n += 1