Cylinders
GenB31415 opened this issue · comments
Hi @flaport,
I have to add a cylinder aligned || z in 3D.
There are various references in general how to create a cylinder.
https://stackoverflow.com/questions/26989131/add-cylinder-to-plot
https://stackoverflow.com/questions/64725784/color-of-the-cylinder-in-python
But what may be the optimal way to do that in fdtd?
[03-objects-of-arbitrary-shape]
Thank you in advance.
@GenB31415 I think you can modify the 03-objects-of-arbitrary-shape example into 3d to make the circle into a cylinder, like this:
grid = fdtd.Grid(shape = (300, 300, 100), ...)
...
refractive_index = 1.7
x = y = np.linspace(-1,1,100)
X, Y = np.meshgrid(x, y)
circle_mask = X**2 + Y**2 < 1
permittivity = np.ones((100,100,10,3)) + circle_mask[:,:,None,None]*(refractive_index**2 - 1)
grid[170:270, 100:200, 45:55] = fdtd.Object(permittivity=permittivity, name="object")
That should give a z-axis aligned cylinder with diameter 100 and height 10. There's nothing really special about a cylinder, it's just a stack of circles; the None,None
adds two extra size-1 axes (one for z and one for anisotropic permittivity), and numpy broadcasting makes a stack of the circle_mask along the extra axes to match the (100,100,10,3)
shape.
Indeed. stacking circles is the recommended way.
Hi @aizvorski @flaport
Many thanks, this works. Is it possible by similar manner to create the the walled empty cylinder with the internal r1 and external r2 radiuses respectively? Thanks again.
Ideally this would be done by creating two overlapping Objects, however overlapping objects is currently not really supported. Alternatively you can change the grid.inverse_permittivity
array manually. First create the bigger cylinder directly into the grid.inverse_permittivity array, then create the smaller one.
Hi @flaport
I've followed your comments in the attached files. In addition, I expanded the task a little. I usually prefer to study a 3D system, so.
- I have placed a cylinder with walls in the center.
- To visualize the structure of the field by slices, I use the well-known standard approach, which allows us to move and view the slices of the field along the z-axis using the mouse wheel.
- I also applied the simplest Monte Carlo technique to see the geometry of the field. To this end I use N = 1000 randomly distributed point sources, please see the attached figure, where is shown the field slice for z=50.
Thanks for the comments.
circular_object00e.zip
Sorry, the number of sources is N=55 (not 1000)
Hey @GenB31415 , this looks cool! Can you add this to the examples folder and create a PR for this?