1 #ifndef ABLATELIBRARY_TCHEMSOOT_HPP
2 #define ABLATELIBRARY_TCHEMSOOT_HPP
4 #include <Kokkos_Core.hpp>
7 #ifndef KOKKOS_ENABLE_CUDA
13 #include "TChem_KineticModelData.hpp"
14 #include "chemistryModel.hpp"
15 #include "eos/tChemSoot/pressure.hpp"
16 #include "eos/tChemSoot/sensibleEnthalpy.hpp"
17 #include "eos/tChemSoot/sensibleInternalEnergy.hpp"
18 #include "eos/tChemSoot/speedOfSound.hpp"
19 #include "eos/tChemSoot/stateVectorSoot.hpp"
20 #include "eos/tChemSoot/temperature.hpp"
21 #include "monitors/logs/log.hpp"
22 #include "tChemSoot/sootConstants.hpp"
23 #include "utilities/intErrorChecker.hpp"
25 namespace ablate::eos {
27 namespace tChemLib = TChem;
29 class TChemSoot :
public TChemBase,
public std::enable_shared_from_this<ablate::eos::TChemSoot> {
53 explicit TChemSoot(std::filesystem::path
mechanismFile, std::shared_ptr<ablate::monitors::logs::Log> = {},
const std::shared_ptr<ablate::parameters::Parameters>& options = {});
61 [[nodiscard]] ThermodynamicFunction
GetThermodynamicFunction(ThermodynamicProperty property,
const std::vector<domain::Field>& fields)
const override;
69 [[nodiscard]] ThermodynamicTemperatureFunction
GetThermodynamicTemperatureFunction(ThermodynamicProperty property,
const std::vector<domain::Field>& fields)
const override;
77 [[nodiscard]] EOSFunction
GetFieldFunctionFunction(
const std::string& field, ThermodynamicProperty property1, ThermodynamicProperty property2,
78 std::vector<std::string> otherProperties)
const override;
84 [[nodiscard]]
const std::vector<std::string>&
GetProgressVariables()
const override {
return progressVariables; }
108 void View(std::ostream& stream)
const override;
124 [[nodiscard]] std::shared_ptr<FunctionContext>
BuildFunctionContext(ablate::eos::ThermodynamicProperty property,
const std::vector<domain::Field>& fields)
const;
134 static PetscErrorCode DensityFunction(
const PetscReal conserved[], PetscReal* property,
void* ctx);
135 static PetscErrorCode TemperatureFunction(
const PetscReal conserved[], PetscReal* property,
void* ctx);
136 static PetscErrorCode PressureFunction(
const PetscReal conserved[], PetscReal* property,
void* ctx);
137 static PetscErrorCode InternalSensibleEnergyFunction(
const PetscReal conserved[], PetscReal* property,
void* ctx);
138 static PetscErrorCode SensibleEnthalpyFunction(
const PetscReal conserved[], PetscReal* property,
void* ctx);
139 static PetscErrorCode SpecificHeatConstantVolumeFunction(
const PetscReal conserved[], PetscReal* property,
void* ctx);
140 static PetscErrorCode SpecificHeatConstantPressureFunction(
const PetscReal conserved[], PetscReal* property,
void* ctx);
141 static PetscErrorCode SpeedOfSoundFunction(
const PetscReal conserved[], PetscReal* property,
void* ctx);
142 static PetscErrorCode SpeciesSensibleEnthalpyFunction(
const PetscReal conserved[], PetscReal* property,
void* ctx);
154 static PetscErrorCode DensityTemperatureFunction(
const PetscReal conserved[], PetscReal T, PetscReal* property,
void* ctx);
155 static PetscErrorCode TemperatureTemperatureFunction(
const PetscReal conserved[], PetscReal T, PetscReal* property,
void* ctx);
156 static PetscErrorCode PressureTemperatureFunction(
const PetscReal conserved[], PetscReal T, PetscReal* property,
void* ctx);
157 static PetscErrorCode InternalSensibleEnergyTemperatureFunction(
const PetscReal conserved[], PetscReal T, PetscReal* property,
void* ctx);
158 static PetscErrorCode SensibleEnthalpyTemperatureFunction(
const PetscReal conserved[], PetscReal T, PetscReal* property,
void* ctx);
159 static PetscErrorCode SpecificHeatConstantVolumeTemperatureFunction(
const PetscReal conserved[], PetscReal T, PetscReal* property,
void* ctx);
160 static PetscErrorCode SpecificHeatConstantPressureTemperatureFunction(
const PetscReal conserved[], PetscReal T, PetscReal* property,
void* ctx);
161 static PetscErrorCode SpeedOfSoundTemperatureFunction(
const PetscReal conserved[], PetscReal T, PetscReal* property,
void* ctx);
162 static PetscErrorCode SpeciesSensibleEnthalpyTemperatureFunction(
const PetscReal conserved[], PetscReal T, PetscReal* property,
void* ctx);
173 using ThermodynamicTemperatureStaticFunction = PetscErrorCode (*)(
const PetscReal conserved[], PetscReal temperature, PetscReal* property,
void* ctx);
174 std::map<ThermodynamicProperty, std::tuple<
ThermodynamicStaticFunction, ThermodynamicTemperatureStaticFunction, std::function<ordinal_type(ordinal_type)>>> thermodynamicFunctions = {
175 {ThermodynamicProperty::Density, {DensityFunction, DensityTemperatureFunction, [](
auto) {
return 0; }}},
176 {ThermodynamicProperty::Pressure,
177 {PressureFunction, PressureTemperatureFunction, ablate::eos::tChemSoot::Temperature::getWorkSpaceSize}} ,
178 {ThermodynamicProperty::Temperature, {TemperatureFunction, TemperatureTemperatureFunction, ablate::eos::tChemSoot::Temperature::getWorkSpaceSize}},
179 {ThermodynamicProperty::InternalSensibleEnergy, {InternalSensibleEnergyFunction, InternalSensibleEnergyTemperatureFunction, ablate::eos::tChemSoot::SensibleInternalEnergy::getWorkSpaceSize}},
180 {ThermodynamicProperty::SensibleEnthalpy, {SensibleEnthalpyFunction, SensibleEnthalpyTemperatureFunction, ablate::eos::tChemSoot::SensibleEnthalpy::getWorkSpaceSize}},
181 {ThermodynamicProperty::SpecificHeatConstantVolume, {SpecificHeatConstantVolumeFunction, SpecificHeatConstantVolumeTemperatureFunction, [](
auto nSpec) {
return nSpec; }}},
182 {ThermodynamicProperty::SpecificHeatConstantPressure,
183 {SpecificHeatConstantPressureFunction,
184 SpecificHeatConstantPressureTemperatureFunction,
185 ablate::eos::tChemSoot::Temperature::getWorkSpaceSize}} ,
186 {ThermodynamicProperty::SpeedOfSound, {SpeedOfSoundFunction, SpeedOfSoundTemperatureFunction, ablate::eos::tChemSoot::SpeedOfSound::getWorkSpaceSize}},
187 {ThermodynamicProperty::SpeciesSensibleEnthalpy,
188 {SpeciesSensibleEnthalpyFunction,
189 SpeciesSensibleEnthalpyTemperatureFunction,
190 ablate::eos::tChemSoot::Temperature::getWorkSpaceSize}}
208 inline static const std::vector<real_type> CS_Nasa7TLow = {-3.108720720e-01, 4.403536860e-03, 1.903941180e-06, -6.385469660e-09, 2.989642480e-12, -1.086507940e+02, 1.113829530e+00};
209 inline static const std::vector<real_type> CS_Nasa7THigh = {1.455718290e+00, 1.717022160e-03, -6.975627860e-07, 1.352770320e-10, -9.675906520e-15, -6.951388140e+02, -8.525830330e+00};
212 inline static real_type CarbonEnthalpy_R_T(
const real_type& Temp) {
214 double t200 = CS_Nasa7TLow.at(5) / 200. + CS_Nasa7TLow.at(0) +
215 200. * (CS_Nasa7TLow.at(1) / 2. + 200. * (CS_Nasa7TLow.at(2) / 3. + 200. * (CS_Nasa7TLow.at(3) / 4. + 200. * CS_Nasa7TLow.at(4) / 5.)));
216 double t300 = CS_Nasa7TLow.at(5) / 300. + CS_Nasa7TLow.at(0) +
217 300. * (CS_Nasa7TLow.at(1) / 2. + 300. * (CS_Nasa7TLow.at(2) / 3. + 300. * (CS_Nasa7TLow.at(3) / 4. + 300. * CS_Nasa7TLow.at(4) / 5.)));
218 return t200 - (t300 - t200) / 100. * (200. - Temp);
219 }
else if (Temp <= 1000.)
220 return CS_Nasa7TLow.at(5) / Temp + CS_Nasa7TLow.at(0) +
221 Temp * (CS_Nasa7TLow.at(1) / 2. + Temp * (CS_Nasa7TLow.at(2) / 3. + Temp * (CS_Nasa7TLow.at(3) / 4. + Temp * CS_Nasa7TLow.at(4) / 5.)));
222 else if (Temp <= 5000.)
223 return CS_Nasa7THigh.at(5) / Temp + CS_Nasa7THigh.at(0) +
224 Temp * (CS_Nasa7THigh.at(1) / 2. + Temp * (CS_Nasa7THigh.at(2) / 3. + Temp * (CS_Nasa7THigh.at(3) / 4. + Temp * CS_Nasa7THigh.at(4) / 5.)));
226 double t5000 = CS_Nasa7THigh.at(5) / 5000. + CS_Nasa7THigh.at(0) +
227 5000. * (CS_Nasa7THigh.at(1) / 2. + 5000. * (CS_Nasa7THigh.at(2) / 3. + 5000. * (CS_Nasa7THigh.at(3) / 4. + 5000. * CS_Nasa7THigh.at(4) / 5.)));
228 double t4900 = CS_Nasa7THigh.at(5) / 4900. + CS_Nasa7THigh.at(0) +
229 4900. * (CS_Nasa7THigh.at(1) / 2. + 4900. * (CS_Nasa7THigh.at(2) / 3. + 4900. * (CS_Nasa7THigh.at(3) / 4. + 4900. * CS_Nasa7THigh.at(4) / 5.)));
230 return t5000 + (t5000 - t4900) / 100. * (Temp - 5000.);
234 inline static double CarbonCp_R(
const double& Temp) {
236 double t200 = CS_Nasa7TLow.at(0) + 200. * (CS_Nasa7TLow.at(1) + 200. * (CS_Nasa7TLow.at(2) + 200. * (CS_Nasa7TLow.at(3) + 200. * CS_Nasa7TLow.at(4))));
237 double t300 = CS_Nasa7TLow.at(0) + 300. * (CS_Nasa7TLow.at(1) + 300. * (CS_Nasa7TLow.at(2) + 300. * (CS_Nasa7TLow.at(3) + 300. * CS_Nasa7TLow.at(4))));
238 return t200 - (t300 - t200) / 100. * (200 - Temp);
239 }
else if (Temp <= 1000)
240 return CS_Nasa7TLow.at(0) + Temp * (CS_Nasa7TLow.at(1) + Temp * (CS_Nasa7TLow.at(2) + Temp * (CS_Nasa7TLow.at(3) + Temp * CS_Nasa7TLow.at(4))));
241 else if (Temp <= 5000)
242 return CS_Nasa7THigh.at(0) + Temp * (CS_Nasa7THigh.at(1) + Temp * (CS_Nasa7THigh.at(2) + Temp * (CS_Nasa7THigh.at(3) + Temp * CS_Nasa7THigh.at(4))));
244 double t5000 = CS_Nasa7THigh.at(0) + 5000. * (CS_Nasa7THigh.at(1) + 5000. * (CS_Nasa7THigh.at(2) + 5000. * (CS_Nasa7THigh.at(3) + 5000. * CS_Nasa7THigh.at(4))));
245 double t4900 = CS_Nasa7THigh.at(0) + 4900. * (CS_Nasa7THigh.at(1) + 4900. * (CS_Nasa7THigh.at(2) + 4900. * (CS_Nasa7THigh.at(3) + 4900. * CS_Nasa7THigh.at(4))));
246 return t5000 + (t5000 - t4900) / 100. * (Temp - 5000.);
254 return (ablate::eos::TChemSoot::CarbonEnthalpy_R_T(temperature) * temperature * RUNIV * 1.0e3 / tChemSoot::MWCarbon) -
255 (ablate::eos::TChemSoot::CarbonEnthalpy_R_T(TREF) * TREF * RUNIV * 1.0e3 / tChemSoot::MWCarbon);
262 namespace ablate::eos {
264 namespace tChemLib = TChem;
266 class TChemSoot :
public TChemBase,
public std::enable_shared_from_this<ablate::eos::TChemSoot> {
271 static inline std::string
CSolidName =
"C(S)";
278 static inline const std::string errorMessage =
"Using the TChemSoot requires serial build of Kokkos.";
285 explicit TChemSoot(std::filesystem::path
mechanismFile, std::shared_ptr<ablate::monitors::logs::Log>
log = {},
const std::shared_ptr<ablate::parameters::Parameters>& options = {})
287 throw std::runtime_error(errorMessage);
296 [[nodiscard]] ThermodynamicFunction
GetThermodynamicFunction(ThermodynamicProperty property,
const std::vector<domain::Field>& fields)
const override {
throw std::runtime_error(errorMessage); }
304 [[nodiscard]] ThermodynamicTemperatureFunction
GetThermodynamicTemperatureFunction(ThermodynamicProperty property,
const std::vector<domain::Field>& fields)
const override {
305 throw std::runtime_error(errorMessage);
314 [[nodiscard]] EOSFunction
GetFieldFunctionFunction(
const std::string& field, ThermodynamicProperty property1, ThermodynamicProperty property2,
315 std::vector<std::string> otherProperties)
const override {
316 throw std::runtime_error(errorMessage);
323 [[nodiscard]]
const std::vector<std::string>&
GetProgressVariables()
const override {
throw std::runtime_error(errorMessage); }
329 [[nodiscard]] std::map<std::string, double>
GetElementInformation()
const override {
throw std::runtime_error(errorMessage); }
335 [[nodiscard]] std::map<std::string, std::map<std::string, int>>
GetSpeciesElementalInformation()
const override {
throw std::runtime_error(errorMessage); }
341 [[nodiscard]] std::map<std::string, double>
GetSpeciesMolecularMass()
const override {
throw std::runtime_error(errorMessage); }
347 void View(std::ostream& stream)
const override {
throw std::runtime_error(errorMessage); }
Definition: tChemBase.hpp:25
std::shared_ptr< ablate::monitors::logs::Log > log
an optional log file for tchem echo redirection
Definition: tChemBase.hpp:34
const std::filesystem::path mechanismFile
the mechanismFile may be chemkin or yaml based
Definition: tChemBase.hpp:31
TChemBase(const std::string &eosName, std::filesystem::path mechanismFile, const std::shared_ptr< ablate::monitors::logs::Log > &={}, const std::shared_ptr< ablate::parameters::Parameters > &options={})
Definition: tChemBase.cpp:10
Definition: tChemSoot.hpp:29
ThermodynamicTemperatureFunction GetThermodynamicTemperatureFunction(ThermodynamicProperty property, const std::vector< domain::Field > &fields) const override
Definition: tChemSoot.cpp:92
std::map< std::string, double > GetElementInformation() const override
Definition: tChemSoot.cpp:652
ThermodynamicFunction GetThermodynamicFunction(ThermodynamicProperty property, const std::vector< domain::Field > &fields) const override
Definition: tChemSoot.cpp:87
static void FillWorkingVectorFromDensityMassFractions(double density, double temperature, const double *densityYi, const tChemSoot::StateVectorSoot< real_type_1d_view_host > &stateVector)
Definition: tChemSoot.cpp:377
std::shared_ptr< SourceCalculator > CreateSourceCalculator(const std::vector< domain::Field > &fields, const ablate::domain::Range &cellRange) override
Definition: tChemSoot.cpp:714
std::shared_ptr< FunctionContext > BuildFunctionContext(ablate::eos::ThermodynamicProperty property, const std::vector< domain::Field > &fields) const
Definition: tChemSoot.cpp:38
EOSFunction GetFieldFunctionFunction(const std::string &field, ThermodynamicProperty property1, ThermodynamicProperty property2, std::vector< std::string > otherProperties) const override
Definition: tChemSoot.cpp:407
static std::string CSolidName
Definition: tChemSoot.hpp:34
PetscErrorCode(*)(const PetscReal conserved[], PetscReal *property, void *ctx) ThermodynamicStaticFunction
Definition: tChemSoot.hpp:172
void View(std::ostream &stream) const override
Definition: tChemSoot.cpp:97
TChemSoot(std::filesystem::path mechanismFile, std::shared_ptr< ablate::monitors::logs::Log >={}, const std::shared_ptr< ablate::parameters::Parameters > &options={})
Definition: tChemSoot.cpp:18
const std::set< ThermodynamicProperty > speciesSizedProperties
Definition: tChemSoot.hpp:196
static std::string SootNumberDensityName
Definition: tChemSoot.hpp:39
static double ComputeSolidCarbonSensibleEnthalpy(double temperature)
Definition: tChemSoot.hpp:253
std::map< std::string, double > GetSpeciesMolecularMass() const override
Definition: tChemSoot.cpp:701
std::map< std::string, std::map< std::string, int > > GetSpeciesElementalInformation() const override
Definition: tChemSoot.cpp:668
const std::vector< std::string > & GetProgressVariables() const override
Definition: tChemSoot.hpp:84
Definition: stateVectorSoot.hpp:14