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 constraints and objective output #76

Merged
merged 6 commits into from
Oct 1, 2021
Merged

Fix constraints and objective output #76

merged 6 commits into from
Oct 1, 2021

Conversation

jefalon
Copy link
Collaborator

@jefalon jefalon commented Sep 30, 2021

Purpose

Fixes two bugs. First, by splitting up_k during the update step of ControlUpdater(), u_k and p_k update allowing for computation of objective values and constraints during optimization. Second, replacing assignment of control to creation of new Constants() in WindFarmManager restore taylor_test convergence of order 2.

Type of change

Select the appropriate type(s) that describe this PR

  • 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

In order to properly test the Taylor test, we would need to setup a regression test for each objective. That might be too much.

Checklist

Put an x in the boxes that apply.

  • I have run existing tests which pass locally with my changes
  • I have added new tests or examples that prove my fix is effective or that my feature works
  • I have added necessary documentation

@jefalon
Copy link
Collaborator Author

jefalon commented Sep 30, 2021

@johnjasa, one test I'd like to do to feel perfectly comfortable with the constraints is the prob.check_totals() from OpenMDAO to see if the gradients of the constraints are working. Unfortunately, I am unable to get that to work as it gets stuck during the prob.run_model() step. Any suggestions?

Edit: nevermind I just had too many turbines which made run_model take forever. Reducing the test to 2 turbines resulted in the desired output

@johnjasa
Copy link
Collaborator

Nice, great resolution, @jefalon! Did the computed gradients match the FD well?

@jefalon
Copy link
Collaborator Author

jefalon commented Sep 30, 2021

not exactly:

-------------------------
Group: Group 'Full Model'
-------------------------
  Full Model: 'cons_comp_0.con_0' wrt 'DVs'
    Analytic Magnitude : 1.354340e+05
          Fd Magnitude : 7.174046e+04 (fd:None)
    Absolute Error (Jan - Jfd) : 2.069118e+05 *

    Relative Error (Jan - Jfd) / Jfd : 2.884172e+00 *

    Raw Analytic Derivative (Jfor)
[[  85131.02062371   -3775.04290323 -105205.2978261    -3559.38237232]]

    Raw FD Derivative (Jfd)
[[-39681.2109375  -1354.7109375  59744.4375       928.1484375]]

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  Full Model: 'obj_comp.obj' wrt 'DVs'
    Analytic Magnitude : 1.032296e-04
          Fd Magnitude : 1.032261e-04 (fd:None)
    Absolute Error (Jan - Jfd) : 1.428940e-08

    Relative Error (Jan - Jfd) / Jfd : 1.384282e-04 *

    Raw Analytic Derivative (Jfor)
[[-3.84775201e-05 -1.73090123e-05  9.38306753e-05  8.48712344e-06]]

    Raw FD Derivative (Jfd)
[[-3.84859741e-05 -1.73160806e-05  9.38223675e-05  8.48341733e-06]]

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

The gradient of the objective function seem right, but the power constraints seem very wrong. That said, it seems like OpenMDAO is only using a 1e-6 perturbation.

|    |    |    x_0: 0.0
|    |    |    y_0: -1537.0
|    |    |    x_1: 1e-06
|    |    |    y_1: 1537.0

Since these are in meters, that is like shifting the turbine by a micrometer and expecting a good response. Seem off

@johnjasa
Copy link
Collaborator

Oh yes, those are quite wrong for the constraint, the top section. Is that with the power constraint, not the spacing constraint? I think we have more digging to do. There's a chance the FD is wrong, but I wouldn't expect the computed gradients to be of opposite sign like we're seeing.

@jefalon
Copy link
Collaborator Author

jefalon commented Sep 30, 2021

I just updated my comment to include more information. Additionally, the min_dist constraint seems to work flawlessly (I just turned it off to emphasize the power constraint)

@johnjasa
Copy link
Collaborator

Right on, I hear what you're saying about the step size. We could try a few different step sizes to see if the computed power constraint is correct.

I guess what we're stepping towards is that the power objective has correct gradients, right? But the power constraint doesn't. So we need to find out the implementation difference.

Copy link
Collaborator

@johnjasa johnjasa left a comment

Choose a reason for hiding this comment

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

Great fixes here, Jeff! All good to merge on my end.

@jefalon jefalon merged commit 195b6a3 into NREL:dev Oct 1, 2021
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

2 participants