linearUpwind.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-2018 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 "linearUpwind.H"
27 #include "fvMesh.H"
28 
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
30 
31 template<class Type>
34 (
36 ) const
37 {
38  const fvMesh& mesh = this->mesh();
39 
41  (
43  (
44  IOobject
45  (
46  "linearUpwind::correction(" + vf.name() + ')',
47  mesh.time().timeName(),
48  mesh,
49  IOobject::NO_READ,
50  IOobject::NO_WRITE,
51  false
52  ),
53  mesh,
55  )
56  );
57 
59 
60  const surfaceScalarField& faceFlux = this->faceFlux_;
61 
62  const labelList& owner = mesh.owner();
63  const labelList& neighbour = mesh.neighbour();
64 
65  const volVectorField& C = mesh.C();
66  const surfaceVectorField& Cf = mesh.Cf();
67 
68  tmp<fv::gradScheme<scalar>> gradScheme_
69  (
71  (
72  mesh,
73  mesh.gradScheme(gradSchemeName_)
74  )
75  );
76 
77  for (direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
78  {
79  tmp<volVectorField> tgradVf =
80  gradScheme_().grad(vf.component(cmpt), gradSchemeName_);
81 
82  const volVectorField& gradVf = tgradVf();
83 
84  forAll(faceFlux, facei)
85  {
86  const label celli =
87  (faceFlux[facei] > 0) ? owner[facei] : neighbour[facei];
88 
89  setComponent(sfCorr[facei], cmpt) =
90  (Cf[facei] - C[celli]) & gradVf[celli];
91  }
92 
94  Boundary& bSfCorr = sfCorr.boundaryFieldRef();
95 
96  forAll(bSfCorr, patchi)
97  {
98  fvsPatchField<Type>& pSfCorr = bSfCorr[patchi];
99 
100  if (pSfCorr.coupled())
101  {
102  const labelUList& pOwner = mesh.boundary()[patchi].faceCells();
103  const vectorField& pCf = Cf.boundaryField()[patchi];
104  const scalarField& pFaceFlux = faceFlux.boundaryField()[patchi];
105 
106  const vectorField pGradVfNei
107  (
108  gradVf.boundaryField()[patchi].patchNeighbourField()
109  );
110 
111  // Build the d-vectors
112  const vectorField pd
113  (
114  Cf.boundaryField()[patchi].patch().delta()
115  );
116 
117  forAll(pOwner, facei)
118  {
119  label own = pOwner[facei];
120 
121  if (pFaceFlux[facei] > 0)
122  {
123  setComponent(pSfCorr[facei], cmpt) =
124  (pCf[facei] - C[own])
125  & gradVf[own];
126  }
127  else
128  {
129  setComponent(pSfCorr[facei], cmpt) =
130  (pCf[facei] - pd[facei] - C[own])
131  & pGradVfNei[facei];
132  }
133  }
134  }
135  }
136  }
137 
138  return tsfCorr;
139 }
140 
141 
142 template<>
145 (
146  const volVectorField& vf
147 ) const
148 {
149  const fvMesh& mesh = this->mesh();
150 
152  (
154  (
155  IOobject
156  (
157  "linearUpwind::correction(" + vf.name() + ')',
158  mesh.time().timeName(),
159  mesh,
160  IOobject::NO_READ,
161  IOobject::NO_WRITE,
162  false
163  ),
164  mesh,
166  )
167  );
168 
169  surfaceVectorField& sfCorr = tsfCorr.ref();
170 
171  const surfaceScalarField& faceFlux = this->faceFlux_;
172 
173  const labelList& owner = mesh.owner();
174  const labelList& neighbour = mesh.neighbour();
175 
176  const volVectorField& C = mesh.C();
177  const surfaceVectorField& Cf = mesh.Cf();
178 
179  tmp<fv::gradScheme<vector>> gradScheme_
180  (
182  (
183  mesh,
184  mesh.gradScheme(gradSchemeName_)
185  )
186  );
187 
188  tmp<volTensorField> tgradVf = gradScheme_().grad(vf, gradSchemeName_);
189  const volTensorField& gradVf = tgradVf();
190 
191  forAll(faceFlux, facei)
192  {
193  const label celli =
194  (faceFlux[facei] > 0) ? owner[facei] : neighbour[facei];
195  sfCorr[facei] = (Cf[facei] - C[celli]) & gradVf[celli];
196  }
197 
198 
199  typename surfaceVectorField::Boundary& bSfCorr = sfCorr.boundaryFieldRef();
200 
201  forAll(bSfCorr, patchi)
202  {
203  fvsPatchVectorField& pSfCorr = bSfCorr[patchi];
204 
205  if (pSfCorr.coupled())
206  {
207  const labelUList& pOwner = mesh.boundary()[patchi].faceCells();
208  const vectorField& pCf = Cf.boundaryField()[patchi];
209  const scalarField& pFaceFlux = faceFlux.boundaryField()[patchi];
210 
211  const tensorField pGradVfNei
212  (
213  gradVf.boundaryField()[patchi].patchNeighbourField()
214  );
215 
216  // Build the d-vectors
217  vectorField pd(Cf.boundaryField()[patchi].patch().delta());
218 
219  forAll(pOwner, facei)
220  {
221  label own = pOwner[facei];
222 
223  if (pFaceFlux[facei] > 0)
224  {
225  pSfCorr[facei] = (pCf[facei] - C[own]) & gradVf[own];
226  }
227  else
228  {
229  pSfCorr[facei] =
230  (pCf[facei] - pd[facei] - C[own]) & pGradVfNei[facei];
231  }
232  }
233  }
234  }
235 
236  return tsfCorr;
237 }
238 
239 
240 namespace Foam
241 {
243 }
244 
245 // ************************************************************************* //
#define makelimitedSurfaceInterpolationScheme(SS)
Graphite solid properties.
Definition: C.H:48
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
const word & name() const
Return name.
Definition: IOobject.H:297
const surfaceVectorField & Cf() const
Return face centres as surfaceVectorField.
const Boundary & boundaryField() const
Return const-reference to the boundary field.
uint8_t direction
Definition: direction.H:45
tmp< GeometricField< cmptType, PatchField, GeoMesh > > component(const direction) const
Return a component of the field.
Generic GeometricField class.
static word timeName(const scalar, const int precision=precision_)
Return time name of given scalar time.
Definition: Time.C:626
Generic dimensioned Type class.
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:243
const labelUList & neighbour() const
Internal face neighbour.
Definition: fvMesh.H:288
const dimensionSet & dimensions() const
Return dimensions.
dynamicFvMesh & mesh
virtual bool coupled() const
Return true if this patch field is coupled.
static const zero Zero
Definition: zero.H:97
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:61
ITstream & gradScheme(const word &name) const
Definition: fvSchemes.C:440
const labelUList & owner() const
Internal face owner.
Definition: fvMesh.H:282
Internal & ref()
Return a reference to the dimensioned internal field.
label patchi
Abstract base class for gradient schemes.
Definition: gradScheme.H:60
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
linearUpwind interpolation scheme class derived from upwind and returns upwind weighting factors and ...
Definition: linearUpwind.H:52
virtual tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > correction(const GeometricField< Type, fvPatchField, volMesh > &) const
Return the explicit correction to the face-interpolate.
Definition: linearUpwind.C:34
const volVectorField & C() const
Return cell centres as volVectorField.
A class for managing temporary objects.
Definition: PtrList.H:53
label & setComponent(label &l, const direction)
Definition: label.H:79
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
An abstract base class with a fat-interface to all derived classes covering all possible ways in whic...
Definition: fvsPatchField.H:65
Namespace for OpenFOAM.
const fvBoundaryMesh & boundary() const
Return reference to boundary mesh.
Definition: fvMesh.C:545