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 -------------------------------------------------------------------------------
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 "skewCorrectedSnGrad.H"
29 #include "volFields.H"
30 #include "surfaceFields.H"
31 #include "linear.H"
32 #include "fvcGrad.H"
33 #include "gaussGrad.H"
34 
35 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
36 
37 template<class Type>
40 (
42 ) const
43 {
44  const fvMesh& mesh = this->mesh();
45 
47  (
48  IOobject
49  (
50  "snGradCorr("+vf.name()+')',
51  vf.instance(),
52  mesh,
53  IOobject::NO_READ,
54  IOobject::NO_WRITE
55  ),
56  mesh,
57  vf.dimensions()*mesh.nonOrthDeltaCoeffs().dimensions()
58  );
59  auto& ssf = tssf.ref();
60 
61  ssf.setOriented();
62  ssf = dimensioned<Type>(ssf.dimensions(), Zero);
63 
64 
65  typedef typename
67  CmptGradType;
68 
69  const labelUList& owner = mesh.owner();
70  const labelUList& neighbour = mesh.neighbour();
71 
72  const vectorField& Sf = mesh.Sf().internalField();
73  const scalarField& magSf = mesh.magSf().internalField();
74 
75  vectorField nf(Sf/magSf);
76 
77  const vectorField& Cf = mesh.Cf().internalField();
78  const vectorField& C = mesh.C().internalField();
79 
80  const scalarField& deltaCoeffs =
81  mesh.deltaCoeffs().internalField();
82 
84  (
85  IOobject
86  (
87  "kP",
88  vf.instance(),
89  mesh,
90  IOobject::NO_READ,
91  IOobject::NO_WRITE
92  ),
93  mesh,
95  );
96  vectorField& kPI = kP.ref().field();
97 
99  (
100  IOobject
101  (
102  "kN",
103  vf.instance(),
104  mesh,
105  IOobject::NO_READ,
106  IOobject::NO_WRITE
107  ),
108  mesh,
110  );
111  vectorField& kNI = kN.ref().field();
112 
113  kPI = Cf - vectorField(C, owner);
114  kPI -= Sf*(Sf&kPI)/sqr(magSf);
115 
116  kNI = Cf - vectorField(C, neighbour);
117  kNI -= Sf*(Sf&kNI)/sqr(magSf);
118 
119  forAll(kP.boundaryField(), patchI)
120  {
121  if (kP.boundaryField()[patchI].coupled())
122  {
123  kP.boundaryFieldRef()[patchI] =
124  mesh.boundary()[patchI].Cf()
125  - mesh.boundary()[patchI].Cn();
126 
127  kP.boundaryFieldRef()[patchI] -=
128  mesh.boundary()[patchI].Sf()
129  *(
130  mesh.boundary()[patchI].Sf()
131  & kP.boundaryField()[patchI]
132  )
133  /sqr(mesh.boundary()[patchI].magSf());
134 
135  kN.boundaryFieldRef()[patchI] =
136  mesh.Cf().boundaryField()[patchI]
137  - (
138  mesh.boundary()[patchI].Cn()
139  + mesh.boundary()[patchI].delta()
140  );
141 
142  kN.boundaryFieldRef()[patchI] -=
143  mesh.boundary()[patchI].Sf()
144  *(
145  mesh.boundary()[patchI].Sf()
146  & kN.boundaryField()[patchI]
147  )
148  /sqr(mesh.boundary()[patchI].magSf());
149  }
150  }
151 
152  for (direction cmpt = 0; cmpt < pTraits<Type>::nComponents; ++cmpt)
153  {
155  (
157  (
158  mesh,
159  mesh.gradScheme("grad(" + vf.name() + ')')
160  )()
161  .grad(vf.component(cmpt))
162  );
163 
164  const Field<CmptGradType>& cmptGradI = cmptGrad.internalField();
165 
166  // Skewness and non-rothogonal correction
167  {
168  ssf.ref().field().replace
169  (
170  cmpt,
171  (
172  (kNI&Field<CmptGradType>(cmptGradI, neighbour))
173  - (kPI&Field<CmptGradType>(cmptGradI, owner))
174  )
175  *deltaCoeffs
176  );
177  }
178 
179  forAll(ssf.boundaryField(), patchI)
180  {
181  if (ssf.boundaryField()[patchI].coupled())
182  {
183  ssf.boundaryFieldRef()[patchI].replace
184  (
185  cmpt,
186  (
187  (
188  kN.boundaryField()[patchI]
189  & cmptGrad.boundaryField()[patchI]
190  .patchNeighbourField()
191  )
192  - (
193  kP.boundaryField()[patchI]
194  & cmptGrad.boundaryField()[patchI]
195  .patchInternalField()
196  )
197  )
198  *mesh.deltaCoeffs().boundaryField()[patchI]
199  );
200  }
201  }
202  }
203 
204  // // construct GeometricField<Type, fvsPatchField, surfaceMesh>
205  // tmp<GeometricField<Type, fvsPatchField, surfaceMesh>> tssf =
206  // linear<typename outerProduct<vector, Type>::type>(mesh).dotInterpolate
207  // (
208  // mesh.nonOrthCorrectionVectors(),
209  // gradScheme<Type>::New
210  // (
211  // mesh,
212  // mesh.gradScheme("grad(" + vf.name() + ')')
213  // )().grad(vf, "grad(" + vf.name() + ')')
214  // );
215  //
216  // tssf.ref().rename("snGradCorr(" + vf.name() + ')');
217 
218  return tssf;
219 }
220 
221 
222 template<class Type>
225 (
227 ) const
228 {
229  const fvMesh& mesh = this->mesh();
230 
232  (
233  IOobject
234  (
235  "snGradCorr("+vf.name()+')',
236  vf.instance(),
237  mesh,
238  IOobject::NO_READ,
239  IOobject::NO_WRITE
240  ),
241  mesh,
242  vf.dimensions()*mesh.nonOrthDeltaCoeffs().dimensions()
243  );
244  auto& ssf = tssf.ref();
245  ssf.setOriented();
246 
247  for (direction cmpt = 0; cmpt < pTraits<Type>::nComponents; ++cmpt)
248  {
249  ssf.replace
250  (
251  cmpt,
253  .fullGradCorrection(vf.component(cmpt))
254  );
255  }
256 
257  return tssf;
258 }
259 
260 
261 // ************************************************************************* //
volFields.H
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
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:53
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
Simple central-difference snGrad scheme with non-orthogonal correction.
Definition: skewCorrectedSnGrad.H:59
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:225
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:228
Foam::Field< vector >
Foam::fv::skewCorrectedSnGrad::fullGradCorrection
tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > fullGradCorrection(const GeometricField< Type, fvPatchField, volMesh > &) const
Definition: skewCorrectedSnGrad.C:40
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::dimensioned
Generic dimensioned Type class.
Definition: dimensionedScalarFwd.H:43
Foam::fv::gradScheme
Abstract base class for gradient schemes.
Definition: gradScheme.H:62
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:83
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
Traits class for primitives.
Definition: pTraits.H:54
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