fourthGrad.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 "fourthGrad.H"
27 #include "leastSquaresGrad.H"
28 #include "gaussGrad.H"
29 #include "fvMesh.H"
30 #include "volMesh.H"
31 #include "surfaceMesh.H"
32 #include "GeometricField.H"
34 
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 
37 template<class Type>
39 <
41  <
45  >
46 >
48 (
49  const GeometricField<Type, fvPatchField, volMesh>& vsf,
50  const word& name
51 ) const
52 {
53  // The fourth-order gradient is calculated in two passes. First,
54  // the standard least-square gradient is assembled. Then, the
55  // fourth-order correction is added to the second-order accurate
56  // gradient to complete the accuracy.
57 
58  typedef typename outerProduct<vector, Type>::type GradType;
59 
60  const fvMesh& mesh = vsf.mesh();
61 
62  // Assemble the second-order least-square gradient
63  // Calculate the second-order least-square gradient
64  tmp<GeometricField<GradType, fvPatchField, volMesh>> tsecondfGrad
65  = leastSquaresGrad<Type>(mesh).grad
66  (
67  vsf,
68  "leastSquaresGrad(" + vsf.name() + ")"
69  );
70  const GeometricField<GradType, fvPatchField, volMesh>& secondfGrad =
71  tsecondfGrad();
72 
73  tmp<GeometricField<GradType, fvPatchField, volMesh>> tfGrad
74  (
75  new GeometricField<GradType, fvPatchField, volMesh>
76  (
77  IOobject
78  (
79  name,
80  vsf.instance(),
81  mesh,
82  IOobject::NO_READ,
83  IOobject::NO_WRITE
84  ),
85  secondfGrad
86  )
87  );
88  GeometricField<GradType, fvPatchField, volMesh>& fGrad = tfGrad.ref();
89 
90  const vectorField& C = mesh.C();
91 
92  const surfaceScalarField& lambda = mesh.weights();
93 
94  // Get reference to least square vectors
95  const leastSquaresVectors& lsv = leastSquaresVectors::New(mesh);
96  const surfaceVectorField& ownLs = lsv.pVectors();
97  const surfaceVectorField& neiLs = lsv.nVectors();
98 
99  // owner/neighbour addressing
100  const labelUList& own = mesh.owner();
101  const labelUList& nei = mesh.neighbour();
102 
103  // Assemble the fourth-order gradient
104 
105  // Internal faces
106  forAll(own, facei)
107  {
108  Type dDotGradDelta = 0.5*
109  (
110  (C[nei[facei]] - C[own[facei]])
111  & (secondfGrad[nei[facei]] - secondfGrad[own[facei]])
112  );
113 
114  fGrad[own[facei]] -= lambda[facei]*ownLs[facei]*dDotGradDelta;
115  fGrad[nei[facei]] -= (1.0 - lambda[facei])*neiLs[facei]*dDotGradDelta;
116  }
117 
118  // Boundary faces
119  forAll(vsf.boundaryField(), patchi)
120  {
121  if (secondfGrad.boundaryField()[patchi].coupled())
122  {
123  const fvsPatchVectorField& patchOwnLs =
124  ownLs.boundaryField()[patchi];
125 
126  const scalarField& lambdap = lambda.boundaryField()[patchi];
127 
128  const fvPatch& p = vsf.boundaryField()[patchi].patch();
129 
130  const labelUList& faceCells = p.faceCells();
131 
132  // Build the d-vectors
133  vectorField pd(p.delta());
134 
135  const Field<GradType> neighbourSecondfGrad
136  (
137  secondfGrad.boundaryField()[patchi].patchNeighbourField()
138  );
139 
140  forAll(faceCells, patchFacei)
141  {
142  fGrad[faceCells[patchFacei]] -=
143  0.5*lambdap[patchFacei]*patchOwnLs[patchFacei]
144  *(
145  pd[patchFacei]
146  & (
147  neighbourSecondfGrad[patchFacei]
148  - secondfGrad[faceCells[patchFacei]]
149  )
150  );
151  }
152  }
153  }
154 
155  fGrad.correctBoundaryConditions();
157 
158  return tfGrad;
159 }
160 
161 
162 // ************************************************************************* //
fvsPatchField< vector > fvsPatchVectorField
tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh >> grad(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Definition: fvcGrad.C:52
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
type
Types of root.
Definition: Roots.H:52
GeometricField< vector, fvsPatchField, surfaceMesh > surfaceVectorField
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:66
volVectorField vectorField(fieldObject, mesh)
typeOfRank< typename pTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank) >::type type
Definition: products.H:90
Generic GeometricField class.
UList< label > labelUList
Definition: UList.H:64
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Mesh data needed to do the Finite Volume discretisation.
Definition: volMesh.H:53
dynamicFvMesh & mesh
U correctBoundaryConditions()
volScalarField scalarField(fieldObject, mesh)
label patchi
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.
A class for managing temporary objects.
Definition: PtrList.H:53
GeometricField< scalar, fvsPatchField, surfaceMesh > surfaceScalarField