From 303c0167045dcd13905abbebaa4c52fc5d912ceb Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Tue, 29 Nov 2022 14:33:31 +0000 Subject: [PATCH] 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 --- .../timeActivatedFileUpdate.C | 28 +++++++++---------- .../timeActivatedFileUpdate.H | 12 ++++---- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/functionObjects/utilities/timeActivatedFileUpdate/timeActivatedFileUpdate.C b/src/functionObjects/utilities/timeActivatedFileUpdate/timeActivatedFileUpdate.C index c8e384793d..7f5c492b04 100644 --- a/src/functionObjects/utilities/timeActivatedFileUpdate/timeActivatedFileUpdate.C +++ b/src/functionObjects/utilities/timeActivatedFileUpdate/timeActivatedFileUpdate.C @@ -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; diff --git a/src/functionObjects/utilities/timeActivatedFileUpdate/timeActivatedFileUpdate.H b/src/functionObjects/utilities/timeActivatedFileUpdate/timeActivatedFileUpdate.H index 0316705037..2155a12f4e 100644 --- a/src/functionObjects/utilities/timeActivatedFileUpdate/timeActivatedFileUpdate.H +++ b/src/functionObjects/utilities/timeActivatedFileUpdate/timeActivatedFileUpdate.H @@ -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> timeVsFile_; + //- List of filenames vs time + List> fileVsTime_; //- Index of last file copied label lastIndex_;