-
Notifications
You must be signed in to change notification settings - Fork 634
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 integration weights to account for cylindrical coordinates #2470
base: master
Are you sure you want to change the base?
Conversation
I think that might be wrong — for a dipole source, what you want to do is not quite interpolation, I think. Really you should think of it as a certain integral you need to match (e.g. a finite-width delta approximation you are trying to sample, such that the integral remains the same). |
Would be good to check that it computes ∫ₐᵇf(r)rdr exactly for any affine f(r). It should suffice to check that it integrates 1 and r exactly for various intervals [a,b] |
Hmm I'm still not convinced that there's a problem with the current implementation of a dipole in cylindrical coordinates. First, consider the problem in cartesian coordinates:
where Meep currently defines the weights using simple linear interpolation, such that: (The Now, consider the problem in cylindrical coordinates:
where the only difference here is Let's see what happens when we "integrate" over the weights by summing them together: ...which is exactly what we want! Whereas in cartesian coordinates, we expect the integral of our delta function to sum to 1, we expect the integral in cylindrical coordinates for our delta function to sum to So again, I'm not sure the issue is with the weights of the dipole source... |
... and yet, experimentally, the code doesn't seem to be behaving as intended. I ran a simple test where I have a 1D cylindrical simulation, and I pull the weights of a dipole that I "slide" along import meep as mp
import numpy as np
import matplotlib.pyplot as plt
sim = mp.Simulation(
resolution=10,
cell_size=mp.Vector3(100,0,0),
dimensions=mp.CYLINDRICAL,
m=1,
)
sim.init_sim()
r_bank = np.linspace(0.5,100,50)
w_bank = []
for r in r_bank:
(x,y,z,w) = sim.get_array_metadata(mp.Volume(center=mp.Vector3(r,0,0),size=mp.Vector3(0,0,0)),)
w_bank.append(w)
plt.figure()
plt.plot(r_bank,r_bank,color='k',label='ideal weights')
plt.plot(r_bank,w_bank, color='r',label='measured weights')
plt.xlabel("$r$ postion")
plt.ylabel("sum of weights")
plt.legend()
plt.savefig("weights.png")
plt.show() (Now I'm using |
As a useful reference, here is a schematic of ΔV in cylindrical coordinates from slide 2 of these lecture notes: |
As I previously commented in #2108, I think there could be a bug in Lines 481 to 484 in aedc794
The normalization is As a test, I modified the point source in python/examples/point_dipole_cyl.py to include |
Wait, I thought this was already known (per our previous discussion). In fact, I thought this was why the test divides by This isn't a "bug", just a matter of convention. My above comment discusses this. (By the way, we do have an extra Lines 308 to 316 in aedc794
and it is applied to the source... just within the weights themselves: Line 273 in aedc794
Lines 371 to 383 in aedc794
) EDIT: wait, @oskooi, I think you're on to something. Notice that the weight update passes in
and the "global" scaling you are describing shouldn't exist at all. It should be done at the chunk level. |
@oskooi you can try this patch to see if this resolves the behavior you're seeing: |
There are still |
Bummer.
Why is this unexpected? I would expect them to be different if the dipole is changing.
Yes this is expected. I didn't write any logic to check for dipoles in the chunk code (which is much harder). So tests involving source volumes (not dipoles) or going to have an additional scale factor with this patch. I wanted to test if this fixed the issue before addressing all corner cases. |
Since the extraction efficiency is a dimensionless quantity, scaling the amplitude of a point source by a constant factor should not affect its result. The scale factor would only affect dimensionful quantities such as the radiated flux (numerator) and source power (denominator) which indeed it does. |
But the point of this is that the point source is changing. We aren't just changing the relative amplitude, we're changing the profile. LEE is highly dependent on the type of source (position, size, polarization, etc). So the LEE should in fact change (otherwise, we wouldn't bother fixing the bug). (Recall that nothing in meep is a true point source. It's a projection onto the closest grid points) |
To be clear, there are two separate issues here:
(A symptom of the fact that the latter is just about discretization is that you should find that it goes away as you crank up the resolution. i.e. try your test from #2108 at a higher resolution, and you should find that it approaches a constant at a smaller radius.) |
But from my comment above, I think we already interpolating in cylindrical coordinates correctly. So the issue doesn't appear to be the method (or math) but something else (perhaps the implementation?) |
Looks like the discretization error for a point source As a demonstration, here are results for dipole emission in vacuum (same test in #2108) plotting radiated flux / Simulation layout with dipole at |
closes #2467.
This PR attempts to compute the proper integration weights for$r$ in cylindrical coordinates. There are a few things to be aware of:
abort
if the user attempts to place a source or monitor that spansdV
term in the weight itself here. This required some additional modification to theloop_in_chunks()
function, but doesn't seem to affect theIVEC_LOOP_WEIGHT
macro (contrary to what the notes suggest) so I left that alonem
simulations sequentially, even for just two points relatively close toI think this PR is more in the noise floor when it comes to comparing accuracy of a cylindrical simulation and a true 3D simulation with dipole sources.
@stevengj, since the issue isn't with source grid weights themselves, can you think of any other factors that would impact a dipole source in cylindrical coordinates?