1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
29 // These are for old syntax compatibility:
32 #include "IStringStream.H"
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 int Foam::solution::debug(::Foam::debug::debugSwitch("solution", 0));
38 // List of sub-dictionaries to rewrite
40 static const Foam::List<Foam::word> subDictNames
42 Foam::IStringStream("(preconditioner smoother)")()
47 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
49 void Foam::solution::read(const dictionary& dict)
51 if (dict.found("cache"))
53 cache_ = dict.subDict("cache");
54 caching_ = cache_.lookupOrDefault("active", true);
57 if (dict.found("relaxationFactors"))
59 relaxationFactors_ = dict.subDict("relaxationFactors");
62 relaxationFactors_.readIfPresent("default", defaultRelaxationFactor_);
64 if (dict.found("solvers"))
66 solvers_ = dict.subDict("solvers");
67 upgradeSolverDict(solvers_);
72 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
74 Foam::solution::solution
76 const objectRegistry& obr,
77 const fileName& dictName
88 obr.readOpt() == IOobject::MUST_READ
89 ? IOobject::MUST_READ_IF_MODIFIED
95 cache_(ITstream("cache", tokenList())()),
97 relaxationFactors_(ITstream("relaxationFactors", tokenList())()),
98 defaultRelaxationFactor_(0),
99 solvers_(ITstream("solvers", tokenList())())
103 readOpt() == IOobject::MUST_READ
104 || readOpt() == IOobject::MUST_READ_IF_MODIFIED
107 read(solutionDict());
112 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
114 Foam::label Foam::solution::upgradeSolverDict
122 // backward compatibility:
123 // recast primitive entries into dictionary entries
124 forAllIter(dictionary, dict, iter)
126 if (!iter().isDict())
128 Istream& is = iter().stream();
134 // special treatment for very old syntax
135 subdict = BICCG::solverDict(is);
137 else if (name == "ICCG")
139 // special treatment for very old syntax
140 subdict = ICCG::solverDict(is);
144 subdict.add("solver", name);
145 subdict <<= dictionary(is);
147 // preconditioner and smoother entries can be
148 // 1) primitiveEntry w/o settings,
149 // 2) or a dictionaryEntry.
150 // transform primitiveEntry with settings -> dictionaryEntry
151 forAll(subDictNames, dictI)
153 const word& dictName = subDictNames[dictI];
154 entry* ePtr = subdict.lookupEntryPtr(dictName,false,false);
156 if (ePtr && !ePtr->isDict())
158 Istream& is = ePtr->stream();
164 newDict.add(dictName, name);
165 newDict <<= dictionary(is);
167 subdict.set(dictName, newDict);
174 // write out information to help people adjust to the new syntax
175 if (verbose && Pstream::master())
177 Info<< "// using new solver syntax:\n"
178 << iter().keyword() << subdict << endl;
181 // overwrite with dictionary entry
182 dict.set(iter().keyword(), subdict);
192 bool Foam::solution::cache(const word& name) const
198 Info<< "Cache: find entry for " << name << endl;
201 return cache_.found(name);
210 bool Foam::solution::relax(const word& name) const
214 Info<< "Find relax for " << name << endl;
218 relaxationFactors_.found(name)
219 || relaxationFactors_.found("default");
223 Foam::scalar Foam::solution::relaxationFactor(const word& name) const
227 Info<< "Lookup relaxationFactor for " << name << endl;
230 if (relaxationFactors_.found(name))
232 return readScalar(relaxationFactors_.lookup(name));
234 else if (defaultRelaxationFactor_ > SMALL)
236 return defaultRelaxationFactor_;
242 "Foam::solution::relaxationFactor(const word&)",
244 ) << "Cannot find relaxationFactor for '" << name
245 << "' or a suitable default value."
246 << exit(FatalIOError);
253 const Foam::dictionary& Foam::solution::solutionDict() const
257 return subDict(word(lookup("select")));
266 const Foam::dictionary& Foam::solution::solverDict(const word& name) const
270 InfoIn("solution::solverDict(const word&)")
271 << "Lookup solver for " << name << endl;
274 return solvers_.subDict(name);
278 const Foam::dictionary& Foam::solution::solver(const word& name) const
282 InfoIn("solution::solver(const word&)")
283 << "Lookup solver for " << name << endl;
286 return solvers_.subDict(name);
290 bool Foam::solution::read()
292 if (regIOobject::read())
294 read(solutionDict());
305 // ************************************************************************* //