Commit 4f1bb834 authored by Mark Olesen's avatar Mark Olesen
Browse files

lduMatrix now takes a dictionary instead of an Istream for the solver controls

  - can now use dictionary substitutions and regular expressions in
    system/fvSolution

  - foamUpgradeFvSolution application to convert system/fvSolution
    (with -test option)

motion solver syntax left as-is.
parent 507e7a1b
foamUpgradeFvSolution.C
EXE = $(FOAM_APPBIN)/foamUpgradeFvSolution
/*---------------------------------------------------------------------------*\
========= |
\\ / 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;
}
// ************************************************************************* //
......@@ -259,7 +259,7 @@ public:
const FieldField<Field, scalar>& interfaceBouCoeffs,
const FieldField<Field, scalar>& 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<Field, scalar>& interfaceBouCoeffs,
const FieldField<Field, scalar>& 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<Field, scalar>& interfaceBouCoeffs,
const FieldField<Field, scalar>& interfaceIntCoeffs,
const lduInterfaceFieldPtrsList& interfaces,
Istream& solverData
const dictionary& solverControls
);
// Selectors
......@@ -317,7 +317,7 @@ public:
const FieldField<Field, scalar>& interfaceBouCoeffs,
const FieldField<Field, scalar>& 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<Field, scalar>& interfaceBouCoeffs,
const FieldField<Field, scalar>& 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<preconditioner> 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
......
......@@ -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>
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);
......
......@@ -34,7 +34,6 @@ namespace Foam
defineRunTimeSelectionTable(lduMatrix::smoother, asymMatrix);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Foam::autoPtr<Foam::lduMatrix::smoother> Foam::lduMatrix::smoother::New
......@@ -44,23 +43,37 @@ Foam::autoPtr<Foam::lduMatrix::smoother> Foam::lduMatrix::smoother::New
const FieldField<Field, scalar>& interfaceBouCoeffs,
const FieldField<Field, scalar>& 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> 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> 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<lduMatrix::smoother>(NULL);
......
......@@ -45,10 +45,10 @@ Foam::autoPtr<Foam::lduMatrix::solver> Foam::lduMatrix::solver::New
const FieldField<Field, scalar>& interfaceBouCoeffs,
const FieldField<Field, scalar>& 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> 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> 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> Foam::lduMatrix::solver::New
interfaceBouCoeffs,
interfaceIntCoeffs,
interfaces,
solverData
solverControls
)
);
}
......@@ -129,7 +127,7 @@ Foam::autoPtr<Foam::lduMatrix::solver> 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<Field, scalar>& interfaceBouCoeffs,
const FieldField<Field, scalar>& 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<label>("maxIter", 1000);
tolerance_ = controlDict_.lookupOrDefault<scalar>("tolerance", 1e-6);
relTol_ = controlDict_.lookupOrDefault<scalar>("relTol", 0);
}
void Foam::lduMatrix::solver::read(Istream& solverData)
void Foam::lduMatrix::solver::read(const dictionary& solverControls)
{
word solverName(solverData);
solverData >> controlDict_;
controlDict_ = solverControls;
readControls();
}
......
......@@ -43,7 +43,7 @@ namespace Foam
Foam::DICPreconditioner::DICPreconditioner
(
const lduMatrix::solver& sol,
Istream&
const dictionary&
)
:
lduMatrix::preconditioner(sol),
......
......@@ -67,11 +67,11 @@ public:
// Constructors
//- Construct from matrix components and preconditioner data stream
//- Construct from matrix components and preconditioner solver controls
DICPreconditioner
(
const lduMatrix::solver& sol,
Istream& preconditionerData
const lduMatrix::solver&,
const dictionary& solverControlsUnused
);
......