From 1932addc2c213b5fd95b88277661b6fd4ea85669 Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Tue, 7 Sep 2021 21:03:55 +0100 Subject: [PATCH] TDACChemistryModel: Rationalised interface to reduction and tabulation methods Most tabulation and reduction specific code in TDACChemistryModel has been moved into the appropriate tabulation and reduction classes and the "none" methods of each simplified so that they can be instantiated without any user input. This allows the "none" tabulation and reduction methods to be selected automatically when the "tabulation" or "reduction" entries are not present in the chemistryProperties dictionary so that the TDACChemistryModel can be run in the same manner as the standardChemistryModel when tabulation and reduction are not required. This is the first step towards merging TDACChemistryModel with standardChemistryModel. --- .../chemistry/TDAC/chemistryProperties.cfg | 6 - .../TDAC/chemistryPropertiesFlame.cfg | 6 - .../TDACChemistryModel/TDACChemistryModel.C | 144 ++----------- .../TDACChemistryModel/TDACChemistryModel.H | 41 +--- .../TDACChemistryModel/TDACChemistryModelI.H | 25 --- .../TDACChemistryModel/reduction/DAC/DAC.C | 60 +++--- .../TDACChemistryModel/reduction/DAC/DAC.H | 4 +- .../TDACChemistryModel/reduction/DRG/DRG.C | 44 ++-- .../TDACChemistryModel/reduction/DRG/DRG.H | 6 +- .../reduction/DRGEP/DRGEP.C | 68 +++--- .../reduction/DRGEP/DRGEP.H | 6 +- .../TDACChemistryModel/reduction/EFA/EFA.C | 62 +++--- .../TDACChemistryModel/reduction/EFA/EFA.H | 8 +- .../TDACChemistryModel/reduction/PFA/PFA.C | 56 ++--- .../TDACChemistryModel/reduction/PFA/PFA.H | 8 +- .../chemistryReduction/chemistryReduction.C | 112 ++++++++++ .../chemistryReduction/chemistryReduction.H | 156 ++++++++++++++ .../chemistryReduction/chemistryReductionI.H | 53 +++++ .../chemistryReductionMethod.C | 11 +- .../chemistryReductionMethod.H | 51 ++--- .../chemistryReductionMethodI.H | 35 +-- .../chemistryReductionMethodNew.C | 89 ++++---- .../noChemistryReduction.C | 6 +- .../noChemistryReduction.H | 13 +- .../TDACChemistryModel/tabulation/ISAT/ISAT.C | 204 +++++++++++++----- .../TDACChemistryModel/tabulation/ISAT/ISAT.H | 55 ++++- .../tabulation/ISAT/binaryTree/binaryTree.C | 14 +- .../tabulation/ISAT/binaryTree/binaryTree.H | 11 +- .../ISAT/chemPointISAT/chemPointISAT.C | 32 +-- .../ISAT/chemPointISAT/chemPointISAT.H | 14 +- .../chemistryTabulationMethod.C | 9 +- .../chemistryTabulationMethod.H | 41 +--- .../chemistryTabulationMethodNew.C | 89 ++++---- .../noChemistryTabulation.C | 6 +- .../noChemistryTabulation.H | 25 ++- 35 files changed, 903 insertions(+), 667 deletions(-) create mode 100644 src/thermophysicalModels/chemistryModel/chemistryModel/TDACChemistryModel/reduction/chemistryReduction/chemistryReduction.C create mode 100644 src/thermophysicalModels/chemistryModel/chemistryModel/TDACChemistryModel/reduction/chemistryReduction/chemistryReduction.H create mode 100644 src/thermophysicalModels/chemistryModel/chemistryModel/TDACChemistryModel/reduction/chemistryReduction/chemistryReductionI.H diff --git a/etc/caseDicts/solvers/chemistry/TDAC/chemistryProperties.cfg b/etc/caseDicts/solvers/chemistry/TDAC/chemistryProperties.cfg index 4ba574f81a..befb1a76dc 100644 --- a/etc/caseDicts/solvers/chemistry/TDAC/chemistryProperties.cfg +++ b/etc/caseDicts/solvers/chemistry/TDAC/chemistryProperties.cfg @@ -8,9 +8,6 @@ reduction { - // Activate reduction - active on; - // Switch logging of the reduction statistics and performance log on; @@ -41,9 +38,6 @@ reduction tabulation { - // Activate tabulation - active on; - // Switch logging of the tabulation statistics and performance log on; diff --git a/etc/caseDicts/solvers/chemistry/TDAC/chemistryPropertiesFlame.cfg b/etc/caseDicts/solvers/chemistry/TDAC/chemistryPropertiesFlame.cfg index 03f4018327..a3d5e2d47a 100644 --- a/etc/caseDicts/solvers/chemistry/TDAC/chemistryPropertiesFlame.cfg +++ b/etc/caseDicts/solvers/chemistry/TDAC/chemistryPropertiesFlame.cfg @@ -8,9 +8,6 @@ reduction { - // Activate reduction - active on; - // Switch logging of the reduction statistics and performance log on; @@ -41,9 +38,6 @@ reduction tabulation { - // Activate tabulation - active on; - // Switch logging of the tabulation statistics and performance log on; diff --git a/src/thermophysicalModels/chemistryModel/chemistryModel/TDACChemistryModel/TDACChemistryModel.C b/src/thermophysicalModels/chemistryModel/chemistryModel/TDACChemistryModel/TDACChemistryModel.C index 8749e7aeee..6d76516c4f 100644 --- a/src/thermophysicalModels/chemistryModel/chemistryModel/TDACChemistryModel/TDACChemistryModel.C +++ b/src/thermophysicalModels/chemistryModel/chemistryModel/TDACChemistryModel/TDACChemistryModel.C @@ -37,25 +37,12 @@ Foam::TDACChemistryModel::TDACChemistryModel ) : standardChemistryModel(thermo), - timeSteps_(0), + log_(this->lookupOrDefault("log", false)), NsDAC_(this->nSpecie_), completeC_(this->nSpecie_, 0), reactionsDisabled_(this->reactions_.size(), false), completeToSimplifiedIndex_(this->nSpecie_, -1), - simplifiedToCompleteIndex_(this->nSpecie_), - tabulationResults_ - ( - IOobject - ( - thermo.phasePropertyName("TabulationResults"), - this->time().timeName(), - this->mesh(), - IOobject::NO_READ, - IOobject::AUTO_WRITE - ), - this->mesh(), - scalar(0) - ) + simplifiedToCompleteIndex_(this->nSpecie_) { const basicSpecieMixture& composition = this->thermo().composition(); @@ -94,20 +81,7 @@ Foam::TDACChemistryModel::TDACChemistryModel *this ); - if (mechRed_->log()) - { - cpuReduceFile_ = logFile("cpu_reduce.out"); - nActiveSpeciesFile_ = logFile("nActiveSpecies.out"); - } - - if (tabulation_->log()) - { - cpuAddFile_ = logFile("cpu_add.out"); - cpuGrowFile_ = logFile("cpu_grow.out"); - cpuRetrieveFile_ = logFile("cpu_retrieve.out"); - } - - if (mechRed_->log() || tabulation_->log()) + if (log_) { cpuSolveFile_ = logFile("cpu_solve.out"); } @@ -362,7 +336,6 @@ void Foam::TDACChemistryModel::jacobian d2TdtdT /= ccp; // d(dpdt)/dc = 0 (pressure is assumed constant) - // d(dpdt)/dT = 0 (pressure is assumed constant) } @@ -374,27 +347,15 @@ Foam::scalar Foam::TDACChemistryModel::solve const DeltaTType& deltaT ) { - // Increment counter of time-step - timeSteps_++; - const bool reduced = mechRed_->active(); + tabulation_->reset(); const basicSpecieMixture& composition = this->thermo().composition(); // CPU time analysis - const clockTime clockTime_= clockTime(); + const clockTime clockTime_ = clockTime(); clockTime_.timeIncrement(); - scalar reduceMechCpuTime_ = 0; - scalar addNewLeafCpuTime_ = 0; - scalar growCpuTime_ = 0; scalar solveChemistryCpuTime_ = 0; - scalar searchISATCpuTime_ = 0; - - this->resetTabulationResults(); - - // Average number of active species - scalar nActiveSpecies = 0; - scalar nAvg = 0; basicChemistryModel::correct(); @@ -445,15 +406,13 @@ Foam::scalar Foam::TDACChemistryModel::solve // When tabulation is active (short-circuit evaluation for retrieve) // It first tries to retrieve the solution of the system with the // information stored through the tabulation method - if (tabulation_->active() && tabulation_->retrieve(phiq, Rphiq)) + if (tabulation_->retrieve(phiq, Rphiq)) { // Retrieved solution stored in Rphiq for (label i=0; inSpecie(); i++) { c[i] = rhoi*Rphiq[i]/this->specieThermos_[i].W(); } - - searchISATCpuTime_ += clockTime_.timeIncrement(); } // This position is reached when tabulation is not used OR // if the solution is not retrieved. @@ -468,9 +427,6 @@ Foam::scalar Foam::TDACChemistryModel::solve { // Reduce mechanism change the number of species (only active) mechRed_->reduceMechanism(pi, Ti, c, celli); - nActiveSpecies += mechRed_->NsSimp(); - nAvg++; - reduceMechCpuTime_ += clockTime_.timeIncrement(); } // Calculate the chemical source terms @@ -506,13 +462,14 @@ Foam::scalar Foam::TDACChemistryModel::solve timeLeft -= dt; } + if (log_) { solveChemistryCpuTime_ += clockTime_.timeIncrement(); } // If tabulation is used, we add the information computed here to // the stored points (either expand or add) - if (tabulation_->active()) + if (tabulation_->tabulates()) { forAll(c, i) { @@ -522,18 +479,7 @@ Foam::scalar Foam::TDACChemistryModel::solve Rphiq[Rphiq.size()-2] = pi; Rphiq[Rphiq.size()-1] = deltaT[celli]; - label growOrAdd = - tabulation_->add(phiq, Rphiq, celli, rhoi, deltaT[celli]); - if (growOrAdd) - { - this->setTabulationResultsAdd(celli); - addNewLeafCpuTime_ += clockTime_.timeIncrement(); - } - else - { - this->setTabulationResultsGrow(celli); - growCpuTime_ += clockTime_.timeIncrement(); - } + tabulation_->add(phiq, Rphiq, celli, rhoi, deltaT[celli]); } // When operations are done and if mechanism reduction is active, @@ -557,51 +503,15 @@ Foam::scalar Foam::TDACChemistryModel::solve } } - if (mechRed_->log() || tabulation_->log()) + if (log_) { cpuSolveFile_() << this->time().timeOutputValue() << " " << solveChemistryCpuTime_ << endl; } - if (mechRed_->log()) - { - cpuReduceFile_() - << this->time().timeOutputValue() - << " " << reduceMechCpuTime_ << endl; - } - - if (tabulation_->active()) - { - // Every time-step, look if the tabulation should be updated - tabulation_->update(); - - // Write the performance of the tabulation - tabulation_->writePerformance(); - - if (tabulation_->log()) - { - cpuRetrieveFile_() - << this->time().timeOutputValue() - << " " << searchISATCpuTime_ << endl; - - cpuGrowFile_() - << this->time().timeOutputValue() - << " " << growCpuTime_ << endl; - - cpuAddFile_() - << this->time().timeOutputValue() - << " " << addNewLeafCpuTime_ << endl; - } - } - - if (reduced && nAvg && mechRed_->log()) - { - // Write average number of species - nActiveSpeciesFile_() - << this->time().timeOutputValue() - << " " << nActiveSpecies/nAvg << endl; - } + mechRed_->update(); + tabulation_->update(); if (Pstream::parRun()) { @@ -647,34 +557,4 @@ Foam::scalar Foam::TDACChemistryModel::solve } -template -void Foam::TDACChemistryModel:: -setTabulationResultsAdd -( - const label celli -) -{ - tabulationResults_[celli] = 0; -} - - -template -void Foam::TDACChemistryModel:: -setTabulationResultsGrow(const label celli) -{ - tabulationResults_[celli] = 1; -} - - -template -void Foam::TDACChemistryModel:: -setTabulationResultsRetrieve -( - const label celli -) -{ - tabulationResults_[celli] = 2; -} - - // ************************************************************************* // diff --git a/src/thermophysicalModels/chemistryModel/chemistryModel/TDACChemistryModel/TDACChemistryModel.H b/src/thermophysicalModels/chemistryModel/chemistryModel/TDACChemistryModel/TDACChemistryModel.H index a423ddcc17..917dfce7ab 100644 --- a/src/thermophysicalModels/chemistryModel/chemistryModel/TDACChemistryModel/TDACChemistryModel.H +++ b/src/thermophysicalModels/chemistryModel/chemistryModel/TDACChemistryModel/TDACChemistryModel.H @@ -85,7 +85,8 @@ class TDACChemistryModel { // Private member data - label timeSteps_; + //- Switch to select performance logging + Switch log_; // Mechanism reduction label NsDAC_; @@ -94,35 +95,16 @@ class TDACChemistryModel Field reactionsDisabled_; Field