FreeFOAM The Cross-Platform CFD Toolkit
linearUpwindV.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 | Copyright (C) 1991-2010 OpenCFD Ltd.
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 "linearUpwindV.H"
27 #include <finiteVolume/fvMesh.H>
28 #include <finiteVolume/volFields.H>
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 template<class Type>
36 (
38 ) const
39 {
40  const fvMesh& mesh = this->mesh();
41 
43  (
45  (
46  IOobject
47  (
48  vf.name(),
49  mesh.time().timeName(),
50  mesh
51  ),
52  mesh,
54  (
55  vf.name(),
56  vf.dimensions(),
58  )
59  )
60  );
61 
63 
64  const surfaceScalarField& faceFlux = this->faceFlux_;
65  const surfaceScalarField& w = mesh.weights();
66 
67  const labelList& own = mesh.owner();
68  const labelList& nei = mesh.neighbour();
69 
70  const vectorField& C = mesh.C();
71  const vectorField& Cf = mesh.Cf();
72 
75  gradVf = gradScheme_().grad(vf);
76 
77  forAll(faceFlux, facei)
78  {
79  vector maxCorr;
80 
81  if (faceFlux[facei] > 0.0)
82  {
83  maxCorr =
84  (1.0 - w[facei])
85  *(vf[nei[facei]] - vf[own[facei]]);
86 
87  sfCorr[facei] =
88  (Cf[facei] - C[own[facei]]) & gradVf[own[facei]];
89  }
90  else
91  {
92  maxCorr =
93  w[facei]*(vf[own[facei]] - vf[nei[facei]]);
94 
95  sfCorr[facei] =
96  (Cf[facei] - C[nei[facei]]) & gradVf[nei[facei]];
97  }
98 
99  scalar sfCorrs = magSqr(sfCorr[facei]);
100  scalar maxCorrs = sfCorr[facei] & maxCorr;
101 
102  if (sfCorrs > 0)
103  {
104  if (maxCorrs < 0)
105  {
106  sfCorr[facei] = vector::zero;
107  }
108  else if (sfCorrs > maxCorrs)
109  {
110  sfCorr[facei] *= maxCorrs/(sfCorrs + VSMALL);
111  }
112  }
113  else if (sfCorrs < 0)
114  {
115  if (maxCorrs > 0)
116  {
117  sfCorr[facei] = vector::zero;
118  }
119  else if (sfCorrs < maxCorrs)
120  {
121  sfCorr[facei] *= maxCorrs/(sfCorrs - VSMALL);
122  }
123  }
124  }
125 
126  return tsfCorr;
127 }
128 
129 
130 namespace Foam
131 {
133 }
134 
135 // ************************ vim: set sw=4 sts=4 et: ************************ //