lduMatrixSmoother.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 {
32  defineRunTimeSelectionTable(lduMatrix::smoother, symMatrix);
33  defineRunTimeSelectionTable(lduMatrix::smoother, asymMatrix);
34 }
35 
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 
40 (
41  const dictionary& solverControls
42 )
43 {
44  word name;
45 
46  // handle primitive or dictionary entry
47  const entry& e = solverControls.lookupEntry("smoother", false, false);
48  if (e.isDict())
49  {
50  e.dict().lookup("smoother") >> name;
51  }
52  else
53  {
54  e.stream() >> name;
55  }
56 
57  return name;
58 }
59 
60 
62 (
63  const word& fieldName,
64  const lduMatrix& matrix,
65  const FieldField<Field, scalar>& interfaceBouCoeffs,
66  const FieldField<Field, scalar>& interfaceIntCoeffs,
67  const lduInterfaceFieldPtrsList& interfaces,
68  const dictionary& solverControls
69 )
70 {
71  word name;
72 
73  // handle primitive or dictionary entry
74  const entry& e = solverControls.lookupEntry("smoother", false, false);
75  if (e.isDict())
76  {
77  e.dict().lookup("smoother") >> name;
78  }
79  else
80  {
81  e.stream() >> name;
82  }
83 
84  // not (yet?) needed:
85  // const dictionary& controls = e.isDict() ? e.dict() : dictionary::null;
86 
87  if (matrix.symmetric())
88  {
89  symMatrixConstructorTable::iterator constructorIter =
90  symMatrixConstructorTablePtr_->find(name);
91 
92  if (constructorIter == symMatrixConstructorTablePtr_->end())
93  {
94  FatalIOErrorInFunction(solverControls)
95  << "Unknown symmetric matrix smoother "
96  << name << nl << nl
97  << "Valid symmetric matrix smoothers are :" << endl
98  << symMatrixConstructorTablePtr_->sortedToc()
99  << exit(FatalIOError);
100  }
101 
103  (
104  constructorIter()
105  (
106  fieldName,
107  matrix,
108  interfaceBouCoeffs,
109  interfaceIntCoeffs,
110  interfaces
111  )
112  );
113  }
114  else if (matrix.asymmetric())
115  {
116  asymMatrixConstructorTable::iterator constructorIter =
117  asymMatrixConstructorTablePtr_->find(name);
118 
119  if (constructorIter == asymMatrixConstructorTablePtr_->end())
120  {
121  FatalIOErrorInFunction(solverControls)
122  << "Unknown asymmetric matrix smoother "
123  << name << nl << nl
124  << "Valid asymmetric matrix smoothers are :" << endl
125  << asymMatrixConstructorTablePtr_->sortedToc()
126  << exit(FatalIOError);
127  }
128 
130  (
131  constructorIter()
132  (
133  fieldName,
134  matrix,
135  interfaceBouCoeffs,
136  interfaceIntCoeffs,
137  interfaces
138  )
139  );
140  }
141  else
142  {
143  FatalIOErrorInFunction(solverControls)
144  << "cannot solve incomplete matrix, "
145  "no diagonal or off-diagonal coefficient"
146  << exit(FatalIOError);
147 
148  return autoPtr<lduMatrix::smoother>(nullptr);
149  }
150 }
151 
152 
153 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
154 
156 (
157  const word& fieldName,
158  const lduMatrix& matrix,
159  const FieldField<Field, scalar>& interfaceBouCoeffs,
160  const FieldField<Field, scalar>& interfaceIntCoeffs,
161  const lduInterfaceFieldPtrsList& interfaces
162 )
163 :
164  fieldName_(fieldName),
165  matrix_(matrix),
166  interfaceBouCoeffs_(interfaceBouCoeffs),
167  interfaceIntCoeffs_(interfaceIntCoeffs),
168  interfaces_(interfaces)
169 {}
170 
171 
172 // ************************************************************************* //
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
virtual const dictionary & dict() const =0
Return dictionary if this entry is a 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:801
Generic field type.
Definition: FieldField.H:51
static word getName(const dictionary &)
Find the smoother name (directly or from a sub-dictionary)
A class for handling words, derived from string.
Definition: word.H:59
bool asymmetric() const
Definition: lduMatrix.H:623
virtual bool isDict() const
Return true if this entry is a dictionary.
Definition: entry.H:156
smoother(const word &fieldName, const lduMatrix &matrix, const FieldField< Field, scalar > &interfaceBouCoeffs, const FieldField< Field, scalar > &interfaceIntCoeffs, const lduInterfaceFieldPtrsList &interfaces)
static const char nl
Definition: Ostream.H:260
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
lduMatrix is a general matrix class in which the coefficients are stored as three arrays...
Definition: lduMatrix.H:79
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:335
static autoPtr< smoother > New(const word &fieldName, const lduMatrix &matrix, const FieldField< Field, scalar > &interfaceBouCoeffs, const FieldField< Field, scalar > &interfaceIntCoeffs, const lduInterfaceFieldPtrsList &interfaces, const dictionary &solverControls)
Return a new smoother.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
const doubleScalar e
Elementary charge.
Definition: doubleScalar.H:105
virtual ITstream & stream() const =0
Return token stream if this entry is a primitive entry.
bool symmetric() const
Definition: lduMatrix.H:609
Namespace for OpenFOAM.
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:844
IOerror FatalIOError