36 namespace chemistryTabulationMethods
46 Foam::chemistryTabulationMethods::ISAT::ISAT
48 const dictionary& chemistryProperties,
49 const dictionary& coeffDict,
53 chemistryTabulationMethod
59 log_(coeffDict.lookupOrDefault<Switch>(
"log", false)),
60 reduction_(chemistry_.reduction()),
61 chemisTree_(*this, coeffDict),
67 coeffDict.lookupOrDefault(
"chPMaxLifeTime", INT_MAX)
69 maxGrowth_(coeffDict.lookupOrDefault(
"maxGrowth", INT_MAX)),
70 checkEntireTreeInterval_
72 coeffDict.lookupOrDefault(
"checkEntireTreeInterval", INT_MAX)
76 coeffDict.lookupOrDefault
79 (chemisTree_.maxNLeafs() - 1)
85 coeffDict.lookupOrDefault
87 "minBalanceThreshold", 0.1*chemisTree_.maxNLeafs()
90 MRURetrieve_(coeffDict.lookupOrDefault(
"MRURetrieve", false)),
91 maxMRUSize_(coeffDict.lookupOrDefault(
"maxMRUSize", 0)),
93 growPoints_(coeffDict.lookupOrDefault(
"growPoints", true)),
94 tolerance_(coeffDict.lookupOrDefault(
"tolerance", 1
e-4)),
98 addNewLeafCpuTime_(0),
100 searchISATCpuTime_(0),
115 cleaningRequired_(false)
117 const dictionary& scaleDict(coeffDict.subDict(
"scaleFactor"));
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");
138 nRetrievedFile_ =
chemistry.logFile(
"found_isat.out");
139 nGrowthFile_ =
chemistry.logFile(
"growth_isat.out");
140 nAddFile_ =
chemistry.logFile(
"add_isat.out");
141 sizeFile_ =
chemistry.logFile(
"size_isat.out");
143 cpuAddFile_ =
chemistry.logFile(
"cpu_add.out");
144 cpuGrowFile_ =
chemistry.logFile(
"cpu_grow.out");
145 cpuRetrieveFile_ =
chemistry.logFile(
"cpu_retrieve.out");
150 Foam::chemistryTabulationMethods::ISAT::ISAT
159 chemistryProperties.subDict(
"tabulation"),
173 void Foam::chemistryTabulationMethods::ISAT::addToMRU
178 if (maxMRUSize_ > 0 && MRURetrieve_)
181 bool isInList =
false;
184 for ( ; iter != MRUList_.end(); ++iter)
195 if (iter() != MRUList_.first())
198 MRUList_.remove(iter);
201 MRUList_.insert(
phi0);
206 if (MRUList_.size() == maxMRUSize_)
208 MRUList_.remove(iter);
209 MRUList_.insert(
phi0);
213 MRUList_.insert(
phi0);
220 void Foam::chemistryTabulationMethods::ISAT::calcNewC
227 const label nEqns = chemistry_.nEqns();
228 const List<label>& completeToSimplified =
phi0->completeToSimplifiedIndex();
239 Rphiq =
phi0->Rphi();
240 for (
label i=0; i<nEqns - 2; i++)
244 const label si = completeToSimplified[i];
250 for (
label j=0; j<nEqns + 1; j++)
254 ? completeToSimplified[j]
255 : j - (nEqns - 2) +
phi0->nActive();
259 Rphiq[i] += gradientsMatrix(si, sj)*dphi[j];
272 for (
label j=0; j<nEqns + 1; j++)
274 Rphiq[i] += gradientsMatrix(i, j)*dphi[j];
279 Rphiq[i] =
max(0, Rphiq[i]);
284 bool Foam::chemistryTabulationMethods::ISAT::grow
299 if (
phi0->nGrowth() > maxGrowth_)
301 cleaningRequired_ =
true;
302 phi0->toRemove() =
true;
309 if (
phi0->checkSolution(phiq, Rphiq))
311 return phi0->grow(phiq);
321 bool Foam::chemistryTabulationMethods::ISAT::cleanAndBalance()
323 bool treeModified(
false);
327 chemPointISAT*
x = chemisTree_.treeMin();
330 chemPointISAT* xtmp = chemisTree_.treeSuccessor(
x);
332 const scalar elapsedTimeSteps = timeSteps() -
x->timeTag();
334 if ((elapsedTimeSteps > chPMaxLifeTime_) || (
x->nGrowth() > maxGrowth_))
336 chemisTree_.deleteLeaf(
x);
349 chemisTree_.size() > minBalanceThreshold_
350 && chemisTree_.depth() >
354 chemisTree_.balance();
360 return (treeModified && !chemisTree_.isFull());
364 void Foam::chemistryTabulationMethods::ISAT::computeA
377 const label si = chemistry_.sToc(i);
378 Rphiqs[i] = Rphiq[si];
380 Rphiqs[
nSpecie] = Rphiq[Rphiq.size() - 3];
381 Rphiqs[
nSpecie + 1] = Rphiq[Rphiq.size() - 2];
382 Rphiqs[
nSpecie + 2] = Rphiq[Rphiq.size() - 1];
394 chemistry_.jacobian(runTime_.value(), Rphiqs, li, dYTpdt,
A);
406 LUscalarMatrix LUA(
A);
430 cpuTime_.cpuTimeIncrement();
433 bool retrieved(
false);
437 if (chemisTree_.size())
439 chemisTree_.binaryTreeSearch(phiq, chemisTree_.root(),
phi0);
444 if (
phi0->inEOA(phiq))
450 else if (chemisTree_.secondaryBTSearch(phiq,
phi0))
454 else if (MRURetrieve_)
459 >::iterator iter = MRUList_.begin();
461 for ( ; iter != MRUList_.end(); ++iter)
464 if (
phi0->inEOA(phiq))
476 lastSearch_ =
nullptr;
481 phi0->increaseNumRetrieve();
482 const scalar elapsedTimeSteps = timeSteps() -
phi0->timeTag();
486 if (elapsedTimeSteps > chPMaxLifeTime_ && !
phi0->toRemove())
488 cleaningRequired_ =
true;
489 phi0->toRemove() =
true;
491 lastSearch_->lastTimeUsed() = timeSteps();
493 calcNewC(
phi0, phiq, Rphiq);
499 searchISATCpuTime_ += cpuTime_.cpuTimeIncrement();
517 cpuTime_.cpuTimeIncrement();
520 label growthOrAddFlag = 1;
524 if (lastSearch_ && growPoints_)
526 if (grow(lastSearch_, phiq, Rphiq))
530 addToMRU(lastSearch_);
532 tabulationResults_[li] = 1;
536 growCpuTime_ += cpuTime_.cpuTimeIncrement();
540 return growthOrAddFlag;
547 if (chemisTree().isFull())
552 if (!cleanAndBalance())
562 >::iterator iter = MRUList_.begin();
563 for ( ; iter != MRUList_.end(); ++iter)
571 chemisTree().clear();
581 chemisTree().insertNewLeaf
598 lastSearch_ =
nullptr;
602 const label ASize = chemistry_.nEqns() + 1;
604 computeA(
A, Rphiq, li, deltaT);
606 chemisTree().insertNewLeaf
617 if (lastSearch_ !=
nullptr)
619 addToMRU(lastSearch_);
623 tabulationResults_[li] = 0;
627 addNewLeafCpuTime_ += cpuTime_.cpuTimeIncrement();
630 return growthOrAddFlag;
639 << runTime_.userTimeValue() <<
" " << nRetrieved_ <<
endl;
643 << runTime_.userTimeValue() <<
" " << nGrowth_ <<
endl;
647 << runTime_.userTimeValue() <<
" " << nAdd_ <<
endl;
651 << runTime_.userTimeValue() <<
" "
652 << chemisTree_.size() <<
endl;
655 << runTime_.userTimeValue()
656 <<
" " << searchISATCpuTime_ <<
endl;
657 searchISATCpuTime_ = 0;
660 << runTime_.userTimeValue()
661 <<
" " << growCpuTime_ <<
endl;
665 << runTime_.userTimeValue()
666 <<
" " << addNewLeafCpuTime_ <<
endl;
667 addNewLeafCpuTime_ = 0;
677 forAll(tabulationResults_, i)
679 tabulationResults_[i] = 2;
686 bool updated = cleanAndBalance();
#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.
An STL-conforming iterator.
Template class for non-intrusive linked lists.
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.
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()
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Extends base chemistry model adding an ODESystem and the reduction maps needed for tabulation.
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
defineTypeNameAndDebug(ISAT, 0)
addToRunTimeSelectionTable(chemistryTabulationMethod, ISAT, dictionary)
const dimensionedScalar phi0
Magnetic flux quantum: default SI units: [Wb].
const dimensionedScalar e
Elementary charge.
static const coefficient A("A", dimPressure, 611.21)
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 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
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
basicChemistryModel & chemistry
fluidMulticomponentThermo & thermo