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

Reverse engineer filtered and projected design variables #2462

Merged
merged 18 commits into from
May 3, 2023

Conversation

mochen4
Copy link
Collaborator

@mochen4 mochen4 commented Apr 6, 2023

Sometimes, it is desirable to have some specific initial guess for the topological optimization. With the presence of filtering and projection function, we can do a mini-optimization to reverse engineer the design variables whose filtered projection matches the desired structure.

@mochen4
Copy link
Collaborator Author

mochen4 commented Apr 6, 2023

For a completely binary target structure:
image

The difference (target-mapping(target)) after mapping would be:
image

With the mini-optimization, the difference (target-mapping(optimized x)) looks like:
image

where mapping includes filter with radius=0.1 and projection with beta=8.

from autograd import grad


def reverse_design(target, processing, maxiter=50):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would be nice to have docstrings and typehints.

@codecov-commenter
Copy link

codecov-commenter commented Apr 6, 2023

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 73.94%. Comparing base (9bc3f2c) to head (fe3ac3d).
Report is 122 commits behind head on master.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2462      +/-   ##
==========================================
+ Coverage   73.82%   73.94%   +0.11%     
==========================================
  Files          17       18       +1     
  Lines        5269     5293      +24     
==========================================
+ Hits         3890     3914      +24     
  Misses       1379     1379              
Files with missing lines Coverage Δ
python/adjoint/__init__.py 84.61% <100.00%> (+1.28%) ⬆️
python/adjoint/unfilter_design.py 100.00% <100.00%> (ø)

@mochen4 mochen4 marked this pull request as ready for review April 13, 2023 18:41
@@ -0,0 +1,52 @@
import nlopt
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe change this to a lazy import inside the function, so that NLopt is only required if you want to run this particular function.

python/Makefile.am Outdated Show resolved Hide resolved
@stevengj
Copy link
Collaborator

Probably add a test.

def test_reverse_design(self):
"""Verifies that the reverse_design finds better initialization for specific
design than that design itself as initialization."""
print("*** TESTING reverse_design ***")
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is too loose of a test.

I would do a gold master test where you just verify that you reproduce the results of a previous run that you checked manually.

@mochen4 mochen4 changed the base branch from master to loop_in_chunks_fixes April 28, 2023 19:08
@mochen4 mochen4 changed the base branch from loop_in_chunks_fixes to master April 28, 2023 19:09
@stevengj
Copy link
Collaborator

stevengj commented Apr 28, 2023

Should pass the new periodic_axes keyword from #2465 through to the filter functions?

Maybe not needed since the filtering is specified by a user function.

python/adjoint/reverse_design.py Outdated Show resolved Hide resolved
python/adjoint/reverse_design.py Outdated Show resolved Hide resolved
return projected_field.flatten()

reverse_x = mpa.reverse_design(target, processing)
tol = 1e-5
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this value supposed to match the ftol = 1e-5 in reverse_design.py?

Copy link
Collaborator Author

@mochen4 mochen4 May 3, 2023

Choose a reason for hiding this comment

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

Not really. This value is just a small number to ensure future versions will have equally satisfying performance. I changed it to a smaller value.

Copy link
Collaborator

@oskooi oskooi left a comment

Choose a reason for hiding this comment

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

LGTM.

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.

4 participants