Skip to content

OpenFOAM monitoring and post-processing using pandas

License

Notifications You must be signed in to change notification settings

staneuski/foamio

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

foamio

OpenFOAM addons, Python routines and helpers.

CLI

  • Convert all Z-cutPlanes from .vtk to .vtp and generate a .pvd-file matching the case name
    foam_case=<path>
    foamio convert $foam_case/postProcessing/cutPlanes && \
    foamio -v generate $foam_case/postProcessing/cutPlanes --pattern='*(z).vtp' --outfile=$foam_case/postProcessing/$(basename $foam_case).pvd
  • Clean up a case (including postProcessing/) from a particular time-step
    foam_case=<path>
    foamio --debug clean $foam_case --interval '<time>:' --exclude-first && \
    foamio clean $foam_case/postProcessing/ -i "$(foamListTimes -case $foam_case -latestTime):"
  • Clean up a case (including postProcessing/) from a particular time-step but using foamListTimes -rm
    foam_case=<path>
    foamListTimes -case $foam_case -time '<time>:' -rm && \:
    foamio clean $foam_case/postProcessing/ -i "$(foamListTimes -case $foam_case -latestTime):"
  • Create tabulated entry for physicalProperties using CoolProp:
    foamio -v tabulate H2O constant/ --pressure 1e+05 5e+06 2500 --temperature 293.15 393.15 100 --entries DMASS HMASS CPMASS CVMASS VISCOSITY CONDUCTIVITY
    
    Generated entry can be imported in mixture dictionary as:
    equationOfState
    {
        rho
        {
            #include "H2O.DMASS"
        }
    }

Module

  • Read OpenFOAM-dictionary (with #calcs, etc.) as cached Python-dict:
    from functools import cache
    from pathlib import Path
    import tempfile
    
    from foamio.foam import Caller as Foam, read
    @cache
    def read_dict(root: Path, orig: Path) -> dict:
        """
        Args:
            root (Path): Absolute path to OpenFOAM-case.
            orig (Path): OpenFOAM-dictionary path relative to FOAM_CASE.
        """
    
        # foamio.foam.read works only for expanded dictionaries => expand to a temporary file using `foamDictionary` and read from this file
        with tempfile.NamedTemporaryFile(dir=root / orig.parent) as tmp:
            fname = Path(tmp.name).relative_to(root)
            Foam().Dictionary(orig, case=root, expand=True, output=str(fname))
            return read(root, tmp.name)

About

OpenFOAM monitoring and post-processing using pandas

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages