Skip to content

[WIP] Multizone adjoints for turbomachinery #2446

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 12 commits into
base: develop
Choose a base branch
from

Conversation

joshkellyjak
Copy link
Contributor

Proposed Changes

This is a cleaned up PR of the fixes needed for multizone adjoints for turbomachinery from the previous PR of @oleburghardt and I's work.

This hopefully is useable, so if you would like to test and report please feel free to contact me on Slack.

TODO:

  • Fix eddy viscosity tape issue in CNSSolver
  • Add turbomachinery objective functions + constraints
  • Include MZ testcase

Related Work

Now closed PR #2317

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.

  • [ X ] 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.

Comment on lines +675 to 677
AD::EndPreacc();

/*--- Max is not differentiable, so we not register them for preacc. ---*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the difference between ending the preaccumulation before or after?

}
} else if (Multizone_Problem && DiscreteAdjoint) {
SU2_MPI::Error(string("OUTPUT_WRT_FREQ cannot be specified for this solver "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
SU2_MPI::Error(string("OUTPUT_WRT_FREQ cannot be specified for this solver "
SU2_MPI::Error("OUTPUT_WRT_FREQ cannot be specified for this solver "

Comment on lines +3425 to +3426
"(writing of restart and sensitivity files not possible for multizone discrete adjoint during runtime yet).\n"
"Please remove this option from the config file, output files will be written when solver finalizes.\n"), CURRENT_FUNCTION);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm I'm pretty sure it is possible

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is one for @oleburghardt

Copy link
Contributor

@oleburghardt oleburghardt Mar 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes and no, writing the files is fine, but the continuation of the multi-zone discrete adjoint solver is erratic. My guess is that some indices aren't cleared properly before re-recording the tape. (Writing adjoint solution variables to file only, without re-recording at all and without sensitivities, might give us some hints.)
The debug mode could eventually pin down where exactly things go wrong.

Comment on lines -222 to +229
BPressure = config->GetPressureOut_BC();
Temperature = config->GetTotalTemperatureIn_BC();

if (!reset){
AD::RegisterInput(BPressure);
AD::RegisterInput(Temperature);
}

BPressure = config->GetPressureOut_BC();
Temperature = config->GetTotalTemperatureIn_BC();

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these wrong but not the others that follow the same pattern?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This threw a tagging error, and if I remember correctly it's because in the other sections the variables it accesses are directly used in the solver, whereas in the Giles implementation they are not, creating a mismatch in tags.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we fix it in a way that keeps a clear pattern for doing this type of thing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can give it a go

… to run in quasi-MZ approach. (NEEDS CLEANING)
Comment on lines +693 to +696
// /*--- Turbo Specific Post-Procesisng ---*/
// if (config_container[iZone]->GetBoolTurbomachinery()){
// direct_iteration[iZone][INST_0]->Postprocess(output_container[iZone], integration_container, geometry_container, solver_container, numerics_container, config_container, surface_movement, grid_movement, FFDBox, iZone, INST_0);
// }

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.

Copilot Autofix

AI about 1 month ago

To fix the problem, we need to either remove the commented-out code entirely or reinstate it into the program. Since the code appears to be functional and related to "Turbo Specific Post-Processing," it is likely intended to be part of the program's functionality. Therefore, the best approach is to reinstate the code by uncommenting it. This ensures that the functionality is included and tested, and it eliminates the distraction of commented-out code.

The changes will be made in the DirectIteration method of the CDiscAdjMultizoneDriver class, specifically around line 693. The commented-out code will be uncommented, and the indentation will be adjusted to match the surrounding code.

Suggested changeset 1
SU2_CFD/src/drivers/CDiscAdjMultizoneDriver.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/drivers/CDiscAdjMultizoneDriver.cpp b/SU2_CFD/src/drivers/CDiscAdjMultizoneDriver.cpp
--- a/SU2_CFD/src/drivers/CDiscAdjMultizoneDriver.cpp
+++ b/SU2_CFD/src/drivers/CDiscAdjMultizoneDriver.cpp
@@ -692,6 +692,6 @@
 
-  // /*--- Turbo Specific Post-Procesisng ---*/
-  // if (config_container[iZone]->GetBoolTurbomachinery()){
-  //   direct_iteration[iZone][INST_0]->Postprocess(output_container[iZone], integration_container, geometry_container, solver_container, numerics_container, config_container, surface_movement, grid_movement, FFDBox, iZone, INST_0);
-  // }
+  /*--- Turbo Specific Post-Processing ---*/
+  if (config_container[iZone]->GetBoolTurbomachinery()) {
+    direct_iteration[iZone][INST_0]->Postprocess(output_container[iZone], integration_container, geometry_container, solver_container, numerics_container, config_container, surface_movement, grid_movement, FFDBox, iZone, INST_0);
+  }
 
EOF
@@ -692,6 +692,6 @@

// /*--- Turbo Specific Post-Procesisng ---*/
// if (config_container[iZone]->GetBoolTurbomachinery()){
// direct_iteration[iZone][INST_0]->Postprocess(output_container[iZone], integration_container, geometry_container, solver_container, numerics_container, config_container, surface_movement, grid_movement, FFDBox, iZone, INST_0);
// }
/*--- Turbo Specific Post-Processing ---*/
if (config_container[iZone]->GetBoolTurbomachinery()) {
direct_iteration[iZone][INST_0]->Postprocess(output_container[iZone], integration_container, geometry_container, solver_container, numerics_container, config_container, surface_movement, grid_movement, FFDBox, iZone, INST_0);
}

Copilot is powered by AI and may make mistakes. Always verify output.
Comment on lines +92 to +99
// BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS {
// if (config->GetBoolTurbomachinery()){
// /*--- Average quantities at the inflow and outflow boundaries ---*/
// solver_container[MainSolver]->TurboAverageProcess(solver_container, geometry,config,INFLOW);
// solver_container[MainSolver]->TurboAverageProcess(solver_container, geometry, config, OUTFLOW);
// }
// }
// END_SU2_OMP_SAFE_GLOBAL_ACCESS

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.

Copilot Autofix

AI about 1 month ago

To fix the issue, we need to either remove the commented-out code entirely or reinstate it into the program. Since there is no explicit indication that this code is obsolete, and it appears to be part of a specific functionality (SU2_OMP_SAFE_GLOBAL_ACCESS), the best course of action is to reinstate the code. This will ensure that the functionality is preserved and can be tested and maintained as part of the codebase. If the functionality is not currently needed, it can be conditionally compiled using preprocessor directives (e.g., #ifdef) to avoid confusion while keeping the code accessible for future use.

The changes will involve uncommenting the block of code between // BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS and // END_SU2_OMP_SAFE_GLOBAL_ACCESS and ensuring that it integrates correctly with the surrounding code.


Suggested changeset 1
SU2_CFD/src/integration/CIntegration.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/integration/CIntegration.cpp b/SU2_CFD/src/integration/CIntegration.cpp
--- a/SU2_CFD/src/integration/CIntegration.cpp
+++ b/SU2_CFD/src/integration/CIntegration.cpp
@@ -91,9 +91,8 @@
 
-  // BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS {
-  //   if (config->GetBoolTurbomachinery()){
-  //       /*--- Average quantities at the inflow and outflow boundaries ---*/
-  //     solver_container[MainSolver]->TurboAverageProcess(solver_container, geometry,config,INFLOW);
-  //     solver_container[MainSolver]->TurboAverageProcess(solver_container, geometry, config, OUTFLOW);
-  //   }
-  // }
+  // BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS
+  if (config->GetBoolTurbomachinery()){
+      /*--- Average quantities at the inflow and outflow boundaries ---*/
+    solver_container[MainSolver]->TurboAverageProcess(solver_container, geometry, config, INFLOW);
+    solver_container[MainSolver]->TurboAverageProcess(solver_container, geometry, config, OUTFLOW);
+  }
   // END_SU2_OMP_SAFE_GLOBAL_ACCESS
EOF
@@ -91,9 +91,8 @@

// BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS {
// if (config->GetBoolTurbomachinery()){
// /*--- Average quantities at the inflow and outflow boundaries ---*/
// solver_container[MainSolver]->TurboAverageProcess(solver_container, geometry,config,INFLOW);
// solver_container[MainSolver]->TurboAverageProcess(solver_container, geometry, config, OUTFLOW);
// }
// }
// BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS
if (config->GetBoolTurbomachinery()){
/*--- Average quantities at the inflow and outflow boundaries ---*/
solver_container[MainSolver]->TurboAverageProcess(solver_container, geometry, config, INFLOW);
solver_container[MainSolver]->TurboAverageProcess(solver_container, geometry, config, OUTFLOW);
}
// END_SU2_OMP_SAFE_GLOBAL_ACCESS
Copilot is powered by AI and may make mistakes. Always verify output.
Comment on lines +494 to +495
// CGeometry::ComputeWallDistance(config, geometry);
// }

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.

Copilot Autofix

AI about 1 month ago

To resolve the issue, we need to either remove the commented-out code or reinstate it into the codebase. Since the surrounding comments suggest that the code might be part of a turbo simulation workflow, we should carefully evaluate whether the commented-out code is still relevant. If it is, we should reinstate it; otherwise, we should remove it entirely.

In this case, the commented-out code does not appear to be actively used or necessary for the current implementation. Therefore, the best course of action is to remove the commented-out code to improve readability and maintainability.


Suggested changeset 1
SU2_CFD/src/iteration/CDiscAdjFluidIteration.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/iteration/CDiscAdjFluidIteration.cpp b/SU2_CFD/src/iteration/CDiscAdjFluidIteration.cpp
--- a/SU2_CFD/src/iteration/CDiscAdjFluidIteration.cpp
+++ b/SU2_CFD/src/iteration/CDiscAdjFluidIteration.cpp
@@ -493,3 +493,3 @@
 
-      //   CGeometry::ComputeWallDistance(config, geometry);
+      
       // }
EOF
@@ -493,3 +493,3 @@

// CGeometry::ComputeWallDistance(config, geometry);

// }
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.

3 participants