36 namespace chemistryTabulationMethods
57 coeffsDict_(chemistryProperties.
subDict(
"tabulation")),
58 chemistry_(chemistry),
59 log_(coeffsDict_.lookupOrDefault<
Switch>(
"log",
false)),
60 reduction_(chemistry_.reduction()),
61 chemisTree_(*
this, coeffsDict_),
62 scaleFactor_(chemistry.
nEqns() + 1, 1),
63 runTime_(chemistry.
time()),
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)
117 dictionary scaleDict(coeffsDict_.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");
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();
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;
296 return phi0->
grow(phiq);
306 bool Foam::chemistryTabulationMethods::ISAT::cleanAndBalance()
308 bool treeModified(
false);
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];
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);
382 for (
label i=0; i<nSpecie + 2; i++)
384 for (
label j=0; j<nSpecie + 2; j++)
390 A(nSpecie + 2, nSpecie + 2) = 1;
400 A(nSpecie + 1, i) = 0;
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;
467 const scalar elapsedTimeSteps = timeSteps() - phi0->
timeTag();
471 if (elapsedTimeSteps > chPMaxLifeTime_ && !phi0->
toRemove())
473 cleaningRequired_ =
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();
const fvMesh & mesh() const
Return const access to the mesh database.
#define forAll(list, i)
Loop across all elements in list.
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
static word phasePropertyName(const word &name, const word &phaseName)
Name of a property for a given phase.
dimensionedScalar log(const dimensionedScalar &ds)
A list of keyword definitions, which are a keyword followed by any number of values (e...
Class to perform the LU decomposition on a symmetric matrix.
Template class for non-intrusive linked lists.
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.
autoPtr< OFstream > logFile(const word &name) const
Create and return a TDAC log file of the given name.
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 ...
A simple wrapper around bool so that it can be read as a word: true/false, on/off, yes/no, y/n, t/f, or none/any.
An STL-conforming iterator.
virtual label add(const scalarField &phiq, const scalarField &Rphiq, const label nActive, const label li, const scalar deltaT)
Add information to the tabulation.
addToRunTimeSelectionTable(chemistryTabulationMethod, ISAT, dictionary)
Macros for easy insertion into run-time selection tables.
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
const List< label > & completeToSimplifiedIndex() const
virtual bool retrieve(const Foam::scalarField &phiq, scalarField &Rphiq)
Find the closest stored leaf of phiQ and store the result in.
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...
defineTypeNameAndDebug(ISAT, 0)
static word timeName(const scalar, const int precision=curPrecision_)
Return time name of given scalar time.
const scalarField & phi() const
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 & Rphi() const
const fluidReactionThermo & thermo() const
Return const access to the thermo.
An abstract class for chemistry tabulation.
const Time & time() const
Return time.
void increaseNumRetrieve()
Increases the number of retrieves the chempoint has generated.
ISAT(const dictionary &chemistryProperties, const odeChemistryModel &chemistry)
Construct from dictionary.
bool inEOA(const scalarField &phiq)
To RETRIEVE the mapping from the stored chemPoint phi, the query.
const scalarSquareMatrix & A() const
const doubleScalar e
Elementary charge.
const dimensionedScalar phi0
Magnetic flux quantum: default SI units: [Wb].
void deleteDemandDrivenData(DataPtr &dataPtr)
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Extends base chemistry model adding an ODESystem and the reduction maps needed for tabulation...
virtual label nEqns() const
Number of ODE's to solve.
void inv(scalarSquareMatrix &M) const
Set M to the inverse of this square matrix.
virtual void writePerformance()