예제 #1
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)

    # 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)
# 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
    precice.write_data(u_np1)

    dt = precice.advance(dt)

    # roll back to checkpoint
    if precice.is_action_required(precice.action_read_iteration_checkpoint()):