ref_out << u_ref ranks << mesh_rank error_total, error_pointwise = compute_errors(u_n, u_ref, V) error_out << error_pointwise # set t_1 = t_0 + dt, this gives u_D^1 u_D.t = t + dt(0) # call dt(0) to evaluate FEniCS Constant. Todo: is there a better way? f.t = t + dt(0) flux = Function(V_g) flux.rename("Flux", "") while precice.is_coupling_ongoing(): if precice.is_action_required(precice.action_write_iteration_checkpoint()): # write checkpoint precice.store_checkpoint(u_n, t, n) read_data = precice.read_data() if problem is ProblemType.DIRICHLET and (domain_part is DomainPart.CIRCULAR or domain_part is DomainPart.RECTANGLE): # We have to data for an arbitrary point that is not on the circle, to obtain exact solution. # See https://github.com/precice/fenics-adapter/issues/113 for details. read_data[(0, 0)] = u_D(0, 0) # 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)
mesh_rank.rename("myRank", "") # Generating output files solution_out = File("output/%s.pvd" % precice.get_participant_name()) ranks = File("output/ranks%s.pvd" % precice.get_participant_name()) # output solution and reference solution at t=0, n=0 n = 0 print('output u^%d and u_ref^%d' % (n, n)) solution_out << u_n ranks << mesh_rank while precice.is_coupling_ongoing(): # write checkpoint if precice.is_action_required(precice.action_write_iteration_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(volume_term, read_data) f.assign(interpolate(volume_term, V)) dt_inv.assign(1 / dt) # Compute solution u^n+1, use bcs u^n and coupling bcs a, L = lhs(F), rhs(F) solve(a == L, u_np1, bc) # Write data to preCICE according to which problem is being solved