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

unit test and documentation for MaterialGrid #1508

Merged
merged 4 commits into from
Feb 24, 2021

Conversation

oskooi
Copy link
Collaborator

@oskooi oskooi commented Feb 22, 2021

Adds a unit test and documentation to the User Interface for MaterialGrid.

A test (python/tests/material_grid.py) was added in #1242 but it does not seem to actually be doing anything (other than verify that an instance of the MaterialGrid object can be instantiated). The test added in this PR is based on the resonant mode calculation from #1500 which was later modified to use subpixel smoothing in #1503.

Separately, it might be useful to rename the member variable design_parameter of the MaterialGrid class to e.g. density_grid to make it more general since usage of the MaterialGrid does not necessarily always have to involve the adjoint solver.

function defining an interface at $u(x)=\eta$ with a smoothing factor $\beta$ ($\beta=\infty$ gives an unsmoothed,
discontinuous interface). The projection operator is `tanh(beta*eta) + tanh(beta*(x-eta))) / (tanh(beta*eta) +
tanh(beta*(1-eta)))` involving the parameters `beta` ($\beta$: "smoothness" of the turn on) and `eta` ($\eta$:
erosion/dilation). The level set provides a general approach for defining a *discontinuous* representation of the otherwise
Copy link
Collaborator

Choose a reason for hiding this comment

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

s/representation of the otherwise/function from otherwise/

scheme with properties `subpixel_maxeval` and `subpixel_tol` which can be specified using the [`Simulation`](#Simulation)
constructor.

Grids which are symmetric (e.g., mirror, rotation) must be explicitly defined. This requires overlapping a given
Copy link
Collaborator

Choose a reason for hiding this comment

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

s/This requires/One way to implement this is by/

constructor.

Grids which are symmetric (e.g., mirror, rotation) must be explicitly defined. This requires overlapping a given
`MaterialGrid` object with a symmetrized copy of itself. In this case, the overlapping grid points are combined using
Copy link
Collaborator

Choose a reason for hiding this comment

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

In the case of spatially overlapping MaterialGrid objects (with no intervening objects), any overlapping points are computed using


Grids which are symmetric (e.g., mirror, rotation) must be explicitly defined. This requires overlapping a given
`MaterialGrid` object with a symmetrized copy of itself. In this case, the overlapping grid points are combined using
the method `grid_type` which is one of `"U_MIN"` (minimum of two grid values), `"U_PROD"` (product), `"U_SUM"` (sum),
Copy link
Collaborator

Choose a reason for hiding this comment

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

minimum of the overlapping grid values

Copy link
Collaborator

Choose a reason for hiding this comment

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

U_SUM is the mean, not the sum

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe it should be renamed to U_MEAN

Creates a `MaterialGrid` object.

The input are two materials `medium1` and `medium2` which are linearly interpolated at each grid point using
a NumPy array `design_parameters` of size `grid_size` (a 3-tuple or `Vector3` of integers) with floating-point values in
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe call it weights and a "weight function"

self.assertAlmostEqual(freq_ref, freq_matgrid[-1], 2)

## verify that the relative error is decreasing with increasing resolution
self.assertLess(abs(freq_matgrid[1]-freq_ref),abs(freq_matgrid[0]-freq_ref))
Copy link
Collaborator

Choose a reason for hiding this comment

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

We really should check that it's less by some factor, say by a factor of 3 (ideally 4, but…)

@stevengj stevengj merged commit a079d9b into NanoComp:master Feb 24, 2021
@oskooi oskooi deleted the matgrid_test_docs branch February 24, 2021 03:38
bencbartlett pushed a commit to bencbartlett/meep that referenced this pull request Sep 9, 2021
* unit test and documentation for MaterialGrid

* fixes and tweaks

* more fixes

* fix test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants