Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use waveform iteration with partitioned-heat-conduction/fenics/heat.py #281

Merged
merged 12 commits into from
Nov 20, 2023
Prev Previous commit
Next Next commit
Also write data at intermediate time steps.
BenjaminRodenberg committed Nov 14, 2023
commit 6a75a9663ee3c37337051655beb8b4c78d296de0
64 changes: 54 additions & 10 deletions partitioned-heat-conduction/fenics/heat.py
Original file line number Diff line number Diff line change
@@ -157,13 +157,25 @@ def determine_gradient(V_g, u, flux):

# output solution and reference solution at t=0, n=0
n = 0
print('output u^%d and u_ref^%d' % (n, n))
temperature_out << (u_n, t)
ref_out << u_ref
print("output u^%d and u_ref^%d" % (n, n))
ranks << mesh_rank

error_total, error_pointwise = compute_errors(u_n, u_ref, V)
error_out << error_pointwise

# create buffer for output. We need this buffer, because we only want to write the converged output at the end of the window, but we also want to write the samples that are resulting from substeps inside the window
u_write = []
ref_write = []
error_write = []
# copy data to buffer and rename
uu = u_n.copy()
uu.rename("u","")
u_write.append((uu, t))
uu_ref = u_ref.copy()
uu_ref.rename("u_ref","")
ref_write.append(uu_ref)
err = error_pointwise.copy()
err.rename("err","")
error_write.append(err)

# set t_1 = t_0 + dt, this gives u_D^1
# call dt(0) to evaluate FEniCS Constant. Todo: is there a better way?
@@ -180,6 +192,17 @@ def determine_gradient(V_g, u, flux):
if precice.requires_writing_checkpoint():
precice.store_checkpoint(u_n, t, n)

# output solution and reference solution at t_n+1 and substeps (read from buffer)
print('output u^%d and u_ref^%d' % (n, n))
for sample in u_write:
temperature_out << sample

for sample in ref_write:
ref_out << sample

for sample in error_write:
error_out << error_pointwise

dt.assign(np.min([fenics_dt, precice_dt]))
read_data = precice.read_data(dt)

@@ -208,25 +231,46 @@ def determine_gradient(V_g, u, flux):
u_n.assign(u_cp)
t = t_cp
n = n_cp
# empty buffer if window has not converged
u_write = []
ref_write = []
error_write = []
else: # update solution
u_n.assign(u_np1)
t += float(dt)
n += 1
# copy data to buffer and rename
uu = u_n.copy()
uu.rename("u","u")
u_write.append((uu, t))
uu_ref = u_ref.copy()
uu_ref.rename("u_ref","u_ref")
ref_write.append(uu_ref)
err = error_pointwise.copy()
err.rename("err","err")
error_write.append(err)

if precice.is_time_window_complete():
u_ref = interpolate(u_D, V)
u_ref.rename("reference", " ")
error, error_pointwise = compute_errors(u_n, u_ref, V, total_error_tol=error_tol)
print('n = %d, t = %.2f: L2 error on domain = %.3g' % (n, t, error))
# output solution and reference solution at t_n+1
print('output u^%d and u_ref^%d' % (n, n))
temperature_out << (u_n, t)
ref_out << u_ref
error_out << error_pointwise
print("n = %d, t = %.2f: L2 error on domain = %.3g" % (n, t, error))


# Update Dirichlet BC
u_D.t = t + float(dt)
f.t = t + float(dt)

# output solution and reference solution at t_n+1 and substeps (read from buffer)
print("output u^%d and u_ref^%d" % (n, n))
for sample in u_write:
temperature_out << sample

for sample in ref_write:
ref_out << sample

for sample in error_write:
error_out << error_pointwise

# Hold plot
precice.finalize()