LeastSquaresGrad.H
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) 2013-2015 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 Class
25  Foam::fv::LeastSquaresGrad
26 
27 Description
28  Gradient calculated using weighted least-squares on an arbitrary stencil.
29  The stencil type is provided via a template argument and any cell-based
30  stencil is supported:
31 
32  \table
33  Stencil | Connections | Scheme name
34  centredCFCCellToCellStencil | cell-face-cell | Not Instantiated
35  centredCPCCellToCellStencil | cell-point-cell | pointCellsLeastSquares
36  centredCECCellToCellStencil | cell-edge-cell | edgeCellsLeastSquares
37  \endtable
38 
39  The first of these is not instantiated by default as the standard
40  leastSquaresGrad is equivalent and more efficient.
41 
42  \heading Usage
43 
44  Example of the gradient specification:
45  \verbatim
46  gradSchemes
47  {
48  default pointCellsLeastSquares;
49  }
50  \endverbatim
51 
52 See Also
53  Foam::fv::LeastSquaresVectors
54  Foam::fv::leastSquaresGrad
55 
56 SourceFiles
57  LeastSquaresGrad.C
58  LeastSquaresVectors.H
59  LeastSquaresVectors.C
60 
61 \*---------------------------------------------------------------------------*/
62 
63 #ifndef LeastSquaresGrad_H
64 #define LeastSquaresGrad_H
65 
66 #include "gradScheme.H"
67 
68 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
69 
70 namespace Foam
71 {
72 
73 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
74 
75 namespace fv
76 {
77 
78 /*---------------------------------------------------------------------------*\
79  Class LeastSquaresGrad Declaration
80 \*---------------------------------------------------------------------------*/
81 
82 template<class Type, class Stencil>
83 class LeastSquaresGrad
84 :
85  public fv::gradScheme<Type>
86 {
87  // Private Data
88 
89  //- Minimum determinant criterion to choose extra cells
90  scalar minDet_;
91 
92 
93  // Private Member Functions
94 
95  //- Disallow default bitwise copy construct
97 
98  //- Disallow default bitwise assignment
99  void operator=(const LeastSquaresGrad&);
100 
101 
102 public:
103 
104  //- Runtime type information
105  TypeName("LeastSquares");
106 
107 
108  // Constructors
109 
110  //- Construct from Istream
111  LeastSquaresGrad(const fvMesh& mesh, Istream& schemeData)
112  :
113  gradScheme<Type>(mesh)
114  {}
115 
116 
117  // Member Functions
118 
119  //- Return the gradient of the given field to the gradScheme::grad
120  // for optional caching
121  virtual tmp
122  <
125  > calcGrad
126  (
128  const word& name
129  ) const;
130 };
131 
132 
133 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
134 
135 } // End namespace fv
136 
137 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
138 
139 } // End namespace Foam
140 
141 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
142 
143 // Add the patch constructor functions to the hash tables
144 
145 #define makeLeastSquaresGradTypeScheme(SS, STENCIL, TYPE) \
146  typedef Foam::fv::LeastSquaresGrad<Foam::TYPE, Foam::STENCIL> \
147  LeastSquaresGrad##TYPE##STENCIL##_; \
148  \
149  defineTemplateTypeNameAndDebugWithName \
150  (LeastSquaresGrad##TYPE##STENCIL##_, #SS, 0); \
151  \
152  namespace Foam \
153  { \
154  namespace fv \
155  { \
156  typedef LeastSquaresGrad<Foam::TYPE, Foam::STENCIL> \
157  LeastSquaresGrad##TYPE##STENCIL##_; \
158  \
159  gradScheme<Foam::TYPE>::addIstreamConstructorToTable \
160  <LeastSquaresGrad<Foam::TYPE, Foam::STENCIL> > \
161  add##SS##STENCIL##TYPE##IstreamConstructorToTable_; \
162  } \
163  }
164 
165 #define makeLeastSquaresGradScheme(SS, STENCIL) \
166  typedef Foam::fv::LeastSquaresVectors<Foam::STENCIL> \
167  LeastSquaresVectors##STENCIL##_; \
168  \
169  defineTemplateTypeNameAndDebugWithName \
170  (LeastSquaresVectors##STENCIL##_, #SS, 0); \
171  \
172  makeLeastSquaresGradTypeScheme(SS,STENCIL,scalar) \
173  makeLeastSquaresGradTypeScheme(SS,STENCIL,vector)
174 
175 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
176 
177 #ifdef NoRepository
178 # include "LeastSquaresGrad.C"
179 #endif
180 
181 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
182 
183 #endif
184 
185 // ************************************************************************* //
Foam::fvPatchField
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:65
Foam::fv::LeastSquaresGrad::calcGrad
virtual tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh > > calcGrad(const GeometricField< Type, fvPatchField, volMesh > &vsf, const word &name) const
Return the gradient of the given field to the gradScheme::grad.
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:118
Foam::volMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: volMesh.H:47
Foam::fv::LeastSquaresGrad::LeastSquaresGrad
LeastSquaresGrad(const fvMesh &mesh, Istream &schemeData)
Construct from Istream.
Definition: LeastSquaresGrad.H:126
Foam::outerProduct::type
typeOfRank< typename pTraits< arg1 >::cmptType, int(pTraits< arg1 >::rank)+int(pTraits< arg2 >::rank) >::type type
Definition: products.H:72
Foam::fv::LeastSquaresGrad::minDet_
scalar minDet_
Minimum determinant criterion to choose extra cells.
Definition: LeastSquaresGrad.H:105
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
Foam::fv::gradScheme::mesh
const fvMesh & mesh() const
Return mesh reference.
Definition: gradScheme.H:122
gradScheme.H
Foam::fv::LeastSquaresGrad::TypeName
TypeName("LeastSquares")
Runtime type information.
Foam::fv::gradScheme
Abstract base class for gradient schemes.
Definition: gradScheme.H:60
Foam::fv::LeastSquaresGrad::LeastSquaresGrad
LeastSquaresGrad(const LeastSquaresGrad &)
Disallow default bitwise copy construct.
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
LeastSquaresGrad.C
fv
labelList fv(nPoints)
Foam::fv::LeastSquaresGrad
Gradient calculated using weighted least-squares on an arbitrary stencil. The stencil type is provide...
Definition: LeastSquaresGrad.H:98
Foam::fv::LeastSquaresGrad::operator=
void operator=(const LeastSquaresGrad &)
Disallow default bitwise assignment.
Foam::GeometricField
Generic GeometricField class.
Definition: surfaceFieldsFwd.H:52
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47