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

Fix gradient in turbine example #38

Merged
merged 28 commits into from
Jan 15, 2025
Merged

Fix gradient in turbine example #38

merged 28 commits into from
Jan 15, 2025

Conversation

jwallwork23
Copy link
Member

Closes #37.

While #36 re-enables the turbines in the turbine example, there's still something not right because the optimisation progress is non-monotonic and the control turbine area occasionally goes to zero.

I added a Taylor test and found that the gradient of the QoI wasn't being computed correctly with the existing setup. I tracked the problem down to the turbine_density expression, which includes several terms. By projecting this expression into $\mathbb{P}1_{DG}$ space, the Taylor test passed.

In addition, this PR overhauls the plotting functionality.

@jwallwork23 jwallwork23 added the bug Something isn't working label Jan 9, 2025
@jwallwork23 jwallwork23 requested a review from acse-ej321 January 9, 2025 18:03
@jwallwork23 jwallwork23 self-assigned this Jan 9, 2025
Copy link
Collaborator

@acse-ej321 acse-ej321 left a comment

Choose a reason for hiding this comment

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

I added a comment flagging some remaining Constant usages. Otherwise, the code ran successfully for me this time.

# NOTE: negative because we want maximum

# Add a regularisation term for constraining the control
area = assemble(Constant(1.0) * ufl.dx(domain=mesh))
alpha = 1.0 / area
alpha = Constant(1.0 / area)
Copy link
Collaborator

Choose a reason for hiding this comment

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

You have changed all the other Constant terms to be in terms of R space except here and line 157. Just flagging with a comment in case this was unintentional.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for pointing this out. I've updated it to use Thetis' new domain_constant in df4692e.

@jwallwork23
Copy link
Member Author

Okay it seems to be working now! The key fix was for the regularisation term - the sign was wrong and y2 and y3 were the wrong way round.

@jwallwork23 jwallwork23 merged commit 20f2026 into main Jan 15, 2025
1 check passed
@jwallwork23 jwallwork23 deleted the 37_fix-turbine-gradient branch January 15, 2025 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Turbine solver still isn't right
2 participants