linearUpwindTemplates.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-2022 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 
28 // * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
29 
30 template<class Type>
32 (
33  const fvMesh& mesh,
34  const surfaceScalarField& faceFlux
35 )
36 :
37  upwind<Type>(mesh, faceFlux),
38  gradSchemeName_("grad")
39 {}
40 
41 
42 template<class Type>
44 (
45  const fvMesh& mesh,
46  Istream& schemeData
47 )
48 :
49  upwind<Type>(mesh, schemeData),
50  gradSchemeName_(schemeData)
51 {}
52 
53 
54 template<class Type>
56 (
57  const fvMesh& mesh,
58  const surfaceScalarField& faceFlux,
59  Istream& schemeData
60 )
61 :
62  upwind<Type>(mesh, faceFlux, schemeData),
63  gradSchemeName_(schemeData)
64 {}
65 
66 
67 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
68 
69 template<class Type>
72 (
73  const VolField<Type>& vf
74 ) const
75 {
76  const fvMesh& mesh = this->mesh();
77 
78  tmp<SurfaceField<Type>> tsfCorr
79  (
81  (
82  "linearUpwind::correction(" + vf.name() + ')',
83  mesh,
85  )
86  );
87 
88  SurfaceField<Type>& sfCorr = tsfCorr.ref();
89 
90  const surfaceScalarField& faceFlux = this->faceFlux_;
91 
92  const labelList& owner = mesh.owner();
93  const labelList& neighbour = mesh.neighbour();
94 
95  const volVectorField& C = mesh.C();
96  const surfaceVectorField& Cf = mesh.Cf();
97 
98  tmp<fv::gradScheme<scalar>> gradScheme_
99  (
101  (
102  mesh,
103  mesh.schemes().grad(gradSchemeName_)
104  )
105  );
106 
107  for (direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
108  {
109  tmp<volVectorField> tgradVf =
110  gradScheme_().grad(vf.component(cmpt), gradSchemeName_);
111 
112  const volVectorField& gradVf = tgradVf();
113 
114  forAll(faceFlux, facei)
115  {
116  const label celli =
117  (faceFlux[facei] > 0) ? owner[facei] : neighbour[facei];
118 
119  setComponent(sfCorr[facei], cmpt) =
120  (Cf[facei] - C[celli]) & gradVf[celli];
121  }
122 
123  typename SurfaceField<Type>::
124  Boundary& bSfCorr = sfCorr.boundaryFieldRef();
125 
126  forAll(bSfCorr, patchi)
127  {
128  fvsPatchField<Type>& pSfCorr = bSfCorr[patchi];
129 
130  if (pSfCorr.coupled())
131  {
132  const labelUList& pOwner = mesh.boundary()[patchi].faceCells();
133  const vectorField& pCf = Cf.boundaryField()[patchi];
134  const scalarField& pFaceFlux = faceFlux.boundaryField()[patchi];
135 
136  const vectorField pGradVfNei
137  (
138  gradVf.boundaryField()[patchi].patchNeighbourField()
139  );
140 
141  // Build the d-vectors
142  const vectorField pd
143  (
144  Cf.boundaryField()[patchi].patch().delta()
145  );
146 
147  forAll(pOwner, facei)
148  {
149  label own = pOwner[facei];
150 
151  if (pFaceFlux[facei] > 0)
152  {
153  setComponent(pSfCorr[facei], cmpt) =
154  (pCf[facei] - C[own])
155  & gradVf[own];
156  }
157  else
158  {
159  setComponent(pSfCorr[facei], cmpt) =
160  (pCf[facei] - pd[facei] - C[own])
161  & pGradVfNei[facei];
162  }
163  }
164  }
165  }
166  }
167 
168  return tsfCorr;
169 }
170 
171 
172 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Graphite solid properties.
Definition: C.H:51
const dimensionSet & dimensions() const
Return dimensions.
Generic GeometricField class.
const Boundary & boundaryField() const
Return const-reference to the boundary field.
tmp< GeometricField< cmptType, PatchField, GeoMesh > > component(const direction) const
Return a component of the field.
Boundary & boundaryFieldRef()
Return a reference to the boundary field.
const word & name() const
Return name.
Definition: IOobject.H:310
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
Generic dimensioned Type class.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:99
const volVectorField & C() const
Return cell centres.
const labelUList & owner() const
Internal face owner.
Definition: fvMesh.H:469
const fvBoundaryMesh & boundary() const
Return reference to boundary mesh.
Definition: fvMesh.C:857
const fvSchemes & schemes() const
Return the fvSchemes.
Definition: fvMesh.C:1751
const surfaceVectorField & Cf() const
Return face centres.
const labelUList & neighbour() const
Internal face neighbour.
Definition: fvMesh.H:475
ITstream & grad(const word &name) const
Definition: fvSchemes.C:485
Abstract base class for gradient schemes.
Definition: gradScheme.H:63
An abstract base class with a fat-interface to all derived classes covering all possible ways in whic...
Definition: fvsPatchField.H:83
virtual bool coupled() const
Return true if this patch field is coupled.
virtual tmp< SurfaceField< Type > > correction(const VolField< Type > &) const
Return the explicit correction to the face-interpolate.
linearUpwind(const fvMesh &mesh, const surfaceScalarField &faceFlux)
Construct from faceFlux.
A class for managing temporary objects.
Definition: tmp.H:55
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:181
Upwind interpolation scheme class.
Definition: upwind.H:54
label patchi
static const zero Zero
Definition: zero.H:97
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
label & setComponent(label &l, const direction)
Definition: label.H:86
uint8_t direction
Definition: direction.H:45