solution.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "solution.H"
00028 #include "Time.H"
00029
00030
00031 #include "BICCG.H"
00032 #include "ICCG.H"
00033 #include "IStringStream.H"
00034
00035
00036
00037 int Foam::solution::debug(::Foam::debug::debugSwitch("solution", 0));
00038
00039
00041 static const Foam::List<Foam::word> subDictNames
00042 (
00043 Foam::IStringStream("(preconditioner smoother)")()
00044 );
00046
00047
00048
00049 Foam::solution::solution(const objectRegistry& obr, const fileName& dictName)
00050 :
00051 IOdictionary
00052 (
00053 IOobject
00054 (
00055 dictName,
00056 obr.time().system(),
00057 obr,
00058 IOobject::MUST_READ,
00059 IOobject::NO_WRITE
00060 )
00061 ),
00062 relaxationFactors_
00063 (
00064 ITstream("relaxationFactors",
00065 tokenList())()
00066 ),
00067 defaultRelaxationFactor_(0),
00068 solvers_(ITstream("solvers", tokenList())())
00069 {
00070 read();
00071 }
00072
00073
00074
00075
00076 Foam::label Foam::solution::upgradeSolverDict
00077 (
00078 dictionary& dict,
00079 const bool verbose
00080 )
00081 {
00082 label nChanged = 0;
00083
00084
00085
00086 forAllIter(dictionary, dict, iter)
00087 {
00088 if (!iter().isDict())
00089 {
00090 Istream& is = iter().stream();
00091 word name(is);
00092 dictionary subdict;
00093
00094 if (name == "BICCG")
00095 {
00096
00097 subdict = BICCG::solverDict(is);
00098 }
00099 else if (name == "ICCG")
00100 {
00101
00102 subdict = ICCG::solverDict(is);
00103 }
00104 else
00105 {
00106 subdict.add("solver", name);
00107 subdict <<= dictionary(is);
00108
00109
00110
00111
00112
00113 forAll(subDictNames, dictI)
00114 {
00115 const word& dictName = subDictNames[dictI];
00116 entry* ePtr = subdict.lookupEntryPtr(dictName,false,false);
00117
00118 if (ePtr && !ePtr->isDict())
00119 {
00120 Istream& is = ePtr->stream();
00121 is >> name;
00122
00123 if (!is.eof())
00124 {
00125 dictionary newDict;
00126 newDict.add(dictName, name);
00127 newDict <<= dictionary(is);
00128
00129 subdict.set(dictName, newDict);
00130 }
00131 }
00132 }
00133 }
00134
00135
00136
00137 if (verbose && Pstream::master())
00138 {
00139 Info<< "// using new solver syntax:\n"
00140 << iter().keyword() << subdict << endl;
00141 }
00142
00143
00144 dict.set(iter().keyword(), subdict);
00145
00146 nChanged++;
00147 }
00148 }
00149
00150 return nChanged;
00151 }
00152
00153
00154 bool Foam::solution::read()
00155 {
00156 if (regIOobject::read())
00157 {
00158 const dictionary& dict = solutionDict();
00159
00160 if (dict.found("relaxationFactors"))
00161 {
00162 relaxationFactors_ = dict.subDict("relaxationFactors");
00163 }
00164
00165 relaxationFactors_.readIfPresent("default", defaultRelaxationFactor_);
00166
00167 if (dict.found("solvers"))
00168 {
00169 solvers_ = dict.subDict("solvers");
00170 upgradeSolverDict(solvers_);
00171 }
00172
00173 return true;
00174 }
00175 else
00176 {
00177 return false;
00178 }
00179 }
00180
00181
00182 const Foam::dictionary& Foam::solution::solutionDict() const
00183 {
00184 if (found("select"))
00185 {
00186 return subDict(word(lookup("select")));
00187 }
00188 else
00189 {
00190 return *this;
00191 }
00192 }
00193
00194
00195 bool Foam::solution::relax(const word& name) const
00196 {
00197 if (debug)
00198 {
00199 Info<< "Find relax for " << name << endl;
00200 }
00201
00202 return
00203 relaxationFactors_.found(name)
00204 || relaxationFactors_.found("default");
00205 }
00206
00207
00208 Foam::scalar Foam::solution::relaxationFactor(const word& name) const
00209 {
00210 if (debug)
00211 {
00212 Info<< "Lookup relaxationFactor for " << name << endl;
00213 }
00214
00215 if (relaxationFactors_.found(name))
00216 {
00217 return readScalar(relaxationFactors_.lookup(name));
00218 }
00219 else if (defaultRelaxationFactor_ > SMALL)
00220 {
00221 return defaultRelaxationFactor_;
00222 }
00223 else
00224 {
00225 FatalIOErrorIn
00226 (
00227 "Foam::solution::relaxationFactor(const word&)",
00228 relaxationFactors_
00229 ) << "Cannot find relaxationFactor for '" << name
00230 << "' or a suitable default value."
00231 << exit(FatalIOError);
00232
00233 return 0;
00234 }
00235 }
00236
00237
00238 const Foam::dictionary& Foam::solution::solverDict(const word& name) const
00239 {
00240 if (debug)
00241 {
00242 InfoIn("solution::solverDict(const word&)")
00243 << "Lookup solver for " << name << endl;
00244 }
00245
00246 return solvers_.subDict(name);
00247 }
00248
00249
00250 const Foam::dictionary& Foam::solution::solver(const word& name) const
00251 {
00252 if (debug)
00253 {
00254 InfoIn("solution::solver(const word&)")
00255 << "Lookup solver for " << name << endl;
00256 }
00257
00258 return solvers_.subDict(name);
00259 }
00260
00261
00262
Copyright © 2000-2009 OpenCFD Ltd