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 names to child DVGeos #201

Merged
merged 25 commits into from
Nov 13, 2023
Merged

Add names to child DVGeos #201

merged 25 commits into from
Nov 13, 2023

Conversation

anilyil
Copy link
Contributor

@anilyil anilyil commented May 17, 2023

Purpose

This PR changes how DVGeo class tracks its children. Old implementation just appended the children to a list, which is then indexed in order. The current implementation saves the child DVGeometries in the self.children dictionary. The keys of the dictionary are the names of each child DVGeo. This makes the code a lot more readable since each child DVGeo is referenced by its name.

The old functionality is maintained, and unless users were accessing the child DVGeometries in a hacky way by indexing the old list, everything should work fine. Some output names might be different, but we can also fix this behavior. The names of the added pointsets will be the same if users don't provide a name for the child DVGeo.

I will apply a similar set of changes to the mphys wrapper once #193 is merged.

Expected time until merged

2 weeks

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

Checklist

  • I have run flake8 and black to make sure the Python code adheres to PEP-8 and is consistently formatted
  • I have formatted the Fortran code with fprettify or C/C++ code with clang-format as applicable
  • 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

@anilyil anilyil requested a review from a team as a code owner May 17, 2023 02:59
@anilyil anilyil changed the title Children dict Add names to child DVGeos May 17, 2023
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 gave a quick pass and it looks ok to me, see my comment below. Maybe we should also add a test for activeChildren?

@@ -752,6 +752,11 @@ def coordXfer(coords, mode="fwd", applyDisplacement=True, **kwargs):
# compNames is only needed for DVGeometryMulti, so remove it if passed
kwargs.pop("compNames", None)

# check if we want a custom subset of child DVGeos
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like an interesting addition, could you please add a short description of the arg and intended functionality in the docstrings for addPointSet?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added docstring

@anilyil
Copy link
Contributor Author

anilyil commented Aug 29, 2023

I changed how constraints are added when a childIdx was being provided to use the names. Only relevant example of this that I could find in my computer was in the private tutorial. Created a PR to update it for this change: https://github.com/mdolab/private-MACH-tutorial/pull/96

@anilyil anilyil requested review from hajdik and bernardopacini and removed request for ArshSaja August 29, 2023 10:50
@anilyil
Copy link
Contributor Author

anilyil commented Aug 29, 2023

I added tests for the new capability, @marcomangano. @hajdik and @bernardopacini, I modified the MPhys wrapper accordingly. This is backwards breaking for the runscripts, though the fix needed is minimal and the current behavior is much more human readable imo. Please take a look and let me know.

This PR is ready for review.

@codecov
Copy link

codecov bot commented Aug 31, 2023

Codecov Report

Merging #201 (4f155ef) into main (4b82a60) will increase coverage by 0.01%.
The diff coverage is 63.75%.

@@            Coverage Diff             @@
##             main     #201      +/-   ##
==========================================
+ Coverage   65.02%   65.04%   +0.01%     
==========================================
  Files          47       47              
  Lines       12106    12112       +6     
==========================================
+ Hits         7872     7878       +6     
  Misses       4234     4234              
Files Coverage Δ
pygeo/constraints/DVCon.py 71.70% <100.00%> (ø)
pygeo/mphys/mphys_dvgeo.py 0.00% <0.00%> (ø)
pygeo/parameterization/DVGeo.py 68.91% <76.80%> (+0.09%) ⬆️

📣 Codecov offers a browser extension for seamless coverage viewing on GitHub. Try it in Chrome or Firefox today!

bernardopacini
bernardopacini previously approved these changes Sep 12, 2023
Copy link
Contributor

@bernardopacini bernardopacini left a comment

Choose a reason for hiding this comment

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

The changes here look good to me, just a question regarding compatibility:

  • How does this affect other DVGeo variants such as DVGeoMulti or DVGeoAxi? If I am not mistaken, it should be fine because they inherit this base anyways, right?

@anilyil
Copy link
Contributor Author

anilyil commented Sep 14, 2023

DVGeoMulti tracks multiple regular DVGeo objects, that can have child DVGeos. DVGeoMulti itself does not have child DVGeos attached, so this will work for that directly.

I am not sure about DVGeoAxi. I don't even know if anyone is using it.

@hajdik, you mentioned the DVGeo class has a name attribute. Should we change the approach here to rely on that name attribute?

@hajdik
Copy link
Contributor

hajdik commented Sep 18, 2023

Should we change the approach here to rely on that name attribute?

Yes, there is a name attribute in the BaseDVGeo class so everything inheriting from that has access to it, I think it makes sense to use that since it's already there.

@anilyil
Copy link
Contributor Author

anilyil commented Oct 10, 2023

@hajdik, I made the suggested change on using the name attribute. This PR is ready for another round of review

@sseraj sseraj linked an issue Oct 17, 2023 that may be closed by this pull request
dIdPt[5, 1, 2] = 1.0
dIdx = DVGeo.totalSensitivity(dIdPt, ptName)

handler.root_add_dict(f"dIdx_{ptName}", dIdx, rtol=1e-10, atol=1e-10)
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like the test is failing here with KeyError: 'child1_span1' but once that's fixed I'm good with this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -908,17 +941,28 @@ def addGlobalDV(self, dvName, value, func, lower=None, upper=None, scale=1.0, co
Use a string for a single configuration or a list for multiple
configurations. The default value of None implies that the design
variable applies to *ALL* configurations.
prependName : bool
Flag to determine if self.name attribute is prepended to this DV name.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add something in the docstring about why this option exists?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@anilyil anilyil requested a review from hajdik October 26, 2023 13:08
@anilyil
Copy link
Contributor Author

anilyil commented Nov 6, 2023

@marcomangano @bernardopacini can one of you take a look at this again?

Copy link
Contributor

@bernardopacini bernardopacini left a comment

Choose a reason for hiding this comment

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

Apologies for the delay, this looks good to me! Thanks for the changes.

@hajdik hajdik merged commit e47a454 into mdolab:main Nov 13, 2023
12 checks passed
@anilyil anilyil deleted the children_dict branch November 13, 2023 16:55
@bernardopacini bernardopacini mentioned this pull request Dec 11, 2023
13 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.

Update childIdx to use a string rather than just an index
4 participants