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 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 
34 
36 {
37  forAll(phiPsiCorrs[0], facei)
38  {
39  scalar sumPos = 0;
40  scalar sumNeg = 0;
41 
42  for (int phasei=0; phasei<phiPsiCorrs.size(); phasei++)
43  {
44  if (phiPsiCorrs[phasei][facei] > 0)
45  {
46  sumPos += phiPsiCorrs[phasei][facei];
47  }
48  else
49  {
50  sumNeg += phiPsiCorrs[phasei][facei];
51  }
52  }
53 
54  scalar sum = sumPos + sumNeg;
55 
56  if (sum > 0 && sumPos > VSMALL)
57  {
58  scalar lambda = -sumNeg/sumPos;
59 
60  for (int phasei=0; phasei<phiPsiCorrs.size(); phasei++)
61  {
62  if (phiPsiCorrs[phasei][facei] > 0)
63  {
64  phiPsiCorrs[phasei][facei] *= lambda;
65  }
66  }
67  }
68  else if (sum < 0 && sumNeg < -VSMALL)
69  {
70  scalar lambda = -sumPos/sumNeg;
71 
72  for (int phasei=0; phasei<phiPsiCorrs.size(); phasei++)
73  {
74  if (phiPsiCorrs[phasei][facei] < 0)
75  {
76  phiPsiCorrs[phasei][facei] *= lambda;
77  }
78  }
79  }
80  }
81 }
82 
83 
85 (
86  const UPtrList<const scalarField>& alphas,
87  UPtrList<scalarField>& phiPsiCorrs,
88  const labelHashSet& fixed
89 )
90 {
91  labelHashSet notFixed(identity(phiPsiCorrs.size()));
92  notFixed -= fixed;
93 
94  forAll(phiPsiCorrs[0], facei)
95  {
96  scalar alphaNotFixed = 0, corrNotFixed = 0;
97  forAllConstIter(labelHashSet, notFixed, iter)
98  {
99  alphaNotFixed += alphas[iter.key()][facei];
100  corrNotFixed += phiPsiCorrs[iter.key()][facei];
101  }
102 
103  scalar corrFixed = 0;
105  {
106  corrFixed += phiPsiCorrs[iter.key()][facei];
107  }
108 
109  const scalar sumCorr = corrNotFixed + corrFixed;
110 
111  const scalar lambda = - sumCorr/alphaNotFixed;
112 
113  forAllConstIter(labelHashSet, notFixed, iter)
114  {
115  phiPsiCorrs[iter.key()][facei] += lambda*alphas[iter.key()][facei];
116  }
117  }
118 }
119 
120 // ************************************************************************* //
profiling.H
Foam::UPtrList::size
label size() const noexcept
The number of elements in the list.
Definition: UPtrListI.H:90
phasei
label phasei
Definition: pEqn.H:27
Foam::HashSet< label, Hash< label > >
forAllConstIter
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object.
Definition: stdFoam.H:338
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
Foam::MULES::limitSum
void limitSum(UPtrList< scalarField > &phiPsiCorrs)
Definition: MULES.C:35
Foam::UPtrList
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
Definition: UPtrList.H:63
Foam::fixed
IOstream & fixed(IOstream &io)
Definition: IOstream.H:441
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.