Skip to content

Conversation

@Cristopher-Morales
Copy link
Contributor

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.

Current status:

• SU2 clones Cantera in the subprojects directory if Cantera is not found.
• SU2 creates a meson.build if that files does not exist using cantera_meson_build.py within the subprojects/cantera folder. This meson.build file is needed for compiling SU2 with the option -Denable-cantera=true.
• Cantera must be precompiled before compiling SU2.
• Cantera is built and compiled using SCons, following the compilation procedure explained in the following link:
https://cantera.org/dev/develop/compiling/compilation-reqs.html
A conda environment is created and activated as depicted in the cantera.org website. Then, the following commands are used for building and installing Cantera within the folder SU2/subprojects/cantera:

   Build: 
         scons build boost_inc_dir=$PWD/include prefix=$PWD/install libdirname=$PWD/install/lib f90_interface=n system_eigen=n system_fmt=n system_yamlcpp=n system_sundials=n system_blas_lapack=n optimize=n`

   install:

         scons install

• After compiling Cantera, SU2 can be built with Cantera as follows (for example):

    ./meson.py build -Dwarning_level=2 -Denable-autodiff=false -Denable-directdiff=false -Dwith-mpi=enabled -Denable-cgns=true -Denable-tecio=false -Denable-cantera=true --prefix=/path_to_SU2_directory/SU2

• -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:

• Compile Cantera simultaneously with SU2 when -Denable-cantera=true.
• 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.

  • I am submitting my contribution to the develop branch.
  • My contribution generates no new compiler warnings (try with --warnlevel=3 when using meson).
  • My contribution is commented and consistent with SU2 style (https://su2code.github.io/docs_v7/Style-Guide/).
  • I used the pre-commit hook to prevent dirty commits and used pre-commit run --all to format old commits.
  • I have added a test case that demonstrates my contribution, if necessary.
  • I have updated appropriate documentation (Tutorials, Docs Page, config_template.cpp), if necessary.

* \brief Get High temperature applied during spark ignition.
* \return Spark Temperature.
*/
const su2double GetSpark_Temperature(void) const {

Check warning

Code scanning / CodeQL

Constant return type on member Warning

The 'const' modifier has no effect on return types. The 'const' modifying the return type can be removed.

Copilot Autofix

AI 2 days ago

In general, to fix this kind of issue you should remove any top-level const qualifier on a value return type, and, if the intention was to have a const member function, ensure the const appears after the parameter list instead. For pointer or reference return types, you should only remove the superfluous outer const and leave any meaningful inner qualifiers.

For this specific case, GetSpark_Temperature is declared as const su2double GetSpark_Temperature(void) const. The method is already correctly marked as a const member function by the trailing const. The leading const before su2double is the superfluous qualifier that CodeQL is complaining about. The best fix without changing runtime behavior is to remove that leading const, leaving the function as su2double GetSpark_Temperature(void) const { ... }. No other code or imports are required.

Only one region in Common/include/CConfig.hpp needs to be edited: the declaration/definition of GetSpark_Temperature around line 4063. We simply adjust the signature; the body and all surrounding code remain unchanged.

Suggested changeset 1
Common/include/CConfig.hpp

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/Common/include/CConfig.hpp b/Common/include/CConfig.hpp
--- a/Common/include/CConfig.hpp
+++ b/Common/include/CConfig.hpp
@@ -4060,7 +4060,7 @@
    * \brief Get High temperature applied during spark ignition.
    * \return Spark Temperature.
    */
-  const su2double GetSpark_Temperature(void) const {
+  su2double GetSpark_Temperature(void) const {
     return Spark_Temperature;
   }
 
EOF
@@ -4060,7 +4060,7 @@
* \brief Get High temperature applied during spark ignition.
* \return Spark Temperature.
*/
const su2double GetSpark_Temperature(void) const {
su2double GetSpark_Temperature(void) const {
return Spark_Temperature;
}

Copilot is powered by AI and may make mistakes. Always verify output.

#include <cmath>

// #include <numeric>

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.

Copilot Autofix

AI 2 days ago

In general, to fix commented-out code, either remove it entirely if it is no longer needed, or reinstate it as active code if it is required for functionality. If the intent is to document an example snippet, it should be reformatted to avoid looking like disabled code (for example, quoting it or explaining it in prose).

For this specific case, the best fix with no functional change is to remove the commented-out include directive // #include <numeric> from SU2_CFD/src/fluid/CFluidCantera.cpp. There is no indication in the shown code that <numeric> is needed (no calls to std::accumulate or similar), so uncommenting it would introduce an unused include, while leaving it as a comment keeps triggering the static analysis warning. Removing that single line resolves the CodeQL issue cleanly without affecting behavior. No additional methods, imports, or definitions are needed.

Suggested changeset 1
SU2_CFD/src/fluid/CFluidCantera.cpp

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/SU2_CFD/src/fluid/CFluidCantera.cpp b/SU2_CFD/src/fluid/CFluidCantera.cpp
--- a/SU2_CFD/src/fluid/CFluidCantera.cpp
+++ b/SU2_CFD/src/fluid/CFluidCantera.cpp
@@ -29,7 +29,6 @@
 
 #include <cmath>
 
-// #include <numeric>
 #ifdef USE_CANTERA
 #include <cantera/core.h>
 #include <cantera/kinetics/Reaction.h>
EOF
@@ -29,7 +29,6 @@

#include <cmath>

// #include <numeric>
#ifdef USE_CANTERA
#include <cantera/core.h>
#include <cantera/kinetics/Reaction.h>
Copilot is powered by AI and may make mistakes. Always verify output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants