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

Approximate material grid smoothing (β=∞) #1951

Draft
wants to merge 34 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
5fd8cf6
subpixel averaging for boundaries of variable-material objects
stevengj Oct 10, 2020
d67b1f2
rm obsolete references to meepgeom::is_file
stevengj Oct 14, 2020
6a9f7dd
bugfix
stevengj Oct 20, 2020
bf5296c
undo spurious change
stevengj Jun 22, 2021
a480ffd
add proper kernels for sphere caps
smartalecH Feb 16, 2022
5c38aa7
clean up comments
smartalecH Feb 16, 2022
bb07eaa
checkpoint
smartalecH Feb 18, 2022
92499af
merge in previous updates from subpixel_varmat
smartalecH Feb 18, 2022
1652a62
minor tweaks to kill errors
smartalecH Feb 19, 2022
ee071de
enable smoothing
smartalecH Feb 21, 2022
b544afd
get gradients working both with and without averaging
smartalecH Feb 23, 2022
5f59014
adjust FD step
smartalecH Feb 26, 2022
8bfbb77
fix boundary case when spatial gradient doesn't exist
smartalecH Mar 2, 2022
1880b0d
refactor
smartalecH Mar 8, 2022
fa35e16
add duals
smartalecH Mar 9, 2022
3aa3c09
fix interface artifacts and get gradients working
smartalecH Mar 10, 2022
b1fd007
Merge branch 'master' of https://github.com/NanoComp/meep into inf_sm…
smartalecH Mar 10, 2022
5c07d78
minor formatting
smartalecH Mar 21, 2022
25f9437
update makefile
smartalecH Apr 7, 2022
b69a5d1
fix bug in fill fraction
smartalecH May 18, 2022
69265e9
rebase
smartalecH May 25, 2022
7a558fd
fix matgrid test bug
smartalecH May 25, 2022
9ac153e
fix damping test failure
smartalecH May 25, 2022
3349aee
revamp matgrid test and add comments
smartalecH May 26, 2022
35ec6d8
update tests and add comments to code
smartalecH May 29, 2022
fabd531
approximate material-grid smoothing
stevengj Jul 29, 2022
9793cf5
reformat
stevengj Jul 29, 2022
c88ca4a
rebase
smartalecH Aug 9, 2022
83fd9ef
add function to update m number
smartalecH Aug 12, 2022
2dff39e
update change m number too
smartalecH Aug 12, 2022
2230adb
precommit cleanup
smartalecH Aug 12, 2022
33ea63a
precommit cleanup
smartalecH Aug 12, 2022
1d78417
incorporate m changes
smartalecH Aug 13, 2022
d3f5ef9
add threshold check for normal vector to mitigate floating point sens…
smartalecH Aug 18, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions libpympb/pympb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,12 +369,9 @@ int mode_solver::mean_epsilon(symmetric_matrix *meps, symmetric_matrix *meps_inv

bool o1_is_var = o1 && meep_geom::is_variable(o1->material);
bool o2_is_var = o2 && meep_geom::is_variable(o2->material);
bool default_is_var_or_file =
meep_geom::is_variable(default_material) || meep_geom::is_file(default_material);
bool default_is_var = meep_geom::is_variable(default_material);

if (o1_is_var || o2_is_var ||
(default_is_var_or_file &&
(!o1 || !o2 || meep_geom::is_file(o1->material) || meep_geom::is_file(o2->material)))) {
if (o1_is_var || o2_is_var || (default_is_var && (!o1 || !o2))) {
return 0; /* arbitrary material functions are non-analyzable */
}

Expand Down
20 changes: 20 additions & 0 deletions python/adjoint/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
from scipy import signal, special

import meep as mp
from scipy import special
from scipy import signal
import skfmm
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it necessary to include this additional module just for its signed distance function (rather than write our own or find a similar function in e.g. SciPy)? skfmm does not seem to be widely used which could make installing it a challenge for some users building from source.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

could make installing it a challenge for some users building from source.

From their docs:

pip install scikit-fmm

What's challenging about this particular package vs numpy, scipy, etc.?

It's convenient for testing, but we can remove it if it really is a challenge to install.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I ran into some package conflicts during the pip install. In general, it is useful to keep the number of package dependencies, particularly smaller ones, to a minimum.

from scipy import interpolate


def _proper_pad(x, n):
Expand Down Expand Up @@ -874,3 +878,19 @@ def gray_indicator(x):
density-based topology optimization. Archive of Applied Mechanics, 86(1-2), 189-218.
"""
return npa.mean(4 * x.flatten() * (1 - x.flatten())) * 100

def make_sdf(data):
'''
Assume the input, data, is the desired output shape
(i.e. 1d, 2d, or 3d) and that it's values are between
0 and 1.
'''
# create signed distance function
sd = skfmm.distance(data- 0.5 , dx = 1)

# interpolate zero-levelset onto 0.5-levelset
x = [np.min(sd.flatten()), 0, np.max(sd.flatten())]
y = [0, 0.5, 1]
f = interpolate.interp1d(x, y, kind='linear')

return f(sd)
3 changes: 1 addition & 2 deletions python/adjoint/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
_Z_AXIS = 1

# default finite difference step size when calculating Aᵤ
FD_DEFAULT = 1e-3

FD_DEFAULT = 1e-6

class DesignRegion:
def __init__(self, design_parameters, volume=None, size=None, center=mp.Vector3()):
Expand Down
4 changes: 1 addition & 3 deletions python/meep.i
Original file line number Diff line number Diff line change
Expand Up @@ -1504,8 +1504,6 @@ void _get_gradient(PyObject *grad, double scalegrad,
%ignore material_type_equal;
%ignore is_variable;
%ignore is_variable;
%ignore is_file;
%ignore is_file;
%ignore is_medium;
%ignore is_medium;
%ignore is_metal;
Expand Down Expand Up @@ -1986,7 +1984,7 @@ meep_geom::geom_epsilon* _set_materials(meep::structure * s,
geps = existing_geps;
} else {
geps = meep_geom::make_geom_epsilon(s, &gobj_list, center, _ensure_periodicity, _default_material,
extra_materials);
extra_materials, use_anisotropic_averaging);
}
if (set_materials) {
meep_geom::set_materials_from_geom_epsilon(s, geps, use_anisotropic_averaging, tol,
Expand Down
1 change: 1 addition & 0 deletions python/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ numpy
parameterized
pytest
scipy
scikit-fmm
Loading