10#if defined(WITH_CANTERA)
22 Cantera::addDirectory(
"/aia/opt/cantera/build/data");
39 "Unequal reference temperature values in NASA coefficients and species standard enthalpy of formation");
50 : m_noSpecies(noSpecies), noVariables(nDim + 2 + noSpecies) {
86 :
m_noSpecies(noSpecies), noVariables(nDim + 2 + noSpecies) {
128 mTerm(1, AT_,
"Diffusion model in properties file does not match any implemented model. Terminating.");
142 mAlloc(molarMass, noSpecies,
"FvSysEqnDetChem::SpeciesProperties::molarMass", AT_);
143 mAlloc(fMolarMass, noSpecies,
"FvSysEqnDetChem::SpeciesProperties::fMolarMass", AT_);
144 mAlloc(specificGasConstant, noSpecies,
"FvSysEqnDetChem::SpeciesProperties::specificGasConstant", AT_);
145 mAlloc(fSpecificGasConstant, noSpecies,
"FvSysEqnDetChem::SpeciesProperties::fSpecificGasConstant", AT_);
146 mAlloc(standardHeatFormation, noSpecies,
"FvSysEqnDetChem::SpeciesProperties::standardHeatFormation", AT_);
148 this->getSpeciesProperties(noSpecies, sysEqn);
175 std::shared_ptr<Cantera::Solution> sol(
177 std::shared_ptr<Cantera::ThermoPhase> gas(sol->thermo());
179 const MInt numberMechanismSpecies = gas->nSpecies();
181 if(numberMechanismSpecies != noSpecies) {
182 std::cerr <<
"noSpecies in mechanism file: " << numberMechanismSpecies
183 <<
". noSpecies in simulation properties file: " << noSpecies << std::endl;
185 "Number of species included in the mechanism file does not correspond to the number of species defined "
186 "in the properties-file. Terminating.");
189 gas->getMolecularWeights(molarMass);
190 speciesName = gas->speciesNames();
193 standardHeatFormation[s] = gas->Hf298SS(s);
194 molarMass[s] /= 1000.0;
195 fMolarMass[s] = F1 / molarMass[s];
196 standardHeatFormation[s] /= 1000.0;
197 standardHeatFormation[s] = standardHeatFormation[s] * fMolarMass[s];
198 specificGasConstant[s] = sysEqn.
m_gasConstant * fMolarMass[s];
199 fSpecificGasConstant[s] = F1 / specificGasConstant[s];
202 auto stringIterator = std::find(speciesName.begin(), speciesName.end(), majorSpecies);
203 if(stringIterator == speciesName.end()) {
204 mTerm(1, AT_,
"Given major species name was not found in the species name vector. Terminating.");
206 majorSpeciesIndex = std::distance(speciesName.begin(), stringIterator);
210 for(
MInt s = 0; s < noSpecies; s++) {
211 speciesMap.insert(std::pair<std::string, MInt>(speciesName[s], s));
215 std::cout <<
"Detailed chemistry species properties." << std::endl;
216 for(
MInt s = 0; s < numberMechanismSpecies; s++) {
217 std::cout << speciesName[s] <<
". Molar mass: " << molarMass[s] <<
". Heat formation: " << standardHeatFormation[s]
218 <<
". Specific gas constant: " << specificGasConstant[s] << std::endl;
233 mAlloc(lowTemp, noNASACoefficients * noSpecies,
"FvSysEqnDetChem::NASACoefficients::lowTemp", AT_);
234 mAlloc(highTemp, noNASACoefficients * noSpecies,
"FvSysEqnDetChem::NASACoefficients::highTemp", AT_);
236 mAlloc(integralLowTemp, noNASACoefficientsCpPolynomial * noSpecies,
237 "FvSysEqnDetChem::NASACoefficients::integralLowTemp", AT_);
238 mAlloc(integralHighTemp, noNASACoefficientsCpPolynomial * noSpecies,
239 "FvSysEqnDetChem::NASACoefficients::integralHighTemp", AT_);
241 mAlloc(lowTempIntegrationConstantsEnergy, noSpecies,
242 "FvSysEqnDetChem::NASACoefficients::lowTempIntegrationConstantsEnergy", AT_);
243 mAlloc(highTempIntegrationConstantsEnergy, noSpecies,
244 "FvSysEqnDetChem::NASACoefficients::highTempIntegrationConstantsEnergy", AT_);
246 mAlloc(lowTempIntegrationConstantsEnthalpy, noSpecies,
247 "FvSysEqnDetChem::NASACoefficients::lowTempIntegrationConstantsEnthalpy", AT_);
248 mAlloc(highTempIntegrationConstantsEnthalpy, noSpecies,
249 "FvSysEqnDetChem::NASACoefficients::highTempIntegrationConstantsEnthalpy", AT_);
251 this->getNASACoefficients(noSpecies, sysEqn);
252 this->computeSensibleEnergyIntegrationConstants(sysEqn);
288 std::shared_ptr<Cantera::Solution> sol(
290 std::shared_ptr<Cantera::ThermoPhase> gas(sol->thermo());
292 MFloat* totalNASACoefficients =
nullptr;
293 mAlloc(totalNASACoefficients, totalNumberCoefficientsPerSpecies * noSpecies,
294 "FvSysEqnDetChem::NASACoefficients::getNASACoefficients::totalNASACoefficients", AT_);
296 MFloat*
const NASACoeffs = ALIGNED_F(totalNASACoefficients);
299 MInt offset = totalNumberCoefficientsPerSpecies * s;
300 MFloat*
const speciesNASACoeffs = ALIGNED_F(NASACoeffs + offset);
302 shared_ptr<Cantera::Species> species = gas->species(s);
303 shared_ptr<Cantera::SpeciesThermoInterpType> thermoPhaseInf = species->thermo;
307 doublereal tlow, thigh, pref;
310 thermoPhaseInf->reportParameters(n, type, tlow, thigh, pref, speciesNASACoeffs);
314 const MInt offset = totalNumberCoefficientsPerSpecies * s;
315 const MInt offsetRegion = noNASACoefficients * s;
316 for(
MInt i = 0; i < totalNumberCoefficientsPerSpecies; i++) {
319 }
else if((i > 0) && (i < (noNASACoefficients + 1))) {
320 const MInt index = i - 1;
321 highTemp[offsetRegion + index] = totalNASACoefficients[offset + i];
323 const MInt index = i - 1 - noNASACoefficients;
324 lowTemp[offsetRegion + index] = totalNASACoefficients[offset + i];
330 const MInt offsetRegion = noNASACoefficients * s;
331 const MInt offsetIntegral = noNASACoefficientsCpPolynomial * s;
332 for(
MInt i = 0; i < 5; i++) {
333 integralLowTemp[offsetIntegral + i] = lowTemp[offsetRegion + i] / (i + 1);
334 integralHighTemp[offsetIntegral + i] = highTemp[offsetRegion + i] / (i + 1);
342 MInt offset = s * totalNumberCoefficientsPerSpecies;
343 MInt offset2 = s * noNASACoefficients;
344 MInt offset3 = s * noNASACoefficientsCpPolynomial;
346 for(
MInt i = 0; i < totalNumberCoefficientsPerSpecies; i++) {
347 std::cout << totalNASACoefficients[offset + i] <<
" ";
349 std::cout << std::endl;
351 for(
MInt i = 0; i < noNASACoefficients; i++) {
352 std::cout << highTemp[offset2 + i] <<
" ";
354 std::cout << std::endl;
355 for(
MInt i = 0; i < noNASACoefficientsCpPolynomial; i++) {
356 std::cout << integralHighTemp[offset3 + i] <<
" ";
358 std::cout << std::endl;
359 for(
MInt i = 0; i < noNASACoefficients; i++) {
360 std::cout << lowTemp[offset2 + i] <<
" ";
362 std::cout << std::endl;
363 for(
MInt i = 0; i < noNASACoefficientsCpPolynomial; i++) {
364 std::cout << integralLowTemp[offset3 + i] <<
" ";
366 std::cout << std::endl;
388 MFloat limitTRefEnergy = F0, limitLowTempRegionEnergy = F0, limitHighTempRegionEnergy = F0;
389 MFloat limitTRefEnthalpy = F0, limitLowTempRegionEnthalpy = F0, limitHighTempRegionEnthalpy = F0;
392 MInt offsetIntegralCoeffs = noNASACoefficientsCpPolynomial * s;
395 for(
MInt i = 4; (i < 5) && (i >= 0); i--) {
396 limitTRefEnergy = limitTRefEnergy * referenceTemp + integralLowTemp[offsetIntegralCoeffs + i];
397 limitLowTempRegionEnergy = limitLowTempRegionEnergy * transitionTemp + integralLowTemp[offsetIntegralCoeffs + i];
398 limitHighTempRegionEnergy =
399 limitHighTempRegionEnergy * transitionTemp + integralHighTemp[offsetIntegralCoeffs + i];
401 limitTRefEnthalpy = limitTRefEnthalpy * referenceTemp + integralLowTemp[offsetIntegralCoeffs + i];
402 limitLowTempRegionEnthalpy =
403 limitLowTempRegionEnthalpy * transitionTemp + integralLowTemp[offsetIntegralCoeffs + i];
404 limitHighTempRegionEnthalpy =
405 limitHighTempRegionEnthalpy * transitionTemp + integralHighTemp[offsetIntegralCoeffs + i];
408 limitTRefEnergy *= speciesSpecificGasConstant;
409 limitLowTempRegionEnergy *= speciesSpecificGasConstant;
410 limitHighTempRegionEnergy *= speciesSpecificGasConstant;
412 limitTRefEnthalpy *= speciesSpecificGasConstant * referenceTemp;
413 limitLowTempRegionEnthalpy *= speciesSpecificGasConstant * transitionTemp;
414 limitHighTempRegionEnthalpy *= speciesSpecificGasConstant * transitionTemp;
416 limitTRefEnergy = (limitTRefEnergy - speciesSpecificGasConstant) * referenceTemp;
417 limitLowTempRegionEnergy = (limitLowTempRegionEnergy - speciesSpecificGasConstant) * transitionTemp;
418 limitHighTempRegionEnergy = (limitHighTempRegionEnergy - speciesSpecificGasConstant) * transitionTemp;
421 lowTempIntegrationConstantsEnergy[s] = limitTRefEnergy;
422 highTempIntegrationConstantsEnergy[s] = limitTRefEnergy - limitLowTempRegionEnergy + limitHighTempRegionEnergy;
424 lowTempIntegrationConstantsEnthalpy[s] = limitTRefEnthalpy;
425 highTempIntegrationConstantsEnthalpy[s] =
426 limitTRefEnthalpy - limitLowTempRegionEnthalpy + limitHighTempRegionEnthalpy;
442 const MInt noDiffusionCoefficients,
443 const MInt noThermalDiffusionCoefficients)
517 "Using detailed chemistry equation system without CANTERA compilation. Recompile enabling --with-cantera in "
518 "configure.py file or select a different equation system. Terminating now.");
void mAlloc(T *&a, const MLong N, const MString &objectName, MString function)
allocates memory for one-dimensional array 'a' of size N
MBool mDeallocate(T *&a)
deallocates the memory previously allocated for element 'a'
Class containing the special methods of the detailed chemistry formulation. Inherits from the Navier-...
MInt m_noSurfaceCoefficients
void readProperties()
Reads important variable values from the properties.toml file.
MFloat m_fuelOxidizerStochiometricRatio
ConservativeVariables * CV
void allocateNoDiffusionCoefficients(const MInt)
Allocates the correct number of diffusion coefficients depending on the chosen diffusion model....
MInt m_noDiffusionCoefficients
MBool m_computeSrfcCoeffsEveryRKStep
MString m_reactionMechanism
FvSysEqnDetChem(const MInt solverId, const MInt noSpecies)
Construct a new FvSysEqnDetChem<nDim>::FvSysEqnDetChem object.
SpeciesProperties * m_species
NASACoefficients * m_NASA
MInt m_noThermalDiffusionCoefficients
MInt string2enum(MString theString)
This global function translates strings in their corresponding enum values (integer values)....
void mTerm(const MInt errorCode, const MString &location, const MString &message)
Static indices for accessing conservative variables in nDim spatial dimensions.
ConservativeVariables(const MInt noSpecies)
Construct a new FvSysEqnDetChem<nDim>::ConservativeVariables::ConservativeVariables object.
~ConservativeVariables()
Destroy the FvSysEqnDetChem<nDim>::ConservativeVariables::ConservativeVariables object.
static constexpr MInt RHO_C
Static indices for accessing flux variables. In this SysEqn identical to the conservative variables.
FluxVariables(const MInt noSpecies)
Construct a new FvSysEqnDetChem<nDim>::FluxVariables::FluxVariables object.
Stores all NASA coefficients. NASA coefficients are used to compute the cp and cv values....
void getNASACoefficients(const MInt noSpecies, const FvSysEqnDetChem< nDim > &sysEqn)
Gets the species 7-NASA Coefficients from the given mechanism file. The NASA Coefficients are then us...
static constexpr MFloat referenceTemp
~NASACoefficients()
Destroy the FvSysEqnDetChem<nDim>::NASACoefficients::NASACoefficients object.
NASACoefficients(const MInt noSpecies, const FvSysEqnDetChem< nDim > &sysEqn)
Construct a new FvSysEqnDetChem<nDim>::NASACoefficients::NASACoefficients object. This object stores ...
void computeSensibleEnergyIntegrationConstants(const FvSysEqnDetChem< nDim > &sysEqn)
Computes the sensible energy and enthalpy integration constants to reuse later (for low and high temp...
Static indices for accessing primitive variables in nDim spatial dimensions.
PrimitiveVariables(const MInt noSpecies)
Construct a new FvSysEqnDetChem<nDim>::PrimitiveVariables::PrimitiveVariables object.
~PrimitiveVariables()
Destroy the FvSysEqnDetChem<nDim>::PrimitiveVariables::PrimitiveVariables object.
Struct for storing all relevant species information, which is read from a given mechanism file.
std::vector< MString > speciesName
~SpeciesProperties()
Destroy the FvSysEqnDetChem<nDim>::SpeciesProperties::SpeciesProperties object.
MFloat * specificGasConstant
SpeciesProperties(const MInt noSpecies, const FvSysEqnDetChem< nDim > &sysEqn)
Construct a new FvSysEqnDetChem<nDim>::SpeciesProperties::SpeciesProperties object.
const MFloat referenceTemp
void getSpeciesProperties(const MInt noSpecies, const FvSysEqnDetChem< nDim > &sysEqn)
Gets important species information and stores it in the member variables of the species struct.
Static indices for accessing surface coefficients.
const MInt m_noThermalDiffusionCoefficients
const MInt m_noDiffusionCoefficients
SurfaceCoefficients(const MInt noSpecies, const MInt noDiffusionCoefficients, const MInt noThermalDiffusionCoefficients)
Construct a new FvSysEqnDetChem<nDim>::SurfaceCoefficients::SurfaceCoefficients object.
~SurfaceCoefficients()
Destroy the FvSysEqnDetChem<nDim>::SurfaceCoefficients::SurfaceCoefficients object.