From d6a5a3299e9c948bf2cb3a6088fa91c23b8da919 Mon Sep 17 00:00:00 2001 From: andy Date: Mon, 23 Nov 2009 17:18:24 +0000 Subject: [PATCH] new function object: timeActivatedFileUpdate --- .../functionObjects/utilities/Make/files | 3 + .../IOtimeActivatedFileUpdate.H | 50 ++++++ .../timeActivatedFileUpdate/controlDict | 67 ++++++++ .../timeActivatedFileUpdate.C | 147 +++++++++++++++++ .../timeActivatedFileUpdate.H | 151 ++++++++++++++++++ .../timeActivatedFileUpdateFunctionObject.C | 47 ++++++ .../timeActivatedFileUpdateFunctionObject.H | 55 +++++++ 7 files changed, 520 insertions(+) create mode 100644 src/postProcessing/functionObjects/utilities/timeActivatedFileUpdate/IOtimeActivatedFileUpdate.H create mode 100644 src/postProcessing/functionObjects/utilities/timeActivatedFileUpdate/controlDict create mode 100644 src/postProcessing/functionObjects/utilities/timeActivatedFileUpdate/timeActivatedFileUpdate.C create mode 100644 src/postProcessing/functionObjects/utilities/timeActivatedFileUpdate/timeActivatedFileUpdate.H create mode 100644 src/postProcessing/functionObjects/utilities/timeActivatedFileUpdate/timeActivatedFileUpdateFunctionObject.C create mode 100644 src/postProcessing/functionObjects/utilities/timeActivatedFileUpdate/timeActivatedFileUpdateFunctionObject.H diff --git a/src/postProcessing/functionObjects/utilities/Make/files b/src/postProcessing/functionObjects/utilities/Make/files index 40a33c238d..a93fad2eda 100644 --- a/src/postProcessing/functionObjects/utilities/Make/files +++ b/src/postProcessing/functionObjects/utilities/Make/files @@ -4,4 +4,7 @@ staticPressure/staticPressureFunctionObject.C dsmcFields/dsmcFields.C dsmcFields/dsmcFieldsFunctionObject.C +timeActivatedFileUpdate/timeActivatedFileUpdate.C +timeActivatedFileUpdate/timeActivatedFileUpdateFunctionObject.C + LIB = $(FOAM_LIBBIN)/libutilityFunctionObjects diff --git a/src/postProcessing/functionObjects/utilities/timeActivatedFileUpdate/IOtimeActivatedFileUpdate.H b/src/postProcessing/functionObjects/utilities/timeActivatedFileUpdate/IOtimeActivatedFileUpdate.H new file mode 100644 index 0000000000..e0e197f74c --- /dev/null +++ b/src/postProcessing/functionObjects/utilities/timeActivatedFileUpdate/IOtimeActivatedFileUpdate.H @@ -0,0 +1,50 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2009-2009 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Typedef + Foam::IOtimeActivatedFileUpdate + +Description + Instance of the generic IOOutputFilter for timeActivatedFileUpdate. + +\*---------------------------------------------------------------------------*/ + +#ifndef IOtimeActivatedFileUpdate_H +#define IOtimeActivatedFileUpdate_H + +#include "timeActivatedFileUpdate.H" +#include "IOOutputFilter.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + typedef IOOutputFilter IOtimeActivatedFileUpdate; +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/postProcessing/functionObjects/utilities/timeActivatedFileUpdate/controlDict b/src/postProcessing/functionObjects/utilities/timeActivatedFileUpdate/controlDict new file mode 100644 index 0000000000..635cefc4e8 --- /dev/null +++ b/src/postProcessing/functionObjects/utilities/timeActivatedFileUpdate/controlDict @@ -0,0 +1,67 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: 1.6 | +| \\ / A nd | Web: www.OpenFOAM.org | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + location "system"; + object controlDict; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +application icoFoam; + +startFrom startTime; + +startTime 0; + +stopAt endTime; + +endTime 0.5; + +deltaT 0.005; + +writeControl timeStep; + +writeInterval 20; + +purgeWrite 0; + +writeFormat ascii; + +writePrecision 6; + +writeCompression uncompressed; + +timeFormat general; + +timePrecision 6; + +runTimeModifiable yes; + +functions +{ + fileUpdate1 + { + type timeActivatedFileUpdate; + functionObjectLibs ("libutilityFunctionObjects.so"); + outputControl timeStep; + outputInterval 1; + fileToUpdate "$FOAM_CASE/system/fvSolution"; + timeVsFile + ( + (-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") + ); + } +} + +// ************************************************************************* // diff --git a/src/postProcessing/functionObjects/utilities/timeActivatedFileUpdate/timeActivatedFileUpdate.C b/src/postProcessing/functionObjects/utilities/timeActivatedFileUpdate/timeActivatedFileUpdate.C new file mode 100644 index 0000000000..306538e4bf --- /dev/null +++ b/src/postProcessing/functionObjects/utilities/timeActivatedFileUpdate/timeActivatedFileUpdate.C @@ -0,0 +1,147 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2009-2009 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "timeActivatedFileUpdate.H" +#include "objectRegistry.H" +#include "Time.H" +#include "dictionary.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(timeActivatedFileUpdate, 0); +} + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +void Foam::timeActivatedFileUpdate::updateFile() +{ + label i = lastIndex_; + while + ( + i < timeVsFile_.size()-1 + && timeVsFile_[i+1].first() < obr_.time().value() + ) + { + i++; + } + + if (i > lastIndex_) + { + Info<< "\ntimeActivatedFileUpdate: copying file" << nl + << timeVsFile_[i].second() << nl << "to:" << nl << fileToUpdate_ + << nl << endl; + + cp(timeVsFile_[i].second(), fileToUpdate_); + lastIndex_ = i; + } +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::timeActivatedFileUpdate::timeActivatedFileUpdate +( + const word& name, + const objectRegistry& obr, + const dictionary& dict, + const bool loadFromFiles +) +: + name_(name), + obr_(obr), + active_(true), + fileToUpdate_(dict.lookup("fileToUpdate")), + timeVsFile_(), + lastIndex_(-1) +{ + read(dict); +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::timeActivatedFileUpdate::~timeActivatedFileUpdate() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::timeActivatedFileUpdate::read(const dictionary& dict) +{ + if (active_) + { + dict.lookup("fileToUpdate") >> fileToUpdate_; + dict.lookup("timeVsFile") >> timeVsFile_; + + lastIndex_ = -1; + fileToUpdate_.expand(); + + Info<< "timeActivatedFileUpdate: time vs file list:" << nl; + forAll(timeVsFile_, i) + { + timeVsFile_[i].second() = timeVsFile_[i].second().expand(); + if (!isFile(timeVsFile_[i].second())) + { + FatalErrorIn("timeActivatedFileUpdate::read(const dictionary&)") + << "File: " << timeVsFile_[i].second() << " not found" + << nl << exit(FatalError); + } + + Info<< " " << timeVsFile_[i].first() << tab + << timeVsFile_[i].second() << endl; + } + Info<< endl; + + updateFile(); + } +} + + +void Foam::timeActivatedFileUpdate::execute() +{ + if (active_) + { + updateFile(); + } +} + + +void Foam::timeActivatedFileUpdate::end() +{ + // Do nothing +} + + +void Foam::timeActivatedFileUpdate::write() +{ + // Do nothing +} + + +// ************************************************************************* // diff --git a/src/postProcessing/functionObjects/utilities/timeActivatedFileUpdate/timeActivatedFileUpdate.H b/src/postProcessing/functionObjects/utilities/timeActivatedFileUpdate/timeActivatedFileUpdate.H new file mode 100644 index 0000000000..2c566ab1d1 --- /dev/null +++ b/src/postProcessing/functionObjects/utilities/timeActivatedFileUpdate/timeActivatedFileUpdate.H @@ -0,0 +1,151 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2009-2009 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Class + Foam::timeActivatedFileUpdate + +Description + +SourceFiles + timeActivatedFileUpdate.C + IOtimeActivatedFileUpdate.H + +\*---------------------------------------------------------------------------*/ + +#ifndef timeActivatedFileUpdate_H +#define timeActivatedFileUpdate_H + +#include "pointFieldFwd.H" +#include "Tuple2.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// Forward declaration of classes +class objectRegistry; +class dictionary; +class mapPolyMesh; + +/*---------------------------------------------------------------------------*\ + Class timeActivatedFileUpdate Declaration +\*---------------------------------------------------------------------------*/ + +class timeActivatedFileUpdate +{ + // Private data + + //- Name of this set of timeActivatedFileUpdate objects + word name_; + + const objectRegistry& obr_; + + //- On/off switch + bool active_; + + //- Name of file to update + fileName fileToUpdate_; + + //- List of times vs filenames + List > timeVsFile_; + + //- Index of last file copied + label lastIndex_; + + + // Private Member Functions + + //- Update file + void updateFile(); + + //- Disallow default bitwise copy construct + timeActivatedFileUpdate(const timeActivatedFileUpdate&); + + //- Disallow default bitwise assignment + void operator=(const timeActivatedFileUpdate&); + + +public: + + //- Runtime type information + TypeName("timeActivatedFileUpdate"); + + + // Constructors + + //- Construct for given objectRegistry and dictionary. + // Allow the possibility to load fields from files + timeActivatedFileUpdate + ( + const word& name, + const objectRegistry&, + const dictionary&, + const bool loadFromFiles = false + ); + + + //- Destructor + virtual ~timeActivatedFileUpdate(); + + + // Member Functions + + //- Return name of the set of timeActivatedFileUpdate + virtual const word& name() const + { + return name_; + } + + //- Read the timeActivatedFileUpdate data + virtual void read(const dictionary&); + + //- Execute, currently does nothing + virtual void execute(); + + //- Execute at the final time-loop, currently does nothing + virtual void end(); + + //- Calculate the timeActivatedFileUpdate and write + virtual void write(); + + //- Update for changes of mesh + virtual void updateMesh(const mapPolyMesh&) + {} + + //- Update for changes of mesh + virtual void movePoints(const pointField&) + {} +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/postProcessing/functionObjects/utilities/timeActivatedFileUpdate/timeActivatedFileUpdateFunctionObject.C b/src/postProcessing/functionObjects/utilities/timeActivatedFileUpdate/timeActivatedFileUpdateFunctionObject.C new file mode 100644 index 0000000000..29a26be3d4 --- /dev/null +++ b/src/postProcessing/functionObjects/utilities/timeActivatedFileUpdate/timeActivatedFileUpdateFunctionObject.C @@ -0,0 +1,47 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2009-2009 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "timeActivatedFileUpdateFunctionObject.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineNamedTemplateTypeNameAndDebug + ( + timeActivatedFileUpdateFunctionObject, + 0 + ); + + addToRunTimeSelectionTable + ( + functionObject, + timeActivatedFileUpdateFunctionObject, + dictionary + ); +} + +// ************************************************************************* // diff --git a/src/postProcessing/functionObjects/utilities/timeActivatedFileUpdate/timeActivatedFileUpdateFunctionObject.H b/src/postProcessing/functionObjects/utilities/timeActivatedFileUpdate/timeActivatedFileUpdateFunctionObject.H new file mode 100644 index 0000000000..c0dd16ab98 --- /dev/null +++ b/src/postProcessing/functionObjects/utilities/timeActivatedFileUpdate/timeActivatedFileUpdateFunctionObject.H @@ -0,0 +1,55 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2009-2009 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Typedef + Foam::timeActivatedFileUpdateFunctionObject + +Description + FunctionObject wrapper around timeActivatedFileUpdate to allow it to be + created via the functions list within controlDict. + +SourceFiles + timeActivatedFileUpdateFunctionObject.C + +\*---------------------------------------------------------------------------*/ + +#ifndef timeActivatedFileUpdateFunctionObject_H +#define timeActivatedFileUpdateFunctionObject_H + +#include "timeActivatedFileUpdate.H" +#include "OutputFilterFunctionObject.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + typedef OutputFilterFunctionObject + timeActivatedFileUpdateFunctionObject; +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* //