From dfd82248e26c567f198fcb306b47bd6b7d26f41b Mon Sep 17 00:00:00 2001 From: henry Date: Tue, 20 Oct 2009 18:30:55 +0100 Subject: [PATCH] First level of support for cached temporary fields. --- applications/test/fieldDependency/Make/files | 3 + .../test/fieldDependency/Make/options | 5 + .../test/fieldDependency/fieldDependency.C | 102 ++++++++++++++++++ src/OpenFOAM/matrices/solution/solution.C | 91 +++++++++------- src/OpenFOAM/matrices/solution/solution.H | 13 ++- 5 files changed, 172 insertions(+), 42 deletions(-) create mode 100644 applications/test/fieldDependency/Make/files create mode 100644 applications/test/fieldDependency/Make/options create mode 100644 applications/test/fieldDependency/fieldDependency.C diff --git a/applications/test/fieldDependency/Make/files b/applications/test/fieldDependency/Make/files new file mode 100644 index 0000000000..98fd335a17 --- /dev/null +++ b/applications/test/fieldDependency/Make/files @@ -0,0 +1,3 @@ +fieldDependency.C + +EXE = $(FOAM_USER_APPBIN)/fieldDependency diff --git a/applications/test/fieldDependency/Make/options b/applications/test/fieldDependency/Make/options new file mode 100644 index 0000000000..fa15f12452 --- /dev/null +++ b/applications/test/fieldDependency/Make/options @@ -0,0 +1,5 @@ +EXE_INC = \ + -I$(LIB_SRC)/finiteVolume/lnInclude + +EXE_LIBS = \ + -lfiniteVolume diff --git a/applications/test/fieldDependency/fieldDependency.C b/applications/test/fieldDependency/fieldDependency.C new file mode 100644 index 0000000000..fa3c7b2e86 --- /dev/null +++ b/applications/test/fieldDependency/fieldDependency.C @@ -0,0 +1,102 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-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 + +Description + Test field dependencies. + +\*---------------------------------------------------------------------------*/ + +#include "argList.H" +#include "Time.H" +#include "volFields.H" + +using namespace Foam; + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +// Main program: + +int main(int argc, char *argv[]) +{ + #include "setRootCase.H" + #include "createTime.H" + #include "createMesh.H" + + Info<< "Creating field T\n" << endl; + volScalarField T + ( + IOobject + ( + "T", + runTime.timeName(), + mesh, + IOobject::NO_READ, + IOobject::AUTO_WRITE + ), + mesh, + dimensionedScalar("zero", dimless, 0) + ); + + Info<< "Creating field p\n" << endl; + volScalarField p + ( + IOobject + ( + "p", + runTime.timeName(), + mesh, + IOobject::NO_READ, + IOobject::AUTO_WRITE + ), + mesh, + dimensionedScalar("zero", dimless, 0) + ); + + + Info<< "p.eventNo:" << p.eventNo() << endl; + Info<< "p.uptodate:" << p.upToDate("T")<< endl; + + // Change T and mark as uptodate. + Info<< "Changing T" << endl; + T = 0.0; + T.setUpToDate(); + Info<< "T.eventNo:" << T.eventNo() << endl; + + // Check p dependency: + Info<< "p.uptodate:" << p.upToDate("T")<< endl; + + // Change p and mark as uptodate. + Info<< "Changing p." << endl; + p.setUpToDate(); + Info<< "p.uptodate:" << p.upToDate("T")<< endl; + Info<< "p.eventNo:" << p.eventNo() << endl; + + + Info<< "End\n" << endl; + + return 0; +} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/matrices/solution/solution.C b/src/OpenFOAM/matrices/solution/solution.C index 030b3df9ae..c63dceec4e 100644 --- a/src/OpenFOAM/matrices/solution/solution.C +++ b/src/OpenFOAM/matrices/solution/solution.C @@ -59,11 +59,8 @@ Foam::solution::solution(const objectRegistry& obr, const fileName& dictName) IOobject::NO_WRITE ) ), - relaxationFactors_ - ( - ITstream("relaxationFactors", - tokenList())() - ), + cache_(ITstream("cache", tokenList())()), + relaxationFactors_(ITstream("relaxationFactors", tokenList())()), defaultRelaxationFactor_(0), solvers_(ITstream("solvers", tokenList())()) { @@ -151,44 +148,14 @@ Foam::label Foam::solution::upgradeSolverDict } -bool Foam::solution::read() +bool Foam::solution::cache(const word& name) const { - if (regIOobject::read()) + if (debug) { - const dictionary& dict = solutionDict(); - - if (dict.found("relaxationFactors")) - { - relaxationFactors_ = dict.subDict("relaxationFactors"); - } - - relaxationFactors_.readIfPresent("default", defaultRelaxationFactor_); - - if (dict.found("solvers")) - { - solvers_ = dict.subDict("solvers"); - upgradeSolverDict(solvers_); - } - - return true; + Info<< "Find cache entry for " << name << endl; } - else - { - return false; - } -} - -const Foam::dictionary& Foam::solution::solutionDict() const -{ - if (found("select")) - { - return subDict(word(lookup("select"))); - } - else - { - return *this; - } + return cache_.found(name); } @@ -235,6 +202,19 @@ Foam::scalar Foam::solution::relaxationFactor(const word& name) const } +const Foam::dictionary& Foam::solution::solutionDict() const +{ + if (found("select")) + { + return subDict(word(lookup("select"))); + } + else + { + return *this; + } +} + + const Foam::dictionary& Foam::solution::solverDict(const word& name) const { if (debug) @@ -259,4 +239,37 @@ const Foam::dictionary& Foam::solution::solver(const word& name) const } +bool Foam::solution::read() +{ + if (regIOobject::read()) + { + const dictionary& dict = solutionDict(); + + if (dict.found("cache")) + { + cache_ = dict.subDict("cache"); + } + + if (dict.found("relaxationFactors")) + { + relaxationFactors_ = dict.subDict("relaxationFactors"); + } + + relaxationFactors_.readIfPresent("default", defaultRelaxationFactor_); + + if (dict.found("solvers")) + { + solvers_ = dict.subDict("solvers"); + upgradeSolverDict(solvers_); + } + + return true; + } + else + { + return false; + } +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/matrices/solution/solution.H b/src/OpenFOAM/matrices/solution/solution.H index d3bf008475..36724bf495 100644 --- a/src/OpenFOAM/matrices/solution/solution.H +++ b/src/OpenFOAM/matrices/solution/solution.H @@ -53,6 +53,9 @@ class solution { // Private data + //- Dictionary of temporary fields to cache + dictionary cache_; + //- Dictionary of relaxation factors for all the fields dictionary relaxationFactors_; @@ -62,6 +65,7 @@ class solution //- Dictionary of solver parameters for all the fields dictionary solvers_; + // Private Member Functions //- Disallow default bitwise copy construct and assignment @@ -90,9 +94,8 @@ public: // Access - //- Return the selected sub-dictionary of solvers if the "select" - // keyword is given, otherwise return the complete dictionary - const dictionary& solutionDict() const; + //- Return true if the given field should be cached + bool cache(const word& name) const; //- Return true if the relaxation factor is given for the field bool relax(const word& name) const; @@ -100,6 +103,10 @@ public: //- Return the relaxation factor for the given field scalar relaxationFactor(const word& name) const; + //- Return the selected sub-dictionary of solvers if the "select" + // keyword is given, otherwise return the complete dictionary + const dictionary& solutionDict() const; + //- Return the solver controls dictionary for the given field const dictionary& solverDict(const word& name) const;