FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include <OpenFOAM/lduMatrix.H>
00027 
00028 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00029 
00030 namespace Foam
00031 {
00032     defineRunTimeSelectionTable(lduMatrix::preconditioner, symMatrix);
00033     defineRunTimeSelectionTable(lduMatrix::preconditioner, asymMatrix);
00034 }
00035 
00036 
00037 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00038 
00039 Foam::word
00040 Foam::lduMatrix::preconditioner::getName
00041 (
00042     const dictionary& solverControls
00043 )
00044 {
00045     word name;
00046 
00047     // handle primitive or dictionary entry
00048     const entry& e = solverControls.lookupEntry("preconditioner", false, false);
00049     if (e.isDict())
00050     {
00051         e.dict().lookup("preconditioner") >> name;
00052     }
00053     else
00054     {
00055         e.stream() >> name;
00056     }
00057 
00058     return name;
00059 }
00060 
00061 
00062 Foam::autoPtr<Foam::lduMatrix::preconditioner>
00063 Foam::lduMatrix::preconditioner::New
00064 (
00065     const solver& sol,
00066     const dictionary& solverControls
00067 )
00068 {
00069     word name;
00070 
00071     // handle primitive or dictionary entry
00072     const entry& e = solverControls.lookupEntry("preconditioner", false, false);
00073     if (e.isDict())
00074     {
00075         e.dict().lookup("preconditioner") >> name;
00076     }
00077     else
00078     {
00079         e.stream() >> name;
00080     }
00081 
00082     const dictionary& controls = e.isDict() ? e.dict() : dictionary::null;
00083 
00084     if (sol.matrix().symmetric())
00085     {
00086         symMatrixConstructorTable::iterator constructorIter =
00087             symMatrixConstructorTablePtr_->find(name);
00088 
00089         if (constructorIter == symMatrixConstructorTablePtr_->end())
00090         {
00091             FatalIOErrorIn
00092             (
00093                 "lduMatrix::preconditioner::New"
00094                 "(const solver&, const dictionary&)",
00095                 controls
00096             )   << "Unknown symmetric matrix preconditioner "
00097                 << name << nl << nl
00098                 << "Valid symmetric matrix preconditioners :" << endl
00099                 << symMatrixConstructorTablePtr_->sortedToc()
00100                 << exit(FatalIOError);
00101         }
00102 
00103         return autoPtr<lduMatrix::preconditioner>
00104         (
00105             constructorIter()
00106             (
00107                 sol,
00108                 controls
00109             )
00110         );
00111     }
00112     else if (sol.matrix().asymmetric())
00113     {
00114         asymMatrixConstructorTable::iterator constructorIter =
00115             asymMatrixConstructorTablePtr_->find(name);
00116 
00117         if (constructorIter == asymMatrixConstructorTablePtr_->end())
00118         {
00119             FatalIOErrorIn
00120             (
00121                 "lduMatrix::preconditioner::New"
00122                 "(const solver&, const dictionary&)",
00123                 controls
00124             )   << "Unknown asymmetric matrix preconditioner "
00125                 << name << nl << nl
00126                 << "Valid asymmetric matrix preconditioners :" << endl
00127                 << asymMatrixConstructorTablePtr_->sortedToc()
00128                 << exit(FatalIOError);
00129         }
00130 
00131         return autoPtr<lduMatrix::preconditioner>
00132         (
00133             constructorIter()
00134             (
00135                 sol,
00136                 controls
00137             )
00138         );
00139     }
00140     else
00141     {
00142         FatalIOErrorIn
00143         (
00144             "lduMatrix::preconditioner::New"
00145             "(const solver&, const dictionary&)",
00146             controls
00147         )   << "cannot solve incomplete matrix, "
00148                "no diagonal or off-diagonal coefficient"
00149             << exit(FatalIOError);
00150 
00151         return autoPtr<lduMatrix::preconditioner>(NULL);
00152     }
00153 }
00154 
00155 
00156 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines