@@ -38,7 +38,7 @@ def main(inflow: 'inflow velocity' = 10,
3838
3939 # time approximations
4040 t0 = lambda f : function .replace_arguments (f , {arg : function .Argument (arg + '0' , shape = shape , dtype = dtype )
41- for arg , (shape , dtype ) in f .arguments .items () if arg != 'dt' })
41+ for arg , (shape , dtype ) in f .arguments .items ()})
4242 # TR interpolation
4343 tθ = lambda f : theta * f + (1 - theta ) * t0 (f )
4444 # 1st order FD
@@ -64,14 +64,6 @@ def main(inflow: 'inflow velocity' = 10,
6464 ns .u_i = 'umesh_i + urel_i' # total velocity
6565 ns .p = 'pbasis_n ?lhs_n' # pressure
6666
67- # initialization of dofs
68- meshdofs = numpy .zeros (len (ns .dbasis ))
69- meshdofs0 = meshdofs
70- meshdofs00 = meshdofs
71- meshdofs000 = meshdofs
72- lhs = numpy .zeros (len (ns .ubasis ))
73- lhs0 = lhs
74-
7567 # for visualization
7668 bezier = domain .sample ('bezier' , 2 )
7769
@@ -135,6 +127,10 @@ def main(inflow: 'inflow velocity' = 10,
135127 #lhs0 = solver.solve_linear('lhs', res_stokes, constrain=cons, arguments=dict(meshdofs=meshdofs, meshdofs0=meshdofs0, meshdofs00=meshdofs00, meshdofs000=meshdofs000, dt=dt))
136128
137129 timestep = 0
130+ arguments = dict (lhs = numpy .zeros (len (ns .ubasis )), meshdofs = numpy .zeros (len (ns .dbasis )), dt = timestepsize )
131+
132+ nhist = 4 # history length required by the formulation
133+ arguments .update ((k + '0' * i , v ) for k , v in tuple (arguments .items ()) for i in range (nhist ))
138134
139135 while interface .is_coupling_ongoing ():
140136 with treelog .context (f'timestep { timestep } ' ):
@@ -148,36 +144,21 @@ def main(inflow: 'inflow velocity' = 10,
148144
149145 # save checkpoint
150146 if interface .is_action_required (precice .action_write_iteration_checkpoint ()):
151- checkpoint = timestep , lhs , lhs0 , meshdofs , meshdofs0 , meshdofs00 , meshdofs000
147+ checkpoint = timestep , arguments
152148 interface .mark_action_fulfilled (precice .action_write_iteration_checkpoint ())
153149
154150 # advance variables
155151 timestep += 1
156- lhs00 = lhs0
157- lhs0 = lhs
158- meshdofs0000 = meshdofs000
159- meshdofs000 = meshdofs00
160- meshdofs00 = meshdofs0
161- meshdofs0 = meshdofs
162- dt = min (precice_dt , timestepsize )
163-
164- # solve mesh deformation
165- meshdofs = solver .optimize ('meshdofs' , meshsqr , constrain = meshcons )
166-
167- # solve fluid equations
168- lhs = solver .newton ('lhs' , res , lhs0 = lhs0 , constrain = cons ,
169- arguments = dict (lhs0 = lhs0 , dt = dt , meshdofs = meshdofs , meshdofs0 = meshdofs0 ,
170- meshdofs00 = meshdofs00 , meshdofs000 = meshdofs000 , meshdofs0000 = meshdofs0000 )
171- ).solve (tol = 1e-6 )
152+ arguments = {k + '0' * (i + 1 ): arguments [k + '0' * i ] for k in ('lhs' , 'meshdofs' , 'dt' ) for i in range (nhist )}
153+ arguments ['dt' ] = dt = min (precice_dt , timestepsize )
154+ arguments ['meshdofs' ] = solver .optimize ('meshdofs' , meshsqr , constrain = meshcons ) # solve mesh deformation
155+ arguments ['lhs' ] = arguments ['lhs0' ] # initial guess for newton
156+ arguments ['lhs' ] = solver .newton ('lhs' , res , arguments = arguments , constrain = cons ).solve (tol = 1e-6 ) # solve fluid equations
157+ arguments ['F' ] = solver .solve_linear ('F' , resF , constrain = consF , arguments = arguments )
172158
173159 # write forces to interface
174160 if interface .is_write_data_required (dt ):
175- F = solver .solve_linear ('F' , resF , constrain = consF ,
176- arguments = dict (lhs00 = lhs00 , lhs0 = lhs0 , lhs = lhs , dt = dt , meshdofs = meshdofs ,
177- meshdofs0 = meshdofs0 , meshdofs00 = meshdofs00 ,
178- meshdofs000 = meshdofs000 , meshdofs0000 = meshdofs0000 ))
179- # writedata = couplingsample.eval(ns.F, F=F) # for stresses
180- writedata = couplingsample .eval ('F_i d:x' @ ns , F = F , meshdofs = meshdofs ) * \
161+ writedata = couplingsample .eval ('F_i d:x' @ ns , ** arguments ) * \
181162 numpy .concatenate ([p .weights for p in couplingsample .points ])[:, numpy .newaxis ]
182163 interface .write_block_vector_data (writedataID , dataIndices , writedata )
183164
@@ -186,12 +167,11 @@ def main(inflow: 'inflow velocity' = 10,
186167
187168 # read checkpoint if required
188169 if interface .is_action_required (precice .action_read_iteration_checkpoint ()):
189- timestep , lhs , lhs0 , meshdofs , meshdofs0 , meshdofs00 , meshdofs000 = checkpoint
170+ timestep , arguments = checkpoint
190171 interface .mark_action_fulfilled (precice .action_read_iteration_checkpoint ())
191172
192173 if interface .is_time_window_complete ():
193- x , u , p = bezier .eval (['x_i' , 'u_i' , 'p' ] @ ns , lhs = lhs , meshdofs = meshdofs , meshdofs0 = meshdofs0 ,
194- meshdofs00 = meshdofs00 , meshdofs000 = meshdofs000 , meshdofs0000 = meshdofs0000 , dt = dt )
174+ x , u , p = bezier .eval (['x_i' , 'u_i' , 'p' ] @ ns , ** arguments )
195175 export .triplot ('velocity.jpg' , x , numpy .linalg .norm (u , axis = 1 ), tri = bezier .tri , cmap = 'jet' )
196176 export .triplot ('pressure.jpg' , x , p , tri = bezier .tri , cmap = 'jet' )
197177 with treelog .add (treelog .DataLog ()):
0 commit comments