コード例 #1
0
ファイル: heat.py プロジェクト: swipswaps/tutorials-1
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)
コード例 #2
0
ファイル: solid.py プロジェクト: BenjaminRodenberg/tutorials
ranks << mesh_rank

# Create output file
file_out = File("output/%s.pvd" % precice.get_participant_name())
file_out << u_n

print("output vtk for time = {}".format(float(t)))
n = 0

fluxes = Function(V_g)
fluxes.rename("Fluxes", "")

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()

    # 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
    determine_heat_flux(V_g, u_np1, k, fluxes)
    fluxes_y = fluxes.sub(1)  # only exchange y component of flux.