mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
First level of support for cached temporary fields.
This commit is contained in:
3
applications/test/fieldDependency/Make/files
Normal file
3
applications/test/fieldDependency/Make/files
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
fieldDependency.C
|
||||||
|
|
||||||
|
EXE = $(FOAM_USER_APPBIN)/fieldDependency
|
||||||
5
applications/test/fieldDependency/Make/options
Normal file
5
applications/test/fieldDependency/Make/options
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
EXE_INC = \
|
||||||
|
-I$(LIB_SRC)/finiteVolume/lnInclude
|
||||||
|
|
||||||
|
EXE_LIBS = \
|
||||||
|
-lfiniteVolume
|
||||||
102
applications/test/fieldDependency/fieldDependency.C
Normal file
102
applications/test/fieldDependency/fieldDependency.C
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
@ -59,11 +59,8 @@ Foam::solution::solution(const objectRegistry& obr, const fileName& dictName)
|
|||||||
IOobject::NO_WRITE
|
IOobject::NO_WRITE
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
relaxationFactors_
|
cache_(ITstream("cache", tokenList())()),
|
||||||
(
|
relaxationFactors_(ITstream("relaxationFactors", tokenList())()),
|
||||||
ITstream("relaxationFactors",
|
|
||||||
tokenList())()
|
|
||||||
),
|
|
||||||
defaultRelaxationFactor_(0),
|
defaultRelaxationFactor_(0),
|
||||||
solvers_(ITstream("solvers", tokenList())())
|
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();
|
Info<< "Find cache entry for " << name << endl;
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
return cache_.found(name);
|
||||||
const Foam::dictionary& Foam::solution::solutionDict() const
|
|
||||||
{
|
|
||||||
if (found("select"))
|
|
||||||
{
|
|
||||||
return subDict(word(lookup("select")));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -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
|
const Foam::dictionary& Foam::solution::solverDict(const word& name) const
|
||||||
{
|
{
|
||||||
if (debug)
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
@ -53,6 +53,9 @@ class solution
|
|||||||
{
|
{
|
||||||
// Private data
|
// Private data
|
||||||
|
|
||||||
|
//- Dictionary of temporary fields to cache
|
||||||
|
dictionary cache_;
|
||||||
|
|
||||||
//- Dictionary of relaxation factors for all the fields
|
//- Dictionary of relaxation factors for all the fields
|
||||||
dictionary relaxationFactors_;
|
dictionary relaxationFactors_;
|
||||||
|
|
||||||
@ -62,6 +65,7 @@ class solution
|
|||||||
//- Dictionary of solver parameters for all the fields
|
//- Dictionary of solver parameters for all the fields
|
||||||
dictionary solvers_;
|
dictionary solvers_;
|
||||||
|
|
||||||
|
|
||||||
// Private Member Functions
|
// Private Member Functions
|
||||||
|
|
||||||
//- Disallow default bitwise copy construct and assignment
|
//- Disallow default bitwise copy construct and assignment
|
||||||
@ -90,9 +94,8 @@ public:
|
|||||||
|
|
||||||
// Access
|
// Access
|
||||||
|
|
||||||
//- Return the selected sub-dictionary of solvers if the "select"
|
//- Return true if the given field should be cached
|
||||||
// keyword is given, otherwise return the complete dictionary
|
bool cache(const word& name) const;
|
||||||
const dictionary& solutionDict() const;
|
|
||||||
|
|
||||||
//- Return true if the relaxation factor is given for the field
|
//- Return true if the relaxation factor is given for the field
|
||||||
bool relax(const word& name) const;
|
bool relax(const word& name) const;
|
||||||
@ -100,6 +103,10 @@ public:
|
|||||||
//- Return the relaxation factor for the given field
|
//- Return the relaxation factor for the given field
|
||||||
scalar relaxationFactor(const word& name) const;
|
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
|
//- Return the solver controls dictionary for the given field
|
||||||
const dictionary& solverDict(const word& name) const;
|
const dictionary& solverDict(const word& name) const;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user