Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
11License
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
35namespace Foam
36{
37
39{
40 return phi;
41}
42
44{
45 return magSqr(phi);
46}
47
49{
50 return magSqr(phi);
52
53}
54
55// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56
57template<class Type, class NVDweight>
59(
60 const GeometricField<Type, faPatchField, areaMesh>& phi
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
73 tmp<areaScalarField> tvf = limiter(phi);
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 // No zero-length vectors (after normalise)
112 if (d.magSqr() < ROOTSMALL)
113 {
114 d = vector::uniform(SMALL);
115 // OR: d = vector::uniform(0.57735*SMALL);
116 }
117
118 weights[edge] =
119 this->weight
120 (
121 weights[edge],
122 edgeFlux_[edge],
123 vf[owner[edge]],
124 vf[neighbour[edge]],
125 gradc[owner[edge]],
126 gradc[neighbour[edge]],
127 d
128 );
129 }
130
131
132 auto& bWeights = weightingFactors.boundaryFieldRef();
133
134 forAll(bWeights, patchI)
135 {
136 if (bWeights[patchI].coupled())
137 {
138 scalarField& pWeights = bWeights[patchI];
139
140 const scalarField& pEdgeFlux = edgeFlux_.boundaryField()[patchI];
141
142 scalarField pVfP(vf.boundaryField()[patchI].patchInternalField());
143
144 scalarField pVfN(vf.boundaryField()[patchI].patchNeighbourField());
145
146 vectorField pGradcP
147 (
148 gradc.boundaryField()[patchI].patchInternalField()
149 );
150
151 vectorField pGradcN
152 (
153 gradc.boundaryField()[patchI].patchNeighbourField()
154 );
155
156 vectorField CP
157 (
158 mesh.areaCentres().boundaryField()[patchI].patchInternalField()
159 );
160
161 vectorField CN
162 (
163 mesh.areaCentres().boundaryField()[patchI]
164 .patchNeighbourField()
165 );
166
167 vectorField nP
168 (
169 mesh.faceAreaNormals().boundaryField()[patchI]
170 .patchInternalField()
171 );
172
173 vectorField nN
174 (
175 mesh.faceAreaNormals().boundaryField()[patchI]
176 .patchNeighbourField()
177 );
178
179 scalarField pLPN
180 (
181 mesh.edgeInterpolation::lPN().boundaryField()[patchI]
182 );
183
184 forAll(pWeights, edgeI)
185 {
186 vector d(CN[edgeI] - CP[edgeI]);
187
188 if (pEdgeFlux[edgeI] > 0)
189 {
190 d.removeCollinear(nP[edgeI]);
191 }
192 else
193 {
194 d.removeCollinear(nN[edgeI]);
195 }
196 d.normalise();
197 d *= pLPN[edgeI];
198
199 // No zero-length vectors (after normalise)
200 if (d.magSqr() < ROOTSMALL)
201 {
202 d = vector::uniform(SMALL);
203 // OR: d = vector::uniform(0.57735*SMALL);
204 }
205
206 pWeights[edgeI] =
207 this->weight
208 (
209 pWeights[edgeI],
210 pEdgeFlux[edgeI],
211 pVfP[edgeI],
212 pVfN[edgeI],
213 pGradcP[edgeI],
214 pGradcN[edgeI],
215 d
216 );
217 }
218 }
219 }
220
221 return tWeightingFactors;
222}
223
224
225// ************************************************************************* //
label n
Generic GeometricField class.
Internal & ref(const bool updateAccessTime=true)
Same as internalFieldRef().
Internal::FieldType & primitiveFieldRef(const bool updateAccessTime=true)
Return a reference to the internal field values.
Boundary & boundaryFieldRef(const bool updateAccessTime=true)
Return a reference to the boundary field.
const Boundary & boundaryField() const noexcept
Return const-reference to the boundary field.
static Form uniform(const Cmpt &s)
Return a VectorSpace with all elements = s.
Vector< Cmpt > & normalise(const scalar tol=ROOTVSMALL)
Inplace normalise the vector by its magnitude.
Definition VectorI.H:114
scalar magSqr() const
The length (L2-norm) squared of the vector.
Definition VectorI.H:76
Vector< Cmpt > & removeCollinear(const Vector< Cmpt > &unitVec)
Inplace removal of components that are collinear to the given unit vector.
Definition VectorI.H:136
const faMesh & mesh() const
Return mesh reference.
An edge is a list of two vertex labels. This can correspond to a directed graph edge or an edge on a ...
Definition edge.H:62
Finite area mesh (used for 2-D non-Euclidian finite area method) defined using a patch of faces on a ...
Definition faMesh.H:140
virtual tmp< edgeScalarField > weights(const GeometricField< Type, faPatchField, areaMesh > &) const
Return the interpolation weighting factors.
Definition faNVDscheme.C:52
const edgeScalarField & edgeFlux_
Definition faNVDscheme.H:68
A class for managing temporary objects.
Definition tmp.H:75
T & ref() const
Return non-const reference to the contents of a non-null managed pointer.
Definition tmpI.H:235
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
bool coupled
dynamicFvMesh & mesh
Calculate the gradient of the given field.
tmp< GeometricField< typename outerProduct< vector, Type >::type, faPatchField, areaMesh > > grad(const GeometricField< Type, faePatchField, edgeMesh > &ssf)
Definition facGrad.C:51
Namespace for OpenFOAM.
GeometricField< tensor, faPatchField, areaMesh > areaTensorField
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
GeometricField< vector, faPatchField, areaMesh > areaVectorField
GeometricField< scalar, faePatchField, edgeMesh > edgeScalarField
GeometricField< scalar, faPatchField, areaMesh > areaScalarField
Field< vector > vectorField
Specialisation of Field<T> for vector.
Vector< scalar > vector
Definition vector.H:57
UList< label > labelUList
A UList of labels.
Definition UList.H:75
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
tmp< areaScalarField > limiter(const areaScalarField &phi)
Definition faNVDscheme.C:31
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299