Skip to content

Aero-Structural Discrete Adjoint Sensitivities and Python Wrapper Developments #1750

Open
patelha57 wants to merge 167 commits intodevelopfrom
feature_pysu2_fsi_adjoint
Open

Aero-Structural Discrete Adjoint Sensitivities and Python Wrapper Developments #1750
patelha57 wants to merge 167 commits intodevelopfrom
feature_pysu2_fsi_adjoint

Conversation

@patelha57
Copy link
Copy Markdown
Contributor

@patelha57 patelha57 commented Sep 5, 2022

Motivation

Fundamental bottlenecks exist for industrial adoption of high-fidelity physics codes with fully coupled discrete adjoint sensitivity analysis. These bottlenecks include a lack of flexibility, modularity, and robustness of the computational tools, as well as the potential startup development costs needed to implement and verify the MDAO features. The purpose of this work is to facilitate the coupling of SU2 with external structural codes (e.g. NASTRAN, TACS, Airbus structural suite Lagrange) for gradient-based aerodynamic shape and structural sizing optimization using dedicated frameworks (e.g. OpenMDAO).

Startup development costs include the creation of modular tools that are designed to be driven by another framework like OpenMDAO, rather than to drive execution themselves. However, leveraging those MDAO frameworks assumes that software codes and modules to be coupled exist, have appropriate data structures, execution and query APIs, and are wrapped in Python for flexibility and ease of use. The proposed changes were motivated with the goal of making SU2 more modular and flexible, particularly to facilitate its integration into large-scale MDAO frameworks. For more details on the motivation, methodology, and verification & validation results, please refer to our paper from AIAA Aviation 2022.

Proposed Changes

@aa-g and I propose the following code updates:

  1. Implementation of residual-based discrete adjoint solver as CDiscAdjResidualSolver
    a. New config option: KIND_DISC_ADJ

  2. Enhancements and standardization of SU2 Python API
    a. Add pysu2/pysu2ad methods
    b. Standardize Python API and function names
    c. Overloaded getter/setter methods to make data handling more flexible

Related Work

These efforts are related to Issue #1262, Pull Request #1300, and Discussion #1325.

PR Checklist

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

WallyMaier and others added 30 commits May 7, 2020 14:20
@bigfooted
Copy link
Copy Markdown
Contributor

If you can add a test in parallel_regression_ad.py and add some kind of tutorial testcase, then it looks good to go for me. Maybe @pcarruscag can chime in and give additional code suggestions

@bigfooted
Copy link
Copy Markdown
Contributor

Hi @patelha57 what is the current status? Would be nice to see a couple of older PR's get merged into develop, especially this one.

@patelha57
Copy link
Copy Markdown
Contributor Author

Hi @patelha57 what is the current status? Would be nice to see a couple of older PR's get merged into develop, especially this one.

No additional code development needed from my POV (please correct me if I'm wrong!). Just need to fix these regression tests failures, add example for the residual solver adjoint, and add documentation.

Comment on lines +62 to +101
/*!
* \brief Get total sensitivity of the objective function w.r.t. surface coordinates or displacements at mesh
* vertices. \return Total sensitivity of the objective function w.r.t. the un-deformed coordinates.
*/
vector<vector<passivedouble>> GetObjectiveCoordinatesTotalSensitivities() const;

/*!
* \brief Get total sensitivity of the objective function w.r.t. surface coordinates or displacements at a mesh
* vertex. \param[in] iPoint - Mesh vertex index. \return Total sensitivity of the objective function w.r.t. the
* un-deformed coordinates.
*/
vector<passivedouble> GetObjectiveCoordinatesTotalSensitivities(unsigned long iPoint) const;

/*!
* \brief Get total sensitivity of the objective function w.r.t. surface coordinates or displacements at marker
* vertices. \param[in] iMarker - Marker identifier. \return Total sensitivity of the objective function w.r.t. the
* surface coordinates.
*/
vector<vector<passivedouble>> GetMarkerObjectiveCoordinatesTotalSensitivities(unsigned short iMarker) const;

/*!
* \brief Get total sensitivity of the objective function w.r.t. surface coordinates or displacements at a marker
* vertex. \param[in] iMarker - Marker identifier. \param[in] iVertex - Marker vertex index. \return Total sensitivity
* of the objective function w.r.t. the surface coordinates.
*/
vector<passivedouble> GetMarkerObjectiveCoordinatesTotalSensitivities(unsigned short iMarker,
unsigned long iVertex) const;

/*!
* \brief Get total sensitivity of the objective function w.r.t. the design variables.
* \return Total sensitivity of the objective function w.r.t. the design variables.
*/
vector<vector<passivedouble>> GetObjectiveDesignVariablesTotalSensitivities() const;

/*!
* \brief Get total sensitivity of the objective function w.r.t. a design variable.
* \param[in] iDV - Design Variable index.
* \return Total sensitivity of the objective function w.r.t. a design variable.
*/
vector<passivedouble> GetObjectiveDesignVariablesTotalSensitivities(unsigned short iDV) const;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This interface is not adequate, there is a better alternative as I've explained before.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You are talking about the matrix view implementation, correct?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yep, there is a recent example of doing that for another type of container here https://github.com/su2code/SU2/pull/2388/changes

import sys
import pysu2ad
from optparse import OptionParser
import numpy as np

Check notice

Code scanning / CodeQL

Unused import Note

Import of 'np' is not used.

Copilot Autofix

AI 1 day ago

To fix an unused-import issue, you remove the import statement for the symbol that is never referenced. This eliminates an unnecessary dependency and clarifies which modules are actually required.

Here, the best fix is to delete the line import numpy as np in TestCases/py_wrapper/disc_adj_residual_solver/run_adjoint.py (line 4). No other code in this file refers to np, so no additional changes are needed. This preserves all existing functionality while cleaning up the import list.

Suggested changeset 1
TestCases/py_wrapper/disc_adj_residual_solver/run_adjoint.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/disc_adj_residual_solver/run_adjoint.py b/TestCases/py_wrapper/disc_adj_residual_solver/run_adjoint.py
--- a/TestCases/py_wrapper/disc_adj_residual_solver/run_adjoint.py
+++ b/TestCases/py_wrapper/disc_adj_residual_solver/run_adjoint.py
@@ -1,7 +1,6 @@
 import sys
 import pysu2ad
 from optparse import OptionParser
-import numpy as np
 
 
 def main():
EOF
@@ -1,7 +1,6 @@
import sys
import pysu2ad
from optparse import OptionParser
import numpy as np


def main():
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.

6 participants