Skip to content

Commit c8e6dee

Browse files
IshaanDesaiBenjaminRodenberg
authored andcommitted
Ensuring consistency in FEniCS scripts for FSI tutorial cases (#142)
* Making SU2- and OpenFOAM- case of perp-flap for FEniCS consistent
1 parent cdef4f0 commit c8e6dee

File tree

2 files changed

+23
-28
lines changed

2 files changed

+23
-28
lines changed

FSI/flap_perp_2D/OpenFOAM-FEniCS/Solid/perp-flap.py

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,25 @@
11
# Import required libs
22
from fenics import Constant, Function, AutoSubDomain, RectangleMesh, VectorFunctionSpace, interpolate, \
3-
TrialFunction, TestFunction, Point, Expression, DirichletBC, nabla_grad, SubDomain, \
4-
Identity, inner, dx, ds, sym, grad, lhs, rhs, dot, File, solve, PointSource, assemble_system, MPI, MeshFunction
5-
import dolfin
6-
3+
TrialFunction, TestFunction, Point, Expression, DirichletBC, nabla_grad, Identity, inner, dx, ds, \
4+
sym, grad, lhs, rhs, dot, File, solve, PointSource, assemble_system, MPI, MeshFunction
75
from ufl import nabla_div
86
import numpy as np
97
import matplotlib.pyplot as plt
108
from fenicsprecice import Adapter
119
from enum import Enum
1210

1311

14-
class clampedBoundary(SubDomain):
15-
def inside(self, x, on_boundary):
16-
tol = 1E-14
17-
if on_boundary and abs(x[1]) < tol:
18-
return True
19-
else:
20-
return False
12+
# define the two kinds of boundary: clamped and coupling Neumann Boundary
13+
def clamped_boundary(x, on_boundary):
14+
return on_boundary and abs(x[1]) < tol
15+
2116

17+
def neumann_boundary(x, on_boundary):
18+
"""
19+
determines whether a node is on the coupling boundary
2220
23-
class neumannBoundary(SubDomain):
24-
def inside(self, x, on_boundary):
25-
tol = 1E-14
26-
if on_boundary and ((abs(x[1] - 1) < tol) or abs(abs(x[0]) - W / 2) < tol):
27-
return True
28-
else:
29-
return False
21+
"""
22+
return on_boundary and ((abs(x[1] - 1) < tol) or abs(abs(x[0]) - W / 2) < tol)
3023

3124

3225
# Geometry and material properties
@@ -51,6 +44,9 @@ def inside(self, x, on_boundary):
5144
# create Function Space
5245
V = VectorFunctionSpace(mesh, 'P', 2)
5346

47+
# BCs
48+
tol = 1E-14
49+
5450
# Trial and Test Functions
5551
du = TrialFunction(V)
5652
v = TestFunction(V)
@@ -66,19 +62,21 @@ def inside(self, x, on_boundary):
6662
f_N_function = interpolate(Expression(("1", "0"), degree=1), V)
6763
u_function = interpolate(Expression(("0", "0"), degree=1), V)
6864

65+
coupling_boundary = AutoSubDomain(neumann_boundary)
66+
fixed_boundary = AutoSubDomain(clamped_boundary)
67+
6968
precice = Adapter(adapter_config_filename="precice-adapter-config-fsi-s.json")
7069

7170
# Initialize the coupling interface
7271
# Function space V is passed twice as both read and write functions are defined using the same space
73-
precice_dt = precice.initialize(neumannBoundary(), read_function_space=V, write_object=V,
74-
fixed_boundary=clampedBoundary())
72+
precice_dt = precice.initialize(coupling_boundary, read_function_space=V, write_object=V, fixed_boundary=fixed_boundary)
7573

7674
fenics_dt = precice_dt # if fenics_dt == precice_dt, no subcycling is applied
7775
# fenics_dt = 0.02 # if fenics_dt < precice_dt, subcycling is applied
7876
dt = Constant(np.min([precice_dt, fenics_dt]))
7977

8078
# clamp the beam at the bottom
81-
bc = DirichletBC(V, Constant((0, 0)), clampedBoundary())
79+
bc = DirichletBC(V, Constant((0, 0)), fixed_boundary)
8280

8381
# alpha method parameters
8482
alpha_m = Constant(0.2)

FSI/flap_perp_2D/SU2-FEniCS/Solid/perp-flap.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
from fenics import Constant, Function, AutoSubDomain, RectangleMesh, VectorFunctionSpace, interpolate, \
33
TrialFunction, TestFunction, Point, Expression, DirichletBC, nabla_grad, project, \
44
Identity, inner, dx, ds, sym, grad, lhs, rhs, dot, File, solve, PointSource, assemble_system
5-
import dolfin
6-
75
from ufl import nabla_div
86
import numpy as np
97
import matplotlib.pyplot as plt
@@ -63,26 +61,25 @@ def neumann_boundary(x, on_boundary):
6361

6462
# Function to calculate displacement Deltas
6563
u_delta = Function(V)
64+
u_ref = Function(V)
6665

6766
f_N_function = interpolate(Expression(("1", "0"), degree=1), V)
6867
u_function = interpolate(Expression(("0", "0"), degree=1), V)
6968

7069
coupling_boundary = AutoSubDomain(neumann_boundary)
70+
fixed_boundary = AutoSubDomain(clamped_boundary)
7171

7272
precice = Adapter(adapter_config_filename="precice-adapter-config-fsi-s.json")
7373

74-
clamped_boundary_domain = AutoSubDomain(clamped_boundary)
75-
force_boundary = AutoSubDomain(neumann_boundary)
76-
7774
# Initialize the coupling interface
78-
precice_dt = precice.initialize(coupling_boundary, read_function_space=V, write_object=V, fixed_boundary=clamped_boundary_domain)
75+
precice_dt = precice.initialize(coupling_boundary, read_function_space=V, write_object=V, fixed_boundary=fixed_boundary)
7976

8077
fenics_dt = precice_dt # if fenics_dt == precice_dt, no subcycling is applied
8178
# fenics_dt = 0.02 # if fenics_dt < precice_dt, subcycling is applied
8279
dt = Constant(np.min([precice_dt, fenics_dt]))
8380

8481
# clamp the beam at the bottom
85-
bc = DirichletBC(V, Constant((0, 0)), clamped_boundary)
82+
bc = DirichletBC(V, Constant((0, 0)), fixed_boundary)
8683

8784
# alpha method parameters
8885
alpha_m = Constant(0.2)

0 commit comments

Comments
 (0)