1
1
# Import required libs
2
2
from fenics import Constant , Function , AutoSubDomain , RectangleMesh , VectorFunctionSpace , interpolate , \
3
- TrialFunction , TestFunction , Point , Expression , DirichletBC , nabla_grad , \
4
- Identity , inner , dx , ds , sym , grad , lhs , rhs , dot , File , solve , PointSource , assemble_system
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
5
import dolfin
6
6
7
7
from ufl import nabla_div
11
11
from enum import Enum
12
12
13
13
14
- # define the two kinds of boundary: clamped and coupling Neumann Boundary
15
- def clamped_boundary (x , on_boundary ):
16
- return on_boundary and abs (x [1 ]) < tol
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
17
21
18
22
19
- def neumann_boundary (x , on_boundary ):
20
- """
21
- determines whether a node is on the coupling boundary
22
-
23
- """
24
- return on_boundary and ((abs (x [1 ] - 1 ) < tol ) or abs (abs (x [0 ]) - W / 2 ) < tol )
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
25
30
26
31
27
32
# Geometry and material properties
@@ -46,9 +51,6 @@ def neumann_boundary(x, on_boundary):
46
51
# create Function Space
47
52
V = VectorFunctionSpace (mesh , 'P' , 2 )
48
53
49
- # BCs
50
- tol = 1E-14
51
-
52
54
# Trial and Test Functions
53
55
du = TrialFunction (V )
54
56
v = TestFunction (V )
@@ -64,24 +66,19 @@ def neumann_boundary(x, on_boundary):
64
66
f_N_function = interpolate (Expression (("1" , "0" ), degree = 1 ), V )
65
67
u_function = interpolate (Expression (("0" , "0" ), degree = 1 ), V )
66
68
67
- coupling_boundary = AutoSubDomain (neumann_boundary )
68
-
69
69
precice = Adapter (adapter_config_filename = "precice-adapter-config-fsi-s.json" )
70
70
71
- clamped_boundary_domain = AutoSubDomain (clamped_boundary )
72
- force_boundary = AutoSubDomain (neumann_boundary )
73
-
74
71
# Initialize the coupling interface
75
72
# Function space V is passed twice as both read and write functions are defined using the same space
76
- precice_dt = precice .initialize (coupling_boundary , read_function_space = V , write_object = V ,
77
- fixed_boundary = clamped_boundary_domain )
73
+ precice_dt = precice .initialize (neumannBoundary () , read_function_space = V , write_object = V ,
74
+ fixed_boundary = clampedBoundary () )
78
75
79
76
fenics_dt = precice_dt # if fenics_dt == precice_dt, no subcycling is applied
80
77
# fenics_dt = 0.02 # if fenics_dt < precice_dt, subcycling is applied
81
78
dt = Constant (np .min ([precice_dt , fenics_dt ]))
82
79
83
80
# clamp the beam at the bottom
84
- bc = DirichletBC (V , Constant ((0 , 0 )), clamped_boundary )
81
+ bc = DirichletBC (V , Constant ((0 , 0 )), clampedBoundary () )
85
82
86
83
# alpha method parameters
87
84
alpha_m = Constant (0.2 )
@@ -179,11 +176,18 @@ def avg(x_old, x_new, alpha):
179
176
u_tip .append (0.0 )
180
177
E_ext = 0
181
178
179
+ # mark mesh w.r.t ranks
180
+ mesh_rank = MeshFunction ("size_t" , mesh , mesh .topology ().dim ())
181
+ mesh_rank .set_all (MPI .rank (MPI .comm_world ) + 0 )
182
+ mesh_rank .rename ("myRank" , "" )
183
+
182
184
displacement_out = File ("Solid/FSI-S/u_fsi.pvd" )
185
+ ranks = File ("Solid/FSI-S/ranks%s.pvd" % precice .get_participant_name ())
183
186
184
187
u_n .rename ("Displacement" , "" )
185
188
u_np1 .rename ("Displacement" , "" )
186
189
displacement_out << u_n
190
+ ranks << mesh_rank
187
191
188
192
while precice .is_coupling_ongoing ():
189
193
0 commit comments