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

update interpolation weight in get_array_slice #1460

Closed
wants to merge 1 commit into from

Conversation

oskooi
Copy link
Collaborator

@oskooi oskooi commented Dec 31, 2020

Addresses #1456 (comment).

@stevengj
Copy link
Collaborator

I assume it passes the tests locally?

@oskooi
Copy link
Collaborator Author

oskooi commented Jan 1, 2021

python/tests/array_metadata.py is failing with and without including the weights array W in computing the integral:

Ez = sim.get_dft_array(dft_obj, mp.Ez, 0)
(X,Y,Z,W) = sim.get_array_metadata(dft_cell=dft_obj)
Eps = sim.get_array(vol=nonpml_vol, component=mp.Dielectric)
EpsE2 = np.real(Eps*np.conj(Ez)*Ez)
xm, ym = np.meshgrid(X, Y)
vec_func_sum = np.sum(W*(xm**2 + 2*ym**2))
pulse_modal_volume = np.sum(W*EpsE2)/np.max(EpsE2) * vec_func_sum

The error from this branch:

======================================================================
FAIL: test_array_metadata (__main__.TestArrayMetadata)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "python/tests/array_metadata.py", line 83, in test_array_metadata
    self.assertAlmostEqual(cw_modal_volume/pulse_modal_volume, 1.00, places=2)
AssertionError: (0.9768618126950315+0j) != 1.0 within 2 places

@oskooi
Copy link
Collaborator Author

oskooi commented Jan 1, 2021

Not including the weights from get_array_metadata in computing the test integral np.sum(EpsE2)/np.max(EpsE2) * np.sum(xm**2 + 2*ym**2) from array_metadata.py makes the result much larger than the reference value computing using the field function. Thus, even with the change to the weights in this PR, the weights must still be included in computing the integral which is not what we expected.

Fixing the failing test just requires reducing the tolerance slightly.

@stevengj
Copy link
Collaborator

stevengj commented Jan 4, 2021

Actually, it looks like the collapsed arrays do not include the edge weights, so we don't need to remove them:

meep/src/dft.cpp

Lines 786 to 800 in 4d4ccb7

/*****************************************************************/
/* For collapsing empty dimensions, we want to retain interpolation
weights for empty dimensions, but not interpolation weights for
integration of edge pixels (for retain_interp_weights == true).
All of the weights are stored in (s0, s1, e0, e1), so we make
a copy of these with the weights for non-empty dimensions set to 1. */
vec s0i(s0), s1i(s1), e0i(e0), e1i(e1);
LOOP_OVER_DIRECTIONS(fc->gv.dim, d) {
if (!empty_dim[d]) {
s0i.set_direction(d, 1.0);
s1i.set_direction(d, 1.0);
e0i.set_direction(d, 1.0);
e1i.set_direction(d, 1.0);
}
}

@stevengj stevengj closed this Jan 4, 2021
@oskooi oskooi deleted the slice_interp_weight branch January 4, 2021 19:35
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