31 template<
class ThermoType>
43 chemisTree_(chemistry, this->coeffsDict_),
44 scaleFactor_(chemistry.
nEqns() + 1, 1),
45 runTime_(chemistry.
time()),
48 this->coeffsDict_.lookupOrDefault(
"chPMaxLifeTime", INT_MAX)
50 maxGrowth_(this->coeffsDict_.lookupOrDefault(
"maxGrowth", INT_MAX)),
51 checkEntireTreeInterval_
53 this->coeffsDict_.lookupOrDefault(
"checkEntireTreeInterval", INT_MAX)
57 this->coeffsDict_.lookupOrDefault
60 (chemisTree_.maxNLeafs() - 1)
61 /(
log(scalar(chemisTree_.maxNLeafs()))/
log(2.0))
66 this->coeffsDict_.lookupOrDefault
68 "minBalanceThreshold", 0.1*chemisTree_.maxNLeafs()
71 MRURetrieve_(this->coeffsDict_.lookupOrDefault(
"MRURetrieve",
false)),
72 maxMRUSize_(this->coeffsDict_.lookupOrDefault(
"maxMRUSize", 0)),
74 growPoints_(this->coeffsDict_.lookupOrDefault(
"growPoints",
true)),
78 cleaningRequired_(
false)
82 dictionary scaleDict(this->coeffsDict_.subDict(
"scaleFactor"));
83 label Ysize = this->chemistry_.Y().size();
84 scalar otherScaleFactor = scaleDict.
lookup<scalar>(
"otherSpecies");
85 for (
label i=0; i<Ysize; i++)
87 if (!scaleDict.found(this->chemistry_.Y()[i].member()))
89 scaleFactor_[i] = otherScaleFactor;
94 scaleDict.lookup<scalar>(this->chemistry_.Y()[i].member());
97 scaleFactor_[Ysize] = scaleDict.lookup<scalar>(
"Temperature");
98 scaleFactor_[Ysize + 1] = scaleDict.lookup<scalar>(
"Pressure");
99 scaleFactor_[Ysize + 2] = scaleDict.lookup<scalar>(
"deltaT");
104 nRetrievedFile_ = chemistry.
logFile(
"found_isat.out");
105 nGrowthFile_ = chemistry.
logFile(
"growth_isat.out");
106 nAddFile_ = chemistry.
logFile(
"add_isat.out");
107 sizeFile_ = chemistry.
logFile(
"size_isat.out");
114 template<
class ThermoType>
121 template<
class ThermoType>
127 if (maxMRUSize_ > 0 && MRURetrieve_)
130 bool isInList =
false;
133 for ( ; iter != MRUList_.
end(); ++iter)
144 if (iter() != MRUList_.
first())
147 MRUList_.remove(iter);
150 MRUList_.insert(phi0);
155 if (MRUList_.size() == maxMRUSize_)
157 MRUList_.remove(iter);
158 MRUList_.insert(phi0);
162 MRUList_.insert(phi0);
169 template<
class ThermoType>
177 label nEqns = this->chemistry_.nEqns();
178 bool mechRedActive = this->chemistry_.mechRed()->
active();
179 Rphiq = phi0->
Rphi();
186 for (
label i=0; i<nEqns-3; i++)
190 label si = completeToSimplified[i];
194 for (
label j=0; j<nEqns-2; j++)
196 label sj = completeToSimplified[j];
199 Rphiq[i] += gradientsMatrix(si, sj)*dphi[j];
213 Rphiq[i] =
max(0, Rphiq[i]);
219 Rphiq[i] =
max(0, Rphiq[i]);
224 for (
label j=0; j<nEqns; j++)
226 Rphiq[i] += gradientsMatrix(i, j)*dphi[j];
230 Rphiq[i] =
max(0, Rphiq[i]);
236 template<
class ThermoType>
252 if (phi0->
nGrowth() > maxGrowth_)
254 cleaningRequired_ =
true;
264 return phi0->
grow(phiq);
274 template<
class ThermoType>
278 bool treeModified(
false);
286 chemisTree_.treeSuccessor(x);
288 scalar elapsedTimeSteps = this->chemistry_.timeSteps() - x->
timeTag();
290 if ((elapsedTimeSteps > chPMaxLifeTime_) || (x->
nGrowth() > maxGrowth_))
292 chemisTree_.deleteLeaf(x);
305 chemisTree_.size() > minBalanceThreshold_
306 && chemisTree_.depth() >
307 maxDepthFactor_*
log(scalar(chemisTree_.size()))/
log(2.0)
310 chemisTree_.balance();
316 return (treeModified && !chemisTree_.isFull());
320 template<
class ThermoType>
330 bool mechRedActive = this->chemistry_.mechRed()->
active();
331 label speciesNumber = this->chemistry_.nSpecie();
333 for (
label i=0; i<speciesNumber; i++)
338 s2c = this->chemistry_.simplifiedToCompleteIndex()[i];
340 Rcq[i] = rhoi*Rphiq[s2c]/this->chemistry_.specieThermos()[s2c].W();
342 Rcq[speciesNumber] = Rphiq[Rphiq.
size() - 3];
343 Rcq[speciesNumber + 1] = Rphiq[Rphiq.
size() - 2];
344 Rcq[speciesNumber + 2] = Rphiq[Rphiq.
size() - 1];
356 this->chemistry_.jacobian(runTime_.value(), Rcq, li, dcdt, A);
360 for (
label i=0; i<speciesNumber; i++)
366 si = this->chemistry_.simplifiedToCompleteIndex()[i];
369 for (
label j=0; j<speciesNumber; j++)
374 sj = this->chemistry_.simplifiedToCompleteIndex()[j];
377 -dt*this->chemistry_.specieThermos()[si].W()
378 /this->chemistry_.specieThermos()[sj].W();
383 A(i, speciesNumber) *=
384 -dt*this->chemistry_.specieThermos()[si].W()/rhoi;
385 A(i, speciesNumber + 1) *=
386 -dt*this->chemistry_.specieThermos()[si].W()/rhoi;
391 for (
label i=0; i<speciesNumber; i++)
396 si = this->chemistry_.simplifiedToCompleteIndex()[i];
399 A(speciesNumber, i) *=
400 -dt*rhoi/this->chemistry_.specieThermos()[si].W();
401 A(speciesNumber + 1, i) *=
402 -dt*rhoi/this->chemistry_.specieThermos()[si].W();
405 A(speciesNumber, speciesNumber) = -dt*A(speciesNumber, speciesNumber) + 1;
407 A(speciesNumber + 1, speciesNumber + 1) =
408 -dt*A(speciesNumber + 1, speciesNumber + 1) + 1;
410 A(speciesNumber + 2, speciesNumber + 2) = 1;
419 for (
label i=0; i<speciesNumber; i++)
421 A(speciesNumber, i) = 0;
422 A(speciesNumber + 1, i) = 0;
429 template<
class ThermoType>
436 bool retrieved(
false);
440 if (chemisTree_.size())
442 chemisTree_.binaryTreeSearch(phiq, chemisTree_.root(),
phi0);
447 if (phi0->
inEOA(phiq))
453 else if (chemisTree_.secondaryBTSearch(phiq, phi0))
457 else if (MRURetrieve_)
462 >::iterator iter = MRUList_.begin();
464 for ( ; iter != MRUList_.end(); ++iter)
467 if (phi0->
inEOA(phiq))
479 lastSearch_ =
nullptr;
485 scalar elapsedTimeSteps =
486 this->chemistry_.timeSteps() - phi0->
timeTag();
490 if (elapsedTimeSteps > chPMaxLifeTime_ && !phi0->
toRemove())
492 cleaningRequired_ =
true;
495 lastSearch_->lastTimeUsed() = this->chemistry_.timeSteps();
497 calcNewC(phi0, phiq, Rphiq);
510 template<
class ThermoType>
520 label growthOrAddFlag = 1;
523 if (lastSearch_ && growPoints_)
525 if (grow(lastSearch_, phiq, Rphiq))
529 addToMRU(lastSearch_);
531 return growthOrAddFlag;
538 if (chemisTree().isFull())
543 if (!cleanAndBalance())
553 >::iterator iter = MRUList_.begin();
554 for ( ; iter != MRUList_.end(); ++iter)
562 chemisTree().clear();
572 chemisTree().insertNewLeaf
588 lastSearch_ =
nullptr;
592 label ASize = this->chemistry_.nEqns() + 1;
594 computeA(A, Rphiq, li, rho, deltaT);
596 chemisTree().insertNewLeaf
606 if (lastSearch_ !=
nullptr)
608 addToMRU(lastSearch_);
612 return growthOrAddFlag;
616 template<
class ThermoType>
622 << runTime_.timeOutputValue() <<
" " << nRetrieved_ <<
endl;
626 << runTime_.timeOutputValue() <<
" " << nGrowth_ <<
endl;
630 << runTime_.timeOutputValue() <<
" " << nAdd_ <<
endl;
634 << runTime_.timeOutputValue() <<
" " << this->size() <<
endl;
Extends standardChemistryModel by adding the TDAC method.
#define forAll(list, i)
Loop across all elements in list.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
const scalarSquareMatrix & A() const
dimensionedScalar log(const dimensionedScalar &ds)
A list of keyword definitions, which are a keyword followed by any number of values (e...
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
Class to perform the LU decomposition on a symmetric matrix.
Template class for non-intrusive linked lists.
T & first()
Return the first entry added.
void size(const label)
Override size to be inconsistent with allocated storage.
bool checkSolution(const scalarField &phiq, const scalarField &Rphiq)
If phiq is not in the EOA, then the mapping is computed.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Leaf of the binary tree. The chemPoint stores the composition 'phi', the mapping of this composition ...
List< label > & completeToSimplifiedIndex()
virtual bool retrieve(const Foam::scalarField &phiq, scalarField &Rphiq)
Find the closest stored leaf of phiQ and store the result in.
ISAT(const dictionary &chemistryProperties, TDACChemistryModel< ThermoType > &chemistry)
Construct from dictionary.
label size() const
Return the number of elements in matrix (m*n)
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
virtual label add(const scalarField &phiq, const scalarField &Rphiq, const label li, const scalar rho, const scalar deltaT)
Add information to the tabulation.
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
bool grow(const scalarField &phiq)
More details about the minimum-volume ellipsoid covering an.
const scalarField & phi() const
basicChemistryModel & chemistry
const scalarField & Rphi() const
An abstract class for chemistry tabulation.
const Time & time() const
Return time.
virtual label nEqns() const
Number of ODE's to solve.
void increaseNumRetrieve()
Increases the number of retrieves the chempoint has generated.
bool inEOA(const scalarField &phiq)
To RETRIEVE the mapping from the stored chemPoint phi, the query.
autoPtr< OFstream > logFile(const word &name) const
Create and return a TDAC log file of the given name.
Implementation of the ISAT (In-situ adaptive tabulation), for chemistry calculation.
const dimensionedScalar phi0
Magnetic flux quantum: default SI units: [Wb].
void deleteDemandDrivenData(DataPtr &dataPtr)
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
void inv(scalarSquareMatrix &M) const
Set M to the inverse of this square matrix.
virtual void writePerformance()