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

Revert some of the ufl-relateve changes from #505 #508

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions elastic-tube-3d/solid-fenics/solid.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,26 @@ def Wext(u_):
# Functions for updating system state

# Update acceleration
def update_a(u, u_old, v_old, a_old):
dt_ = float(dt)
beta_ = float(beta)
def update_a(u, u_old, v_old, a_old, ufl=True):
if ufl:
dt_ = dt
beta_ = beta
else:
dt_ = float(dt)
beta_ = float(beta)

return ((u - u_old - dt_ * v_old) / beta / dt_ ** 2
- (1 - 2 * beta_) / 2 / beta_ * a_old)


# Update velocity
def update_v(a, u_old, v_old, a_old):
dt_ = float(dt)
gamma_ = float(gamma)
def update_v(a, u_old, v_old, a_old, ufl=True):
if ufl:
dt_ = dt
gamma_ = gamma
else:
dt_ = float(dt)
gamma_ = float(gamma)

return v_old + dt_ * ((1 - gamma_) * a_old + gamma_ * a)

Expand All @@ -131,8 +139,8 @@ def update_fields(u, u_old, v_old, a_old):
v0_vec, a0_vec = v_old.vector(), a_old.vector()

# call update functions
a_vec = update_a(u_vec, u0_vec, v0_vec, a0_vec)
v_vec = update_v(a_vec, u0_vec, v0_vec, a0_vec)
a_vec = update_a(u_vec, u0_vec, v0_vec, a0_vec, ufl=False)
v_vec = update_v(a_vec, u0_vec, v0_vec, a0_vec, ufl=False)

# assign u->u_old
v_old.vector()[:], a_old.vector()[:] = v_vec, a_vec
Expand All @@ -143,8 +151,8 @@ def avg(x_old, x_new, alpha):
return alpha * x_old + (1 - alpha) * x_new


a_np1 = update_a(du, u_n, v_n, a_n)
v_np1 = update_v(a_np1, u_n, v_n, a_n)
a_np1 = update_a(du, u_n, v_n, a_n, ufl=True)
v_np1 = update_v(a_np1, u_n, v_n, a_n, ufl=True)

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

Expand Down
28 changes: 18 additions & 10 deletions perpendicular-flap/solid-fenics/solid.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,26 @@ def Wext(u_):
# Update functions

# Update acceleration
def update_a(u, u_old, v_old, a_old):
dt_ = float(dt)
beta_ = float(beta)
def update_a(u, u_old, v_old, a_old, ufl=True):
if ufl:
dt_ = dt
beta_ = beta
else:
dt_ = float(dt)
beta_ = float(beta)

return ((u - u_old - dt_ * v_old) / beta / dt_ ** 2
- (1 - 2 * beta_) / 2 / beta_ * a_old)


# Update velocity
def update_v(a, u_old, v_old, a_old):
dt_ = float(dt)
gamma_ = float(gamma)
def update_v(a, u_old, v_old, a_old, ufl=True):
if ufl:
dt_ = dt
gamma_ = gamma
else:
dt_ = float(dt)
gamma_ = float(gamma)

return v_old + dt_ * ((1 - gamma_) * a_old + gamma_ * a)

Expand All @@ -154,8 +162,8 @@ def update_fields(u, u_old, v_old, a_old):
v0_vec, a0_vec = v_old.vector(), a_old.vector()

# call update functions
a_vec = update_a(u_vec, u0_vec, v0_vec, a0_vec)
v_vec = update_v(a_vec, u0_vec, v0_vec, a0_vec)
a_vec = update_a(u_vec, u0_vec, v0_vec, a0_vec, ufl=False)
v_vec = update_v(a_vec, u0_vec, v0_vec, a0_vec, ufl=False)

# assign u->u_old
v_old.vector()[:], a_old.vector()[:] = v_vec, a_vec
Expand All @@ -167,8 +175,8 @@ def avg(x_old, x_new, alpha):


# residual
a_np1 = update_a(du, u_n, v_n, a_n)
v_np1 = update_v(a_np1, u_n, v_n, a_n)
a_np1 = update_a(du, u_n, v_n, a_n, ufl=True)
v_np1 = update_v(a_np1, u_n, v_n, a_n, ufl=True)

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

Expand Down