fourthGrad.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) 2011-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 \*---------------------------------------------------------------------------*/
27 
28 #include "fourthGrad.H"
29 #include "leastSquaresGrad.H"
30 #include "gaussGrad.H"
31 #include "fvMesh.H"
32 #include "volMesh.H"
33 #include "surfaceMesh.H"
34 #include "GeometricField.H"
36 
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 
39 template<class Type>
41 <
43  <
47  >
48 >
50 (
51  const GeometricField<Type, fvPatchField, volMesh>& vsf,
52  const word& name
53 ) const
54 {
55  // The fourth-order gradient is calculated in two passes. First,
56  // the standard least-square gradient is assembled. Then, the
57  // fourth-order correction is added to the second-order accurate
58  // gradient to complete the accuracy.
59 
60  typedef typename outerProduct<vector, Type>::type GradType;
61 
62  const fvMesh& mesh = vsf.mesh();
63 
64  // Assemble the second-order least-square gradient
65  // Calculate the second-order least-square gradient
66  tmp<GeometricField<GradType, fvPatchField, volMesh>> tsecondfGrad
67  = leastSquaresGrad<Type>(mesh).grad
68  (
69  vsf,
70  "leastSquaresGrad(" + vsf.name() + ")"
71  );
72  const GeometricField<GradType, fvPatchField, volMesh>& secondfGrad =
73  tsecondfGrad();
74 
75  tmp<GeometricField<GradType, fvPatchField, volMesh>> tfGrad
76  (
77  new GeometricField<GradType, fvPatchField, volMesh>
78  (
79  IOobject
80  (
81  name,
82  vsf.instance(),
83  mesh,
84  IOobject::NO_READ,
85  IOobject::NO_WRITE
86  ),
87  secondfGrad
88  )
89  );
90  GeometricField<GradType, fvPatchField, volMesh>& fGrad = tfGrad.ref();
91 
92  const vectorField& C = mesh.C();
93 
94  const surfaceScalarField& lambda = mesh.weights();
95 
96  // Get reference to least square vectors
97  const leastSquaresVectors& lsv = leastSquaresVectors::New(mesh);
98  const surfaceVectorField& ownLs = lsv.pVectors();
99  const surfaceVectorField& neiLs = lsv.nVectors();
100 
101  // owner/neighbour addressing
102  const labelUList& own = mesh.owner();
103  const labelUList& nei = mesh.neighbour();
104 
105  // Assemble the fourth-order gradient
106 
107  // Internal faces
108  forAll(own, facei)
109  {
110  Type dDotGradDelta = 0.5*
111  (
112  (C[nei[facei]] - C[own[facei]])
113  & (secondfGrad[nei[facei]] - secondfGrad[own[facei]])
114  );
115 
116  fGrad[own[facei]] -= lambda[facei]*ownLs[facei]*dDotGradDelta;
117  fGrad[nei[facei]] -= (1.0 - lambda[facei])*neiLs[facei]*dDotGradDelta;
118  }
119 
120  // Boundary faces
121  forAll(vsf.boundaryField(), patchi)
122  {
123  if (secondfGrad.boundaryField()[patchi].coupled())
124  {
125  const fvsPatchVectorField& patchOwnLs =
126  ownLs.boundaryField()[patchi];
127 
128  const scalarField& lambdap = lambda.boundaryField()[patchi];
129 
130  const fvPatch& p = vsf.boundaryField()[patchi].patch();
131 
132  const labelUList& faceCells = p.faceCells();
133 
134  // Build the d-vectors
135  vectorField pd(p.delta());
136 
137  const Field<GradType> neighbourSecondfGrad
138  (
139  secondfGrad.boundaryField()[patchi].patchNeighbourField()
140  );
141 
142  forAll(faceCells, patchFacei)
143  {
144  fGrad[faceCells[patchFacei]] -=
145  0.5*lambdap[patchFacei]*patchOwnLs[patchFacei]
146  *(
147  pd[patchFacei]
148  & (
149  neighbourSecondfGrad[patchFacei]
150  - secondfGrad[faceCells[patchFacei]]
151  )
152  );
153  }
154  }
155  }
156 
157  fGrad.correctBoundaryConditions();
159 
160  return tfGrad;
161 }
162 
163 
164 // ************************************************************************* //
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::scalarField
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Definition: primitiveFieldsFwd.H:52
p
volScalarField & p
Definition: createFieldRefs.H:8
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
volMesh.H
Foam::fv::fourthGrad::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.
zeroGradientFvPatchField.H
C
volScalarField & C
Definition: readThermalProperties.H:102
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::vectorField
Field< vector > vectorField
Specialisation of Field<T> for vector.
Definition: primitiveFieldsFwd.H:54
leastSquaresGrad.H
correctBoundaryConditions
cellMask correctBoundaryConditions()
gaussGrad.H
Foam::fvsPatchVectorField
fvsPatchField< vector > fvsPatchVectorField
Definition: fvsPatchFieldsFwd.H:48
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
surfaceMesh.H
lambda
dimensionedScalar lambda("lambda", dimTime/sqr(dimLength), laminarTransport)
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
fourthGrad.H
fvMesh.H
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
GeometricField.H
Foam::surfaceScalarField
GeometricField< scalar, fvsPatchField, surfaceMesh > surfaceScalarField
Definition: surfaceFieldsFwd.H:54
Foam::roots::type
type
Types of root.
Definition: Roots.H:54
Foam::labelUList
UList< label > labelUList
A UList of labels.
Definition: UList.H:80
Foam::surfaceVectorField
GeometricField< vector, fvsPatchField, surfaceMesh > surfaceVectorField
Definition: surfaceFieldsFwd.H:57
Foam::GeometricField
Generic GeometricField class.
Definition: areaFieldsFwd.H:53