35 Foam::scalar Foam::chemPointISAT::tolerance_;
39 void Foam::chemPointISAT::qrDecompose
52 for (
label i=
k; i<nCols; i++)
62 for (
label i=
k; i<nCols; i++)
67 for (
label i=
k; i<nCols; i++)
75 for (
label j=
k+1; j<nCols; j++)
78 for (
label i=
k; i<nCols; i++)
83 for (
label i=
k; i<nCols; i++)
91 d[nCols-1] =
R(nCols-1, nCols-1);
94 for (
label i=0; i<nCols; i++)
97 for (
label j=0; j<i; j++)
105 void Foam::chemPointISAT::qrUpdate
116 for (
k=
n-1;
k>=0;
k--)
129 for (
label i=
k-1; i>=0; i--)
136 else if (
mag(w[i]) >
mag(w[i+1]))
138 w[i] =
mag(w[i])*
sqrt(1.0 +
sqr(w[i+1]/w[i]));
142 w[i] =
mag(w[i+1])*
sqrt(1.0 +
sqr(w[i]/w[i+1]));
148 R(0, i) += w[0]*v[i];
158 void Foam::chemPointISAT::rotate
167 scalar
c, fact,
s, w,
y;
172 s = (
b >= 0 ? 1 : -1);
206 const scalar tolerance,
207 const label completeSpaceSize,
209 const label maxNumNewDim,
210 const Switch printProportion,
218 scaleFactor_(scaleFactor),
220 completeSpaceSize_(completeSpaceSize),
223 timeTag_(table.timeSteps()),
224 lastTimeUsed_(table.timeSteps()),
226 maxNumNewDim_(maxNumNewDim),
227 printProportion_(printProportion),
234 scaleFactor_[iddeltaT_] *= phi_[iddeltaT_]/tolerance_;
241 simplifiedToCompleteIndex_.
setSize(nActive_);
244 forAll(completeToSimplifiedIndex_, i)
249 forAll(simplifiedToCompleteIndex_, i)
255 const label reduOrCompDim =
265 for (
label i=0; i<reduOrCompDim; i++)
267 D[i] =
max(
S[i], 0.5);
276 for (
label i=0; i<reduOrCompDim; i++)
278 for (
label j=0; j<reduOrCompDim; j++)
300 qrDecompose(reduOrCompDim, LT_);
314 scaleFactor_(
p.scaleFactor()),
316 completeSpaceSize_(
p.completeSpaceSize()),
317 nGrowth_(
p.nGrowth()),
318 nActive_(
p.nActive()),
319 simplifiedToCompleteIndex_(
p.simplifiedToCompleteIndex()),
320 timeTag_(
p.timeTag()),
321 lastTimeUsed_(
p.lastTimeUsed()),
322 toRemove_(
p.toRemove()),
323 maxNumNewDim_(
p.maxNumNewDim()),
326 completeToSimplifiedIndex_(
p.completeToSimplifiedIndex())
328 tolerance_ =
p.tolerance();
343 table_.reduction() ? nActive_ : completeSpaceSize() - 3;
348 for (
label i=0; i<completeSpaceSize()-3; i++)
357 !(table_.reduction())
358 ||(table_.reduction() && completeToSimplifiedIndex_[i] != -1)
363 ? completeToSimplifiedIndex_[i]
366 for (
label j=si; j<dim; j++)
370 ? simplifiedToCompleteIndex_[j]
373 temp += LT_(si, j)*dphi[sj];
376 temp += LT_(si, dim)*dphi[idT_];
377 temp += LT_(si, dim+1)*dphi[idp_];
378 temp += LT_(si, dim+2)*dphi[iddeltaT_];
382 temp = dphi[i]/(tolerance_*scaleFactor_[i]);
385 epsTemp +=
sqr(temp);
387 if (printProportion_)
397 LT_(dim, dim)*dphi[idT_]
398 +LT_(dim, dim+1)*dphi[idp_]
399 +LT_(dim, dim+2)*dphi[iddeltaT_]
406 LT_(dim+1, dim+1)*dphi[idp_]
407 +LT_(dim+1, dim+2)*dphi[iddeltaT_]
410 epsTemp +=
sqr(LT_[dim+2][dim+2]*dphi[iddeltaT_]);
412 if (printProportion_)
416 LT_(dim, dim)*dphi[idT_]
417 + LT_(dim, dim+1)*dphi[idp_]
421 sqr(LT_(dim+1, dim+1)*dphi[idp_]);
424 sqr(LT_[dim+2][dim+2]*dphi[iddeltaT_]);
427 if (
sqrt(epsTemp) > 1 + tolerance_)
429 if (printProportion_)
433 for (
label i=0; i<completeSpaceSize(); i++)
442 if (maxIndex >= completeSpaceSize() - 3)
444 if (maxIndex == idT_)
448 else if (maxIndex == idp_)
452 else if (maxIndex == iddeltaT_)
459 propName = table_.chemistry().Y()[maxIndex].member();
462 Info<<
"Direction maximum impact to error in ellipsoid: "
465 Info<<
"Proportion to the total error on the retrieve: "
466 <<
max/(epsTemp+small) <<
endl;
491 table_.reduction() ? nActive_ : completeSpaceSize() - 2;
495 for (
label i=0; i<completeSpaceSize()-3; i++)
498 if (table_.reduction())
500 const label si = completeToSimplifiedIndex_[i];
505 for (
label j=0; j<dim; j++)
507 const label sj = simplifiedToCompleteIndex_[j];
508 dRl += Avar(si, j)*dphi[sj];
510 dRl += Avar(si, nActive_)*dphi[idT_];
511 dRl += Avar(si, nActive_+1)*dphi[idp_];
512 dRl += Avar(si, nActive_+2)*dphi[iddeltaT_];
521 for (
label j=0; j<completeSpaceSize(); j++)
523 dRl += Avar(i, j)*dphi[j];
526 eps2 +=
sqr((dR[i]-dRl)/scaleFactorV[i]);
530 if (eps2 > tolerance())
545 const label initNActiveSpecies(nActive_);
547 if (table_.reduction())
549 label activeAdded(0);
554 for (
label i=0; i<completeSpaceSize()-3; i++)
560 completeToSimplifiedIndex_[i] == -1
561 && table_.chemistry().cTos(i) != -1
571 completeToSimplifiedIndex_[i] != -1
572 && table_.chemistry().cTos(i) == -1
583 completeToSimplifiedIndex_[i] == -1
584 && table_.chemistry().cTos(i) == -1
594 if (activeAdded > maxNumNewDim_)
600 nActive_ += dimToAdd.
size();
601 simplifiedToCompleteIndex_.setSize(nActive_);
604 label si = nActive_ - dimToAdd.
size() + i;
606 simplifiedToCompleteIndex_[si] = dimToAdd[i];
607 completeToSimplifiedIndex_[dimToAdd[i]] = si;
616 if (nActive_ > initNActiveSpecies)
624 for (
label i=0; i<initNActiveSpecies; i++)
626 for (
label j=0; j<initNActiveSpecies; j++)
628 LT_(i, j) = LTvar(i, j);
629 A_(i, j) = Avar(i, j);
634 for (
label i=0; i<initNActiveSpecies; i++)
636 for (
label j=1; j>=0; j--)
638 LT_(i, nActive_+j)=LTvar(i, initNActiveSpecies+j);
639 A_(i, nActive_+j)=Avar(i, initNActiveSpecies+j);
640 LT_(nActive_+j, i)=LTvar(initNActiveSpecies+j, i);
641 A_(nActive_+j, i)=Avar(initNActiveSpecies+j, i);
645 LT_(nActive_, nActive_)=
646 LTvar(initNActiveSpecies, initNActiveSpecies);
647 A_(nActive_, nActive_)=
648 Avar(initNActiveSpecies, initNActiveSpecies);
649 LT_(nActive_+1, nActive_+1)=
650 LTvar(initNActiveSpecies+1, initNActiveSpecies+1);
651 A_(nActive_+1, nActive_+1)=
652 Avar(initNActiveSpecies+1, initNActiveSpecies+1);
653 LT_(nActive_+2, nActive_+2)=
654 LTvar(initNActiveSpecies+2, initNActiveSpecies+2);
655 A_(nActive_+2, nActive_+2)=
656 Avar(initNActiveSpecies+2, initNActiveSpecies+2);
658 for (
label i=initNActiveSpecies; i<nActive_;i++)
662 /(tolerance_*scaleFactor_[simplifiedToCompleteIndex_[i]]);
669 table_.reduction() ? nActive_ + 3 : completeSpaceSize();
673 scalar normPhiTilde = 0;
676 for (
label i=0; i<dim; i++)
678 for (
label j=i; j<dim-3; j++)
682 ? simplifiedToCompleteIndex_[j]
685 phiTilde[i] += LT_(i, j)*dphi[sj];
688 phiTilde[i] += LT_(i, dim-3)*dphi[idT_];
689 phiTilde[i] += LT_(i, dim-3+1)*dphi[idp_];
690 phiTilde[i] += LT_(i, dim-3+2)*dphi[iddeltaT_];
692 normPhiTilde +=
sqr(phiTilde[i]);
695 const scalar invSqrNormPhiTilde = 1.0/normPhiTilde;
696 normPhiTilde =
sqrt(normPhiTilde);
699 const scalar gamma = (1/normPhiTilde - 1)*invSqrNormPhiTilde;
703 for (
label i=0; i<dim; i++)
705 for (
label j=0; j<=i;j++)
707 v[i] += phiTilde[j]*LT_(j, i);
711 qrUpdate(LT_,dim, u, v);
#define forAll(list, i)
Loop across all elements in list.
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
void size(const label)
Override size to be inconsistent with allocated storage.
void setSize(const label)
Reset size of List.
Form T() const
Return the transpose of the matrix.
Singular value decomposition of a rectangular matrix.
const scalarRectangularMatrix & V() const
Return the square matrix V.
const scalarRectangularMatrix & U() const
Return U.
const scalarDiagonalMatrix & S() const
Return the singular values.
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Leaf of the binary tree. The chemPoint stores the composition 'phi', the mapping of this composition ...
bool inEOA(const scalarField &phiq)
To RETRIEVE the mapping from the stored chemPoint phi, the query.
const scalarField & scaleFactor() const
bool grow(const scalarField &phiq)
More details about the minimum-volume ellipsoid covering an.
bool checkSolution(const scalarField &phiq, const scalarField &Rphiq)
If phiq is not in the EOA, then the mapping is computed.
chemPointISAT(chemistryTabulationMethods::ISAT &table, const scalarField &phi, const scalarField &Rphi, const scalarSquareMatrix &A, const scalarField &scaleFactor, const scalar tolerance, const label completeSpaceSize, const label nActive, const label maxNumNewDim, const Switch printProportion, binaryNode *node=nullptr)
Construct from components.
const scalarSquareMatrix & A() const
const scalar & tolerance() const
label & completeSpaceSize()
const List< label > & simplifiedToCompleteIndex() const
Implementation of the ISAT (In-situ adaptive tabulation), for chemistry calculation.
const odeChemistryModel & chemistry()
bool reduction() const
Return true if reduction is applied to the state variables.
label sToc(const label si) const
Return the index in the complete set of species.
label cTos(const label ci) const
Return the index in the simplified set of species.
A class for handling words, derived from string.
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(lagrangian::Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(lagrangian::Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(lagrangian::Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.name(), lagrangian::cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
const volSymmTensorField R(IOobject("R", runTime.name(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE), turbulence->R())
const dimensionedScalar sigma
Stefan-Boltzmann constant: default SI units: [W/m^2/K^4].
const dimensionedScalar c
Speed of light in a vacuum.
tmp< fvMatrix< Type > > S(const Pair< tmp< volScalarField::Internal >> &, const VolField< Type > &)
static const coefficient D("D", dimTemperature, 257.14)
static const coefficient A("A", dimPressure, 611.21)
void rotate(const bool reverse, barycentric &coordinates)
Rotation transform. Corrects the coordinates when the track moves.
dimensionedScalar sign(const dimensionedScalar &ds)
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Ostream & endl(Ostream &os)
Add newline and flush stream.
void mag(LagrangianPatchField< scalar > &f, const LagrangianPatchField< Type > &f1)
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
void multiply(LagrangianPatchField< Type > &f, const LagrangianPatchField< scalar > &f1, const LagrangianPatchField< Type > &f2)
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
static scalar R(const scalar a, const scalar x)
SquareMatrix< scalar > scalarSquareMatrix
void sqr(LagrangianPatchField< typename outerProduct< Type, Type >::type > &f, const LagrangianPatchField< Type > &f1)
void sqrt(LagrangianPatchField< scalar > &f, const LagrangianPatchField< scalar > &f1)