diff --git a/applications/test/dictionary/dictionaryTest.C b/applications/test/dictionary/dictionaryTest.C index 37ae9bd90c..d8580bdf54 100644 --- a/applications/test/dictionary/dictionaryTest.C +++ b/applications/test/dictionary/dictionaryTest.C @@ -30,6 +30,7 @@ Description \*---------------------------------------------------------------------------*/ #include "IOstreams.H" +#include "IOobject.H" #include "IFstream.H" #include "dictionary.H" @@ -40,18 +41,12 @@ using namespace Foam; int main(int argc, char *argv[]) { - IFstream dictStream("testDict"); - dictionary testDict(dictStream); + Info<< dictionary(IFstream("testDict")()) << endl; - Info<< testDict << endl; + IOobject::writeDivider(Info); { - dictionary someDict; - someDict.add(keyType("a.*", true), "subdictValue"); - - dictionary dict; - dict.add("someDict", someDict); - dict.add(keyType(".*", true), "parentValue"); + dictionary dict(IFstream("testDictRegex")()); Info<< "dict:" << dict << endl; @@ -64,6 +59,18 @@ int main(int argc, char *argv[]) Info<< "Recursive wildcard find \"def\" in sub directory : " << dict.subDict("someDict").lookup("def", true) << endl; + Info<< "Recursive wildcard find \"foo\" in sub directory : " + << dict.subDict("someDict").lookup("foo", true) + << endl; + Info<< "Recursive wildcard find \"fooz\" in sub directory : " + << dict.subDict("someDict").lookup("fooz", true) + << endl; + Info<< "Recursive wildcard find \"bar\" in sub directory : " + << dict.subDict("someDict").lookup("bar", true) + << endl; + Info<< "Recursive wildcard find \"xxx\" in sub directory : " + << dict.subDict("someDict").lookup("xxx", true) + << endl; } return 0; diff --git a/applications/test/dictionary/testDictRegex b/applications/test/dictionary/testDictRegex new file mode 100644 index 0000000000..d4252cd3be --- /dev/null +++ b/applications/test/dictionary/testDictRegex @@ -0,0 +1,34 @@ +/*-------------------------------*- C++ -*---------------------------------*\ +| ========= | +| \\ / OpenFOAM | +| \\ / | +| \\ / The Open Source CFD Toolbox | +| \\/ http://www.OpenFOAM.org | +\*-------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object testDictRegex; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +#inputMode merge + +".*" parentValue1; +"[n-z].*" parentValue2; +"f.*" parentValue3; + +someDict +{ + foo subdictValue0; + bar $f.*; // should this really match 'foo'? + + // result is dependent on insert order! + "a.*c" subdictValue3; + "ab.*" subdictValue2; + "a.*" subdictValue1; + abcd subdictValue4; +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/applications/utilities/preProcessing/foamUpgradeFvSolution/Make/files b/applications/utilities/preProcessing/foamUpgradeFvSolution/Make/files new file mode 100644 index 0000000000..f667ed655e --- /dev/null +++ b/applications/utilities/preProcessing/foamUpgradeFvSolution/Make/files @@ -0,0 +1,3 @@ +foamUpgradeFvSolution.C + +EXE = $(FOAM_APPBIN)/foamUpgradeFvSolution diff --git a/applications/utilities/preProcessing/foamUpgradeFvSolution/Make/options b/applications/utilities/preProcessing/foamUpgradeFvSolution/Make/options new file mode 100644 index 0000000000..e69de29bb2 diff --git a/applications/utilities/preProcessing/foamUpgradeFvSolution/foamUpgradeFvSolution.C b/applications/utilities/preProcessing/foamUpgradeFvSolution/foamUpgradeFvSolution.C new file mode 100644 index 0000000000..d9e1402a34 --- /dev/null +++ b/applications/utilities/preProcessing/foamUpgradeFvSolution/foamUpgradeFvSolution.C @@ -0,0 +1,104 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2008 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 + +Application + foamUpgradeFvSolution + +Description + Simple tool to upgrade the syntax of system/fvSolution::solvers + +Usage + + - foamUpgradeFvSolution [OPTION] + + @param -test \n + Suppress writing the updated fvSolution file + +\*---------------------------------------------------------------------------*/ + +#include "argList.H" +#include "Time.H" +#include "IOdictionary.H" +#include "solution.H" + +using namespace Foam; + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// Main program: + +int main(int argc, char *argv[]) +{ + argList::noParallel(); + argList::validOptions.insert("test", ""); + +# include "setRootCase.H" +# include "createTime.H" + + IOdictionary solutionDict + ( + IOobject + ( + "fvSolution", + runTime.system(), + runTime, + IOobject::MUST_READ, + IOobject::NO_WRITE, + false + ) + ); + + label nChanged = 0; + entry* e = solutionDict.lookupEntryPtr("solvers", false, false); + if (e && e->isDict()) + { + nChanged = solution::upgradeSolverDict(e->dict(), true); + } + + Info<< nChanged << " solver settings changed" << nl << endl; + if (nChanged) + { + if (args.options().found("test")) + { + Info<< "-test option: no changes made" << nl << endl; + } + else + { + mv + ( + solutionDict.objectPath(), + solutionDict.objectPath() + ".old" + ); + + solutionDict.regIOobject::write(); + + Info<< "Backup to " << (solutionDict.objectPath() + ".old") << nl + << "Write to " << solutionDict.objectPath() << nl << endl; + } + } + + return 0; +} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/db/dictionary/dictionary.C b/src/OpenFOAM/db/dictionary/dictionary.C index 265a2944cb..c0b4b6fb73 100644 --- a/src/OpenFOAM/db/dictionary/dictionary.C +++ b/src/OpenFOAM/db/dictionary/dictionary.C @@ -697,7 +697,7 @@ bool Foam::dictionary::changeKeyword IDLList::replace(iter2(), iter()); delete iter2(); hashedEntries_.erase(iter2); - + } else { diff --git a/src/OpenFOAM/db/dictionary/dictionary.H b/src/OpenFOAM/db/dictionary/dictionary.H index b1d0d186f6..4ace026a01 100644 --- a/src/OpenFOAM/db/dictionary/dictionary.H +++ b/src/OpenFOAM/db/dictionary/dictionary.H @@ -163,16 +163,16 @@ public: dictionary(Istream&); //- Construct as copy given the parent dictionary - dictionary(const dictionary& parentDict, const dictionary& dict); + dictionary(const dictionary& parentDict, const dictionary&); //- Construct top-level dictionary as copy - dictionary(const dictionary& dict); + dictionary(const dictionary&); //- Construct and return clone Foam::autoPtr clone() const; //- Construct top-level dictionary on freestore from Istream - static Foam::autoPtr New(Istream& is); + static Foam::autoPtr New(Istream&); // Destructor @@ -211,12 +211,12 @@ public: //- Search dictionary for given keyword // If recursive search parent dictionaries - bool found(const word& keyword, bool recursive=false) const; + bool found(const word&, bool recursive=false) const; //- Find and return an entry data stream pointer if present // otherwise return NULL. - // If recursive search parent dictionaries. If wildCardMatch - // use wildcards. + // If recursive search parent dictionaries. + // If wildCardMatch use wildcards. const entry* lookupEntryPtr ( const word&, @@ -226,8 +226,8 @@ public: //- Find and return an entry data stream pointer for manipulation // if present otherwise return NULL. - // If recursive search parent dictionaries. If wildCardMatch - // use wildcards. + // If recursive search parent dictionaries. + // If wildCardMatch use wildcards. entry* lookupEntryPtr ( const word&, @@ -236,8 +236,8 @@ public: ); //- Find and return an entry data stream if present otherwise error. - // If recursive search parent dictionaries. If wildCardMatch - // use wildcards. + // If recursive search parent dictionaries. + // If wildCardMatch use wildcards. const entry& lookupEntry ( const word&, @@ -331,13 +331,13 @@ public: //- Add a scalar entry // optionally overwrite an existing entry - void add (const keyType&, const scalar, bool overwrite=false); + void add(const keyType&, const scalar, bool overwrite=false); //- Add a dictionary entry // optionally merge with an existing sub-dictionary void add ( - const keyType& keyword, + const keyType&, const dictionary&, bool mergeEntry=false ); @@ -345,7 +345,7 @@ public: //- Add a T entry // optionally overwrite an existing entry template - void add(const keyType& keyword, const T&, bool overwrite=false); + void add(const keyType&, const T&, bool overwrite=false); //- Assign a new entry, overwrite any existing entry void set(entry*); @@ -354,14 +354,14 @@ public: void set(const entry&); //- Assign a dictionary entry, overwrite any existing entry - void set(const keyType& keyword, const dictionary&); + void set(const keyType&, const dictionary&); //- Assign a T entry, overwrite any existing entry template - void set(const keyType& keyword, const T&); + void set(const keyType&, const T&); //- Remove an entry specified by keyword - bool remove(const word& keyword); + bool remove(const word&); //- Change the keyword for an entry, // optionally forcing overwrite of an existing entry @@ -369,7 +369,7 @@ public: ( const keyType& oldKeyword, const keyType& newKeyword, - bool forceOverwrite = false + bool forceOverwrite=false ); //- Merge entries from the given dictionary. @@ -382,7 +382,7 @@ public: // Write - void write(Ostream& os, bool subDict = true) const; + void write(Ostream&, bool subDict=true) const; // Member Operators diff --git a/src/OpenFOAM/global/argList/argList.C b/src/OpenFOAM/global/argList/argList.C index a2faa64133..ef8f88bfbd 100644 --- a/src/OpenFOAM/global/argList/argList.C +++ b/src/OpenFOAM/global/argList/argList.C @@ -37,19 +37,17 @@ License // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // -namespace Foam -{ - SLList argList::validArgs; - HashTable argList::validOptions; - HashTable argList::validParOptions; -} +Foam::SLList Foam::argList::validArgs; +Foam::HashTable Foam::argList::validOptions; +Foam::HashTable Foam::argList::validParOptions; +bool Foam::argList::bannerEnabled(true); Foam::argList::initValidTables::initValidTables() { - validOptions.insert("case", "dir"); - validOptions.insert("parallel", ""); - validParOptions.insert("parallel", ""); + validOptions.set("case", "dir"); + validOptions.set("parallel", ""); + validParOptions.set("parallel", ""); Pstream::addValidParOptions(validParOptions); } @@ -138,7 +136,7 @@ void Foam::argList::getRootCase() casePath = cwd(); // we could add this back in as '-case'? - // options_.insert("case", casePath); + // options_.set("case", casePath); } rootPath_ = casePath.path(); @@ -285,7 +283,7 @@ Foam::argList::argList string timeString = clock::clockTime(); // Print the banner once only for parallel runs - if (Pstream::master()) + if (Pstream::master() && bannerEnabled) { IOobject::writeBanner(Info, true); Info<< "Exec : " << argListString.c_str() << nl @@ -315,8 +313,6 @@ Foam::argList::argList // For the master if (Pstream::master()) { - fileNameList roots; - // establish rootPath_/globalCase_/case_ for master getRootCase(); @@ -333,45 +329,25 @@ Foam::argList::argList << exit(FatalError); } - dictionary decompositionDict(decompDictStream); - - Switch distributed(false); - - if - ( - decompositionDict.readIfPresent("distributed", distributed) - && distributed - ) - { - decompositionDict.lookup("roots") >> roots; - - if (roots.size() != Pstream::nProcs()-1) - { - FatalError - << "number of entries in decompositionDict::roots" - << " is not equal to the number of slaves " - << Pstream::nProcs()-1 - << exit(FatalError); - } - } - + dictionary decompDict(decompDictStream); label dictNProcs ( readLabel ( - decompositionDict.lookup("numberOfSubdomains") + decompDict.lookup("numberOfSubdomains") ) ); - // Check number of processors. We have nProcs(number of - // actual processes), dictNProcs(wanted number of processes read - // from decompositionDict) and nProcDirs(number of processor - // directories - n/a when running distributed) + // Check number of processors. + // nProcs => number of actual procs + // dictNProcs => number of procs specified in decompositionDict + // nProcDirs => number of processor directories + // (n/a when running distributed) // // - normal running : nProcs = dictNProcs = nProcDirs - // - decomposition to more processors : nProcs = dictNProcs - // - decomposition to less processors : nProcs = nProcDirs + // - decomposition to more processors : nProcs = dictNProcs + // - decomposition to fewer processors : nProcs = nProcDirs if (dictNProcs > Pstream::nProcs()) { FatalError @@ -382,38 +358,23 @@ Foam::argList::argList << exit(FatalError); } - if (!distributed && dictNProcs < Pstream::nProcs()) + // distributed data + if (decompDict.lookupOrDefault("distributed", false)) { - // Possibly going to fewer processors. - // Check if all procDirs are there. - label nProcDirs = 0; - while - ( - dir - ( - rootPath_/globalCase_/"processor" - + name(++nProcDirs) - ) - ) - {} + fileNameList roots; + decompDict.lookup("roots") >> roots; - if (nProcDirs != Pstream::nProcs()) + if (roots.size() != Pstream::nProcs()-1) { FatalError - << "number of processor directories = " - << nProcDirs - << " is not equal to the number of processors = " - << Pstream::nProcs() + << "number of entries in decompositionDict::roots" + << " is not equal to the number of slaves " + << Pstream::nProcs()-1 << exit(FatalError); } - } - - // distributed data - if (roots.size()) - { - bool hadOptCase = options_.found("case"); // Distribute the master's argument list (with new root) + bool hadCaseOpt = options_.found("case"); for ( int slave=Pstream::firstSlave(); @@ -421,8 +382,7 @@ Foam::argList::argList slave++ ) { - options_.erase("case"); - options_.insert + options_.set ( "case", fileName(roots[slave-1])/globalCase_ @@ -431,17 +391,42 @@ Foam::argList::argList OPstream toSlave(Pstream::scheduled, slave); toSlave << args_ << options_; } - options_.erase("case"); // restore [-case dir] - if (hadOptCase) + if (hadCaseOpt) { - options_.insert("case", rootPath_/globalCase_); + options_.set("case", rootPath_/globalCase_); } } else { + // Possibly going to fewer processors. + // Check if all procDirs are there. + if (dictNProcs < Pstream::nProcs()) + { + label nProcDirs = 0; + while + ( + dir + ( + rootPath_/globalCase_/"processor" + + name(++nProcDirs) + ) + ) + {} + + if (nProcDirs != Pstream::nProcs()) + { + FatalError + << "number of processor directories = " + << nProcDirs + << " is not equal to the number of processors = " + << Pstream::nProcs() + << exit(FatalError); + } + } + // Distribute the master's argument list (unaltered) for ( @@ -472,7 +457,6 @@ Foam::argList::argList { // establish rootPath_/globalCase_/case_ getRootCase(); - case_ = globalCase_; } @@ -510,21 +494,21 @@ Foam::argList::argList } - if (Pstream::master()) + if (Pstream::master() && bannerEnabled) { Info<< "Case : " << (rootPath_/globalCase_).c_str() << nl << "nProcs : " << nProcs << endl; - } - if (parRunControl_.parRun() && Pstream::master()) - { - Info<< "Slaves : " << slaveProcs << nl - << "Pstream initialized with:" << nl - << " floatTransfer : " << Pstream::floatTransfer << nl - << " nProcsSimpleSum : " << Pstream::nProcsSimpleSum << nl - << " commsType : " - << Pstream::commsTypeNames[Pstream::defaultCommsType] - << endl; + if (parRunControl_.parRun()) + { + Info<< "Slaves : " << slaveProcs << nl + << "Pstream initialized with:" << nl + << " floatTransfer : " << Pstream::floatTransfer << nl + << " nProcsSimpleSum : " << Pstream::nProcsSimpleSum << nl + << " commsType : " + << Pstream::commsTypeNames[Pstream::defaultCommsType] + << endl; + } } jobInfo.add("root", rootPath_); @@ -546,7 +530,7 @@ Foam::argList::argList sigQuit_.set(); sigSegv_.set(); - if (Pstream::master()) + if (Pstream::master() && bannerEnabled) { Info<< endl; IOobject::writeDivider(Info); @@ -564,6 +548,12 @@ Foam::argList::~argList() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +void Foam::argList::noBanner() +{ + bannerEnabled = false; +} + + void Foam::argList::noParallel() { validOptions.erase("parallel"); diff --git a/src/OpenFOAM/global/argList/argList.H b/src/OpenFOAM/global/argList/argList.H index 648295da84..60dd1c01e9 100644 --- a/src/OpenFOAM/global/argList/argList.H +++ b/src/OpenFOAM/global/argList/argList.H @@ -92,6 +92,7 @@ namespace Foam class argList { // Private data + static bool bannerEnabled; stringList args_; HashTable options_; @@ -213,6 +214,9 @@ public: // Edit + //- Disable emitting the banner information + static void noBanner(); + //- Remove the parallel options static void noParallel(); diff --git a/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrix.H b/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrix.H index 33fcda639d..6a6a09ab92 100644 --- a/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrix.H +++ b/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrix.H @@ -259,7 +259,7 @@ public: const FieldField& interfaceBouCoeffs, const FieldField& interfaceIntCoeffs, const lduInterfaceFieldPtrsList& interfaces, - Istream& solverData + const dictionary& solverControls ), ( fieldName, @@ -267,7 +267,7 @@ public: interfaceBouCoeffs, interfaceIntCoeffs, interfaces, - solverData + solverControls ) ); @@ -282,7 +282,7 @@ public: const FieldField& interfaceBouCoeffs, const FieldField& interfaceIntCoeffs, const lduInterfaceFieldPtrsList& interfaces, - Istream& solverData + const dictionary& solverControls ), ( fieldName, @@ -290,7 +290,7 @@ public: interfaceBouCoeffs, interfaceIntCoeffs, interfaces, - solverData + solverControls ) ); @@ -304,7 +304,7 @@ public: const FieldField& interfaceBouCoeffs, const FieldField& interfaceIntCoeffs, const lduInterfaceFieldPtrsList& interfaces, - Istream& solverData + const dictionary& solverControls ); // Selectors @@ -317,7 +317,7 @@ public: const FieldField& interfaceBouCoeffs, const FieldField& interfaceIntCoeffs, const lduInterfaceFieldPtrsList& interfaces, - Istream& solverData + const dictionary& solverControls ); @@ -359,7 +359,7 @@ public: //- Read and reset the solver parameters from the given stream - virtual void read(Istream& solverData); + virtual void read(const dictionary&); virtual solverPerformance solve ( @@ -467,7 +467,7 @@ public: const FieldField& interfaceBouCoeffs, const FieldField& interfaceIntCoeffs, const lduInterfaceFieldPtrsList& interfaces, - Istream& smootherData + const dictionary& solverControls ); @@ -531,6 +531,9 @@ public: public: + //- Find the preconditioner name (directly or from a sub-dictionary) + static word getName(const dictionary&); + //- Runtime type information virtual const word& type() const = 0; @@ -544,9 +547,9 @@ public: symMatrix, ( const solver& sol, - Istream& preconditionerData + const dictionary& solverControls ), - (sol, preconditionerData) + (sol, solverControls) ); declareRunTimeSelectionTable @@ -556,9 +559,9 @@ public: asymMatrix, ( const solver& sol, - Istream& preconditionerData + const dictionary& solverControls ), - (sol, preconditionerData) + (sol, solverControls) ); @@ -579,7 +582,7 @@ public: static autoPtr New ( const solver& sol, - Istream& preconditionerData + const dictionary& solverControls ); @@ -593,7 +596,7 @@ public: //- Read and reset the preconditioner parameters // from the given stream - virtual void read(Istream& preconditionerData) + virtual void read(const dictionary&) {} //- Return wA the preconditioned form of residual rA diff --git a/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrixPreconditioner.C b/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrixPreconditioner.C index 82f9a19ac2..cb4a645df1 100644 --- a/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrixPreconditioner.C +++ b/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrixPreconditioner.C @@ -37,29 +37,66 @@ namespace Foam // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +Foam::word +Foam::lduMatrix::preconditioner::getName +( + const dictionary& solverControls +) +{ + word name; + + // handle primitive or dictionary entry + const entry& e = solverControls.lookupEntry("preconditioner", false, false); + if (e.isDict()) + { + e.dict().lookup("preconditioner") >> name; + } + else + { + e.stream() >> name; + } + + return name; +} + + Foam::autoPtr Foam::lduMatrix::preconditioner::New ( const solver& sol, - Istream& preconditionerData + const dictionary& solverControls ) { - word preconditionerName(preconditionerData); + word name; + + // handle primitive or dictionary entry + const entry& e = solverControls.lookupEntry("preconditioner", false, false); + if (e.isDict()) + { + e.dict().lookup("preconditioner") >> name; + } + else + { + e.stream() >> name; + } + + const dictionary& controls = e.isDict() ? e.dict() : dictionary::null; if (sol.matrix().symmetric()) { symMatrixConstructorTable::iterator constructorIter = - symMatrixConstructorTablePtr_->find(preconditionerName); + symMatrixConstructorTablePtr_->find(name); if (constructorIter == symMatrixConstructorTablePtr_->end()) { FatalIOErrorIn ( - "lduMatrix::preconditioner::New(const solver&, Istream&)", - preconditionerData + "lduMatrix::preconditioner::New" + "(const solver&, const dictionary&)", + controls ) << "Unknown symmetric matrix preconditioner " - << preconditionerName << endl << endl - << "Valid symmetric matrix preconditioners are :" << endl + << name << nl << nl + << "Valid symmetric matrix preconditioners :" << endl << symMatrixConstructorTablePtr_->toc() << exit(FatalIOError); } @@ -69,24 +106,25 @@ Foam::lduMatrix::preconditioner::New constructorIter() ( sol, - preconditionerData + controls ) ); } else if (sol.matrix().asymmetric()) { asymMatrixConstructorTable::iterator constructorIter = - asymMatrixConstructorTablePtr_->find(preconditionerName); + asymMatrixConstructorTablePtr_->find(name); if (constructorIter == asymMatrixConstructorTablePtr_->end()) { FatalIOErrorIn ( - "lduMatrix::preconditioner::New(const solver&, Istream&)", - preconditionerData + "lduMatrix::preconditioner::New" + "(const solver&, const dictionary&)", + controls ) << "Unknown asymmetric matrix preconditioner " - << preconditionerName << endl << endl - << "Valid asymmetric matrix preconditioners are :" << endl + << name << nl << nl + << "Valid asymmetric matrix preconditioners :" << endl << asymMatrixConstructorTablePtr_->toc() << exit(FatalIOError); } @@ -96,7 +134,7 @@ Foam::lduMatrix::preconditioner::New constructorIter() ( sol, - preconditionerData + controls ) ); } @@ -104,9 +142,10 @@ Foam::lduMatrix::preconditioner::New { FatalIOErrorIn ( - "lduMatrix::preconditioner::New(const solver&, Istream&)", - preconditionerData - ) << "cannot preconditione incomplete matrix, " + "lduMatrix::preconditioner::New" + "(const solver&, const dictionary&)", + controls + ) << "cannot solve incomplete matrix, " "no diagonal or off-diagonal coefficient" << exit(FatalIOError); diff --git a/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrixSmoother.C b/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrixSmoother.C index 7554e4085c..e9aa429683 100644 --- a/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrixSmoother.C +++ b/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrixSmoother.C @@ -34,7 +34,6 @@ namespace Foam defineRunTimeSelectionTable(lduMatrix::smoother, asymMatrix); } - // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // Foam::autoPtr Foam::lduMatrix::smoother::New @@ -44,23 +43,37 @@ Foam::autoPtr Foam::lduMatrix::smoother::New const FieldField& interfaceBouCoeffs, const FieldField& interfaceIntCoeffs, const lduInterfaceFieldPtrsList& interfaces, - Istream& smootherData + const dictionary& solverControls ) { - word smootherName(smootherData); + word name; + + // handle primitive or dictionary entry + const entry& e = solverControls.lookupEntry("smoother", false, false); + if (e.isDict()) + { + e.dict().lookup("smoother") >> name; + } + else + { + e.stream() >> name; + } + + // not (yet?) needed: + // const dictionary& controls = e.isDict() ? e.dict() : dictionary::null; if (matrix.symmetric()) { symMatrixConstructorTable::iterator constructorIter = - symMatrixConstructorTablePtr_->find(smootherName); + symMatrixConstructorTablePtr_->find(name); if (constructorIter == symMatrixConstructorTablePtr_->end()) { FatalIOErrorIn ( - "lduMatrix::smoother::New", smootherData - ) << "Unknown symmetric matrix smoother " << smootherName - << endl << endl + "lduMatrix::smoother::New", solverControls + ) << "Unknown symmetric matrix smoother " + << name << nl << nl << "Valid symmetric matrix smoothers are :" << endl << symMatrixConstructorTablePtr_->toc() << exit(FatalIOError); @@ -81,15 +94,15 @@ Foam::autoPtr Foam::lduMatrix::smoother::New else if (matrix.asymmetric()) { asymMatrixConstructorTable::iterator constructorIter = - asymMatrixConstructorTablePtr_->find(smootherName); + asymMatrixConstructorTablePtr_->find(name); if (constructorIter == asymMatrixConstructorTablePtr_->end()) { FatalIOErrorIn ( - "lduMatrix::smoother::New", smootherData - ) << "Unknown asymmetric matrix smoother " << smootherName - << endl << endl + "lduMatrix::smoother::New", solverControls + ) << "Unknown asymmetric matrix smoother " + << name << nl << nl << "Valid asymmetric matrix smoothers are :" << endl << asymMatrixConstructorTablePtr_->toc() << exit(FatalIOError); @@ -111,8 +124,9 @@ Foam::autoPtr Foam::lduMatrix::smoother::New { FatalIOErrorIn ( - "lduMatrix::smoother::New", smootherData - ) << "cannot solve incomplete matrix, no off-diagonal coefficients" + "lduMatrix::smoother::New", solverControls + ) << "cannot solve incomplete matrix, " + "no diagonal or off-diagonal coefficient" << exit(FatalIOError); return autoPtr(NULL); diff --git a/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrixSolver.C b/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrixSolver.C index 19fd2435a0..4b3b8d97a9 100644 --- a/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrixSolver.C +++ b/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrixSolver.C @@ -45,10 +45,10 @@ Foam::autoPtr Foam::lduMatrix::solver::New const FieldField& interfaceBouCoeffs, const FieldField& interfaceIntCoeffs, const lduInterfaceFieldPtrsList& interfaces, - Istream& solverData + const dictionary& solverControls ) { - word solverName(solverData); + word name(solverControls.lookup("solver")); if (matrix.diagonal()) { @@ -61,22 +61,21 @@ Foam::autoPtr Foam::lduMatrix::solver::New interfaceBouCoeffs, interfaceIntCoeffs, interfaces, - solverData + solverControls ) ); } else if (matrix.symmetric()) { symMatrixConstructorTable::iterator constructorIter = - symMatrixConstructorTablePtr_->find(solverName); + symMatrixConstructorTablePtr_->find(name); if (constructorIter == symMatrixConstructorTablePtr_->end()) { FatalIOErrorIn ( - "lduMatrix::solver::New", solverData - ) << "Unknown symmetric matrix solver " << solverName - << endl << endl + "lduMatrix::solver::New", solverControls + ) << "Unknown symmetric matrix solver " << name << nl << nl << "Valid symmetric matrix solvers are :" << endl << symMatrixConstructorTablePtr_->toc() << exit(FatalIOError); @@ -91,22 +90,21 @@ Foam::autoPtr Foam::lduMatrix::solver::New interfaceBouCoeffs, interfaceIntCoeffs, interfaces, - solverData + solverControls ) ); } else if (matrix.asymmetric()) { asymMatrixConstructorTable::iterator constructorIter = - asymMatrixConstructorTablePtr_->find(solverName); + asymMatrixConstructorTablePtr_->find(name); if (constructorIter == asymMatrixConstructorTablePtr_->end()) { FatalIOErrorIn ( - "lduMatrix::solver::New", solverData - ) << "Unknown asymmetric matrix solver " << solverName - << endl << endl + "lduMatrix::solver::New", solverControls + ) << "Unknown asymmetric matrix solver " << name << nl << nl << "Valid asymmetric matrix solvers are :" << endl << asymMatrixConstructorTablePtr_->toc() << exit(FatalIOError); @@ -121,7 +119,7 @@ Foam::autoPtr Foam::lduMatrix::solver::New interfaceBouCoeffs, interfaceIntCoeffs, interfaces, - solverData + solverControls ) ); } @@ -129,7 +127,7 @@ Foam::autoPtr Foam::lduMatrix::solver::New { FatalIOErrorIn ( - "lduMatrix::solver::New", solverData + "lduMatrix::solver::New", solverControls ) << "cannot solve incomplete matrix, " "no diagonal or off-diagonal coefficient" << exit(FatalIOError); @@ -148,7 +146,7 @@ Foam::lduMatrix::solver::solver const FieldField& interfaceBouCoeffs, const FieldField& interfaceIntCoeffs, const lduInterfaceFieldPtrsList& interfaces, - Istream& solverData + const dictionary& solverControls ) : fieldName_(fieldName), @@ -156,12 +154,7 @@ Foam::lduMatrix::solver::solver interfaceBouCoeffs_(interfaceBouCoeffs), interfaceIntCoeffs_(interfaceIntCoeffs), interfaces_(interfaces), - - controlDict_(solverData), - - maxIter_(1000), - tolerance_(1e-6), - relTol_(0) + controlDict_(solverControls) { readControls(); } @@ -171,16 +164,15 @@ Foam::lduMatrix::solver::solver void Foam::lduMatrix::solver::readControls() { - controlDict_.readIfPresent("maxIter", maxIter_); - controlDict_.readIfPresent("tolerance", tolerance_); - controlDict_.readIfPresent("relTol", relTol_); + maxIter_ = controlDict_.lookupOrDefault