binaryNode.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) 2016-2021 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 "binaryNode.H"
27 
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29 
30 template<class ThermoType>
32 :
33  leafLeft_(nullptr),
34  leafRight_(nullptr),
35  nodeLeft_(nullptr),
36  nodeRight_(nullptr),
37  parent_(nullptr)
38 {}
39 
40 
41 template<class ThermoType>
43 (
44  chemPointISAT<ThermoType>* elementLeft,
45  chemPointISAT<ThermoType>* elementRight,
47 )
48 :
49  leafLeft_(elementLeft),
50  leafRight_(elementRight),
51  nodeLeft_(nullptr),
52  nodeRight_(nullptr),
53  parent_(parent),
54  v_(elementLeft->completeSpaceSize(), 0)
55 {
56  calcV(elementLeft, elementRight, v_);
57  a_ = calcA(elementLeft, elementRight);
58 }
59 
60 
61 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
62 
63 template<class ThermoType>
65 (
66  chemPointISAT<ThermoType>*& elementLeft,
67  chemPointISAT<ThermoType>*& elementRight,
68  scalarField& v
69 )
70 {
71  // LT is the transpose of the L matrix
72  scalarSquareMatrix& LT = elementLeft->LT();
73  bool mechReductionActive = elementLeft->chemistry().mechRed()->active();
74 
75  // Difference of composition in the full species domain
76  scalarField phiDif(elementRight->phi() - elementLeft->phi());
77  const scalarField& scaleFactor(elementLeft->scaleFactor());
78  scalar epsTol = elementLeft->tolerance();
79 
80  // v = LT.T()*LT*phiDif
81  for (label i=0; i<elementLeft->completeSpaceSize(); i++)
82  {
83  label si = i;
84  bool outOfIndexI = true;
85  if (mechReductionActive)
86  {
87  if (i<elementLeft->completeSpaceSize() - 3)
88  {
89  si = elementLeft->completeToSimplifiedIndex()[i];
90  outOfIndexI = (si == -1);
91  }
92  else // temperature and pressure
93  {
94  outOfIndexI = false;
95  const label dif = i - (elementLeft->completeSpaceSize() - 3);
96  si = elementLeft->nActiveSpecies() + dif;
97  }
98  }
99  if (!mechReductionActive || (mechReductionActive && !(outOfIndexI)))
100  {
101  v[i] = 0;
102  for (label j=0; j<elementLeft->completeSpaceSize(); j++)
103  {
104  label sj = j;
105  bool outOfIndexJ = true;
106  if (mechReductionActive)
107  {
108  if (j < elementLeft->completeSpaceSize() - 3)
109  {
110  sj = elementLeft->completeToSimplifiedIndex()[j];
111  outOfIndexJ = (sj==-1);
112  }
113  else
114  {
115  outOfIndexJ = false;
116  const label dif =
117  j - (elementLeft->completeSpaceSize() - 3);
118  sj = elementLeft->nActiveSpecies() + dif;
119  }
120  }
121  if
122  (
123  !mechReductionActive
124  ||(mechReductionActive && !(outOfIndexJ))
125  )
126  {
127  // Since L is a lower triangular matrix k=0->min(i, j)
128  for (label k=0; k<=min(si, sj); k++)
129  {
130  v[i] += LT(k, si)*LT(k, sj)*phiDif[j];
131  }
132  }
133  }
134  }
135  else
136  {
137  // When it is an inactive species the diagonal element of LT is
138  // 1/(scaleFactor*epsTol)
139  v[i] = phiDif[i]/sqr(scaleFactor[i]*epsTol);
140  }
141  }
142 }
143 
144 
145 template<class ThermoType>
147 (
148  chemPointISAT<ThermoType>* elementLeft,
149  chemPointISAT<ThermoType>* elementRight
150 )
151 {
152  scalarField phih((elementLeft->phi() + elementRight->phi())/2);
153  scalar a = 0;
154  forAll(phih, i)
155  {
156  a += v_[i]*phih[i];
157  }
158 
159  return a;
160 }
161 
162 
163 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
const scalar & tolerance()
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
scalar calcA(chemPointISAT< ThermoType > *elementLeft, chemPointISAT< ThermoType > *elementRight)
Compute a the product v^T.phih, with phih = (phi0 + phiq)/2.
Definition: binaryNode.C:147
const scalarSquareMatrix & LT() const
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Leaf of the binary tree. The chemPoint stores the composition &#39;phi&#39;, the mapping of this composition ...
List< label > & completeToSimplifiedIndex()
label k
Boltzmann constant.
scalarField v_
Definition: binaryNode.H:69
const scalar & a() const
Definition: binaryNode.H:176
binaryNode()
Construct null.
Definition: binaryNode.C:31
const scalarField & scaleFactor()
TDACChemistryModel< ThermoType > & chemistry()
Access to the TDACChemistryModel.
chemPointISAT< ThermoType > * leafLeft_
Element on the left.
Definition: binaryNode.H:55
Node of the binary tree.
Definition: binaryNode.H:49
const scalarField & phi() const
binaryNode< ThermoType > * parent_
Parent node.
Definition: binaryNode.H:67
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
binaryNode< ThermoType > * nodeRight_
Node which follows on the right.
Definition: binaryNode.H:64
label & completeSpaceSize()
binaryNode< ThermoType > * nodeLeft_
Node which follows on the left.
Definition: binaryNode.H:61
chemPointISAT< ThermoType > * leafRight_
Element on the right.
Definition: binaryNode.H:58
void calcV(chemPointISAT< ThermoType > *&elementLeft, chemPointISAT< ThermoType > *&elementRight, scalarField &v)
Compute vector v:
Definition: binaryNode.C:65