faNVDscheme.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) 2016-2017 Wikki Ltd
9  Copyright (C) 2022 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 "areaFields.H"
30 #include "edgeFields.H"
31 #include "facGrad.H"
32 
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37 
39 {
40  return phi;
41 }
42 
44 {
45  return magSqr(phi);
46 }
47 
49 {
50  return magSqr(phi);
51 }
52 
53 }
54 
55 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56 
57 template<class Type, class NVDweight>
59 (
61 ) const
62 {
63  const faMesh& mesh = this->mesh();
64 
65  tmp<edgeScalarField> tWeightingFactors
66  (
67  new edgeScalarField(mesh.edgeInterpolation::weights())
68  );
69  edgeScalarField& weightingFactors = tWeightingFactors.ref();
70 
71  scalarField& weights = weightingFactors.primitiveFieldRef();
72 
74  const areaScalarField& vf = tvf();
75 
76  const areaVectorField gradc(fac::grad(vf));
77 
78 // edgeVectorField d
79 // (
80 // mesh.Le()
81 // /(mesh.magLe()*mesh.edgeInterpolation::deltaCoeffs())
82 // );
83 
84 // if (!mesh.orthogonal())
85 // {
86 // d -=
87 // mesh.edgeInterpolation::correctionVectors()
88 // /mesh.edgeInterpolation::deltaCoeffs();
89 // }
90 
91  const labelUList& owner = mesh.owner();
92  const labelUList& neighbour = mesh.neighbour();
93  const vectorField& n = mesh.faceAreaNormals().internalField();
94  const vectorField& c = mesh.areaCentres().internalField();
95 
96  forAll(weights, edge)
97  {
98  vector d(c[neighbour[edge]] - c[owner[edge]]);
99 
100  if (edgeFlux_[edge] > 0)
101  {
102  d.removeCollinear(n[owner[edge]]);
103  }
104  else
105  {
106  d.removeCollinear(n[neighbour[edge]]);
107  }
108  d.normalise();
109  d *= mesh.edgeInterpolation::lPN().internalField()[edge];
110 
111  // Do not allow any mag(val) < SMALL
112  if (mag(d) < SMALL)
113  {
114  d = vector::uniform(SMALL);
115  }
116 
117  weights[edge] =
118  this->weight
119  (
120  weights[edge],
121  edgeFlux_[edge],
122  vf[owner[edge]],
123  vf[neighbour[edge]],
124  gradc[owner[edge]],
125  gradc[neighbour[edge]],
126  d
127  );
128  }
129 
130 
131  auto& bWeights = weightingFactors.boundaryFieldRef();
132 
133  forAll(bWeights, patchI)
134  {
135  if (bWeights[patchI].coupled())
136  {
137  scalarField& pWeights = bWeights[patchI];
138 
139  const scalarField& pEdgeFlux = edgeFlux_.boundaryField()[patchI];
140 
141  scalarField pVfP(vf.boundaryField()[patchI].patchInternalField());
142 
143  scalarField pVfN(vf.boundaryField()[patchI].patchNeighbourField());
144 
145  vectorField pGradcP
146  (
147  gradc.boundaryField()[patchI].patchInternalField()
148  );
149 
150  vectorField pGradcN
151  (
152  gradc.boundaryField()[patchI].patchNeighbourField()
153  );
154 
155  vectorField CP
156  (
157  mesh.areaCentres().boundaryField()[patchI].patchInternalField()
158  );
159 
160  vectorField CN
161  (
162  mesh.areaCentres().boundaryField()[patchI]
163  .patchNeighbourField()
164  );
165 
166  vectorField nP
167  (
168  mesh.faceAreaNormals().boundaryField()[patchI]
169  .patchInternalField()
170  );
171 
172  vectorField nN
173  (
174  mesh.faceAreaNormals().boundaryField()[patchI]
175  .patchNeighbourField()
176  );
177 
178  scalarField pLPN
179  (
180  mesh.edgeInterpolation::lPN().boundaryField()[patchI]
181  );
182 
183  forAll(pWeights, edgeI)
184  {
185  vector d(CN[edgeI] - CP[edgeI]);
186 
187  if (pEdgeFlux[edgeI] > 0)
188  {
189  d.removeCollinear(nP[edgeI]);
190  }
191  else
192  {
193  d.removeCollinear(nN[edgeI]);
194  }
195  d.normalise();
196  d *= pLPN[edgeI];
197 
198  // Do not allow any mag(val) < SMALL
199  if (mag(d) < SMALL)
200  {
201  d = vector::uniform(SMALL);
202  }
203 
204  pWeights[edgeI] =
205  this->weight
206  (
207  pWeights[edgeI],
208  pEdgeFlux[edgeI],
209  pVfP[edgeI],
210  pVfN[edgeI],
211  pGradcP[edgeI],
212  pGradcN[edgeI],
213  d
214  );
215  }
216  }
217  }
218 
219  return tWeightingFactors;
220 }
221 
222 
223 // ************************************************************************* //
Finite area mesh (used for 2-D non-Euclidian finite area method) defined using a patch of faces on a ...
Definition: faMesh.H:88
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
T & ref() const
Return non-const reference to the contents of a non-null managed pointer.
Definition: tmpI.H:210
bool coupled(solutionDict.getOrDefault("coupledEnergyField", false))
tmp< areaScalarField > limiter(const areaScalarField &phi)
Definition: faNVDscheme.C:31
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:413
Calculate the gradient of the given field.
dynamicFvMesh & mesh
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:59
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Vector< scalar > vector
Definition: vector.H:57
GeometricField< scalar, faePatchField, edgeMesh > edgeScalarField
Definition: edgeFieldsFwd.H:46
virtual tmp< edgeScalarField > weights(const GeometricField< Type, faPatchField, areaMesh > &) const
Return the interpolation weighting factors.
Definition: faNVDscheme.C:52
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
Internal::FieldType & primitiveFieldRef(const bool updateAccessTime=true)
Return a reference to the internal field values.
const dimensionedScalar c
Speed of light in a vacuum.
Boundary & boundaryFieldRef(const bool updateAccessTime=true)
Return a reference to the boundary field.
label n
Field< vector > vectorField
Specialisation of Field<T> for vector.
A class for managing temporary objects.
Definition: HashPtrTable.H:50
const Boundary & boundaryField() const noexcept
Return const-reference to the boundary field.
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
Namespace for OpenFOAM.
tmp< GeometricField< typename outerProduct< vector, Type >::type, faPatchField, areaMesh >> grad(const GeometricField< Type, faePatchField, edgeMesh > &ssf)
Definition: facGrad.C:49