functionObjects::timeActivatedFileUpdate: Changed file read time specification to user-time

Also changed the keyword timeVsFile to the more logical fileVsTime with
backward-compatibility.

Class
    Foam::functionObjects::timeActivatedFileUpdate

Description
    Performs a file copy/replacement once a specified time has been reached.

Usage
    Example usage to update the fvSolution dictionary at 0.1, 0.2 and 0.3s
    during the run:
    \verbatim
    fileUpdate1
    {
        type            timeActivatedFileUpdate;

        libs            ("libutilityFunctionObjects.so");

        writeControl    timeStep;
        writeInterval   1;
        fileToUpdate    "$FOAM_CASE/system/fvSolution";
        fileVsTime
        (
            (-1 "$FOAM_CASE/system/fvSolution.0")
            (0.10 "$FOAM_CASE/system/fvSolution.10")
            (0.20 "$FOAM_CASE/system/fvSolution.20")
            (0.35 "$FOAM_CASE/system/fvSolution.35")
        );
    }
    \endverbatim

Resolves bug-report https://bugs.openfoam.org/view.php?id=3938
This commit is contained in:
Henry Weller
2022-11-29 14:33:31 +00:00
parent c0ce311444
commit 303c016704
2 changed files with 20 additions and 20 deletions

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -53,8 +53,8 @@ void Foam::functionObjects::timeActivatedFileUpdate::updateFile()
label i = lastIndex_;
while
(
i < timeVsFile_.size()-1
&& timeVsFile_[i+1].first() < time_.value()
i < fileVsTime_.size()-1
&& fileVsTime_[i+1].first() <= time_.userTimeValue()
)
{
i++;
@ -62,11 +62,11 @@ void Foam::functionObjects::timeActivatedFileUpdate::updateFile()
if (i > lastIndex_)
{
Info<< nl << type() << ": copying file" << nl << timeVsFile_[i].second()
Info<< nl << type() << ": copying file" << nl << fileVsTime_[i].second()
<< nl << "to:" << nl << fileToUpdate_ << nl << endl;
fileName destFile(fileToUpdate_ + Foam::name(pid()));
cp(timeVsFile_[i].second(), destFile);
cp(fileVsTime_[i].second(), destFile);
mv(destFile, fileToUpdate_);
lastIndex_ = i;
}
@ -85,7 +85,7 @@ Foam::functionObjects::timeActivatedFileUpdate::timeActivatedFileUpdate
functionObject(name),
time_(runTime),
fileToUpdate_(dict.lookup("fileToUpdate")),
timeVsFile_(),
fileVsTime_(),
lastIndex_(-1)
{
read(dict);
@ -106,24 +106,24 @@ bool Foam::functionObjects::timeActivatedFileUpdate::read
)
{
dict.lookup("fileToUpdate") >> fileToUpdate_;
dict.lookup("timeVsFile") >> timeVsFile_;
dict.lookupBackwardsCompatible({"fileVsTime", "timeVsFile"}) >> fileVsTime_;
lastIndex_ = -1;
fileToUpdate_.expand();
Info<< type() << ": time vs file list:" << nl;
forAll(timeVsFile_, i)
Info<< type() << ": file vs time list:" << nl;
forAll(fileVsTime_, i)
{
timeVsFile_[i].second() = timeVsFile_[i].second().expand();
if (!isFile(timeVsFile_[i].second()))
fileVsTime_[i].second() = fileVsTime_[i].second().expand();
if (!isFile(fileVsTime_[i].second()))
{
FatalErrorInFunction
<< "File: " << timeVsFile_[i].second() << " not found"
<< "File: " << fileVsTime_[i].second() << " not found"
<< nl << exit(FatalError);
}
Info<< " " << timeVsFile_[i].first() << tab
<< timeVsFile_[i].second() << endl;
Info<< " " << fileVsTime_[i].first() << tab
<< fileVsTime_[i].second() << endl;
}
Info<< endl;

View File

@ -27,9 +27,9 @@ Class
Description
Performs a file copy/replacement once a specified time has been reached.
Example usage to update the fvSolution dictionary at various times
throughout the calculation:
Usage
Example usage to update the fvSolution dictionary at 0.1, 0.2 and 0.3s
during the run:
\verbatim
fileUpdate1
{
@ -40,7 +40,7 @@ Description
writeControl timeStep;
writeInterval 1;
fileToUpdate "$FOAM_CASE/system/fvSolution";
timeVsFile
fileVsTime
(
(-1 "$FOAM_CASE/system/fvSolution.0")
(0.10 "$FOAM_CASE/system/fvSolution.10")
@ -88,8 +88,8 @@ class timeActivatedFileUpdate
//- Name of file to update
fileName fileToUpdate_;
//- List of times vs filenames
List<Tuple2<scalar, fileName>> timeVsFile_;
//- List of filenames vs time
List<Tuple2<scalar, fileName>> fileVsTime_;
//- Index of last file copied
label lastIndex_;