binaryNode.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) 2016-2017 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "binaryNode.H"
29 
30 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31 
32 template<class CompType, class ThermoType>
34 :
35  leafLeft_(nullptr),
36  leafRight_(nullptr),
37  nodeLeft_(nullptr),
38  nodeRight_(nullptr),
39  parent_(nullptr),
40  nAdditionalEqns_(0)
41 {}
42 
43 
44 template<class CompType, class ThermoType>
46 (
50 )
51 :
52  leafLeft_(elementLeft),
53  leafRight_(elementRight),
54  nodeLeft_(nullptr),
55  nodeRight_(nullptr),
56  parent_(parent),
57  v_(elementLeft->completeSpaceSize(), 0)
58 {
59  if (elementLeft->variableTimeStep())
60  {
61  nAdditionalEqns_ = 3;
62  }
63  else
64  {
65  nAdditionalEqns_ = 2;
66  }
67 
68  calcV(elementLeft, elementRight, v_);
69  a_ = calcA(elementLeft, elementRight);
70 }
71 
72 
73 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
74 
75 template<class CompType, class ThermoType>
77 (
80  scalarField& v
81 )
82 {
83  // LT is the transpose of the L matrix
84  scalarSquareMatrix& LT = elementLeft->LT();
85  bool mechReductionActive = elementLeft->chemistry().mechRed()->active();
86 
87  // Difference of composition in the full species domain
88  scalarField phiDif(elementRight->phi() - elementLeft->phi());
89  const scalarField& scaleFactor(elementLeft->scaleFactor());
90  scalar epsTol = elementLeft->tolerance();
91 
92  // v = LT.T()*LT*phiDif
93  for (label i=0; i<elementLeft->completeSpaceSize(); i++)
94  {
95  label si = i;
96  bool outOfIndexI = true;
97  if (mechReductionActive)
98  {
99  if (i<elementLeft->completeSpaceSize() - nAdditionalEqns_)
100  {
101  si = elementLeft->completeToSimplifiedIndex()[i];
102  outOfIndexI = (si == -1);
103  }
104  else // temperature and pressure
105  {
106  outOfIndexI = false;
107  const label dif =
108  i - (elementLeft->completeSpaceSize() - nAdditionalEqns_);
109  si = elementLeft->nActiveSpecies() + dif;
110  }
111  }
112  if (!mechReductionActive || (mechReductionActive && !(outOfIndexI)))
113  {
114  v[i] = 0;
115  for (label j=0; j<elementLeft->completeSpaceSize(); j++)
116  {
117  label sj = j;
118  bool outOfIndexJ = true;
119  if (mechReductionActive)
120  {
121  if (j < elementLeft->completeSpaceSize() - nAdditionalEqns_)
122  {
123  sj = elementLeft->completeToSimplifiedIndex()[j];
124  outOfIndexJ = (sj==-1);
125  }
126  else
127  {
128  outOfIndexJ = false;
129  const label dif =
130  j
131  - (
132  elementLeft->completeSpaceSize()
133  - nAdditionalEqns_
134  );
135  sj = elementLeft->nActiveSpecies() + dif;
136  }
137  }
138  if
139  (
140  !mechReductionActive
141  ||(mechReductionActive && !(outOfIndexJ))
142  )
143  {
144  // Since L is a lower triangular matrix k=0->min(i, j)
145  for (label k=0; k<=min(si, sj); k++)
146  {
147  v[i] += LT(k, si)*LT(k, sj)*phiDif[j];
148  }
149  }
150  }
151  }
152  else
153  {
154  // When it is an inactive species the diagonal element of LT is
155  // 1/(scaleFactor*epsTol)
156  v[i] = phiDif[i]/sqr(scaleFactor[i]*epsTol);
157  }
158  }
159 }
160 
161 
162 template<class CompType, class ThermoType>
164 (
167 )
168 {
169  scalarField phih((elementLeft->phi() + elementRight->phi())/2);
170  scalar a = 0;
171  forAll(phih, i)
172  {
173  a += v_[i]*phih[i];
174  }
175 
176  return a;
177 }
178 
179 
180 // ************************************************************************* //
Foam::binaryNode::calcA
scalar calcA(chemPointISAT< CompType, ThermoType > *elementLeft, chemPointISAT< CompType, ThermoType > *elementRight)
Compute a the product v^T.phih, with phih = (phi0 + phiq)/2.
Definition: binaryNode.C:164
Foam::chemPointISAT::LT
const scalarSquareMatrix & LT() const
Definition: chemPointISAT.H:332
Foam::binaryNode::binaryNode
binaryNode()
Construct null.
Definition: binaryNode.C:33
Foam::min
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::chemPointISAT::completeToSimplifiedIndex
List< label > & completeToSimplifiedIndex()
Definition: chemPointISAT.H:347
Foam::chemPointISAT::tolerance
const scalar & tolerance()
Definition: chemPointISAT.H:307
Foam::binaryNode::calcV
void calcV(chemPointISAT< CompType, ThermoType > *&elementLeft, chemPointISAT< CompType, ThermoType > *&elementRight, scalarField &v)
Compute vector v:
Definition: binaryNode.C:77
Foam::chemPointISAT::chemistry
TDACChemistryModel< CompType, ThermoType > & chemistry()
Access to the TDACChemistryModel.
Definition: chemPointISAT.H:277
Foam::Field< scalar >
Foam::chemPointISAT
Leaf of the binary tree. The chemPoint stores the composition 'phi', the mapping of this composition ...
Definition: chemPointISAT.H:142
Foam::chemPointISAT::variableTimeStep
bool variableTimeStep() const
Definition: chemPointISAT.H:398
Foam::chemPointISAT::completeSpaceSize
label & completeSpaceSize()
Definition: chemPointISAT.H:287
Foam::chemPointISAT::scaleFactor
const scalarField & scaleFactor()
Definition: chemPointISAT.H:302
binaryNode.H
Foam::chemPointISAT::phi
const scalarField & phi() const
Definition: chemPointISAT.H:292
Foam::SquareMatrix< scalar >
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:51
Foam::chemPointISAT::nActiveSpecies
label nActiveSpecies()
Definition: chemPointISAT.H:342
Foam::binaryNode
Node of the binary tree.
Definition: binaryNode.H:51
Foam::TDACChemistryModel::mechRed
autoPtr< chemistryReductionMethod< ReactionThermo, ThermoType > > & mechRed()
Definition: TDACChemistryModelI.H:73
k
label k
Boltzmann constant.
Definition: LISASMDCalcMethod2.H:41