lduMatrixPreconditioner.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 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 {
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  controls
93  ) << "Unknown symmetric matrix preconditioner "
94  << name << nl << nl
95  << "Valid symmetric matrix preconditioners :" << endl
96  << symMatrixConstructorTablePtr_->sortedToc()
97  << exit(FatalIOError);
98  }
99 
101  (
102  constructorIter()
103  (
104  sol,
105  controls
106  )
107  );
108  }
109  else if (sol.matrix().asymmetric())
110  {
111  asymMatrixConstructorTable::iterator constructorIter =
112  asymMatrixConstructorTablePtr_->find(name);
113 
114  if (constructorIter == asymMatrixConstructorTablePtr_->end())
115  {
117  (
118  controls
119  ) << "Unknown asymmetric matrix preconditioner "
120  << name << nl << nl
121  << "Valid asymmetric matrix preconditioners :" << endl
122  << asymMatrixConstructorTablePtr_->sortedToc()
123  << exit(FatalIOError);
124  }
125 
127  (
128  constructorIter()
129  (
130  sol,
131  controls
132  )
133  );
134  }
135  else
136  {
138  (
139  controls
140  ) << "cannot solve incomplete matrix, "
141  "no diagonal or off-diagonal coefficient"
142  << exit(FatalIOError);
143 
144  return autoPtr<lduMatrix::preconditioner>(nullptr);
145  }
146 }
147 
148 
149 // ************************************************************************* //
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
const entry & lookupEntry(const word &, bool recursive, bool patternMatch) const
Find and return an entry data stream if present otherwise error.
Definition: dictionary.C:817
static const dictionary null
Null dictionary.
Definition: dictionary.H:242
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:68
Abstract base-class for lduMatrix preconditioners.
Definition: lduMatrix.H:411
static autoPtr< preconditioner > New(const solver &sol, const dictionary &solverControls)
Return a new preconditioner.
static word getName(const dictionary &)
Find the preconditioner name (directly or from a sub-dictionary)
Abstract base-class for lduMatrix solvers.
Definition: lduMatrix.H:94
const lduMatrix & matrix() const
Definition: lduMatrix.H:226
bool symmetric() const
Definition: lduMatrix.H:609
bool asymmetric() const
Definition: lduMatrix.H:623
A class for handling words, derived from string.
Definition: word.H:62
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:318
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
const doubleScalar e
Definition: doubleScalar.H:105
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
IOerror FatalIOError
static const char nl
Definition: Ostream.H:260