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

lduMatrixPreconditioner.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 
00029 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00030 
00031 namespace Foam
00032 {
00033     defineRunTimeSelectionTable(lduMatrix::preconditioner, symMatrix);
00034     defineRunTimeSelectionTable(lduMatrix::preconditioner, asymMatrix);
00035 }
00036 
00037 
00038 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00039 
00040 Foam::word
00041 Foam::lduMatrix::preconditioner::getName
00042 (
00043     const dictionary& solverControls
00044 )
00045 {
00046     word name;
00047 
00048     // handle primitive or dictionary entry
00049     const entry& e = solverControls.lookupEntry("preconditioner", false, false);
00050     if (e.isDict())
00051     {
00052         e.dict().lookup("preconditioner") >> name;
00053     }
00054     else
00055     {
00056         e.stream() >> name;
00057     }
00058 
00059     return name;
00060 }
00061 
00062 
00063 Foam::autoPtr<Foam::lduMatrix::preconditioner>
00064 Foam::lduMatrix::preconditioner::New
00065 (
00066     const solver& sol,
00067     const dictionary& solverControls
00068 )
00069 {
00070     word name;
00071 
00072     // handle primitive or dictionary entry
00073     const entry& e = solverControls.lookupEntry("preconditioner", false, false);
00074     if (e.isDict())
00075     {
00076         e.dict().lookup("preconditioner") >> name;
00077     }
00078     else
00079     {
00080         e.stream() >> name;
00081     }
00082 
00083     const dictionary& controls = e.isDict() ? e.dict() : dictionary::null;
00084 
00085     if (sol.matrix().symmetric())
00086     {
00087         symMatrixConstructorTable::iterator constructorIter =
00088             symMatrixConstructorTablePtr_->find(name);
00089 
00090         if (constructorIter == symMatrixConstructorTablePtr_->end())
00091         {
00092             FatalIOErrorIn
00093             (
00094                 "lduMatrix::preconditioner::New"
00095                 "(const solver&, const dictionary&)",
00096                 controls
00097             )   << "Unknown symmetric matrix preconditioner "
00098                 << name << nl << nl
00099                 << "Valid symmetric matrix preconditioners :" << endl
00100                 << symMatrixConstructorTablePtr_->toc()
00101                 << exit(FatalIOError);
00102         }
00103 
00104         return autoPtr<lduMatrix::preconditioner>
00105         (
00106             constructorIter()
00107             (
00108                 sol,
00109                 controls
00110             )
00111         );
00112     }
00113     else if (sol.matrix().asymmetric())
00114     {
00115         asymMatrixConstructorTable::iterator constructorIter =
00116             asymMatrixConstructorTablePtr_->find(name);
00117 
00118         if (constructorIter == asymMatrixConstructorTablePtr_->end())
00119         {
00120             FatalIOErrorIn
00121             (
00122                 "lduMatrix::preconditioner::New"
00123                 "(const solver&, const dictionary&)",
00124                 controls
00125             )   << "Unknown asymmetric matrix preconditioner "
00126                 << name << nl << nl
00127                 << "Valid asymmetric matrix preconditioners :" << endl
00128                 << asymMatrixConstructorTablePtr_->toc()
00129                 << exit(FatalIOError);
00130         }
00131 
00132         return autoPtr<lduMatrix::preconditioner>
00133         (
00134             constructorIter()
00135             (
00136                 sol,
00137                 controls
00138             )
00139         );
00140     }
00141     else
00142     {
00143         FatalIOErrorIn
00144         (
00145             "lduMatrix::preconditioner::New"
00146             "(const solver&, const dictionary&)",
00147             controls
00148         )   << "cannot solve incomplete matrix, "
00149                "no diagonal or off-diagonal coefficient"
00150             << exit(FatalIOError);
00151 
00152         return autoPtr<lduMatrix::preconditioner>(NULL);
00153     }
00154 }
00155 
00156 
00157 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd