initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / matrices / lduMatrix / lduMatrix / lduMatrixPreconditioner.C
blobc85cf074bed4be606318581f1f63101024c5999e
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "lduMatrix.H"
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 namespace Foam
33     defineRunTimeSelectionTable(lduMatrix::preconditioner, symMatrix);
34     defineRunTimeSelectionTable(lduMatrix::preconditioner, asymMatrix);
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 Foam::word
41 Foam::lduMatrix::preconditioner::getName
43     const dictionary& solverControls
46     word name;
48     // handle primitive or dictionary entry
49     const entry& e = solverControls.lookupEntry("preconditioner", false, false);
50     if (e.isDict())
51     {
52         e.dict().lookup("preconditioner") >> name;
53     }
54     else
55     {
56         e.stream() >> name;
57     }
59     return name;
63 Foam::autoPtr<Foam::lduMatrix::preconditioner>
64 Foam::lduMatrix::preconditioner::New
66     const solver& sol,
67     const dictionary& solverControls
70     word name;
72     // handle primitive or dictionary entry
73     const entry& e = solverControls.lookupEntry("preconditioner", false, false);
74     if (e.isDict())
75     {
76         e.dict().lookup("preconditioner") >> name;
77     }
78     else
79     {
80         e.stream() >> name;
81     }
83     const dictionary& controls = e.isDict() ? e.dict() : dictionary::null;
85     if (sol.matrix().symmetric())
86     {
87         symMatrixConstructorTable::iterator constructorIter =
88             symMatrixConstructorTablePtr_->find(name);
90         if (constructorIter == symMatrixConstructorTablePtr_->end())
91         {
92             FatalIOErrorIn
93             (
94                 "lduMatrix::preconditioner::New"
95                 "(const solver&, const dictionary&)",
96                 controls
97             )   << "Unknown symmetric matrix preconditioner "
98                 << name << nl << nl
99                 << "Valid symmetric matrix preconditioners :" << endl
100                 << symMatrixConstructorTablePtr_->toc()
101                 << exit(FatalIOError);
102         }
104         return autoPtr<lduMatrix::preconditioner>
105         (
106             constructorIter()
107             (
108                 sol,
109                 controls
110             )
111         );
112     }
113     else if (sol.matrix().asymmetric())
114     {
115         asymMatrixConstructorTable::iterator constructorIter =
116             asymMatrixConstructorTablePtr_->find(name);
118         if (constructorIter == asymMatrixConstructorTablePtr_->end())
119         {
120             FatalIOErrorIn
121             (
122                 "lduMatrix::preconditioner::New"
123                 "(const solver&, const dictionary&)",
124                 controls
125             )   << "Unknown asymmetric matrix preconditioner "
126                 << name << nl << nl
127                 << "Valid asymmetric matrix preconditioners :" << endl
128                 << asymMatrixConstructorTablePtr_->toc()
129                 << exit(FatalIOError);
130         }
132         return autoPtr<lduMatrix::preconditioner>
133         (
134             constructorIter()
135             (
136                 sol,
137                 controls
138             )
139         );
140     }
141     else
142     {
143         FatalIOErrorIn
144         (
145             "lduMatrix::preconditioner::New"
146             "(const solver&, const dictionary&)",
147             controls
148         )   << "cannot solve incomplete matrix, "
149                "no diagonal or off-diagonal coefficient"
150             << exit(FatalIOError);
152         return autoPtr<lduMatrix::preconditioner>(NULL);
153     }
157 // ************************************************************************* //