Repository navigation
Adding Cantera fluid model for incompressible reacting flows - #2713
Cristopher-Morales wants to merge 297 commits into
Conversation
|
How difficult would it be to extend this to the compressible solver? |
Have a look at all the changed files that have "INC" in the name :-) |
… with the su2 compiler option
# Conflicts: # SU2_CFD/include/numerics/scalar/scalar_convection.hpp # SU2_CFD/include/numerics/scalar/scalar_diffusion.hpp # SU2_CFD/include/solvers/CSpeciesFlameletSolver.hpp # SU2_CFD/include/variables/CSpeciesVariable.hpp # UnitTests/meson.build
| AddHistoryOutput("RMS_SPECIES_" + config->GetChemical_GasComposition(iVar), "rms[rho*Y_" + config->GetChemical_GasComposition(iVar)+"]", ScreenOutputFormat::FIXED, "RMS_RES", "Root-mean square residual of transported species.", HistoryFieldType::RESIDUAL); | ||
| }else{ | ||
| AddHistoryOutput("RMS_SPECIES_" + std::to_string(iVar), "rms[rho*Y_" + std::to_string(iVar)+"]", ScreenOutputFormat::FIXED, "RMS_RES", "Root-mean square residual of transported species.", HistoryFieldType::RESIDUAL); | ||
| } |
There was a problem hiding this comment.
duplicated code, use helper function
| const unsigned long iter = config->GetIgnitionIter(); | ||
| ignition = ((iter >= spark_iter_start) && (iter <= (spark_iter_start + spark_duration))); | ||
| spark_radius_squared = spark_init[3] * spark_init[3]; | ||
| } |
There was a problem hiding this comment.
duplicated from CIncNSSolver
| } | ||
| if (config->GetCombustion()) flamelet_config_options = config->GetFlameletParsedOptions(); | ||
|
|
||
| if ((config->GetKind_FluidModel() == FLUID_MIXTURE || config->GetKind_FluidModel() == FLUID_CANTERA) && |
There was a problem hiding this comment.
logic repeated many times, make a config option
| * \note Sizes the stack storage of the species edge-flux kernel, which is the performance-critical | ||
| * user of this limit, and the static arrays of the species solver. Larger values slow the kernel down. | ||
| */ | ||
| constexpr unsigned short MAX_TRANSPORTED_SPECIES = 12; |
There was a problem hiding this comment.
look into performance aspects of this
| } | ||
| } | ||
|
|
||
| AD::SetPreaccOut(residual, nVar); |
There was a problem hiding this comment.
may also need jacobian here, check with tape tagging
| /*--- Initialization. ---*/ | ||
| for (auto iVar = 0u; iVar < nVar; iVar++) { | ||
| residual[iVar] = 0.0; | ||
| for (auto jVar = 0; jVar < nVar; jVar++) { |
There was a problem hiding this comment.
comparing signed with unsigned
| Chemistry_Min_Temperature(config->GetCantera_DC_Min_Temp()), | ||
| Correction_Velocity(config->GetCantera_Correction_Velocity()) { | ||
| try { | ||
| sol = std::shared_ptr<Cantera::Solution>(newSolution(Chemical_MechanismFile, Phase_Name, Transport_Model)); |
There was a problem hiding this comment.
newSolution is already a shared_ptr
|
|
||
| void CFluidCantera::SetEnthalpyFormation(const CConfig* config) { | ||
| SetMassFractions(config->GetSpecies_Init()); | ||
| sol->thermo()->setMassFractions(massFractions.data()); |
There was a problem hiding this comment.
are all these mass fractions needed?
| * \ingroup SourceDiscr | ||
| * \author C.Morales Ubal | ||
| */ | ||
| template <class FlowIndices> |
There was a problem hiding this comment.
you don't need FlowIndices, nothing in the class uses it
|
|
||
| const bool implicit = (config->GetKind_TimeIntScheme() == EULER_IMPLICIT); | ||
| const bool axisymmetric = config->GetAxisymmetric(); | ||
| const bool combustion =config->GetCombustion(); |
|
I benchmarked how What slows down
The cases are WhyThe cost grows with the square of the cap, and by about the same absolute amount whatever the number of species. Retired instructions grow too, so this is extra work, not cache effects. A profile at cap 24 shows The source is the default constructor of C2DContainer() noexcept : Base() {}Naming Stack frame size and stack probes are not the cause. The frame is set up once per call, not per edge. A test build with the cap-24 frame but no zero-fill ran at cap-8 speed. Proposed fixAdd an opt-in constructor that skips the zero-fill, and use it only for +/*!
+ * \brief Tag to construct a static-size C2DContainer without initializing its data.
+ */
+struct C2DUninitialized {}; C2DContainer() noexcept : Base() {}
+ /*!
+ * \brief Static-size ctor that leaves the data uninitialized, unlike the default ctor which
+ * value-initializes (zeroes) it. For hot-path temporaries that write before they read.
+ */
+ explicit C2DContainer(C2DUninitialized) noexcept {
+ static_assert(StaticRows != DynamicSize && StaticCols != DynamicSize, "Requires a static size.");
+ }- FORCEINLINE explicit EdgeResidual(size_t nEqn) : nVar(nEqn) {
+ FORCEINLINE explicit EdgeResidual(size_t nEqn)
+ : flux_i(C2DUninitialized{}),
+ flux_j(C2DUninitialized{}),
+ jac_ii(C2DUninitialized{}),
+ jac_ij(C2DUninitialized{}),
+ jac_ji(C2DUninitialized{}),
+ jac_jj(C2DUninitialized{}),
+ nVar(nEqn) {This is safe because every read of an With the fix, compared with the current cap 8 (5 new runs per build, interleaved):
So with the fix, cap 12 is faster than today's cap 8, and cap 24 is within about 2 % of it, which is within run-to-run noise for the serial cases. Correctness checks:
Related: the effective cap is 20
Suggestions
Machine: Apple M2 Pro, macOS 15.7, Apple clang 17.0.0, Open MPI 5.0.8, |
…nto feature_CANTERA_PR
Proposed Changes
This pull request aims to add a fluid model called FLUID_CANTERA for coupling Cantera library with SU2. Cantera library is an open-source library for problems involving chemical kinetics, thermodynamics, and transport processes. This is needed for combustion problems using the incompressible solver.
[UPDATE] adding the cantera option to meson is now sufficient to get cantera coupled to su2.
SU2 can be built with Cantera as follows (for example):
• -Denable-tests=true can be used for testing if Cantera is correctly compiled with SU2, running one of the Cantera fluid unit test cases.
Work in progress:
• Improve cantera coupling, only compile the functionalities needed for SU2. Currently, when cantera is compiled, whole functionalities are compiled. Most of the cantera implementations are not needed for incompressible reacting flows.
• Compile cantera with the AD options. For this purpose, a different repository must be cloned and compiled, where the AD implementation of cantera is located.
• Add regression and unit test cases in the SU2 workflow.
Regarding the coupling between SU2 and Cantera, any advice/suggestion how to improve it would be really appreciated.
Thanks in advance!!
Related Work
Related to pull request #2426
PR Checklist
Put an X by all that apply. You can fill this out after submitting the PR. If you have any questions, don't hesitate to ask! We want to help. These are a guide for you to know what the reviewers will be looking for in your contribution.
pre-commit run --allto format old commits.