facGrad.C
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) 2016-2017 Wikki Ltd
9  Copyright (C) 2023 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "facGrad.H"
30 #include "areaFields.H"
31 #include "edgeFields.H"
32 #include "facEdgeIntegrate.H"
33 #include "faMesh.H"
34 #include "faGradScheme.H"
35 #include "gaussFaGrad.H"
36 
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 
39 namespace Foam
40 {
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 namespace fac
45 {
46 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 
49 template<class Type>
50 tmp
51 <
53  <
55  >
56 >
57 grad
58 (
60 )
61 {
62  return fa::gaussGrad<Type>::gradf(ssf, "grad(" + ssf.name() + ')');
63 }
64 
65 
66 template<class Type>
67 tmp
68 <
70  <
72  >
73 >
74 grad
75 (
77 )
78 {
79  typedef typename outerProduct<vector, Type>::type GradType;
81  (
82  fac::grad(tssf())
83  );
84  tssf.clear();
85  return Grad;
86 }
87 
88 
89 template<class Type>
90 tmp
91 <
93  <
95  >
96 >
97 grad
98 (
100  const word& name
101 )
102 {
103  typedef typename outerProduct<vector,Type>::type GradType;
105 
106  tmp<GradFieldType> tgGrad
107  (
109  (
110  vf.mesh(),
111  vf.mesh().gradScheme(name)
112  )
113  .cref() // const ref to tmp contents
114  .grad(vf).ptr() // steal ptr or deep copy of cached gradient
115  );
116  auto& gGrad = tgGrad.ref();
117 
118  const areaVectorField& n = vf.mesh().faceAreaNormals();
119  gGrad -= n*(n & gGrad);
120  gGrad.correctBoundaryConditions();
121 
122  return tgGrad;
123 }
124 
125 
126 template<class Type>
127 tmp
128 <
130  <
132  >
133 >
134 grad
135 (
137  const word& name
138 )
139 {
140  tmp
141  <
143  <
145  >
146  > tGrad
147  (
148  fac::grad(tvf(), name)
149  );
150  tvf.clear();
151  return tGrad;
152 }
153 
154 
155 template<class Type>
156 tmp
157 <
159  <
161  >
162 >
163 grad
164 (
166 )
167 {
168  return fac::grad(vf, "grad(" + vf.name() + ')');
169 }
170 
171 
172 template<class Type>
173 tmp
174 <
176  <
178  >
179 >
180 grad
181 (
183 )
184 {
185  typedef typename outerProduct<vector, Type>::type GradType;
187  (
188  fac::grad(tvf())
189  );
190  tvf.clear();
191  return Grad;
192 }
193 
194 
195 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
196 
197 } // End namespace fac
198 
199 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
200 
201 } // End namespace Foam
202 
203 // ************************************************************************* //
Calculate the second temporal derivative.
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:195
T & ref() const
Return non-const reference to the contents of a non-null managed pointer.
Definition: tmpI.H:235
tmp< GeometricField< typename outerProduct< vector, Type >::type, faPatchField, areaMesh > > grad(const GeometricField< Type, faPatchField, areaMesh > &, const word &name) const
Calculate and return the grad of the given field which may have been cached.
typeOfRank< typename pTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank) >::type type
Definition: products.H:118
Generic GeometricField class.
Definition: areaFieldsFwd.H:50
faPatchField<Type> abstract base class. This class gives a fat-interface to all derived classes cover...
Definition: areaFieldsFwd.H:56
Calculate the gradient of the given field.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
A class for handling words, derived from Foam::string.
Definition: word.H:63
const Mesh & mesh() const noexcept
Return mesh.
Abstract base class for finite area calculus gradient schemes.
Definition: faGradScheme.H:60
Mesh data needed to do the Finite Area discretisation.
Definition: areaFaMesh.H:47
static tmp< GeometricField< typename outerProduct< vector, Type >::type, faPatchField, areaMesh > > gradf(const GeometricField< Type, faePatchField, edgeMesh > &, const word &name)
Return the gradient of the given field calculated using Gauss&#39; theorem on the given surface field...
label n
A class for managing temporary objects.
Definition: HashPtrTable.H:50
Edge integrate edgeField creating a areaField. Edge sum a edgeField creating a areaField.
Namespace for OpenFOAM.
tmp< GeometricField< typename outerProduct< vector, Type >::type, faPatchField, areaMesh >> grad(const GeometricField< Type, faePatchField, edgeMesh > &ssf)
Definition: facGrad.C:51