Skip to content

Conversation

A-CGray
Copy link
Member

@A-CGray A-CGray commented Jul 24, 2025

Purpose

Least Squares Fitting

I added two methods for least squares fitting, i.e finding the design variables that get as close as possible to some target geometry:

  • fitPointSet attempts to match the coordinates of one pointset already added to the DVGeo to a supplied set of coordinates
  • fitDVGeo is a wrapper around fitPointSet that allows you to do the same least squares fit based on a pointset coming from another DVGeo

Both these methods are implemented in, and only use methods from, BaseDVGeometry, so they should work with any of our parameterisations. This opens up the possibility of doing things like fitting an ESP CAD model to a geometry optimised with an FFD.

Here is an example of me fitting a wing shape generated by one FFD (black) to the shape I got from an optimization using a different FFD (orange)

DVGeoFit

New BaseDVGeomgetry Methods

To implement the fitting methods above, I had to implement two new methods in BaseDVGeometry:

  • getDVBounds
  • getOrigPoints

Renamed getValues

getValues is a vague name that doesn't explain what the method actually does (return the current DV values). So I renamed it getDesignVars, to match setDesignVars. I kept getValues around for now, it simply raises a deprecation warning and then calls getDesignVars

DVGeometry Improvements

There were a bunch of places in the FFD implementation where the same code was copied 4 times to do the same thing with the 4 different types of DV (self.DV_listGlobal, self.DV_listLocal, self.DV_listSectionLocal, self.DV_listSpanwiseLocal). addVariablesPyOpt had a nicer implementation that loops over the 4, so I just copied that approach to a bunch of other parts of the code.

Additionally, the forward jacvec product method, totalSensitivityProd, was not correctly reshaping it's output, so I fixed that, and a part of the MPhys wrapper that was relying on this incorrect behaviour.

ToDos

  • Make fitting work for distributed pointsets?
  • Add tests for least squares fitting

Expected time until merged

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

Copy link

codecov bot commented Jul 25, 2025

Codecov Report

❌ Patch coverage is 69.09871% with 72 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.42%. Comparing base (cecefd2) to head (8f11f64).

Files with missing lines Patch % Lines
pygeo/parameterization/DVGeo.py 67.41% 29 Missing ⚠️
pygeo/parameterization/BaseDVGeo.py 83.51% 15 Missing ⚠️
pygeo/parameterization/DVGeoSketch.py 35.71% 9 Missing ⚠️
pygeo/parameterization/DVGeoMulti.py 33.33% 8 Missing ⚠️
pygeo/parameterization/DVGeoCST.py 36.36% 7 Missing ⚠️
pygeo/parameterization/DVGeoESP.py 71.42% 2 Missing ⚠️
pygeo/mphys/mphys_dvgeo.py 50.00% 1 Missing ⚠️
pygeo/parameterization/DVGeoVSP.py 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #274      +/-   ##
==========================================
+ Coverage   67.00%   67.42%   +0.41%     
==========================================
  Files          47       47              
  Lines       12331    12315      -16     
==========================================
+ Hits         8262     8303      +41     
+ Misses       4069     4012      -57     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant