MULES.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) 2011-2015 OpenFOAM Foundation
9  Copyright (C) 2016-2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
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 "MULES.H"
30 #include "profiling.H"
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
35 {
36  const label nPhases = phiPsiCorrs.size();
37 
38  forAll(phiPsiCorrs[0], facei)
39  {
40  scalar sumPos = 0;
41  scalar sumNeg = 0;
42 
43  for (label phasei = 0; phasei < nPhases; ++phasei)
44  {
45  if (phiPsiCorrs[phasei][facei] > 0)
46  {
47  sumPos += phiPsiCorrs[phasei][facei];
48  }
49  else
50  {
51  sumNeg += phiPsiCorrs[phasei][facei];
52  }
53  }
54 
55  scalar sum = sumPos + sumNeg;
56 
57  if (sum > 0 && sumPos > VSMALL)
58  {
59  scalar lambda = -sumNeg/sumPos;
60 
61  for (label phasei = 0; phasei < nPhases; ++phasei)
62  {
63  if (phiPsiCorrs[phasei][facei] > 0)
64  {
65  phiPsiCorrs[phasei][facei] *= lambda;
66  }
67  }
68  }
69  else if (sum < 0 && sumNeg < -VSMALL)
70  {
71  scalar lambda = -sumPos/sumNeg;
72 
73  for (label phasei = 0; phasei < nPhases; ++phasei)
74  {
75  if (phiPsiCorrs[phasei][facei] < 0)
76  {
77  phiPsiCorrs[phasei][facei] *= lambda;
78  }
79  }
80  }
81  }
82 }
83 
84 
86 (
87  const UPtrList<const scalarField>& alphas,
88  UPtrList<scalarField>& phiPsiCorrs,
89  const labelHashSet& fixed
90 )
91 {
92  labelHashSet notFixed(identity(phiPsiCorrs.size()));
93  notFixed -= fixed;
94 
95  forAll(phiPsiCorrs[0], facei)
96  {
97  scalar alphaNotFixed = 0, corrNotFixed = 0;
98  for (const label phasei : notFixed)
99  {
100  alphaNotFixed += alphas[phasei][facei];
101  corrNotFixed += phiPsiCorrs[phasei][facei];
102  }
103 
104  scalar corrFixed = 0;
105  for (const label phasei : fixed)
106  {
107  corrFixed += phiPsiCorrs[phasei][facei];
108  }
109 
110  const scalar sumCorr = corrNotFixed + corrFixed;
111 
112  const scalar lambda = - sumCorr/alphaNotFixed;
113 
114  for (const label phasei : notFixed)
115  {
116  phiPsiCorrs[phasei][facei] += lambda*alphas[phasei][facei];
117  }
118  }
119 }
120 
121 // ************************************************************************* //
profiling.H
Foam::UPtrList::size
label size() const noexcept
The number of elements in the list.
Definition: UPtrListI.H:106
phasei
label phasei
Definition: pEqn.H:27
Foam::HashSet< label, Hash< label > >
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::MULES::limitSum
void limitSum(UPtrList< scalarField > &phiPsiCorrs)
Definition: MULES.C:34
Foam::UPtrList
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
Definition: UPtrList.H:62
Foam::fixed
IOstream & fixed(IOstream &io)
Definition: IOstream.H:458
lambda
dimensionedScalar lambda("lambda", dimTime/sqr(dimLength), laminarTransport)
Foam::identity
labelList identity(const label len, label start=0)
Create identity map of the given length with (map[i] == i)
Definition: labelList.C:38
Foam::sum
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
Definition: DimensionedFieldFunctions.C:327
MULES.H
MULES: Multidimensional universal limiter for explicit solution.