Skip to content

Commit e350ed9

Browse files
committed
Demonstrate feature in stokes demo
1 parent 3e6928f commit e350ed9

1 file changed

Lines changed: 8 additions & 12 deletions

File tree

python/demo/demo_navier-stokes.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -367,10 +367,10 @@ def jump(phi, n):
367367
if has_adios2:
368368
u_vis = fem.Function(W, name="u_init")
369369
u_vis.interpolate(u_h)
370-
u_file = io.VTXWriter(msh.comm, "u.bp", "w", u_vis)
371-
p_file = io.VTXWriter(msh.comm, "p.bp", "w", p_h)
372-
u_file.write(t)
373-
p_file.write(t)
370+
with io.VTXWriter(msh.comm, "u.bp", "w", u_vis) as file:
371+
file.write(t)
372+
with io.VTXWriter(msh.comm, "p.bp", "w", p_h) as file:
373+
file.write(t)
374374
else:
375375
print("File output requires ADIOS2.")
376376

@@ -422,17 +422,13 @@ def jump(phi, n):
422422
# Write to file
423423
if has_adios2:
424424
u_vis.interpolate(u_h)
425-
u_file.write(t)
426-
p_file.write(t)
425+
with io.VTXWriter(msh.comm, "u.bp", "a", u_vis) as file:
426+
file.write(t)
427+
with io.VTXWriter(msh.comm, "p.bp", "a", u_vis) as file:
428+
file.write(t)
427429

428430
# Update u_n
429431
u_n.x.array[:] = u_h.x.array
430-
431-
try:
432-
u_file.close()
433-
p_file.close()
434-
except NameError:
435-
pass
436432
# -
437433

438434
# Now we compare the computed solution to the exact solution

0 commit comments

Comments
 (0)