11# Import required libs
22from 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
75from ufl import nabla_div
86import numpy as np
97import matplotlib .pyplot as plt
108from fenicsprecice import Adapter
119from 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
5245V = VectorFunctionSpace (mesh , 'P' , 2 )
5346
47+ # BCs
48+ tol = 1E-14
49+
5450# Trial and Test Functions
5551du = TrialFunction (V )
5652v = TestFunction (V )
@@ -66,19 +62,21 @@ def inside(self, x, on_boundary):
6662f_N_function = interpolate (Expression (("1" , "0" ), degree = 1 ), V )
6763u_function = interpolate (Expression (("0" , "0" ), degree = 1 ), V )
6864
65+ coupling_boundary = AutoSubDomain (neumann_boundary )
66+ fixed_boundary = AutoSubDomain (clamped_boundary )
67+
6968precice = 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
7674fenics_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
7876dt = 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
8482alpha_m = Constant (0.2 )
0 commit comments