36 namespace chemistryTabulationMethods
57 coeffsDict_(chemistryProperties.subDict(
"tabulation")),
59 log_(coeffsDict_.lookupOrDefault<
Switch>(
"log", false)),
60 reduction_(chemistry_.reduction()),
61 chemisTree_(*this, coeffsDict_),
67 coeffsDict_.lookupOrDefault(
"chPMaxLifeTime", INT_MAX)
69 maxGrowth_(coeffsDict_.lookupOrDefault(
"maxGrowth", INT_MAX)),
70 checkEntireTreeInterval_
72 coeffsDict_.lookupOrDefault(
"checkEntireTreeInterval", INT_MAX)
76 coeffsDict_.lookupOrDefault
79 (chemisTree_.maxNLeafs() - 1)
85 coeffsDict_.lookupOrDefault
87 "minBalanceThreshold", 0.1*chemisTree_.maxNLeafs()
90 MRURetrieve_(coeffsDict_.lookupOrDefault(
"MRURetrieve", false)),
91 maxMRUSize_(coeffsDict_.lookupOrDefault(
"maxMRUSize", 0)),
93 growPoints_(coeffsDict_.lookupOrDefault(
"growPoints", true)),
94 tolerance_(coeffsDict_.lookupOrDefault(
"tolerance", 1
e-4)),
98 addNewLeafCpuTime_(0),
100 searchISATCpuTime_(0),
115 cleaningRequired_(false)
118 label Ysize = chemistry_.
Y().size();
119 scalar otherScaleFactor = scaleDict.
lookup<scalar>(
"otherSpecies");
120 for (
label i=0; i<Ysize; i++)
122 if (!scaleDict.
found(chemistry_.
Y()[i].member()))
124 scaleFactor_[i] = otherScaleFactor;
129 scaleDict.
lookup<scalar>(chemistry_.
Y()[i].member());
132 scaleFactor_[Ysize] = scaleDict.
lookup<scalar>(
"Temperature");
133 scaleFactor_[Ysize + 1] = scaleDict.
lookup<scalar>(
"Pressure");
134 scaleFactor_[Ysize + 2] = scaleDict.
lookup<scalar>(
"deltaT");
158 void Foam::chemistryTabulationMethods::ISAT::addToMRU
163 if (maxMRUSize_ > 0 && MRURetrieve_)
166 bool isInList =
false;
169 for ( ; iter != MRUList_.end(); ++iter)
180 if (iter() != MRUList_.first())
183 MRUList_.remove(iter);
186 MRUList_.insert(
phi0);
191 if (MRUList_.size() == maxMRUSize_)
193 MRUList_.remove(iter);
194 MRUList_.insert(
phi0);
198 MRUList_.insert(
phi0);
205 void Foam::chemistryTabulationMethods::ISAT::calcNewC
212 const label nEqns = chemistry_.nEqns();
213 const List<label>& completeToSimplified =
phi0->completeToSimplifiedIndex();
224 Rphiq =
phi0->Rphi();
225 for (
label i=0; i<nEqns - 2; i++)
229 const label si = completeToSimplified[i];
235 for (
label j=0; j<nEqns + 1; j++)
239 ? completeToSimplified[j]
240 : j - (nEqns - 2) +
phi0->nActive();
244 Rphiq[i] += gradientsMatrix(si, sj)*dphi[j];
257 for (
label j=0; j<nEqns + 1; j++)
259 Rphiq[i] += gradientsMatrix(i, j)*dphi[j];
264 Rphiq[i] =
max(0, Rphiq[i]);
269 bool Foam::chemistryTabulationMethods::ISAT::grow
284 if (
phi0->nGrowth() > maxGrowth_)
286 cleaningRequired_ =
true;
287 phi0->toRemove() =
true;
294 if (
phi0->checkSolution(phiq, Rphiq))
296 return phi0->grow(phiq);
306 bool Foam::chemistryTabulationMethods::ISAT::cleanAndBalance()
308 bool treeModified(
false);
312 chemPointISAT*
x = chemisTree_.treeMin();
315 chemPointISAT* xtmp = chemisTree_.treeSuccessor(
x);
317 const scalar elapsedTimeSteps = timeSteps() -
x->timeTag();
319 if ((elapsedTimeSteps > chPMaxLifeTime_) || (
x->nGrowth() > maxGrowth_))
321 chemisTree_.deleteLeaf(
x);
334 chemisTree_.size() > minBalanceThreshold_
335 && chemisTree_.depth() >
339 chemisTree_.balance();
345 return (treeModified && !chemisTree_.isFull());
349 void Foam::chemistryTabulationMethods::ISAT::computeA
362 const label si = chemistry_.sToc(i);
363 Rphiqs[i] = Rphiq[si];
365 Rphiqs[
nSpecie] = Rphiq[Rphiq.size() - 3];
366 Rphiqs[
nSpecie + 1] = Rphiq[Rphiq.size() - 2];
367 Rphiqs[
nSpecie + 2] = Rphiq[Rphiq.size() - 1];
379 chemistry_.jacobian(runTime_.value(), Rphiqs, li, dYTpdt,
A);
391 LUscalarMatrix LUA(
A);
415 cpuTime_.cpuTimeIncrement();
418 bool retrieved(
false);
422 if (chemisTree_.size())
424 chemisTree_.binaryTreeSearch(phiq, chemisTree_.root(),
phi0);
429 if (
phi0->inEOA(phiq))
435 else if (chemisTree_.secondaryBTSearch(phiq,
phi0))
439 else if (MRURetrieve_)
444 >::iterator iter = MRUList_.begin();
446 for ( ; iter != MRUList_.end(); ++iter)
449 if (
phi0->inEOA(phiq))
461 lastSearch_ =
nullptr;
466 phi0->increaseNumRetrieve();
467 const scalar elapsedTimeSteps = timeSteps() -
phi0->timeTag();
471 if (elapsedTimeSteps > chPMaxLifeTime_ && !
phi0->toRemove())
473 cleaningRequired_ =
true;
474 phi0->toRemove() =
true;
476 lastSearch_->lastTimeUsed() = timeSteps();
478 calcNewC(
phi0, phiq, Rphiq);
484 searchISATCpuTime_ += cpuTime_.cpuTimeIncrement();
502 cpuTime_.cpuTimeIncrement();
505 label growthOrAddFlag = 1;
509 if (lastSearch_ && growPoints_)
511 if (grow(lastSearch_, phiq, Rphiq))
515 addToMRU(lastSearch_);
517 tabulationResults_[li] = 1;
521 growCpuTime_ += cpuTime_.cpuTimeIncrement();
525 return growthOrAddFlag;
532 if (chemisTree().isFull())
537 if (!cleanAndBalance())
547 >::iterator iter = MRUList_.begin();
548 for ( ; iter != MRUList_.end(); ++iter)
556 chemisTree().clear();
566 chemisTree().insertNewLeaf
583 lastSearch_ =
nullptr;
587 const label ASize = chemistry_.nEqns() + 1;
589 computeA(
A, Rphiq, li, deltaT);
591 chemisTree().insertNewLeaf
602 if (lastSearch_ !=
nullptr)
604 addToMRU(lastSearch_);
608 tabulationResults_[li] = 0;
612 addNewLeafCpuTime_ += cpuTime_.cpuTimeIncrement();
615 return growthOrAddFlag;
624 << runTime_.userTimeValue() <<
" " << nRetrieved_ <<
endl;
628 << runTime_.userTimeValue() <<
" " << nGrowth_ <<
endl;
632 << runTime_.userTimeValue() <<
" " << nAdd_ <<
endl;
636 << runTime_.userTimeValue() <<
" "
637 << chemisTree_.size() <<
endl;
640 << runTime_.userTimeValue()
641 <<
" " << searchISATCpuTime_ <<
endl;
642 searchISATCpuTime_ = 0;
645 << runTime_.userTimeValue()
646 <<
" " << growCpuTime_ <<
endl;
650 << runTime_.userTimeValue()
651 <<
" " << addNewLeafCpuTime_ <<
endl;
652 addNewLeafCpuTime_ = 0;
662 forAll(tabulationResults_, i)
664 tabulationResults_[i] = 2;
671 bool updated = cleanAndBalance();
static const Foam::dimensionedScalar A("A", Foam::dimPressure, 611.21)
#define forAll(list, i)
Loop across all elements in list.
Macros for easy insertion into run-time selection tables.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
An STL-conforming iterator.
Template class for non-intrusive linked lists.
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 ...
An abstract class for chemistry tabulation.
Implementation of the ISAT (In-situ adaptive tabulation), for chemistry calculation.
const odeChemistryModel & chemistry()
virtual bool retrieve(const Foam::scalarField &phiq, scalarField &Rphiq)
Find the closest stored leaf of phiQ and store the result in.
virtual label add(const scalarField &phiq, const scalarField &Rphiq, const label nActive, const label li, const scalar deltaT)
Add information to the tabulation.
virtual void writePerformance()
ISAT(const dictionary &chemistryProperties, const odeChemistryModel &chemistry)
Construct from dictionary.
A list of keyword definitions, which are a keyword followed by any number of values (e....
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Extends base chemistry model adding an ODESystem and the reduction maps needed for tabulation.
autoPtr< OFstream > logFile(const word &name) const
Create and return a TDAC log file of the given name.
const PtrList< volScalarField > & Y() const
Return a reference to the list of mass fraction fields.
defineTypeNameAndDebug(ISAT, 0)
addToRunTimeSelectionTable(chemistryTabulationMethod, ISAT, dictionary)
const dimensionedScalar phi0
Magnetic flux quantum: default SI units: [Wb].
const dimensionedScalar e
Elementary charge.
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.
word name(const bool)
Return a word representation of a bool.
void deleteDemandDrivenData(DataType *&dataPtr)
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
dimensionedScalar log(const dimensionedScalar &ds)
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
SquareMatrix< scalar > scalarSquareMatrix
basicChemistryModel & chemistry
fluidMulticomponentThermo & thermo