Skip to content

Commit e9b0d5a

Browse files
Fix checkpointing. Requires precice/fenics-adapter#170.
1 parent 17a4949 commit e9b0d5a

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

perpendicular-flap/solid-fenics/solid.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ def neumann_boundary(x, on_boundary):
5959
v = TestFunction(V)
6060

6161
u_np1 = Function(V)
62-
saved_u_old = Function(V)
6362

6463
# function known from previous timestep
6564
u_n = Function(V)
@@ -80,15 +79,17 @@ def neumann_boundary(x, on_boundary):
8079

8180
precice_dt = precice.get_max_time_step_size()
8281
fenics_dt = precice_dt # if fenics_dt == precice_dt, no subcycling is applied
83-
# fenics_dt = 0.02 # if fenics_dt < precice_dt, subcycling is applied
82+
# fenics_dt = precice_dt / 5 # if fenics_dt < precice_dt, subcycling is applied
8483
dt = Constant(np.min([precice_dt, fenics_dt]))
8584

8685
# clamp the beam at the bottom
8786
bc = DirichletBC(V, Constant((0, 0)), fixed_boundary)
8887

8988
# alpha method parameters
90-
alpha_m = Constant(0)
91-
alpha_f = Constant(0)
89+
alpha_m = Constant(0.2)
90+
alpha_f = Constant(0.4)
91+
# alpha_m = Constant(0)
92+
# alpha_f = Constant(0)
9293

9394
"""
9495
Check requirements for alpha_m and alpha_f from
@@ -196,13 +197,13 @@ def avg(x_old, x_new, alpha):
196197
while precice.is_coupling_ongoing():
197198

198199
if precice.requires_writing_checkpoint(): # write checkpoint
199-
precice.store_checkpoint(u_n, t, n)
200+
precice.store_checkpoint((u_n, v_n, a_n), t, n)
200201

201202
precice_dt = precice.get_max_time_step_size()
202203
dt = Constant(np.min([precice_dt, fenics_dt]))
203204

204205
# read data from preCICE and get a new coupling expression
205-
read_data = precice.read_data(dt)
206+
read_data = precice.read_data((1-float(alpha_f)) * dt)
206207

207208
# Update the point sources on the coupling boundary with the new read data
208209
Forces_x, Forces_y = precice.get_point_sources(read_data)
@@ -227,17 +228,20 @@ def avg(x_old, x_new, alpha):
227228

228229
# Either revert to old step if timestep has not converged or move to next timestep
229230
if precice.requires_reading_checkpoint(): # roll back to checkpoint
230-
u_cp, t_cp, n_cp = precice.retrieve_checkpoint()
231+
uva_cp, t_cp, n_cp = precice.retrieve_checkpoint()
232+
u_cp, v_cp, a_cp = uva_cp
231233
u_n.assign(u_cp)
234+
v_n.assign(v_cp)
235+
a_n.assign(a_cp)
232236
t = t_cp
233237
n = n_cp
234238
else:
239+
update_fields(u_np1, u_n, v_n, a_n)
235240
u_n.assign(u_np1)
236241
t += float(dt)
237242
n += 1
238243

239244
if precice.is_time_window_complete():
240-
update_fields(u_np1, saved_u_old, v_n, a_n)
241245
if n % 10 == 0:
242246
displacement_out << (u_n, t)
243247

0 commit comments

Comments
 (0)