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-2026 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 "fvcGrad.H"
28 
29 // * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
30 
31 template<class Type>
33 (
34  const fvMesh& mesh,
35  const surfaceScalarField& faceFlux
36 )
37 :
38  upwind<Type>(mesh, faceFlux),
39  gradSchemeName_("grad")
40 {}
41 
42 
43 template<class Type>
45 (
46  const fvMesh& mesh,
47  Istream& schemeData
48 )
49 :
50  upwind<Type>(mesh, schemeData),
51  gradSchemeName_(schemeData)
52 {}
53 
54 
55 template<class Type>
57 (
58  const fvMesh& mesh,
59  const surfaceScalarField& faceFlux,
60  Istream& schemeData
61 )
62 :
63  upwind<Type>(mesh, faceFlux, schemeData),
64  gradSchemeName_(schemeData)
65 {}
66 
67 
68 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
69 
70 template<class Type>
73 (
74  const VolField<Type>& vf
75 ) const
76 {
77  const fvMesh& mesh = this->mesh();
78 
79  tmp<SurfaceField<Type>> tsfCorr
80  (
82  (
83  "linearUpwind::correction(" + vf.name() + ')',
84  mesh,
86  )
87  );
88 
89  SurfaceField<Type>& sfCorr = tsfCorr.ref();
90 
91  const surfaceScalarField& faceFlux = this->faceFlux_;
92 
93  const labelList& owner = mesh.owner();
94  const labelList& neighbour = mesh.neighbour();
95 
96  const volVectorField& C = mesh.C();
97  const surfaceVectorField& Cf = mesh.Cf();
98 
99  tmp<fv::gradScheme<scalar>> gradScheme_
100  (
102  (
103  mesh,
104  mesh.schemes().grad(gradSchemeName_)
105  )
106  );
107 
108  for (direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
109  {
110  tmp<volVectorField> tgradVf =
111  gradScheme_().grad(vf.component(cmpt), gradSchemeName_);
112 
113  const volVectorField& gradVf = tgradVf();
114 
115  forAll(faceFlux, facei)
116  {
117  const label celli =
118  (faceFlux[facei] > 0) ? owner[facei] : neighbour[facei];
119 
120  setComponent(sfCorr[facei], cmpt) =
121  (Cf[facei] - C[celli]) & gradVf[celli];
122  }
123 
124  typename SurfaceField<Type>::
125  Boundary& bSfCorr = sfCorr.boundaryFieldRef();
126 
127  forAll(bSfCorr, patchi)
128  {
129  fvsPatchField<Type>& pSfCorr = bSfCorr[patchi];
130 
131  if (pSfCorr.coupled())
132  {
133  const labelUList& pOwner = mesh.boundary()[patchi].faceCells();
134  const vectorField& pCf = Cf.boundaryField()[patchi];
135  const scalarField& pFaceFlux = faceFlux.boundaryField()[patchi];
136 
137  const vectorField pGradVfNei
138  (
139  gradVf.boundaryField()[patchi].patchNeighbourField()
140  );
141 
142  // Build the d-vectors
143  const vectorField pd
144  (
145  Cf.boundaryField()[patchi].patch().delta()
146  );
147 
148  forAll(pOwner, facei)
149  {
150  const label own = pOwner[facei];
151 
152  if (pFaceFlux[facei] > 0)
153  {
154  setComponent(pSfCorr[facei], cmpt) =
155  (pCf[facei] - C[own])
156  & gradVf[own];
157  }
158  else
159  {
160  setComponent(pSfCorr[facei], cmpt) =
161  (pCf[facei] - pd[facei] - C[own])
162  & pGradVfNei[facei];
163  }
164  }
165  }
166  }
167  }
168 
169  return tsfCorr;
170 }
171 
172 
173 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
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, GeoMesh, Field > > 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:307
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:98
const volVectorField & C() const
Return cell centres.
const labelUList & owner() const
Internal face owner.
Definition: fvMesh.H:490
const fvBoundaryMesh & boundary() const
Return reference to boundary mesh.
Definition: fvMesh.C:934
const fvSchemes & schemes() const
Return the fvSchemes.
Definition: fvMesh.C:1795
const surfaceVectorField & Cf() const
Return face centres.
const labelUList & neighbour() const
Internal face neighbour.
Definition: fvMesh.H:496
ITstream & grad(const word &name) const
Definition: fvSchemes.C:416
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:86
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:197
Upwind interpolation scheme class.
Definition: upwind.H:54
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
Calculate the gradient of the given field.
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