@@ -63,7 +63,7 @@ def determine_gradient(V_g, u, flux):
63
63
64
64
args = parser .parse_args ()
65
65
66
- fenics_dt = .1 # time step size
66
+ fenics_dt = .01 # time step size
67
67
# Error is bounded by coupling accuracy. In theory we would obtain the analytical solution.
68
68
error_tol = args .error_tol
69
69
@@ -112,7 +112,6 @@ def determine_gradient(V_g, u, flux):
112
112
precice .initialize (coupling_boundary , read_function_space = W , write_object = u_D_function )
113
113
precice_dt = precice .get_max_time_step_size ()
114
114
115
-
116
115
dt = Constant (0 )
117
116
dt .assign (np .min ([fenics_dt , precice_dt ]))
118
117
@@ -164,13 +163,32 @@ def determine_gradient(V_g, u, flux):
164
163
165
164
# output solution and reference solution at t=0, n=0
166
165
n = 0
167
- print ('output u^%d and u_ref^%d' % (n , n ))
168
- temperature_out << (u_n , t )
169
- ref_out << u_ref
166
+ print ("output u^%d and u_ref^%d" % (n , n ))
170
167
ranks << mesh_rank
171
168
172
169
error_total , error_pointwise = compute_errors (u_n , u_ref , V )
173
- error_out << error_pointwise
170
+
171
+ # create buffer for output. We need this buffer, because we only want to
172
+ # write the converged output at the end of the window, but we also want to
173
+ # write the samples that are resulting from substeps inside the window
174
+ u_write = []
175
+ ref_write = []
176
+ error_write = []
177
+ # copy data to buffer and rename
178
+ uu = u_n .copy ()
179
+ uu .rename ("u" , "" )
180
+ u_write .append ((uu , t ))
181
+ uu_ref = u_ref .copy ()
182
+ uu_ref .rename ("u_ref" , "" )
183
+ ref_write .append (uu_ref )
184
+ err = error_pointwise .copy ()
185
+ err .rename ("err" , "" )
186
+ error_write .append (err )
187
+
188
+ # set t_1 = t_0 + dt, this gives u_D^1
189
+ # call dt(0) to evaluate FEniCS Constant. Todo: is there a better way?
190
+ u_D .t = t + dt (0 )
191
+ f .t = t + dt (0 )
174
192
175
193
if problem is ProblemType .DIRICHLET :
176
194
flux = Function (V_g )
@@ -182,6 +200,17 @@ def determine_gradient(V_g, u, flux):
182
200
if precice .requires_writing_checkpoint ():
183
201
precice .store_checkpoint (u_n , t , n )
184
202
203
+ # output solution and reference solution at t_n+1 and substeps (read from buffer)
204
+ print ('output u^%d and u_ref^%d' % (n , n ))
205
+ for sample in u_write :
206
+ temperature_out << sample
207
+
208
+ for sample in ref_write :
209
+ ref_out << sample
210
+
211
+ for sample in error_write :
212
+ error_out << error_pointwise
213
+
185
214
precice_dt = precice .get_max_time_step_size ()
186
215
dt .assign (np .min ([fenics_dt , precice_dt ]))
187
216
@@ -217,21 +246,45 @@ def determine_gradient(V_g, u, flux):
217
246
u_n .assign (u_cp )
218
247
t = t_cp
219
248
n = n_cp
249
+ # empty buffer if window has not converged
250
+ u_write = []
251
+ ref_write = []
252
+ error_write = []
220
253
else : # update solution
221
254
u_n .assign (u_np1 )
222
255
t += float (dt )
223
256
n += 1
257
+ # copy data to buffer and rename
258
+ uu = u_n .copy ()
259
+ uu .rename ("u" , "" )
260
+ u_write .append ((uu , t ))
261
+ uu_ref = u_ref .copy ()
262
+ uu_ref .rename ("u_ref" , "" )
263
+ ref_write .append (uu_ref )
264
+ err = error_pointwise .copy ()
265
+ err .rename ("err" , "" )
266
+ error_write .append (err )
224
267
225
268
if precice .is_time_window_complete ():
226
269
u_ref = interpolate (u_D , V )
227
270
u_ref .rename ("reference" , " " )
228
271
error , error_pointwise = compute_errors (u_n , u_ref , V , total_error_tol = error_tol )
229
- print ('n = %d, t = %.2f: L2 error on domain = %.3g' % (n , t , error ))
230
- # output solution and reference solution at t_n+1
231
- print ('output u^%d and u_ref^%d' % (n , n ))
232
- temperature_out << (u_n , t )
233
- ref_out << u_ref
234
- error_out << error_pointwise
272
+ print ("n = %d, t = %.2f: L2 error on domain = %.3g" % (n , t , error ))
273
+
274
+ # Update Dirichlet BC
275
+ u_D .t = t + float (dt )
276
+ f .t = t + float (dt )
277
+
278
+ # output solution and reference solution at t_n+1 and substeps (read from buffer)
279
+ print ("output u^%d and u_ref^%d" % (n , n ))
280
+ for sample in u_write :
281
+ temperature_out << sample
282
+
283
+ for sample in ref_write :
284
+ ref_out << sample
285
+
286
+ for sample in error_write :
287
+ error_out << error_pointwise
235
288
236
289
# Hold plot
237
290
precice .finalize ()
0 commit comments