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-2026 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 #include "noPreconditioner.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
35 }
36 
37 
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 
41 (
42  const dictionary& solverControls
43 )
44 {
45  word name;
46 
47  // handle primitive or dictionary entry
48  const entry& e = solverControls.lookupEntry("preconditioner", false, false);
49  if (e.isDict())
50  {
51  e.dict().lookup("preconditioner") >> name;
52  }
53  else
54  {
55  e.stream() >> name;
56  }
57 
58  return name;
59 }
60 
61 
64 (
65  const solver& sol,
66  const dictionary& solverControls
67 )
68 {
69  word name;
70 
71  // handle primitive or dictionary entry
72  const entry& e = solverControls.lookupEntry("preconditioner", false, false);
73  if (e.isDict())
74  {
75  e.dict().lookup("preconditioner") >> name;
76  }
77  else
78  {
79  e.stream() >> name;
80  }
81 
82  const dictionary& controls = e.isDict() ? e.dict() : dictionary::null;
83 
84  if (sol.matrix().diagonal())
85  {
87  (
89  (
90  sol,
91  controls
92  )
93  );
94  }
95  else if (sol.matrix().symmetric())
96  {
97  symMatrixConstructorTable::iterator constructorIter =
98  symMatrixConstructorTablePtr_->find(name);
99 
100  if (constructorIter == symMatrixConstructorTablePtr_->end())
101  {
103  (
104  controls
105  ) << "Unknown symmetric matrix preconditioner "
106  << name << nl << nl
107  << "Valid symmetric matrix preconditioners :" << endl
108  << symMatrixConstructorTablePtr_->sortedToc()
109  << exit(FatalIOError);
110  }
111 
113  (
114  constructorIter()
115  (
116  sol,
117  controls
118  )
119  );
120  }
121  else if (sol.matrix().asymmetric())
122  {
123  asymMatrixConstructorTable::iterator constructorIter =
124  asymMatrixConstructorTablePtr_->find(name);
125 
126  if (constructorIter == asymMatrixConstructorTablePtr_->end())
127  {
129  (
130  controls
131  ) << "Unknown asymmetric matrix preconditioner "
132  << name << nl << nl
133  << "Valid asymmetric matrix preconditioners :" << endl
134  << asymMatrixConstructorTablePtr_->sortedToc()
135  << exit(FatalIOError);
136  }
137 
139  (
140  constructorIter()
141  (
142  sol,
143  controls
144  )
145  );
146  }
147  else
148  {
150  (
151  controls
152  ) << "cannot solve incomplete matrix, "
153  "no diagonal or off-diagonal coefficient"
154  << exit(FatalIOError);
155 
156  return autoPtr<lduMatrix::preconditioner>(nullptr);
157  }
158 }
159 
160 
161 // ************************************************************************* //
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 keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
const entry & lookupEntry(const word &, bool recursive, bool patternMatch) const
Find and return an entry data stream if present otherwise error.
Definition: dictionary.C:626
static const dictionary null
Null dictionary.
Definition: dictionary.H:261
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 diagonal() const
Definition: lduMatrix.H:595
bool asymmetric() const
Definition: lduMatrix.H:623
Null preconditioner for both symmetric and asymmetric matrices.
A class for handling words, derived from string.
Definition: word.H:63
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:346
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
const doubleScalar e
Definition: doubleScalar.H:106
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
defineRunTimeSelectionTable(fvConstraint, dictionary)
IOerror FatalIOError
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
static const char nl
Definition: Ostream.H:297