OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

lduMatrixSolver.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "lduMatrix.H"
00028 #include "diagonalSolver.H"
00029 
00030 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00031 
00032 namespace Foam
00033 {
00034     defineRunTimeSelectionTable(lduMatrix::solver, symMatrix);
00035     defineRunTimeSelectionTable(lduMatrix::solver, asymMatrix);
00036 }
00037 
00038 
00039 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00040 
00041 Foam::autoPtr<Foam::lduMatrix::solver> Foam::lduMatrix::solver::New
00042 (
00043     const word& fieldName,
00044     const lduMatrix& matrix,
00045     const FieldField<Field, scalar>& interfaceBouCoeffs,
00046     const FieldField<Field, scalar>& interfaceIntCoeffs,
00047     const lduInterfaceFieldPtrsList& interfaces,
00048     const dictionary& solverControls
00049 )
00050 {
00051     word name(solverControls.lookup("solver"));
00052 
00053     if (matrix.diagonal())
00054     {
00055         return autoPtr<lduMatrix::solver>
00056         (
00057             new diagonalSolver
00058             (
00059                 fieldName,
00060                 matrix,
00061                 interfaceBouCoeffs,
00062                 interfaceIntCoeffs,
00063                 interfaces,
00064                 solverControls
00065             )
00066         );
00067     }
00068     else if (matrix.symmetric())
00069     {
00070         symMatrixConstructorTable::iterator constructorIter =
00071             symMatrixConstructorTablePtr_->find(name);
00072 
00073         if (constructorIter == symMatrixConstructorTablePtr_->end())
00074         {
00075             FatalIOErrorIn
00076             (
00077                 "lduMatrix::solver::New", solverControls
00078             )   << "Unknown symmetric matrix solver " << name << nl << nl
00079                 << "Valid symmetric matrix solvers are :" << endl
00080                 << symMatrixConstructorTablePtr_->toc()
00081                 << exit(FatalIOError);
00082         }
00083 
00084         return autoPtr<lduMatrix::solver>
00085         (
00086             constructorIter()
00087             (
00088                 fieldName,
00089                 matrix,
00090                 interfaceBouCoeffs,
00091                 interfaceIntCoeffs,
00092                 interfaces,
00093                 solverControls
00094             )
00095         );
00096     }
00097     else if (matrix.asymmetric())
00098     {
00099         asymMatrixConstructorTable::iterator constructorIter =
00100             asymMatrixConstructorTablePtr_->find(name);
00101 
00102         if (constructorIter == asymMatrixConstructorTablePtr_->end())
00103         {
00104             FatalIOErrorIn
00105             (
00106                 "lduMatrix::solver::New", solverControls
00107             )   << "Unknown asymmetric matrix solver " << name << nl << nl
00108                 << "Valid asymmetric matrix solvers are :" << endl
00109                 << asymMatrixConstructorTablePtr_->toc()
00110                 << exit(FatalIOError);
00111         }
00112 
00113         return autoPtr<lduMatrix::solver>
00114         (
00115             constructorIter()
00116             (
00117                 fieldName,
00118                 matrix,
00119                 interfaceBouCoeffs,
00120                 interfaceIntCoeffs,
00121                 interfaces,
00122                 solverControls
00123             )
00124         );
00125     }
00126     else
00127     {
00128         FatalIOErrorIn
00129         (
00130             "lduMatrix::solver::New", solverControls
00131         )   << "cannot solve incomplete matrix, "
00132                "no diagonal or off-diagonal coefficient"
00133             << exit(FatalIOError);
00134 
00135         return autoPtr<lduMatrix::solver>(NULL);
00136     }
00137 }
00138 
00139 
00140 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00141 
00142 Foam::lduMatrix::solver::solver
00143 (
00144     const word& fieldName,
00145     const lduMatrix& matrix,
00146     const FieldField<Field, scalar>& interfaceBouCoeffs,
00147     const FieldField<Field, scalar>& interfaceIntCoeffs,
00148     const lduInterfaceFieldPtrsList& interfaces,
00149     const dictionary& solverControls
00150 )
00151 :
00152     fieldName_(fieldName),
00153     matrix_(matrix),
00154     interfaceBouCoeffs_(interfaceBouCoeffs),
00155     interfaceIntCoeffs_(interfaceIntCoeffs),
00156     interfaces_(interfaces),
00157     controlDict_(solverControls)
00158 {
00159     readControls();
00160 }
00161 
00162 
00163 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00164 
00165 void Foam::lduMatrix::solver::readControls()
00166 {
00167     maxIter_   = controlDict_.lookupOrDefault<label>("maxIter", 1000);
00168     tolerance_ = controlDict_.lookupOrDefault<scalar>("tolerance", 1e-6);
00169     relTol_    = controlDict_.lookupOrDefault<scalar>("relTol", 0);
00170 }
00171 
00172 
00173 void Foam::lduMatrix::solver::read(const dictionary& solverControls)
00174 {
00175     controlDict_ = solverControls;
00176     readControls();
00177 }
00178 
00179 
00180 Foam::scalar Foam::lduMatrix::solver::normFactor
00181 (
00182     const scalarField& psi,
00183     const scalarField& source,
00184     const scalarField& Apsi,
00185     scalarField& tmpField
00186 ) const
00187 {
00188     // --- Calculate A dot reference value of psi
00189     matrix_.sumA(tmpField, interfaceBouCoeffs_, interfaces_);
00190     tmpField *= gAverage(psi);
00191 
00192     return gSum(mag(Apsi - tmpField) + mag(source - tmpField)) + matrix_.small_;
00193 
00194     // At convergence this simpler method is equivalent to the above
00195     // return 2*gSumMag(source) + matrix_.small_;
00196 }
00197 
00198 
00199 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd