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-2026 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 "GeometricField.H"
32 
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 
35 template<class Type>
37 <
39 >
41 (
42  const VolField<Type>& vsf,
43  const word& name
44 ) const
45 {
46  // The fourth-order gradient is calculated in two passes. First,
47  // the standard least-square gradient is assembled. Then, the
48  // fourth-order correction is added to the second-order accurate
49  // gradient to complete the accuracy.
50 
51  typedef typename outerProduct<vector, Type>::type GradType;
52 
53  const fvMesh& mesh = vsf.mesh();
54 
55  // Assemble the second-order least-square gradient
56  // Calculate the second-order least-square gradient
57  tmp<VolField<GradType>> tsecondfGrad
58  = leastSquaresGrad<Type>(mesh).grad
59  (
60  vsf,
61  "leastSquaresGrad(" + vsf.name() + ")"
62  );
63  const VolField<GradType>& secondfGrad =
64  tsecondfGrad();
65 
66  tmp<VolField<GradType>> tfGrad
67  (
69  (
70  name,
71  secondfGrad
72  )
73  );
74  VolField<GradType>& fGrad = tfGrad.ref();
75 
76  const vectorField& C = mesh.C();
77 
79 
80  // Get reference to least square vectors
81  const leastSquaresVectors& lsv = leastSquaresVectors::New(mesh);
82  const surfaceVectorField& ownLs = lsv.pVectors();
83  const surfaceVectorField& neiLs = lsv.nVectors();
84 
85  // owner/neighbour addressing
86  const labelUList& own = mesh.owner();
87  const labelUList& nei = mesh.neighbour();
88 
89  // Assemble the fourth-order gradient
90 
91  // Internal faces
92  forAll(own, facei)
93  {
94  Type dDotGradDelta = 0.5*
95  (
96  (C[nei[facei]] - C[own[facei]])
97  & (secondfGrad[nei[facei]] - secondfGrad[own[facei]])
98  );
99 
100  fGrad[own[facei]] -= lambda[facei]*ownLs[facei]*dDotGradDelta;
101  fGrad[nei[facei]] -= (1.0 - lambda[facei])*neiLs[facei]*dDotGradDelta;
102  }
103 
104  // Boundary faces
105  forAll(vsf.boundaryField(), patchi)
106  {
107  if (secondfGrad.boundaryField()[patchi].coupled())
108  {
109  const fvsPatchVectorField& patchOwnLs =
110  ownLs.boundaryField()[patchi];
111 
112  const scalarField& lambdap = lambda.boundaryField()[patchi];
113 
114  const fvPatch& p = vsf.boundaryField()[patchi].patch();
115 
116  const labelUList& faceCells = p.faceCells();
117 
118  // Build the d-vectors
119  vectorField pd(p.delta());
120 
121  const Field<GradType> neighbourSecondfGrad
122  (
123  secondfGrad.boundaryField()[patchi].patchNeighbourField()
124  );
125 
126  forAll(faceCells, patchFacei)
127  {
128  fGrad[faceCells[patchFacei]] -=
129  0.5*lambdap[patchFacei]*patchOwnLs[patchFacei]
130  *(
131  pd[patchFacei]
132  & (
133  neighbourSecondfGrad[patchFacei]
134  - secondfGrad[faceCells[patchFacei]]
135  )
136  );
137  }
138  }
139  }
140 
141  fGrad.correctBoundaryConditions();
143 
144  return tfGrad;
145 }
146 
147 
148 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
Generic GeometricField class.
const volVectorField & C() const
Return cell centres.
const labelUList & owner() const
Internal face owner.
Definition: fvMesh.H:490
const labelUList & neighbour() const
Internal face neighbour.
Definition: fvMesh.H:496
virtual tmp< VolField< typename outerProduct< vector, Type >::type > > calcGrad(const VolField< Type > &vsf, const word &name) const
Return the gradient of the given field to the gradScheme::grad.
const surfaceScalarField & weights() const
Return reference to linear difference weighting factors.
A class for managing temporary objects.
Definition: tmp.H:55
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
volScalarField scalarField(fieldObject, mesh)
volVectorField vectorField(fieldObject, mesh)
label patchi
U correctBoundaryConditions()
dimensionedScalar lambda(viscosity->lookup("lambda"))
static const coefficient C("C", dimTemperature, 234.5)
SurfaceField< scalar > surfaceScalarField
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
SurfaceField< vector > surfaceVectorField
UList< label > labelUList
Definition: UList.H:65
fvsPatchField< vector > fvsPatchVectorField
tmp< DimensionedField< TypeR, GeoMesh, Field > > New(const tmp< DimensionedField< TypeR, GeoMesh, Field >> &tdf1, const word &name, const dimensionSet &dimensions)
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
volScalarField & p