lduMatrixPreconditioner.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "lduMatrix.H"
27 
28 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
29 
30 namespace Foam
31 {
32  defineRunTimeSelectionTable(lduMatrix::preconditioner, symMatrix);
33  defineRunTimeSelectionTable(lduMatrix::preconditioner, asymMatrix);
34 }
35 
36 
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 
40 (
41  const dictionary& solverControls
42 )
43 {
44  word name;
45 
46  // handle primitive or dictionary entry
47  const entry& e = solverControls.lookupEntry("preconditioner", false, false);
48  if (e.isDict())
49  {
50  e.dict().lookup("preconditioner") >> name;
51  }
52  else
53  {
54  e.stream() >> name;
55  }
56 
57  return name;
58 }
59 
60 
63 (
64  const solver& sol,
65  const dictionary& solverControls
66 )
67 {
68  word name;
69 
70  // handle primitive or dictionary entry
71  const entry& e = solverControls.lookupEntry("preconditioner", false, false);
72  if (e.isDict())
73  {
74  e.dict().lookup("preconditioner") >> name;
75  }
76  else
77  {
78  e.stream() >> name;
79  }
80 
81  const dictionary& controls = e.isDict() ? e.dict() : dictionary::null;
82 
83  if (sol.matrix().symmetric())
84  {
85  symMatrixConstructorTable::iterator constructorIter =
86  symMatrixConstructorTablePtr_->find(name);
87 
88  if (constructorIter == symMatrixConstructorTablePtr_->end())
89  {
91  (
92  "lduMatrix::preconditioner::New"
93  "(const solver&, const dictionary&)",
94  controls
95  ) << "Unknown symmetric matrix preconditioner "
96  << name << nl << nl
97  << "Valid symmetric matrix preconditioners :" << endl
98  << symMatrixConstructorTablePtr_->sortedToc()
99  << exit(FatalIOError);
100  }
101 
103  (
104  constructorIter()
105  (
106  sol,
107  controls
108  )
109  );
110  }
111  else if (sol.matrix().asymmetric())
112  {
113  asymMatrixConstructorTable::iterator constructorIter =
114  asymMatrixConstructorTablePtr_->find(name);
115 
116  if (constructorIter == asymMatrixConstructorTablePtr_->end())
117  {
119  (
120  "lduMatrix::preconditioner::New"
121  "(const solver&, const dictionary&)",
122  controls
123  ) << "Unknown asymmetric matrix preconditioner "
124  << name << nl << nl
125  << "Valid asymmetric matrix preconditioners :" << endl
126  << asymMatrixConstructorTablePtr_->sortedToc()
127  << exit(FatalIOError);
128  }
129 
131  (
132  constructorIter()
133  (
134  sol,
135  controls
136  )
137  );
138  }
139  else
140  {
142  (
143  "lduMatrix::preconditioner::New"
144  "(const solver&, const dictionary&)",
145  controls
146  ) << "cannot solve incomplete matrix, "
147  "no diagonal or off-diagonal coefficient"
148  << exit(FatalIOError);
149 
151  }
152 }
153 
154 
155 // ************************************************************************* //
virtual bool isDict() const
Return true if this entry is a dictionary.
Definition: entry.H:153
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
virtual const dictionary & dict() const =0
Return dictionary if this entry is a dictionary.
static word getName(const dictionary &)
Find the preconditioner name (directly or from a sub-dictionary)
A class for handling words, derived from string.
Definition: word.H:59
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
static autoPtr< preconditioner > New(const solver &sol, const dictionary &solverControls)
Return a new preconditioner.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
Namespace for OpenFOAM.
static const dictionary null
Null dictionary.
Definition: dictionary.H:193
virtual ITstream & stream() const =0
Return token stream if this entry is a primitive entry.
static const char nl
Definition: Ostream.H:260
const double e
Elementary charge.
Definition: doubleFloat.H:78
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
IOerror FatalIOError
bool asymmetric() const
Definition: lduMatrix.H:605
const lduMatrix & matrix() const
Definition: lduMatrix.H:221
A keyword and a list of tokens is an &#39;entry&#39;.
Definition: entry.H:65
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:452
bool symmetric() const
Definition: lduMatrix.H:600
Abstract base-class for lduMatrix solvers.
Definition: lduMatrix.H:91
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
const entry & lookupEntry(const word &, bool recursive, bool patternMatch) const
Find and return an entry data stream if present otherwise error.
Definition: dictionary.C:428
#define FatalIOErrorIn(functionName, ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:325
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117