Git Product home page Git Product logo

Comments (7)

michalhabera avatar michalhabera commented on August 16, 2024 2

As @garth-wells says, context manager and python's GC is recommended approach. However is not possible for the old XDMFFile::write unless you want to have your time loop wrapped and tabbed in context manager. That being said, once you destroy XDMFFile object the old write() method won't append it. On the other hand new write_checkpoint appends it and "local" context managers are possible for time loops.

There is also a parameter flush_output (https://github.com/FEniCS/dolfinx/blob/master/cpp/dolfin/io/XDMFFile.cpp#L58) which forces underlying HDF file to be closed after every XDMFFile::write method call. That should solve the issue you are reporting.
But I do not like these parameters, especially when they are set to an object as whole (e.g. XDMFFile) but they apply only to part of that object (like XDMFFile::write on functions). Very confusing.

If you'd like to do very quick fix of this I'd recommend putting flush_output = True by default.

from dolfinx.

nate-sime avatar nate-sime commented on August 16, 2024 1

Are there any objections to having XDMF::close back in the python interface? I agree with using with wherever possible, but the nested indentation from with and loops for complicated FE problems could quickly get out of hand...

from dolfinx.

garth-wells avatar garth-wells commented on August 16, 2024
with XDMFFile("out2.xdmf") as f:
   f.write(uu, float(100.0), XDMFFile.Encoding.HDF5)

is the recommended approach. Garbage is collection is complicated, especially when calling 3rd party libs, so we should change the i/o syntax in demos.

from dolfinx.

garth-wells avatar garth-wells commented on August 16, 2024

@michalhabera @nate-sime I would suggest using with where possible, and in other cases use close(). We should update demos to follow this pattern.

from dolfinx.

chrisrichardson avatar chrisrichardson commented on August 16, 2024

You can always use del xdmf2. But probably close is neater

from dolfinx.

garth-wells avatar garth-wells commented on August 16, 2024

@nate-sime is this now resolved?

from dolfinx.

nate-sime avatar nate-sime commented on August 16, 2024

Issues addressed and resolved in PR #77

from dolfinx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.