skewCorrectedSnGrad.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) 2019 Zeljko Tukovic, FSB Zagreb.
9  Copyright (C) 2021 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 "skewCorrectedSnGrad.H"
30 #include "volFields.H"
31 #include "surfaceFields.H"
32 #include "linear.H"
33 #include "fvcGrad.H"
34 #include "gaussGrad.H"
35 
36 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
37 
38 template<class Type>
41 (
43 ) const
44 {
45  const fvMesh& mesh = this->mesh();
46 
48  (
49  IOobject
50  (
51  "snGradCorr("+vf.name()+')',
52  vf.instance(),
53  mesh,
54  IOobject::NO_READ,
55  IOobject::NO_WRITE
56  ),
57  mesh,
58  vf.dimensions()*mesh.nonOrthDeltaCoeffs().dimensions()
59  );
60  auto& ssf = tssf.ref();
61 
62  ssf.setOriented();
63  ssf = dimensioned<Type>(ssf.dimensions(), Zero);
64 
65 
66  typedef typename
68  CmptGradType;
69 
70  const labelUList& owner = mesh.owner();
71  const labelUList& neighbour = mesh.neighbour();
72 
73  const vectorField& Sf = mesh.Sf().internalField();
74  const scalarField& magSf = mesh.magSf().internalField();
75 
76  const vectorField& Cf = mesh.Cf().internalField();
77  const vectorField& C = mesh.C().internalField();
78 
79  const scalarField& deltaCoeffs =
80  mesh.deltaCoeffs().internalField();
81 
83  (
84  IOobject
85  (
86  "kP",
87  vf.instance(),
88  mesh,
89  IOobject::NO_READ,
90  IOobject::NO_WRITE
91  ),
92  mesh,
94  );
95  vectorField& kPI = kP.ref().field();
96 
98  (
99  IOobject
100  (
101  "kN",
102  vf.instance(),
103  mesh,
104  IOobject::NO_READ,
105  IOobject::NO_WRITE
106  ),
107  mesh,
109  );
110  vectorField& kNI = kN.ref().field();
111 
112  kPI = Cf - vectorField(C, owner);
113  kPI -= Sf*(Sf&kPI)/sqr(magSf);
114 
115  kNI = Cf - vectorField(C, neighbour);
116  kNI -= Sf*(Sf&kNI)/sqr(magSf);
117 
118  forAll(kP.boundaryField(), patchI)
119  {
120  if (kP.boundaryField()[patchI].coupled())
121  {
122  kP.boundaryFieldRef()[patchI] =
123  mesh.boundary()[patchI].Cf()
124  - mesh.boundary()[patchI].Cn();
125 
126  kP.boundaryFieldRef()[patchI] -=
127  mesh.boundary()[patchI].Sf()
128  *(
129  mesh.boundary()[patchI].Sf()
130  & kP.boundaryField()[patchI]
131  )
132  /sqr(mesh.boundary()[patchI].magSf());
133 
134  kN.boundaryFieldRef()[patchI] =
135  mesh.Cf().boundaryField()[patchI]
136  - (
137  mesh.boundary()[patchI].Cn()
138  + mesh.boundary()[patchI].delta()
139  );
140 
141  kN.boundaryFieldRef()[patchI] -=
142  mesh.boundary()[patchI].Sf()
143  *(
144  mesh.boundary()[patchI].Sf()
145  & kN.boundaryField()[patchI]
146  )
147  /sqr(mesh.boundary()[patchI].magSf());
148  }
149  }
150 
151  for (direction cmpt = 0; cmpt < pTraits<Type>::nComponents; ++cmpt)
152  {
154  (
156  (
157  mesh,
158  mesh.gradScheme("grad(" + vf.name() + ')')
159  )()
160  .grad(vf.component(cmpt))
161  );
162 
163  const Field<CmptGradType>& cmptGradI = cmptGrad.internalField();
164 
165  // Skewness and non-rothogonal correction
166  {
167  ssf.ref().field().replace
168  (
169  cmpt,
170  (
171  (kNI&Field<CmptGradType>(cmptGradI, neighbour))
172  - (kPI&Field<CmptGradType>(cmptGradI, owner))
173  )
174  *deltaCoeffs
175  );
176  }
177 
178  forAll(ssf.boundaryField(), patchI)
179  {
180  if (ssf.boundaryField()[patchI].coupled())
181  {
182  ssf.boundaryFieldRef()[patchI].replace
183  (
184  cmpt,
185  (
186  (
187  kN.boundaryField()[patchI]
188  & cmptGrad.boundaryField()[patchI]
189  .patchNeighbourField()
190  )
191  - (
192  kP.boundaryField()[patchI]
193  & cmptGrad.boundaryField()[patchI]
194  .patchInternalField()
195  )
196  )
197  *mesh.deltaCoeffs().boundaryField()[patchI]
198  );
199  }
200  }
201  }
202 
203  // // construct GeometricField<Type, fvsPatchField, surfaceMesh>
204  // tmp<GeometricField<Type, fvsPatchField, surfaceMesh>> tssf =
205  // linear<typename outerProduct<vector, Type>::type>(mesh).dotInterpolate
206  // (
207  // mesh.nonOrthCorrectionVectors(),
208  // gradScheme<Type>::New
209  // (
210  // mesh,
211  // mesh.gradScheme("grad(" + vf.name() + ')')
212  // )().grad(vf, "grad(" + vf.name() + ')')
213  // );
214  //
215  // tssf.ref().rename("snGradCorr(" + vf.name() + ')');
216 
217  return tssf;
218 }
219 
220 
221 template<class Type>
224 (
226 ) const
227 {
228  const fvMesh& mesh = this->mesh();
229 
231  (
232  IOobject
233  (
234  "snGradCorr("+vf.name()+')',
235  vf.instance(),
236  mesh,
237  IOobject::NO_READ,
238  IOobject::NO_WRITE
239  ),
240  mesh,
241  vf.dimensions()*mesh.nonOrthDeltaCoeffs().dimensions()
242  );
243  auto& ssf = tssf.ref();
244  ssf.setOriented();
245 
246  for (direction cmpt = 0; cmpt < pTraits<Type>::nComponents; ++cmpt)
247  {
248  ssf.replace
249  (
250  cmpt,
252  .fullGradCorrection(vf.component(cmpt))
253  );
254  }
255 
256  return tssf;
257 }
258 
259 
260 // ************************************************************************* //
volFields.H
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::GeometricField::component
tmp< GeometricField< cmptType, PatchField, GeoMesh > > component(const direction) const
Return a component of the field.
Foam::dimLength
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:52
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
skewCorrectedSnGrad.H
Foam::fac::grad
tmp< GeometricField< typename outerProduct< vector, Type >::type, faPatchField, areaMesh >> grad(const GeometricField< Type, faePatchField, edgeMesh > &ssf)
Definition: facGrad.C:56
Foam::fv::skewCorrectedSnGrad
Surface gradient scheme with skewness and full explicit non-orthogonal corrections.
Definition: skewCorrectedSnGrad.H:70
surfaceFields.H
Foam::surfaceFields.
Foam::GeometricField::internalField
const Internal & internalField() const
Return a const-reference to the dimensioned internal field.
Definition: GeometricFieldI.H:43
Foam::fv::skewCorrectedSnGrad::correction
virtual tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > correction(const GeometricField< Type, fvPatchField, volMesh > &) const
Definition: skewCorrectedSnGrad.C:224
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
Foam::dimensionedVector
dimensioned< vector > dimensionedVector
Dimensioned vector obtained from generic dimensioned type.
Definition: dimensionedVector.H:50
gaussGrad.H
Foam::tmp::ref
T & ref() const
Definition: tmpI.H:227
Foam::Field< vector >
Foam::fv::skewCorrectedSnGrad::fullGradCorrection
tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > fullGradCorrection(const GeometricField< Type, fvPatchField, volMesh > &) const
Definition: skewCorrectedSnGrad.C:41
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::dimensioned
Generic dimensioned Type class.
Definition: dimensionedScalarFwd.H:42
Foam::fv::gradScheme
Abstract base class for gradient schemes.
Definition: gradScheme.H:63
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
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
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:51
Foam::pTraits
A traits class, which is primarily used for primitives.
Definition: pTraits.H:56
fvcGrad.H
Calculate the gradient of the given field.
Foam::UList< label >
Foam::direction
uint8_t direction
Definition: direction.H:52
Foam::roots::type
type
Types of root.
Definition: Roots.H:54
Foam::C
Graphite solid properties.
Definition: C.H:50
Foam::GeometricField< Type, fvPatchField, volMesh >
Foam::outerProduct
Definition: products.H:106
Foam::GeometricField::boundaryField
const Boundary & boundaryField() const
Return const-reference to the boundary field.
Definition: GeometricFieldI.H:62