Skip to content

Commit 597d7a8

Browse files
Apply changes from precice#578.
1 parent 855a692 commit 597d7a8

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

turek-hron-fsi3/precice-config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848

4949
<coupling-scheme:parallel-implicit>
5050
<time-window-size value="1e-3" />
51-
<max-time value="15" />
51+
<max-time value="5" />
5252
<participants first="Fluid" second="Solid" />
5353
<exchange data="Force" mesh="Solid-Mesh" from="Fluid" to="Solid" />
5454
<exchange data="Displacement" mesh="Solid-Mesh" from="Solid" to="Fluid" />

turek-hron-fsi3/solid-fenics/solid.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Import required libs
22
from fenics import Constant, Function, AutoSubDomain, RectangleMesh, VectorFunctionSpace, interpolate, \
33
TrialFunction, TestFunction, Point, Expression, DirichletBC, nabla_grad, \
4-
Identity, inner, dx, sym, grad, lhs, rhs, File, solve, assemble_system, project, div
4+
Identity, inner, dx, sym, grad, lhs, rhs, File, solve, assemble_system, div
55

66
import numpy as np
77
from fenicsprecice import Adapter
@@ -93,10 +93,10 @@ def remaining_boundary(x, on_boundary):
9393
dt = Constant(np.min([precice_dt, fenics_dt]))
9494

9595
# alpha method parameters
96-
# alpha_m = Constant(0.2)
97-
# alpha_f = Constant(0.4)
98-
alpha_m = Constant(0)
99-
alpha_f = Constant(0)
96+
alpha_m = Constant(0.2)
97+
alpha_f = Constant(0.4)
98+
# alpha_m = Constant(0)
99+
# alpha_f = Constant(0)
100100

101101
"""
102102
Check requirements for alpha_m and alpha_f from
@@ -133,7 +133,7 @@ def k(u, v):
133133
return inner(sigma(u), sym(grad(v))) * dx
134134

135135

136-
def update_acceleration(u, u_old, v_old, a_old, ufl=True):
136+
def update_a(u, u_old, v_old, a_old, ufl=True):
137137
if ufl:
138138
dt_ = dt
139139
beta_ = beta
@@ -144,7 +144,7 @@ def update_acceleration(u, u_old, v_old, a_old, ufl=True):
144144
return (u - u_old - dt_ * v_old) / beta / dt_ ** 2 - .5 * (1 - 2 * beta_) / beta_ * a_old
145145

146146

147-
def update_velocity(a, u_old, v_old, a_old, ufl=True):
147+
def update_v(a, u_old, v_old, a_old, ufl=True):
148148
if ufl:
149149
dt_ = dt
150150
gamma_ = gamma
@@ -157,24 +157,25 @@ def update_velocity(a, u_old, v_old, a_old, ufl=True):
157157

158158
def update_fields(u, u_old, v_old, a_old):
159159
"""Update all fields at the end of a timestep."""
160+
u_vec, u0_vec = u.vector(), u_old.vector()
161+
v0_vec, a0_vec = v_old.vector(), a_old.vector()
160162

161163
# call update functions
162-
a_new = update_acceleration(u, u_old, v_old, a_old)
163-
v_new = update_velocity(a_new, u_old, v_old, a_old)
164+
a_vec = update_a(u_vec, u0_vec, v0_vec, a0_vec, ufl=False)
165+
v_vec = update_v(a_vec, u0_vec, v0_vec, a0_vec, ufl=False)
164166

165167
# assign u->u_old
166-
a_old.assign(project(a_new, V))
167-
v_old.assign(project(v_new, V))
168-
u_old.assign(u)
168+
v_old.vector()[:], a_old.vector()[:] = v_vec, a_vec
169+
u_old.vector()[:] = u.vector()
169170

170171

171172
def avg(x_old, x_new, alpha):
172173
return alpha * x_old + (1 - alpha) * x_new
173174

174175

175176
# residual
176-
a_np1 = update_acceleration(du, u_n, v_n, a_n, ufl=True)
177-
v_np1 = update_velocity(a_np1, u_n, v_n, a_n, ufl=True)
177+
a_np1 = update_a(du, u_n, v_n, a_n, ufl=True)
178+
v_np1 = update_v(a_np1, u_n, v_n, a_n, ufl=True)
178179

179180
res = m(avg(a_n, a_np1, alpha_m), v) + k(avg(u_n, du, alpha_f), v)
180181

@@ -238,6 +239,7 @@ def avg(x_old, x_new, alpha):
238239
n = n_cp
239240
else:
240241
update_fields(u_np1, u_n, v_n, a_n)
242+
u_n.assign(u_np1)
241243
t += float(dt)
242244
n += 1
243245

0 commit comments

Comments
 (0)