Skip to content
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

Bugfix for rotating frame sensitivities + add Tapenade checks #121

Merged
merged 147 commits into from
May 17, 2022

Conversation

marcomangano
Copy link
Contributor

@marcomangano marcomangano commented Feb 17, 2021

Purpose

Long overdue, this PR addresses the sensitivities inconsistencies on the current ADflow release when setRotationRate() is included to add a rotation component to the wall BC. The source code fixes (up to commit 0d39d74) have been initially implemented by @Aagaard87 to perform high-fidelity aerodynamic shape optimization of a wind turbine using MACH-Aero.

The old dev-branch with the fixes has been rebased in the current ADflow release, and the code has been further cleaned for clarity. See the discussion on #81 for more details. The final code in this PR is mostly the same as in #81 , but the commit history has been fixed to preserve the development history.
An additional regression test has been added for the real build, while the complex build cannot be performed yet as convergence is obtained with the ANK solver, which is not complex-safe yet.

@SichengHe put a big debugging effort into restructuring the code to have the relevant subroutines relocated in the appropriate file, verify the consistency of the AD process, and ultimately debugging derivatives inconsistencies between adjoint and complex-step derivatives.

Note that this PR also introduces the Tapenade checks on ADflow - currently using version 3.10

Type of change

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (non-backwards-compatible fix or feature)
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no API changes)
  • Documentation update
  • Maintenance update
  • Other (please describe)

Testing

A new test (real only) has been added to test_adjoint.py. The .ref file might need to be retrained on a docker image for consistency. Also note that the test will currently fail because the dedicated mesh has not been uploaded yet.

Checklist

  • I have run flake8 and black to make sure the code adheres to PEP-8 and is consistently formatted
  • I have run unit and regression tests which pass locally with my changes
  • I have added new tests that prove my fix is effective or that my feature works
  • I have added necessary documentation

….py is still hardcoded. This needs to be improved.
…gether. However, it seems from the older commits that these files we add in this commit are crucial. There are a few additions that should be located, but then it should (hopefully) work. Most likely, the error that remains to be fixed now is that some functions already in use are not differentiated correctly (just as in the previous case with inviscidcentralflux()). Hopefully a fix is coming up shortly.
…n hardcoded. Note; this commit will not work without the proper DVGeometry.py file from PyGeo...
… need slipvel() and then we need to move them all to adjointextra_d.f90
…e possible files containing the error for master_b has been narrowed down.
@marcomangano
Copy link
Contributor Author

Alright @anilyil @SichengHe @eirikurj , I tried to cleanup the tapenade makefile by removing some of the dependent variables that "did not look dependent" (i.e. I eyeballed), I tested the adjoint locally but I missed all the jacobian vector product failures happening right now. As @nwu63 mentioned, there's no point in removing stuff by trial and error because even if all the tests pass, we might be missing some zeroed-out partials.

My hot take is that ADflow maintainability in this sense has been already compromised, and we should make a separate effort to fix that and 1) cleanup Makefile_tapenade and 2) update it to work with Tapenade 3.16.

@marcomangano
Copy link
Contributor Author

Alright @anilyil @SichengHe @eirikurj , I tried to cleanup the tapenade makefile by removing some of the dependent variables that "did not look dependent" (i.e. I eyeballed), I tested the adjoint locally but I missed all the jacobian vector product failures happening right now. As @nwu63 mentioned, there's no point in removing stuff by trial and error because even if all the tests pass, we might be missing some zeroed-out partials.

My hot take is that ADflow maintainability in this sense has been already compromised, and we should make a separate effort to fix that and 1) cleanup Makefile_tapenade and 2) update it to work with Tapenade 3.16.

I stand by this, but I managed to fix and complete the cleanup of these routines. All other additions look targeted for the bugfix!

Copy link
Contributor

@sseraj sseraj left a comment

Choose a reason for hiding this comment

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

Nice work on the AD. However, I read through the commented code in outputMod.F90 in earnest for the first time, and I have several comments. You don't have to resolve them all, but some clean up would be nice.

src/output/outputMod.F90 Outdated Show resolved Hide resolved
src/output/outputMod.F90 Outdated Show resolved Hide resolved
src/output/outputMod.F90 Outdated Show resolved Hide resolved
src/output/outputMod.F90 Outdated Show resolved Hide resolved
src/output/outputMod.F90 Outdated Show resolved Hide resolved
src/output/outputMod.F90 Outdated Show resolved Hide resolved
src/output/outputMod.F90 Outdated Show resolved Hide resolved
src/output/outputMod.F90 Outdated Show resolved Hide resolved
src/output/outputMod.F90 Outdated Show resolved Hide resolved
src/output/outputMod.F90 Outdated Show resolved Hide resolved
@marcomangano
Copy link
Contributor Author

Nice work on the AD. However, I read through the commented code in outputMod.F90 in earnest for the first time, and I have several comments. You don't have to resolve them all, but some clean up would be nice.

Good call, I had that in mind but then forgot to actually fix it. Check it out now and let me know if the comments make sense

sseraj
sseraj previously approved these changes May 9, 2022
Copy link
Contributor

@sseraj sseraj left a comment

Choose a reason for hiding this comment

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

Much better, thanks!

sseraj
sseraj previously approved these changes May 10, 2022
@anilyil
Copy link
Contributor

anilyil commented May 10, 2022

I want to do another quick pass some time later this week but I think the PR is good to go. Why were we not getting failures due to the extra timestep_d call? Was it because the contributions there are small or we dont test for that?

@marcomangano
Copy link
Contributor Author

marcomangano commented May 10, 2022

I want to do another quick pass some time later this week but I think the PR is good to go. Why were we not getting failures due to the extra timestep_d call? Was it because the contributions there are small or we dont test for that?

I think it was because of the small contributions, there are no unit tests but we are definitely covering that part of the code with the rotating test we added.

Local dot-product tests match to machine precision!

@anilyil anilyil requested review from sseraj and SichengHe May 16, 2022 14:21
Copy link
Contributor

@sseraj sseraj left a comment

Choose a reason for hiding this comment

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

This is good to merge for me. Do we want to wait for @SichengHe's review?

@anilyil
Copy link
Contributor

anilyil commented May 17, 2022

I am fine with merging it. I just hit re-request on everyone who was involved. I think @marcomangano can do the honors

@sseraj
Copy link
Contributor

sseraj commented May 17, 2022

Go for it @marcomangano and please make the release afterwards as well

@marcomangano marcomangano merged commit bb0b139 into mdolab:main May 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants