Example #1
0
    write_object=V)  # here we define where the coupling should happen

# Define boundary condition on left and right boundary
u0 = Constant(0.0)
bc = DirichletBC(V, u0, boundary)

# Define variational problem, simply copied from FEniCS demo
u = TrialFunction(V)
v = TestFunction(V)
f = Expression("10*exp(-(pow(x[0] - 0.5, 2) + pow(x[1] - 0.5, 2)) / 0.02)",
               degree=2)
g = Expression("sin(5*x[0])", degree=2)
a = inner(grad(u), grad(v)) * dx
L = f * v * dx + g * v * ds

while precice.is_coupling_ongoing(
):  # potential time loop, currently only one timestep is done

    # Compute solution
    u = Function(V)
    solve(a == L, u, bc)

    # Save solution in VTK format
    file = File("poisson.pvd")
    file << u

    # write data to preCICE and advance coupling
    precice.write_data(u)
    precice.advance(precice_dt)

precice.finalize()
Example #2
0
print('output u^%d and u_ref^%d' % (n, n))
temperature_out << u_n
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]))