1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
30 // These are for old syntax compatibility:
33 #include "IStringStream.H"
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 int Foam::solution::debug(::Foam::debug::debugSwitch("solution", 0));
39 // List of sub-dictionaries to rewrite
41 static const Foam::List<Foam::word> subDictNames
43 Foam::IStringStream("(preconditioner smoother)")()
45 //! @endcond localScope
47 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
49 Foam::solution::solution(const objectRegistry& obr, const fileName& dictName)
64 ITstream("relaxationFactors",
67 defaultRelaxationFactor_(0),
68 solvers_(ITstream("solvers", tokenList())())
74 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
76 Foam::label Foam::solution::upgradeSolverDict
84 // backward compatibility:
85 // recast primitive entries into dictionary entries
86 forAllIter(dictionary, dict, iter)
90 Istream& is = iter().stream();
96 // special treatment for very old syntax
97 subdict = BICCG::solverDict(is);
99 else if (name == "ICCG")
101 // special treatment for very old syntax
102 subdict = ICCG::solverDict(is);
106 subdict.add("solver", name);
107 subdict <<= dictionary(is);
109 // preconditioner and smoother entries can be
110 // 1) primitiveEntry w/o settings,
111 // 2) or a dictionaryEntry.
112 // transform primitiveEntry with settings -> dictionaryEntry
113 forAll(subDictNames, dictI)
115 const word& dictName = subDictNames[dictI];
116 entry* ePtr = subdict.lookupEntryPtr(dictName,false,false);
118 if (ePtr && !ePtr->isDict())
120 Istream& is = ePtr->stream();
126 newDict.add(dictName, name);
127 newDict <<= dictionary(is);
129 subdict.set(dictName, newDict);
136 // write out information to help people adjust to the new syntax
137 if (verbose && Pstream::master())
139 Info<< "// using new solver syntax:\n"
140 << iter().keyword() << subdict << endl;
143 // overwrite with dictionary entry
144 dict.set(iter().keyword(), subdict);
154 bool Foam::solution::read()
156 if (regIOobject::read())
158 const dictionary& dict = solutionDict();
160 if (dict.found("relaxationFactors"))
162 relaxationFactors_ = dict.subDict("relaxationFactors");
165 relaxationFactors_.readIfPresent("default", defaultRelaxationFactor_);
167 if (dict.found("solvers"))
169 solvers_ = dict.subDict("solvers");
170 upgradeSolverDict(solvers_);
182 const Foam::dictionary& Foam::solution::solutionDict() const
186 return subDict(word(lookup("select")));
195 bool Foam::solution::relax(const word& name) const
199 Info<< "Find relax for " << name << endl;
203 relaxationFactors_.found(name)
204 || relaxationFactors_.found("default");
208 Foam::scalar Foam::solution::relaxationFactor(const word& name) const
212 Info<< "Lookup relaxationFactor for " << name << endl;
215 if (relaxationFactors_.found(name))
217 return readScalar(relaxationFactors_.lookup(name));
219 else if (defaultRelaxationFactor_ > SMALL)
221 return defaultRelaxationFactor_;
227 "Foam::solution::relaxationFactor(const word&)",
229 ) << "Cannot find relaxationFactor for '" << name
230 << "' or a suitable default value."
231 << exit(FatalIOError);
238 const Foam::dictionary& Foam::solution::solverDict(const word& name) const
242 InfoIn("solution::solverDict(const word&)")
243 << "Lookup solver for " << name << endl;
246 return solvers_.subDict(name);
250 const Foam::dictionary& Foam::solution::solver(const word& name) const
254 InfoIn("solution::solver(const word&)")
255 << "Lookup solver for " << name << endl;
258 return solvers_.subDict(name);
262 // ************************************************************************* //