@@ -19,7 +19,8 @@ def main(side='Dirichlet', n=10, degree=1, timestep=.1, alpha=3., beta=1.3):
1919
2020 # define the Nutils mesh
2121 domain , geom = mesh .rectilinear ([x_grid , y_grid ])
22- coupling_boundary = domain .boundary ['right' if side == 'Dirichlet' else 'left' ]
22+ coupling_boundary = domain .boundary ['right' if side ==
23+ 'Dirichlet' else 'left' ]
2324 coupling_sample = coupling_boundary .sample ('gauss' , degree = degree * 2 )
2425
2526 # Nutils namespace
@@ -37,12 +38,14 @@ def main(side='Dirichlet', n=10, degree=1, timestep=.1, alpha=3., beta=1.3):
3738 ns .readfunc = 'readbasis_n ?readdata_n'
3839
3940 # define the weak form
40- res = domain .integral ('(basis_n dudt - basis_n f + basis_n,i u_,i) d:x' @ ns , degree = degree * 2 )
41+ res = domain .integral (
42+ '(basis_n dudt - basis_n f + basis_n,i u_,i) d:x' @ ns ,
43+ degree = degree * 2 )
4144
4245 # set boundary conditions at non-coupling boundaries
4346 # top and bottom boundary are non-coupling for both sides
44- sqr = domain .boundary ['top,bottom,left' if side == 'Dirichlet'
45- else 'top,bottom,right' ]. integral ( '(u - uexact)^2 d:x' @ ns , degree = degree * 2 )
47+ sqr = domain .boundary ['top,bottom,left' if side == 'Dirichlet' else 'top,bottom,right' ]. integral (
48+ '(u - uexact)^2 d:x' @ ns , degree = degree * 2 )
4649
4750 if side == 'Dirichlet' :
4851 sqr += coupling_sample .integral ('(u - readfunc)^2 d:x' @ ns )
@@ -52,11 +55,20 @@ def main(side='Dirichlet', n=10, degree=1, timestep=.1, alpha=3., beta=1.3):
5255 # preCICE setup
5356 interface = precice .Interface (side , "../precice-config.xml" , 0 , 1 )
5457 mesh_id = interface .get_mesh_id (side + "-Mesh" )
55- vertex_ids = interface .set_mesh_vertices (mesh_id , coupling_sample .eval (ns .x ))
56- precice_write = functools .partial (interface .write_block_scalar_data ,
57- interface .get_data_id ("Temperature" if side == "Neumann" else "Heat-Flux" , mesh_id ), vertex_ids )
58- precice_read = functools .partial (interface .read_block_scalar_data ,
59- interface .get_data_id ("Heat-Flux" if side == "Neumann" else "Temperature" , mesh_id ), vertex_ids )
58+ vertex_ids = interface .set_mesh_vertices (
59+ mesh_id , coupling_sample .eval (ns .x ))
60+ precice_write = functools .partial (
61+ interface .write_block_scalar_data ,
62+ interface .get_data_id (
63+ "Temperature" if side == "Neumann" else "Heat-Flux" ,
64+ mesh_id ),
65+ vertex_ids )
66+ precice_read = functools .partial (
67+ interface .read_block_scalar_data ,
68+ interface .get_data_id (
69+ "Heat-Flux" if side == "Neumann" else "Temperature" ,
70+ mesh_id ),
71+ vertex_ids )
6072
6173 # helper functions to project heat flux to coupling boundary
6274 if side == 'Dirichlet' :
@@ -70,11 +82,18 @@ def main(side='Dirichlet', n=10, degree=1, timestep=.1, alpha=3., beta=1.3):
7082 # While the latter still contains the problematic unbounded term, we
7183 # can use the fact that the flux is a known value at the top and bottom
7284 # via the Dirichlet boundary condition, and impose it as constraints.
73- rightsqr = domain .boundary ['right' ].integral ('flux^2 d:x' @ ns , degree = degree * 2 )
85+ rightsqr = domain .boundary ['right' ].integral (
86+ 'flux^2 d:x' @ ns , degree = degree * 2 )
7487 rightcons = solver .optimize ('fluxdofs' , rightsqr , droptol = 1e-10 )
7588 # rightcons is NaN in dofs that are NOT supported on the right boundary
76- fluxsqr = domain .boundary ['right' ].boundary ['top,bottom' ].integral ('(flux - uexact_,0)^2 d:x' @ ns , degree = degree * 2 )
77- fluxcons = solver .optimize ('fluxdofs' , fluxsqr , droptol = 1e-10 , constrain = np .choose (np .isnan (rightcons ), [np .nan , 0. ]))
89+ fluxsqr = domain .boundary ['right' ].boundary ['top,bottom' ].integral (
90+ '(flux - uexact_,0)^2 d:x' @ ns , degree = degree * 2 )
91+ fluxcons = solver .optimize ('fluxdofs' ,
92+ fluxsqr ,
93+ droptol = 1e-10 ,
94+ constrain = np .choose (np .isnan (rightcons ),
95+ [np .nan ,
96+ 0. ]))
7897 # fluxcons is NaN in dofs that are supported on ONLY the right boundary
7998 fluxres = coupling_sample .integral ('basis_n flux d:x' @ ns ) - res
8099
@@ -100,7 +119,14 @@ def main(side='Dirichlet', n=10, degree=1, timestep=.1, alpha=3., beta=1.3):
100119 # generate output
101120 x , u , uexact = bezier .eval (['x_i' , 'u' , 'uexact' ] @ ns , lhs = lhs , t = t )
102121 with treelog .add (treelog .DataLog ()):
103- export .vtk (side + "-" + str (istep ), bezier .tri , x , Temperature = u , reference = uexact )
122+ export .vtk (
123+ side +
124+ "-" +
125+ str (istep ),
126+ bezier .tri ,
127+ x ,
128+ Temperature = u ,
129+ reference = uexact )
104130
105131 if not interface .is_coupling_ongoing ():
106132 break
@@ -110,9 +136,11 @@ def main(side='Dirichlet', n=10, degree=1, timestep=.1, alpha=3., beta=1.3):
110136 readdata = precice_read ()
111137
112138 # save checkpoint
113- if interface .is_action_required (precice .action_write_iteration_checkpoint ()):
139+ if interface .is_action_required (
140+ precice .action_write_iteration_checkpoint ()):
114141 checkpoint = lhs , t , istep
115- interface .mark_action_fulfilled (precice .action_write_iteration_checkpoint ())
142+ interface .mark_action_fulfilled (
143+ precice .action_write_iteration_checkpoint ())
116144
117145 # prepare next timestep
118146 lhs0 = lhs
@@ -121,16 +149,27 @@ def main(side='Dirichlet', n=10, degree=1, timestep=.1, alpha=3., beta=1.3):
121149 t += dt
122150
123151 # update (time-dependent) boundary condition
124- cons = solver .optimize ('lhs' , sqr , droptol = 1e-15 , arguments = dict (t = t , readdata = readdata ))
152+ cons = solver .optimize (
153+ 'lhs' ,
154+ sqr ,
155+ droptol = 1e-15 ,
156+ arguments = dict (
157+ t = t ,
158+ readdata = readdata ))
125159
126160 # solve nutils timestep
127- lhs = solver .solve_linear ('lhs' , res , constrain = cons , arguments = dict (lhs0 = lhs0 , dt = dt , t = t , readdata = readdata ))
161+ lhs = solver .solve_linear (
162+ 'lhs' , res , constrain = cons , arguments = dict (
163+ lhs0 = lhs0 , dt = dt , t = t , readdata = readdata ))
128164
129165 # write data to interface
130166 if interface .is_write_data_required (dt ):
131167 if side == 'Dirichlet' :
132- fluxdofs = solver .solve_linear ('fluxdofs' , fluxres , arguments = dict (lhs0 = lhs0 , lhs = lhs , dt = dt , t = t ), constrain = fluxcons )
133- write_data = coupling_sample .eval ('flux' @ ns , fluxdofs = fluxdofs )
168+ fluxdofs = solver .solve_linear (
169+ 'fluxdofs' , fluxres , arguments = dict (
170+ lhs0 = lhs0 , lhs = lhs , dt = dt , t = t ), constrain = fluxcons )
171+ write_data = coupling_sample .eval (
172+ 'flux' @ ns , fluxdofs = fluxdofs )
134173 else :
135174 write_data = coupling_sample .eval ('u' @ ns , lhs = lhs )
136175 precice_write (write_data )
@@ -139,9 +178,11 @@ def main(side='Dirichlet', n=10, degree=1, timestep=.1, alpha=3., beta=1.3):
139178 precice_dt = interface .advance (dt )
140179
141180 # read checkpoint if required
142- if interface .is_action_required (precice .action_read_iteration_checkpoint ()):
181+ if interface .is_action_required (
182+ precice .action_read_iteration_checkpoint ()):
143183 lhs , t , istep = checkpoint
144- interface .mark_action_fulfilled (precice .action_read_iteration_checkpoint ())
184+ interface .mark_action_fulfilled (
185+ precice .action_read_iteration_checkpoint ())
145186
146187 interface .finalize ()
147188
0 commit comments