Skip to content

Commit

Permalink
Also write data at intermediate time steps.
Browse files Browse the repository at this point in the history
  • Loading branch information
BenjaminRodenberg committed Nov 14, 2023
1 parent 330136d commit 6a75a96
Showing 1 changed file with 54 additions and 10 deletions.
64 changes: 54 additions & 10 deletions partitioned-heat-conduction/fenics/heat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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)

Expand Down Expand Up @@ -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()

0 comments on commit 6a75a96

Please sign in to comment.