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

Add spanwise shape variables #75

Merged
merged 16 commits into from
Mar 30, 2021
Merged

Add spanwise shape variables #75

merged 16 commits into from
Mar 30, 2021

Conversation

joanibal
Copy link
Collaborator

Purpose

These new design variables control all the FDD nodes along a line in a chosen spanwise direction

This means that for 2D shape optimization with ADflow, you can use spanwise local design variables to parametrize the 2D shape without the need for added linear constraints.

I think this is a lot easier to explain with an examples

Consider the following rectangular FFD with it i,j, and k axes as shown in the figure
image

If a airfoil surface mesh is embedded in the FFD as shown
image

Then adding spanwise shape variables like this

DVGeo.addGeoDVSpanwiseLocal("shape", 'k', lower=-0.5, upper=0.5, axis="z", scale=1.0)

would add the 6 design variables that correspond to the six colors in this figure. Each design variables would control the z location of two FFD points.

image

The test case uses the existing cylinder FFD
image

Type of change

What types of change is it?
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

Explain the steps needed to test the new code to verify that it does indeed address the issue and produce the expected behavior.

Checklist

Put an x in the boxes that apply.

  • [no] I have run flake8 and black to make sure the code adheres to PEP-8 and is consistently formatted
    ^formatting introduced a large amount of change not relevant to the feature
  • 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
    ^ I will after feedback

@joanibal joanibal requested a review from a team as a code owner March 16, 2021 21:42
@joanibal
Copy link
Collaborator Author

I following the same process that Nick used for sectionLocal, but we may want to consider refactoring DVGeometry at some point.

@anilyil
Copy link
Contributor

anilyil commented Mar 17, 2021

I don't understand DVGeometry's inner working as well as @marcomangano so I will pass this down to him. The figures in the PR does a great job at explaining what it does, is there a way we can include them in the docs as well?

@anilyil anilyil requested review from marcomangano and removed request for anilyil March 17, 2021 14:35
@marcomangano
Copy link
Contributor

@joanibal I will carefully review this tomorrow! Just a few points for now:

  1. The tests are failing, is that because you trained your .ref files locally?
  2. Is this for 2D optimization only, or do you envision a broader use?
    2.b I need to check the code/examples, but can you select any of x,y,z and/or "single rows" of control points? Just to get a grasp of the flexibility of this implementation.

I see the point of having this extra feature but I am trying to figure out how usable it can be for general cases.
Also agree that the figures are a great added value and we should add them to the docs somehow :)

@joanibal
Copy link
Collaborator Author

joanibal commented Mar 18, 2021

@marcomangano

  1. guilty as charged. I did train them locally. Why is that a problem again?

  2. I envision broader use. It think it is use for 3D wings too. If you start from a rectangular wing then you can change the shape while keeping a constant airfoil along the span. But I think the best use is for 2D cases.

can you select any of x,y,z and/or "single rows" of control points?

You can do both. Selecting a "single rows" is a bit tricky, but you would do the same way you would for any set of local shape variables (use pointSelect and/or volList)

@marcomangano
Copy link
Contributor

  1. I am not sure if this is an issue for pure-python packages too, but when I added a test (and a locally trained .ref file) for ADflow the tests on the docker configuration were not matching the prescribed tolerances on the docker builds. I guess our local machines always have some different settings and configurations that can alter the results, even in the I/O phase. @nwu63 can you explain this more in detail? I have a pretty qualitative overview of the issue. Anyway, not sure if it applies here, will check the tests soon.

  2. I see your point, this feature does not actually add new capabilities but rather simplify and make our usual parametrization much leaner. Just the benefit for 2D cases is already enough imho

  3. I see, makes sense, will check the details in my review.

Just one last thought before I dive into the code: if not in place already, I would add an assertAllClose check that compares FFD locations and sensitivities of the new DV vs the usual multi-DV approach. This way we can catch any discrepancy in future developments.

@ewu63
Copy link
Collaborator

ewu63 commented Mar 18, 2021

I am not sure if this is an issue for pure-python packages too, but when I added a test (and a locally trained .ref file) for ADflow the tests on the docker configuration were not matching the prescribed tolerances on the docker builds. I guess our local machines always have some different settings and configurations that can alter the results, even in the I/O phase. @nwu63 can you explain this more in detail? I have a pretty qualitative overview of the issue. Anyway, not sure if it applies here, will check the tests soon.

I am not sure where this discrepancy comes from. Sometimes I've had no problems training stuff locally, other times things behave in really strange ways. In this case though, it appears that the ref file was not added to the PR branch?

Copy link
Contributor

@marcomangano marcomangano left a comment

Choose a reason for hiding this comment

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

A lot of new code - but luckily pretty close to the previous GeoDVSectionLocal implementation. As this is an entirely new feature, I don't see risks of breaking anything (unless the user mixes vars in a weird way?) so I think this is pretty much ready - see the comments on testing though.

I added a bunch of comments, mostly for me to try and better understand how pyGeo works. Hope to turn this PR into a chance to improve the code current documentation, any concise comment or explanation is welcome.

Also, I completely agree that at some point pyGeo will need some major refactoring

examples/childffd_warning/warning_childFFD.py Outdated Show resolved Hide resolved
tests/reg_tests/warning_childFFD.py Outdated Show resolved Hide resolved
pygeo/DVConstraints.py Show resolved Hide resolved
@@ -144,9 +145,11 @@ def __init__(self, fileName, complex=False, child=False, faceFreeze=None, *args,
self.nDVG_T = None
self.nDVL_T = None
self.nDVSL_T = None
self.nDVSW_T = None
Copy link
Contributor

Choose a reason for hiding this comment

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

I see you had to come up with a different name because SL was taken, right?
Maybe we could add some line comments here to explain every acronym, just to make things a tiny easier

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

See the new comments in code to address this

pygeo/DVGeometry.py Show resolved Hide resolved
@@ -1955,7 +2122,7 @@ def computeTotalJacobianCS(self, ptSetName, config=None):
return

def addVariablesPyOpt(self, optProb, globalVars=True, localVars=True,
sectionlocalVars=True, ignoreVars=None, freezeVars=None):
sectionlocalVars=True, spanwiselocalVars=True, ignoreVars=None, freezeVars=None):
Copy link
Contributor

Choose a reason for hiding this comment

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

Add documentation for sectionlocalVars and spanwiselocalVars below.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

N = self.FFD.embededVolumes['child%d_coef'%(iChild)].N
self.children[iChild].dCcdXdvl = numpy.zeros((N*3, self.nDV_T))

iDVSpanwiseLocal = self.nDVSW_count
Copy link
Contributor

Choose a reason for hiding this comment

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

I see most of this comes from _sectionlocalDVJacobian but it would be great to have some more inline comments, I am struggling a bit to follow the flow.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

see new added comments

pygeo/DVGeometry.py Outdated Show resolved Hide resolved
leList = [[0, 0, 0 ], [-radius/2, 0, height]]
xAxis = [-1, 0, 0]
yAxis = [0, 1, 0]
DVCon.addLERadiusConstraints(leList, nSpan=5, axis=yAxis,
Copy link
Contributor

Choose a reason for hiding this comment

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

I see this comes from the previous test, but I am not familiar with this script. Why are we using it?

chordDir=xAxis, scaled=False)
# DVCon.writeTecplot('cylinder_constraints.dat')

funcs = {}
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks we are only testing the DVCon sens here... which I guess it is pretty much the same than testing the DV sens directly? See my comment before the review about an additional test - if needed

@marcomangano
Copy link
Contributor

I am not sure where this discrepancy comes from. Sometimes I've had no problems training stuff locally, other times things behave in really strange ways. In this case though, it appears that the ref file was not added to the PR branch?

L M A O, good catch

Copy link
Collaborator

@bbrelje bbrelje left a comment

Choose a reason for hiding this comment

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

I apologize for the delay in review. I am going to focus on the testing because I don't totally understand the implementation code and I trust you did it generally correctly.

Is there any way of verifying with the cylinder test as written that the feature is working as intended, and not just that it's producing the answer you expect. I am not sure a LERadiusConstraint alone is enough for that. a 2d grid of thickness constraints might be (would want to verify that the numbers are the same in the spanwise direction

There also ought to be a verification that this DV isn't used on a non-2D problem; or the test coverage needs to be extended to cover 3D cases.

@joanibal
Copy link
Collaborator Author

I added another test using a 2d grid of thickness constraints as Ben suggested.
I also addressed the comments Marco had in the code.

It is ready for review again.

@ewu63
Copy link
Collaborator

ewu63 commented Mar 26, 2021

Not sure why but there are some merge conflicts, could you resolve those so the newly added test gets run on Azure?

Copy link
Contributor

@marcomangano marcomangano left a comment

Choose a reason for hiding this comment

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

Looks good, thanks for the comments! Let's wait for the tests to run

@ewu63 ewu63 requested a review from marcomangano March 29, 2021 14:13
Copy link
Contributor

@marcomangano marcomangano left a comment

Choose a reason for hiding this comment

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

I think we are good to go! (see comment below). @bbrelje we need your approval of the changes before we merge this.

pygeo/DVConstraints.py Outdated Show resolved Hide resolved
marcomangano
marcomangano previously approved these changes Mar 30, 2021
Copy link
Collaborator

@bbrelje bbrelje left a comment

Choose a reason for hiding this comment

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

I still think it would be best to test the situation where someone tries to use this functionality for a 3D problem (in my view it should throw an error and the test should assert that it throws an error). One minor cleanup item (remove the extra debug statement from DVConstraints).

pygeo/DVConstraints.py Outdated Show resolved Hide resolved
@joanibal
Copy link
Collaborator Author

@bbrelje maybe I'm not getting what you mean by 3D problem. In the newest test, these design variables are used for a 3D problem. I agree the main application is 2D, but it isn't wrong to use these design variables for 3D.

@ewu63
Copy link
Collaborator

ewu63 commented Mar 30, 2021

I still think it would be best to test the situation where someone tries to use this functionality for a 3D problem (in my view it should throw an error and the test should assert that it throws an error). One minor cleanup item (remove the extra debug statement from DVConstraints).

My understanding here is that these DVs can be used in 3D cases, and there are tests/docs covering usage. I'm going to merge this but if you think this PR can be improved, please make an issue @bbrelje.

@ewu63 ewu63 merged commit 974b087 into mdolab:master Mar 30, 2021
@sseraj sseraj mentioned this pull request Mar 31, 2021
12 tasks
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.

5 participants