CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   read volField from startTime or timeName directory (https://www.cfd-online.com/Forums/openfoam-programming-development/204458-read-volfield-starttime-timename-directory.html)

cfdopenfoam July 24, 2018 05:27

read volField from startTime or timeName directory
 
Hi all,

I would like to in a post-processing tool read/construct a volScalarField using IOobject from whether the startTime directory or current time directory, depends on where the corresponding IO file exists. Could someone suggest an elegant way to do this?

Like:

Code:

autoPtr<volScalarField> pPtr
(
    IOobject
    (
        "p",
        runTime.timeName(),
        mesh,
        IOobject::MUST_READ,
        IOobject::NO_WRITE
    ),
    mesh
);

if (pPtr.invalid())  // p-file may not exist in current time directory
{
pPtr.reset
(
    IOobject
    (
        "p",
        runTime.startTime(),
        mesh,
        IOobject::MUST_READ,
        IOobject::NO_WRITE
    ),
    mesh
);
}

;

Not sure if it works. Any hints?


All times are GMT -4. The time now is 11:38.