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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2013-2016 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::fv::LeastSquaresGrad
28 
29 Group
30  grpFvGradSchemes
31 
32 Description
33  Gradient calculated using weighted least-squares on an arbitrary stencil.
34  The stencil type is provided via a template argument and any cell-based
35  stencil is supported:
36 
37  \table
38  Stencil | Connections | Scheme name
39  centredCFCCellToCellStencil | cell-face-cell | Not Instantiated
40  centredCPCCellToCellStencil | cell-point-cell | pointCellsLeastSquares
41  centredCECCellToCellStencil | cell-edge-cell | edgeCellsLeastSquares
42  \endtable
43 
44  The first of these is not instantiated by default as the standard
45  leastSquaresGrad is equivalent and more efficient.
46 
47 Usage
48  Example of the gradient specification:
49  \verbatim
50  gradSchemes
51  {
52  default pointCellsLeastSquares;
53  }
54  \endverbatim
55 
56 See also
57  Foam::fv::LeastSquaresVectors
58  Foam::fv::leastSquaresGrad
59 
60 SourceFiles
61  LeastSquaresGrad.C
62  LeastSquaresVectors.H
63  LeastSquaresVectors.C
64 
65 \*---------------------------------------------------------------------------*/
66 
67 #ifndef LeastSquaresGrad_H
68 #define LeastSquaresGrad_H
69 
70 #include "gradScheme.H"
71 
72 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
73 
74 namespace Foam
75 {
76 
77 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
78 
79 namespace fv
80 {
81 
82 /*---------------------------------------------------------------------------*\
83  Class LeastSquaresGrad Declaration
84 \*---------------------------------------------------------------------------*/
85 
86 template<class Type, class Stencil>
87 class LeastSquaresGrad
88 :
89  public fv::gradScheme<Type>
90 {
91  // Private Data
92 
93  //- Minimum determinant criterion to choose extra cells
94  scalar minDet_;
95 
96 
97  // Private Member Functions
98 
99  //- No copy construct
100  LeastSquaresGrad(const LeastSquaresGrad&) = delete;
101 
102  //- No copy assignment
103  void operator=(const LeastSquaresGrad&) = delete;
104 
105 
106 public:
107 
108  //- Runtime type information
109  TypeName("LeastSquares");
110 
111 
112  // Constructors
113 
114  //- Construct from Istream
115  LeastSquaresGrad(const fvMesh& mesh, Istream& schemeData)
116  :
117  gradScheme<Type>(mesh)
118  {}
119 
120 
121  // Member Functions
122 
123  //- Return the gradient of the given field to the gradScheme::grad
124  // for optional caching
125  virtual tmp
126  <
129  > calcGrad
130  (
132  const word& name
133  ) const;
134 };
135 
136 
137 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
138 
139 } // End namespace fv
140 
141 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
142 
143 } // End namespace Foam
144 
145 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
146 
147 // Add the patch constructor functions to the hash tables
148 
149 #define makeLeastSquaresGradTypeScheme(SS, STENCIL, TYPE) \
150  typedef Foam::fv::LeastSquaresGrad<Foam::TYPE, Foam::STENCIL> \
151  LeastSquaresGrad##TYPE##STENCIL##_; \
152  \
153  defineTemplateTypeNameAndDebugWithName \
154  (LeastSquaresGrad##TYPE##STENCIL##_, #SS, 0); \
155  \
156  namespace Foam \
157  { \
158  namespace fv \
159  { \
160  typedef LeastSquaresGrad<Foam::TYPE, Foam::STENCIL> \
161  LeastSquaresGrad##TYPE##STENCIL##_; \
162  \
163  gradScheme<Foam::TYPE>::addIstreamConstructorToTable \
164  <LeastSquaresGrad<Foam::TYPE, Foam::STENCIL>> \
165  add##SS##STENCIL##TYPE##IstreamConstructorToTable_; \
166  } \
167  }
168 
169 #define makeLeastSquaresGradScheme(SS, STENCIL) \
170  typedef Foam::fv::LeastSquaresVectors<Foam::STENCIL> \
171  LeastSquaresVectors##STENCIL##_; \
172  \
173  defineTemplateTypeNameAndDebugWithName \
174  (LeastSquaresVectors##STENCIL##_, #SS, 0); \
175  \
176  makeLeastSquaresGradTypeScheme(SS,STENCIL,scalar) \
177  makeLeastSquaresGradTypeScheme(SS,STENCIL,vector)
178 
179 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
180 
181 #ifdef NoRepository
182  #include "LeastSquaresGrad.C"
183 #endif
184 
185 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
186 
187 #endif
188 
189 // ************************************************************************* //
Foam::fvPatchField
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: volSurfaceMapping.H:50
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 Foam::string.
Definition: word.H:62
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:59
Foam::volMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: volMesh.H:50
Foam::outerProduct::type
typeOfRank< typename pTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank) >::type type
Definition: products.H:114
Foam::fv::LeastSquaresGrad::LeastSquaresGrad
LeastSquaresGrad(const fvMesh &mesh, Istream &schemeData)
Construct from Istream.
Definition: LeastSquaresGrad.H:130
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::fv::gradScheme::mesh
const fvMesh & mesh() const
Return mesh reference.
Definition: gradScheme.H:124
gradScheme.H
Foam::fv::LeastSquaresGrad::TypeName
TypeName("LeastSquares")
Runtime type information.
Foam::fv::gradScheme
Abstract base class for gradient schemes.
Definition: gradScheme.H:62
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:84
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
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:102
Foam::GeometricField
Generic GeometricField class.
Definition: areaFieldsFwd.H:53