Skip to content

[WIP] pywrapper - custom source terms for all solvers #2388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 41 commits into
base: develop
Choose a base branch
from

Conversation

bigfooted
Copy link
Contributor

@bigfooted bigfooted commented Dec 3, 2024

Proposed Changes

Introduce custom source terms for all solvers through the python wrapper.

  • reproduces the laminar buoyancy driven cavity testcase
  • can simulate a turbulent premixed flame using turbulent flamespeed closure (TFC)

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.

bigfooted and others added 2 commits December 3, 2024 16:18
… type in loop condition

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
unsigned long CDriver::GetNumberOuterIter() const { return config_container[selected_zone]->GetnOuter_Iter(); }

unsigned long CDriver::GetDensity_FreeStreamND() const {
return SU2_TYPE::GetValue(config_container[selected_zone]->GetDensity_FreeStreamND());

Check warning

Code scanning / CodeQL

Lossy function result cast Warning

Return value of type double is implicitly converted to unsigned long.
return SU2_TYPE::GetValue(config_container[selected_zone]->GetDensity_FreeStreamND());
}
unsigned long CDriver::GetForce_Ref() const {
return SU2_TYPE::GetValue(config_container[selected_zone]->GetForce_Ref());

Check warning

Code scanning / CodeQL

Lossy function result cast Warning

Return value of type double is implicitly converted to unsigned long.
@@ -66,6 +76,11 @@

string CDriver::GetSurfaceFileName() const { return config_container[selected_zone]->GetSurfCoeff_FileName(); }

unsigned long CDriver::GetSolution(unsigned short iSOLVER, unsigned long iPoint, unsigned short iVar) {
auto solver = solver_container[iZone][INST_0][MESH_0][iSOLVER];
return SU2_TYPE::GetValue(solver->GetNodes()->GetSolution(iPoint,iVar));

Check warning

Code scanning / CodeQL

Lossy function result cast Warning

Return value of type double is implicitly converted to unsigned long.
iDENSITY = primindex.get("DENSITY")
#print("index of density = ",iDENSITY)

index_Vel = varindex.get("VELOCITY_X")

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable index_Vel is not used.

Copilot Autofix

AI about 1 month ago

To fix the issue, we should remove the assignment to index_Vel entirely, as it is not used anywhere in the code. This will eliminate the unused variable and make the code cleaner. Since the right-hand side of the assignment (varindex.get("VELOCITY_X")) does not have any side effects, it is safe to remove the entire line.


Suggested changeset 1
TestCases/py_wrapper/custom_source/run.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/TestCases/py_wrapper/custom_source/run.py b/TestCases/py_wrapper/custom_source/run.py
--- a/TestCases/py_wrapper/custom_source/run.py
+++ b/TestCases/py_wrapper/custom_source/run.py
@@ -79,4 +79,3 @@
 
-  index_Vel = varindex.get("VELOCITY_X")
-  #print("index of velocity = ",index_Vel)
+  #print("index of velocity = ", varindex.get('VELOCITY_X'))  # Optional: Keep for debugging
   custom_source_vector = [0.0 for i in range(nVars)]
EOF
@@ -79,4 +79,3 @@

index_Vel = varindex.get("VELOCITY_X")
#print("index of velocity = ",index_Vel)
#print("index of velocity = ", varindex.get('VELOCITY_X')) # Optional: Keep for debugging
custom_source_vector = [0.0 for i in range(nVars)]
Copilot is powered by AI and may make mistakes. Always verify output.
solvar = list(SU2Driver.GetSolutionVector(iFLOWSOLVER, iPoint))
# the list with names
solindex = getsolvar(SU2Driver)
primindex = SU2Driver.GetPrimitiveIndices()

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable primindex is not used.

Copilot Autofix

AI 7 days ago

To fix the issue, we should remove the assignment to the unused variable primindex on line 103. Since the variable is not used anywhere in the function, its removal will not affect the functionality of the code. Care should be taken to ensure that the removal does not inadvertently delete any other necessary code or comments.


Suggested changeset 1
TestCases/py_wrapper/turbulent_premixed_psi/run.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/TestCases/py_wrapper/turbulent_premixed_psi/run.py b/TestCases/py_wrapper/turbulent_premixed_psi/run.py
--- a/TestCases/py_wrapper/turbulent_premixed_psi/run.py
+++ b/TestCases/py_wrapper/turbulent_premixed_psi/run.py
@@ -102,3 +102,3 @@
     solindex = getsolvar(SU2Driver)
-    primindex = SU2Driver.GetPrimitiveIndices()
+    # Removed unused variable primindex
     iTEMP = solindex.get("TEMPERATURE")
EOF
@@ -102,3 +102,3 @@
solindex = getsolvar(SU2Driver)
primindex = SU2Driver.GetPrimitiveIndices()
# Removed unused variable primindex
iTEMP = solindex.get("TEMPERATURE")
Copilot is powered by AI and may make mistakes. Always verify output.
Unable to commit as this autofix suggestion is now outdated
bigfooted and others added 7 commits February 24, 2025 21:26
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
for prim in varindex.copy():
if varindex[prim] >=nVars:
del varindex[prim]
varindex = dict(sorted(varindex.items(), key=lambda item: item[1]))

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable varindex is not used.

Copilot Autofix

AI 7 days ago

To fix the issue, we need to address the unused variable varindex. Since the variable is not used after its assignment, we can safely remove the assignment on line 212. This ensures that the code remains clean and avoids unnecessary computations.

If the variable was intended for documentation purposes or debugging, we could rename it to follow conventions for unused variables (e.g., _unused_varindex). However, there is no evidence in the code to suggest this intention.


Suggested changeset 1
TestCases/py_wrapper/turbulent_premixed_psi/run.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/TestCases/py_wrapper/turbulent_premixed_psi/run.py b/TestCases/py_wrapper/turbulent_premixed_psi/run.py
--- a/TestCases/py_wrapper/turbulent_premixed_psi/run.py
+++ b/TestCases/py_wrapper/turbulent_premixed_psi/run.py
@@ -211,3 +211,3 @@
       del varindex[prim]
-  varindex = dict(sorted(varindex.items(), key=lambda item: item[1]))
+  # Removed unused assignment to varindex
 
EOF
@@ -211,3 +211,3 @@
del varindex[prim]
varindex = dict(sorted(varindex.items(), key=lambda item: item[1]))
# Removed unused assignment to varindex

Copilot is powered by AI and may make mistakes. Always verify output.
Unable to commit as this autofix suggestion is now outdated
@@ -615,9 +619,13 @@
*Kind_Data_Giles; /*!< \brief Kind of inlet boundary treatment. */
INLET_TYPE Kind_Inlet;
INLET_TYPE *Kind_Inc_Inlet;

//WALL_SPECIES_TYPE **Wall_SpeciesType;
unsigned short **Wall_SpeciesType;

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.

Copilot Autofix

AI 7 days ago

To resolve the issue, we need to either remove the commented-out code or reinstate it as active code. Since there is no context indicating that the commented-out line is necessary or relevant, the best approach is to remove it entirely. This will improve code readability and eliminate potential confusion for developers.


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
@@ -623,3 +623,3 @@
 
-  //WALL_SPECIES_TYPE **Wall_SpeciesType;
+  
   unsigned short **Wall_SpeciesType;
EOF
@@ -623,3 +623,3 @@

//WALL_SPECIES_TYPE **Wall_SpeciesType;

unsigned short **Wall_SpeciesType;
Copilot is powered by AI and may make mistakes. Always verify output.
Unable to commit as this autofix suggestion is now outdated
su2double** & wall_species_val, unsigned short & nSpecies_per_Wall);
void addWallSpeciesType(const string& name, unsigned short & nMarker_Wall_Species, string * & Marker_Wall_Species,
// WALL_SPECIES_TYPE** & wall_species_type, unsigned short & nSpecies_per_Wall);
unsigned short** & wall_species_type, unsigned short & nSpecies_per_Wall);

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.

Copilot Autofix

AI 7 days ago

To resolve the issue, the commented-out code on line 1354 should be removed. This ensures that the codebase remains clean and avoids confusion for developers. Removing the line does not affect functionality because the uncommented version of the code (line 1355) already serves the intended purpose.

Steps to implement the fix:

  1. Locate the commented-out code on line 1354 in the file Common/include/CConfig.hpp.
  2. Remove the line entirely.
  3. Verify that the removal does not affect the functionality of the surrounding code.

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
@@ -1353,3 +1353,2 @@
   void addWallSpeciesType(const string& name, unsigned short & nMarker_Wall_Species, string * & Marker_Wall_Species,
-//                      WALL_SPECIES_TYPE** & wall_species_type, unsigned short & nSpecies_per_Wall);
                       unsigned short** & wall_species_type, unsigned short & nSpecies_per_Wall);
EOF
@@ -1353,3 +1353,2 @@
void addWallSpeciesType(const string& name, unsigned short & nMarker_Wall_Species, string * & Marker_Wall_Species,
// WALL_SPECIES_TYPE** & wall_species_type, unsigned short & nSpecies_per_Wall);
unsigned short** & wall_species_type, unsigned short & nSpecies_per_Wall);
Copilot is powered by AI and may make mistakes. Always verify output.
Unable to commit as this autofix suggestion is now outdated
Comment on lines +4979 to +4980
//unsigned short* GetKind_Wall_Species(const string& val_marker) const;

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.

Copilot Autofix

AI 7 days ago

To fix the issue, we need to either remove the commented-out code or reinstate it as active code if it is still relevant. Since there is no context suggesting that the function is required, the best course of action is to remove the commented-out line entirely. This will improve code readability and maintainability.


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
@@ -4978,3 +4978,2 @@
    */
-// WALL_SPECIES_TYPE* GetKind_Wall_Species(const string& val_marker) const;
  //unsigned short* GetKind_Wall_Species(const string& val_marker) const;
EOF
@@ -4978,3 +4978,2 @@
*/
// WALL_SPECIES_TYPE* GetKind_Wall_Species(const string& val_marker) const;
//unsigned short* GetKind_Wall_Species(const string& val_marker) const;
Copilot is powered by AI and may make mistakes. Always verify output.
Unable to commit as this autofix suggestion is now outdated
Comment on lines +5644 to +5650
// for (unsigned short iSpecies = 0; iSpecies < nSpecies; iSpecies++) {
// checkScalarBounds(Species_Init[iSpecies], "SPECIES_INIT individual", 0.0, 1.0);
// Species_Init_Sum += Species_Init[iSpecies];
// }
// checkScalarBounds(Species_Init_Sum, "SPECIES_INIT sum", 0.0, 1.0);

// for (iMarker = 0; iMarker < nMarker_Inlet_Species; iMarker++) {

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.

Copilot Autofix

AI 7 days ago

To resolve the issue, we will remove the commented-out code entirely. This approach is appropriate because the surrounding comments and cout statements indicate that bounds checking for species-related quantities is no longer performed. If this functionality is needed in the future, it can be reintroduced with proper testing and integration.

Steps to fix:

  1. Remove the commented-out code block starting from line 5644 to line 5660.
  2. Ensure that the removal does not affect the functionality of the remaining code.

Suggested changeset 1
Common/src/CConfig.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/Common/src/CConfig.cpp b/Common/src/CConfig.cpp
--- a/Common/src/CConfig.cpp
+++ b/Common/src/CConfig.cpp
@@ -5643,19 +5643,3 @@
 cout << "warning: no bounds checked for species" << endl;
-    // if (Kind_Species_Model == SPECIES_MODEL::SPECIES_TRANSPORT) {
-    //   su2double Species_Init_Sum = 0.0;
-    //   for (unsigned short iSpecies = 0; iSpecies < nSpecies; iSpecies++) {
-    //     checkScalarBounds(Species_Init[iSpecies], "SPECIES_INIT individual", 0.0, 1.0);
-    //     Species_Init_Sum += Species_Init[iSpecies];
-    //   }
-    //   checkScalarBounds(Species_Init_Sum, "SPECIES_INIT sum", 0.0, 1.0);
 
-    //   for (iMarker = 0; iMarker < nMarker_Inlet_Species; iMarker++) {
-    //     su2double Inlet_SpeciesVal_Sum = 0.0;
-    //     for (unsigned short iSpecies = 0; iSpecies < nSpecies; iSpecies++) {
-    //       checkScalarBounds(Inlet_SpeciesVal[iMarker][iSpecies], "MARKER_INLET_SPECIES individual", 0.0, 1.0);
-    //       Inlet_SpeciesVal_Sum += Inlet_SpeciesVal[iMarker][iSpecies];
-    //     }
-    //     checkScalarBounds(Inlet_SpeciesVal_Sum, "MARKER_INLET_SPECIES sum", 0.0, 1.0);
-    //   }
-    // }
 
EOF
@@ -5643,19 +5643,3 @@
cout << "warning: no bounds checked for species" << endl;
// if (Kind_Species_Model == SPECIES_MODEL::SPECIES_TRANSPORT) {
// su2double Species_Init_Sum = 0.0;
// for (unsigned short iSpecies = 0; iSpecies < nSpecies; iSpecies++) {
// checkScalarBounds(Species_Init[iSpecies], "SPECIES_INIT individual", 0.0, 1.0);
// Species_Init_Sum += Species_Init[iSpecies];
// }
// checkScalarBounds(Species_Init_Sum, "SPECIES_INIT sum", 0.0, 1.0);

// for (iMarker = 0; iMarker < nMarker_Inlet_Species; iMarker++) {
// su2double Inlet_SpeciesVal_Sum = 0.0;
// for (unsigned short iSpecies = 0; iSpecies < nSpecies; iSpecies++) {
// checkScalarBounds(Inlet_SpeciesVal[iMarker][iSpecies], "MARKER_INLET_SPECIES individual", 0.0, 1.0);
// Inlet_SpeciesVal_Sum += Inlet_SpeciesVal[iMarker][iSpecies];
// }
// checkScalarBounds(Inlet_SpeciesVal_Sum, "MARKER_INLET_SPECIES sum", 0.0, 1.0);
// }
// }

Copilot is powered by AI and may make mistakes. Always verify output.
Unable to commit as this autofix suggestion is now outdated
}
//const WALL_SPECIES_TYPE* CConfig::GetWall_SpeciesType(const string& val_marker) const {
const unsigned short* CConfig::GetWall_SpeciesType(const string& val_marker) const {
unsigned short iMarker_Wall_Species;

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.

Copilot Autofix

AI 7 days ago

To fix the issue, we should either remove the commented-out code entirely or reinstate it if it is still relevant. In this case, since the function CConfig::GetWall_SpeciesType is already implemented in the following lines (9163–9167), the commented-out version of the function is redundant and should be removed. This will improve code readability and maintainability.

Suggested changeset 1
Common/src/CConfig.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/Common/src/CConfig.cpp b/Common/src/CConfig.cpp
--- a/Common/src/CConfig.cpp
+++ b/Common/src/CConfig.cpp
@@ -9161,3 +9161,3 @@
 }
-//const WALL_SPECIES_TYPE* CConfig::GetWall_SpeciesType(const string& val_marker) const {
+
 const unsigned short* CConfig::GetWall_SpeciesType(const string& val_marker) const {
EOF
@@ -9161,3 +9161,3 @@
}
//const WALL_SPECIES_TYPE* CConfig::GetWall_SpeciesType(const string& val_marker) const {

const unsigned short* CConfig::GetWall_SpeciesType(const string& val_marker) const {
Copilot is powered by AI and may make mistakes. Always verify output.
Unable to commit as this autofix suggestion is now outdated
Comment on lines +473 to +483
// //case WALL_SPECIES_TYPE::FLUX:
// case 0:
// cout << "flux" << endl;
// break;
// //case WALL_SPECIES_TYPE::VALUE:
// case 1:
// cout << "value" << endl;
// break;
// default:
// break;
// }

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.

Copilot Autofix

AI 7 days ago

The best way to fix this issue is to either remove the commented-out code entirely if it is no longer needed or reinstate it if it is still relevant and should be part of the active codebase. In this case, the commented-out code appears to be an incomplete switch statement for handling different wall species types. Since there is no indication that this code is actively being used or maintained, it is better to remove it to avoid confusion.

Suggested changeset 1
SU2_CFD/src/solvers/CSpeciesSolver.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/solvers/CSpeciesSolver.cpp b/SU2_CFD/src/solvers/CSpeciesSolver.cpp
--- a/SU2_CFD/src/solvers/CSpeciesSolver.cpp
+++ b/SU2_CFD/src/solvers/CSpeciesSolver.cpp
@@ -475,16 +475,3 @@
   cout << "type = "<<(wallspeciestype[0]) << " " << wallspeciestype[1] << endl;
-  //  switch (config->GetWall_SpeciesType(Marker_Tag)[0]) {
-  //       /*--- incompressible conditions ---*/
-
-  //       //case WALL_SPECIES_TYPE::FLUX:
-  //       case 0:
-  //         cout << "flux" << endl;
-  //       break;
-  //       //case WALL_SPECIES_TYPE::VALUE:
-  //       case 1: 
-  //         cout << "value" << endl;
-  //       break;
-  //       default:
-  //       break;
-  //  }
+// Removed commented-out code block for clarity and maintainability.
 }
EOF
@@ -475,16 +475,3 @@
cout << "type = "<<(wallspeciestype[0]) << " " << wallspeciestype[1] << endl;
// switch (config->GetWall_SpeciesType(Marker_Tag)[0]) {
// /*--- incompressible conditions ---*/

// //case WALL_SPECIES_TYPE::FLUX:
// case 0:
// cout << "flux" << endl;
// break;
// //case WALL_SPECIES_TYPE::VALUE:
// case 1:
// cout << "value" << endl;
// break;
// default:
// break;
// }
// Removed commented-out code block for clarity and maintainability.
}
Copilot is powered by AI and may make mistakes. Always verify output.
Unable to commit as this autofix suggestion is now outdated
solvar = list(SU2Driver.GetSolutionVector(iFLOWSOLVER, iPoint))
# the list with names
solindex = getsolvar(SU2Driver)
primindex = SU2Driver.GetPrimitiveIndices()

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable primindex is not used.

Copilot Autofix

AI 7 days ago

To fix the issue, we will remove the assignment to the unused variable primindex on line 103. Since the variable is not used anywhere in the function or the provided code, its removal will not affect the functionality of the program. This change will make the code cleaner and eliminate the CodeQL warning.


Suggested changeset 1
TestCases/py_wrapper/run.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/TestCases/py_wrapper/run.py b/TestCases/py_wrapper/run.py
--- a/TestCases/py_wrapper/run.py
+++ b/TestCases/py_wrapper/run.py
@@ -102,3 +102,3 @@
     solindex = getsolvar(SU2Driver)
-    primindex = SU2Driver.GetPrimitiveIndices()
+# (Line removed as it is unused)
     iTEMP = solindex.get("TEMPERATURE")
EOF
@@ -102,3 +102,3 @@
solindex = getsolvar(SU2Driver)
primindex = SU2Driver.GetPrimitiveIndices()
# (Line removed as it is unused)
iTEMP = solindex.get("TEMPERATURE")
Copilot is powered by AI and may make mistakes. Always verify output.
Unable to commit as this autofix suggestion is now outdated
for prim in varindex.copy():
if varindex[prim] >=nVars:
del varindex[prim]
varindex = dict(sorted(varindex.items(), key=lambda item: item[1]))

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable varindex is not used.

Copilot Autofix

AI 7 days ago

To fix the issue, we should remove the unused assignment to varindex on line 212. This will eliminate the redundant code and make the program cleaner and easier to maintain. Since the variable varindex is not used after this assignment, removing it will not impact the program's behavior.


Suggested changeset 1
TestCases/py_wrapper/run.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/TestCases/py_wrapper/run.py b/TestCases/py_wrapper/run.py
--- a/TestCases/py_wrapper/run.py
+++ b/TestCases/py_wrapper/run.py
@@ -211,3 +211,3 @@
       del varindex[prim]
-  varindex = dict(sorted(varindex.items(), key=lambda item: item[1]))
+# (Line removed as it is unused)
 
EOF
@@ -211,3 +211,3 @@
del varindex[prim]
varindex = dict(sorted(varindex.items(), key=lambda item: item[1]))
# (Line removed as it is unused)

Copilot is powered by AI and may make mistakes. Always verify output.
Unable to commit as this autofix suggestion is now outdated
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.

1 participant