11# Import required libs
22from 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
55import dolfin
66
77from ufl import nabla_div
1111from enum import Enum
1212
1313
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
1721
1822
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
2530
2631
2732# Geometry and material properties
@@ -46,9 +51,6 @@ def neumann_boundary(x, on_boundary):
4651# create Function Space
4752V = VectorFunctionSpace (mesh , 'P' , 2 )
4853
49- # BCs
50- tol = 1E-14
51-
5254# Trial and Test Functions
5355du = TrialFunction (V )
5456v = TestFunction (V )
@@ -64,24 +66,19 @@ def neumann_boundary(x, on_boundary):
6466f_N_function = interpolate (Expression (("1" , "0" ), degree = 1 ), V )
6567u_function = interpolate (Expression (("0" , "0" ), degree = 1 ), V )
6668
67- coupling_boundary = AutoSubDomain (neumann_boundary )
68-
6969precice = Adapter (adapter_config_filename = "precice-adapter-config-fsi-s.json" )
7070
71- clamped_boundary_domain = AutoSubDomain (clamped_boundary )
72- force_boundary = AutoSubDomain (neumann_boundary )
73-
7471# Initialize the coupling interface
7572# 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 () )
7875
7976fenics_dt = precice_dt # if fenics_dt == precice_dt, no subcycling is applied
8077# fenics_dt = 0.02 # if fenics_dt < precice_dt, subcycling is applied
8178dt = Constant (np .min ([precice_dt , fenics_dt ]))
8279
8380# clamp the beam at the bottom
84- bc = DirichletBC (V , Constant ((0 , 0 )), clamped_boundary )
81+ bc = DirichletBC (V , Constant ((0 , 0 )), clampedBoundary () )
8582
8683# alpha method parameters
8784alpha_m = Constant (0.2 )
@@ -179,11 +176,18 @@ def avg(x_old, x_new, alpha):
179176u_tip .append (0.0 )
180177E_ext = 0
181178
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+
182184displacement_out = File ("Solid/FSI-S/u_fsi.pvd" )
185+ ranks = File ("Solid/FSI-S/ranks%s.pvd" % precice .get_participant_name ())
183186
184187u_n .rename ("Displacement" , "" )
185188u_np1 .rename ("Displacement" , "" )
186189displacement_out << u_n
190+ ranks << mesh_rank
187191
188192while precice .is_coupling_ongoing ():
189193
0 commit comments