Creates a `MaterialGrid` object. The input are two materials `medium1` and `medium2` along with a weight function $u(x)$ which is defined on a rectilinear grid by the NumPy array `weights` of size `grid_size` (a 3-tuple or `Vector3` of integers $N_x$,$N_y$,$N_z$). T
(
self,
grid_size: Union[Vector3, Tuple[float, ...]],
medium1: Medium,
medium2: Medium,
weights: np.ndarray = None,
grid_type: str = "U_DEFAULT",
do_averaging: bool = False,
beta: float = 0,
eta: float = 0.5,
damping: float = 0,
)
| 591 | return np.clip(w, 0.0, 1.0) |
| 592 | |
| 593 | def __init__( |
| 594 | self, |
| 595 | grid_size: Union[Vector3, Tuple[float, ...]], |
| 596 | medium1: Medium, |
| 597 | medium2: Medium, |
| 598 | weights: np.ndarray = None, |
| 599 | grid_type: str = "U_DEFAULT", |
| 600 | do_averaging: bool = False, |
| 601 | beta: float = 0, |
| 602 | eta: float = 0.5, |
| 603 | damping: float = 0, |
| 604 | ): |
| 605 | """ |
| 606 | Creates a `MaterialGrid` object. |
| 607 | |
| 608 | The input are two materials `medium1` and `medium2` along with a weight function $u(x)$ which |
| 609 | is defined on a rectilinear grid by the NumPy array `weights` of size `grid_size` (a 3-tuple or |
| 610 | `Vector3` of integers $N_x$,$N_y$,$N_z$). The resolution of the grid may be nonuniform depending |
| 611 | on the `size` property of the `Block` object as shown in the following example for a 2d `MaterialGrid` |
| 612 | with $N_x=5$ and $N_y=4$. $N_z=0$ implies that the `MaterialGrid` is extruded in the $z$ direction. |
| 613 | The grid points are defined at the corners of the voxels. |
| 614 | |
| 615 |  |
| 616 | |
| 617 | Elements of the `weights` array must be in the range [0,1] where 0 is `medium1` and 1 is `medium2`. |
| 618 | An array of boolean values `False` and `True` will be converted to 0 and 1, respectively. |
| 619 | The `weights` array is used to define a linear interpolation from `medium1` to `medium2`. |
| 620 | Two material types are supported: (1) frequency-independent isotropic $\\varepsilon$ (`epsilon_diag` |
| 621 | and `epsilon_offdiag` are interpolated) and (2) `LorentzianSusceptibility` (`sigma` and `sigma_offdiag` |
| 622 | are interpolated). `medium1` and `medium2` must both be the same type. The materials are |
| 623 | [bilinearly interpolated](https://en.wikipedia.org/wiki/Bilinear_interpolation) from the rectilinear |
| 624 | grid to Meep's [Yee grid](Yee_Lattice.md). |
| 625 | |
| 626 | For improving accuracy, [subpixel smoothing](Subpixel_Smoothing.md) can be enabled by specifying |
| 627 | `do_averaging=True`. If you want to use a material grid to define a (nearly) discontinuous, |
| 628 | piecewise-constant material that is *either* `medium1` or `medium2` almost everywhere, you can |
| 629 | optionally enable a (smoothed) *projection* feature by setting the parameter `beta` to a |
| 630 | positive value. The default is no projection (`beta=0`). When the projection feature is |
| 631 | enabled, the weights $u(x)$ can be thought of as a |
| 632 | [level-set function](https://en.wikipedia.org/wiki/Level-set_method) defining an interface at |
| 633 | $u(x)=\\eta$ with a smoothing factor $\\beta$ where $\\beta=+\\infty$ gives an unsmoothed, |
| 634 | discontinuous interface. The projection operator is $(\\tanh(\\beta\\times\\eta) |
| 635 | +\\tanh(\\beta\\times(u-\\eta)))/(\\tanh(\\beta\\times\\eta)+\\tanh(\\beta\\times(1-\\eta)))$ |
| 636 | involving the parameters `beta` ($\\beta$: bias or "smoothness" of the turn on) and `eta` |
| 637 | ($\\eta$: offset for erosion/dilation). The level set provides a general approach for defining |
| 638 | a *discontinuous* function from otherwise continuously varying (via the bilinear interpolation) |
| 639 | grid values. Subpixel smoothing is fast and accurate because it exploits an analytic formulation |
| 640 | for level-set functions. Note that when subpixel smoothing is enabled via `do_averaging=True`, |
| 641 | projecting the `weights` is done internally using the `beta` parameter. It is therefore not |
| 642 | necessary to manually project the `weights` outside of `MaterialGrid`. However, visualizing |
| 643 | the `weights` used to define the structure does require manually projecting the `weights` yourself. |
| 644 | (Alternatively, you can output the actual structure using [`plot2D`](#data-visualization) or |
| 645 | [`output_epsilon`](#output-functions_1).) |
| 646 | |
| 647 | A nonzero `damping` term creates an artificial conductivity $\\sigma = u(1-u)*$`damping`, which acts as |
| 648 | dissipation loss that penalizes intermediate pixel values of non-binarized structures. The value of |
| 649 | `damping` should be proportional to $2\\pi$ times the typical frequency of the problem. |
| 650 |
nothing calls this directly
no test coverage detected