meanas/search/search_index.json
2026-04-21 21:20:52 -07:00

1 line
No EOL
211 KiB
JSON

{"config":{"lang":["en"],"separator":"[\\s\\-]+","pipeline":["stopWordFilter"],"fields":{"title":{"boost":1000.0},"text":{"boost":1.0},"tags":{"boost":1000000.0}}},"docs":[{"location":"","title":"meanas","text":"<p><code>meanas</code> is a Python package for finite-difference electromagnetic simulation. It combines:</p> <ul> <li><code>meanas.fdfd</code> for frequency-domain operators, sources, waveguide modes, and SCPML</li> <li><code>meanas.fdtd</code> for Yee-grid timestepping, CPML, energy/flux accounting, and phasor extraction</li> <li><code>meanas.fdmath</code> for the shared discrete operators and derivations underneath both solvers</li> </ul> <p>This documentation is built directly from the package docstrings. The API pages are the source of truth for the mathematical derivations and calling conventions.</p>"},{"location":"#examples-and-api-map","title":"Examples and API Map","text":"<p>For most users, the tracked examples under <code>examples/</code> are the right entry point. They show the intended combinations of tools for solving complete problems.</p> <p>Relevant starting examples:</p> <ul> <li><code>examples/fdtd.py</code> for broadband pulse excitation and phasor extraction</li> <li><code>examples/waveguide.py</code> for guided phasor-domain FDTD/FDFD comparison</li> <li><code>examples/waveguide_real.py</code> for real-valued continuous-wave FDTD compared against real fields reconstructed from an FDFD solution, including guided-core, mode-weighted, and guided-mode / residual comparisons</li> <li><code>examples/eme.py</code> for straight-interface mode matching / EME and modal scattering between two nearby waveguide cross-sections</li> <li><code>examples/eme_bend.py</code> for straight-to-bent mode matching with cylindrical bend modes and a cascaded bend-network example</li> <li><code>examples/fdfd.py</code> for direct frequency-domain waveguide excitation</li> </ul> <p>For solver equivalence, prefer the phasor-based examples first. They compare the extracted <code>+\\omega</code> content of the FDTD run directly against the FDFD solution and are the main accuracy benchmarks in the test suite.</p> <p><code>examples/waveguide_real.py</code> answers a different, stricter question: how well a late raw real snapshot matches <code>Re(E_\\omega e^{i\\omega t})</code> on a monitor plane. That diagnostic is useful, but it also includes orthogonal residual structure that the phasor comparison intentionally filters out.</p> <p>The API pages are better read as a toolbox map and derivation reference:</p> <ul> <li>Use the FDTD API for time-domain stepping, CPML, phasor extraction, and real-field reconstruction from FDFD phasors.</li> <li>Use the FDFD API for driven frequency-domain solves and sparse operator algebra.</li> <li>Use the Waveguide API for mode solving, port sources, and overlap windows.</li> <li>Use the fdmath API for the lower-level finite-difference operators and the shared discrete derivations underneath both solvers.</li> </ul>"},{"location":"#build-outputs","title":"Build outputs","text":"<p>The docs build generates two HTML views from the same source:</p> <ul> <li>a normal multi-page site</li> <li>a print-oriented combined page under <code>site/print_page/</code></li> </ul> <p>If <code>htmlark</code> is installed, <code>./make_docs.sh</code> also writes a fully inlined <code>site/standalone.html</code>.</p>"},{"location":"api/","title":"API Overview","text":"<p>The package is documented directly from its docstrings. The most useful entry points are:</p> <ul> <li>meanas: top-level package overview</li> <li>eigensolvers: generic eigenvalue utilities used by the mode solvers</li> <li>fdfd: frequency-domain operators, sources, PML, solvers, and far-field transforms</li> <li>waveguides: straight, cylindrical, and 3D waveguide mode helpers</li> <li>fdtd: timestepping, CPML, energy/flux helpers, and phasor extraction</li> <li>fdmath: shared discrete operators, vectorization helpers, and derivation background</li> </ul> <p>The waveguide and FDTD pages are the best places to start if you want the mathematical derivations rather than just the callable reference.</p>"},{"location":"api/eigensolvers/","title":"eigensolvers","text":""},{"location":"api/eigensolvers/#meanas.eigensolvers","title":"meanas.eigensolvers","text":"<p>Solvers for eigenvalue / eigenvector problems</p>"},{"location":"api/eigensolvers/#meanas.eigensolvers.power_iteration","title":"power_iteration","text":"<pre><code>power_iteration(\n operator: spmatrix,\n guess_vector: NDArray[complex128] | None = None,\n iterations: int = 20,\n) -&gt; tuple[complex, NDArray[numpy.complex128]]\n</code></pre> <p>Use power iteration to estimate the dominant eigenvector of a matrix.</p> <p>Parameters:</p> Name Type Description Default <code>operator</code> <code>spmatrix</code> <p>Matrix to analyze.</p> required <code>guess_vector</code> <code>NDArray[complex128] | None</code> <p>Starting point for the eigenvector. Default is a randomly chosen vector.</p> <code>None</code> <code>iterations</code> <code>int</code> <p>Number of iterations to perform. Default 20.</p> <code>20</code> <p>Returns:</p> Type Description <code>tuple[complex, NDArray[complex128]]</code> <p>(Largest-magnitude eigenvalue, Corresponding eigenvector estimate)</p>"},{"location":"api/eigensolvers/#meanas.eigensolvers.rayleigh_quotient_iteration","title":"rayleigh_quotient_iteration","text":"<pre><code>rayleigh_quotient_iteration(\n operator: spmatrix | LinearOperator,\n guess_vector: NDArray[complex128],\n iterations: int = 40,\n tolerance: float = 1e-13,\n solver: Callable[..., NDArray[complex128]]\n | None = None,\n) -&gt; tuple[complex, NDArray[numpy.complex128]]\n</code></pre> <p>Use Rayleigh quotient iteration to refine an eigenvector guess.</p> <p>Parameters:</p> Name Type Description Default <code>operator</code> <code>spmatrix | LinearOperator</code> <p>Matrix to analyze.</p> required <code>guess_vector</code> <code>NDArray[complex128]</code> <p>Eigenvector to refine.</p> required <code>iterations</code> <code>int</code> <p>Maximum number of iterations to perform. Default 40.</p> <code>40</code> <code>tolerance</code> <code>float</code> <p>Stop iteration if <code>(A - I*eigenvalue) @ v &lt; num_vectors * tolerance</code>, Default 1e-13.</p> <code>1e-13</code> <code>solver</code> <code>Callable[..., NDArray[complex128]] | None</code> <p>Solver function of the form <code>x = solver(A, b)</code>. By default, use scipy.sparse.spsolve for sparse matrices and scipy.sparse.bicgstab for general LinearOperator instances.</p> <code>None</code> <p>Returns:</p> Type Description <code>tuple[complex, NDArray[complex128]]</code> <p>(eigenvalues, eigenvectors)</p>"},{"location":"api/eigensolvers/#meanas.eigensolvers.signed_eigensolve","title":"signed_eigensolve","text":"<pre><code>signed_eigensolve(\n operator: spmatrix | LinearOperator,\n how_many: int,\n negative: bool = False,\n) -&gt; tuple[\n NDArray[numpy.complex128], NDArray[numpy.complex128]\n]\n</code></pre> <p>Find the largest-magnitude positive-only (or negative-only) eigenvalues and eigenvectors of the provided matrix.</p> <p>Parameters:</p> Name Type Description Default <code>operator</code> <code>spmatrix | LinearOperator</code> <p>Matrix to analyze.</p> required <code>how_many</code> <code>int</code> <p>How many eigenvalues to find.</p> required <code>negative</code> <code>bool</code> <p>Whether to find negative-only eigenvalues. Default False (positive only).</p> <code>False</code> <p>Returns:</p> Type Description <code>NDArray[complex128]</code> <p>(sorted list of eigenvalues, 2D ndarray of corresponding eigenvectors)</p> <code>NDArray[complex128]</code> <p><code>eigenvectors[:, k]</code> corresponds to the k-th eigenvalue</p>"},{"location":"api/fdfd/","title":"fdfd","text":""},{"location":"api/fdfd/#meanas.fdfd","title":"meanas.fdfd","text":"<p>Tools for finite difference frequency-domain (FDFD) simulations and calculations.</p> <p>These mostly involve picking a single frequency, then setting up and solving a matrix equation (Ax=b) or eigenvalue problem.</p> <p>Submodules:</p> <ul> <li><code>operators</code>, <code>functional</code>: General FDFD problem setup.</li> <li><code>solvers</code>: Solver interface and reference implementation.</li> <li><code>scpml</code>: Stretched-coordinate perfectly matched layer (SCPML) boundary conditions.</li> <li><code>waveguide_2d</code>: Operators and mode-solver for waveguides with constant cross-section.</li> <li><code>waveguide_3d</code>: Functions for transforming <code>waveguide_2d</code> results into 3D, including mode-source and overlap-window construction.</li> <li><code>farfield</code>, <code>bloch</code>, <code>eme</code>: specialized helper modules for near/far transforms, Bloch-periodic problems, and eigenmode expansion.</li> </ul> <p>================================================================</p> <p>From the \"Frequency domain\" section of <code>meanas.fdmath</code>, we have</p> \\[ \\begin{aligned} \\tilde{E}_{l, \\vec{r}} &amp;= \\tilde{E}_{\\vec{r}} e^{-\\imath \\omega l \\Delta_t} \\\\ \\tilde{H}_{l - \\frac{1}{2}, \\vec{r} + \\frac{1}{2}} &amp;= \\tilde{H}_{\\vec{r} + \\frac{1}{2}} e^{-\\imath \\omega (l - \\frac{1}{2}) \\Delta_t} \\\\ \\tilde{J}_{l, \\vec{r}} &amp;= \\tilde{J}_{\\vec{r}} e^{-\\imath \\omega (l - \\frac{1}{2}) \\Delta_t} \\\\ \\tilde{M}_{l - \\frac{1}{2}, \\vec{r} + \\frac{1}{2}} &amp;= \\tilde{M}_{\\vec{r} + \\frac{1}{2}} e^{-\\imath \\omega l \\Delta_t} \\\\ \\hat{\\nabla} \\times (\\mu^{-1}_{\\vec{r} + \\frac{1}{2}} \\cdot \\tilde{\\nabla} \\times \\tilde{E}_{\\vec{r}}) -\\Omega^2 \\epsilon_{\\vec{r}} \\cdot \\tilde{E}_{\\vec{r}} &amp;= -\\imath \\Omega \\tilde{J}_{\\vec{r}} e^{\\imath \\omega \\Delta_t / 2} \\\\ \\Omega &amp;= 2 \\sin(\\omega \\Delta_t / 2) / \\Delta_t \\end{aligned} \\] <p>resulting in</p> \\[ \\begin{aligned} \\tilde{\\partial}_t &amp;\\Rightarrow -\\imath \\Omega e^{-\\imath \\omega \\Delta_t / 2}\\\\ \\hat{\\partial}_t &amp;\\Rightarrow -\\imath \\Omega e^{ \\imath \\omega \\Delta_t / 2}\\\\ \\end{aligned} \\] <p>Maxwell's equations are then</p> \\[ \\begin{aligned} \\tilde{\\nabla} \\times \\tilde{E}_{\\vec{r}} &amp;= \\imath \\Omega e^{-\\imath \\omega \\Delta_t / 2} \\hat{B}_{\\vec{r} + \\frac{1}{2}} - \\hat{M}_{\\vec{r} + \\frac{1}{2}} \\\\ \\hat{\\nabla} \\times \\hat{H}_{\\vec{r} + \\frac{1}{2}} &amp;= -\\imath \\Omega e^{ \\imath \\omega \\Delta_t / 2} \\tilde{D}_{\\vec{r}} + \\tilde{J}_{\\vec{r}} \\\\ \\tilde{\\nabla} \\cdot \\hat{B}_{\\vec{r} + \\frac{1}{2}} &amp;= 0 \\\\ \\hat{\\nabla} \\cdot \\tilde{D}_{\\vec{r}} &amp;= \\rho_{\\vec{r}} \\end{aligned} \\] <p>With \\(\\Delta_t \\to 0\\), this simplifies to</p> \\[ \\begin{aligned} \\tilde{E}_{l, \\vec{r}} &amp;\\to \\tilde{E}_{\\vec{r}} \\\\ \\tilde{H}_{l - \\frac{1}{2}, \\vec{r} + \\frac{1}{2}} &amp;\\to \\tilde{H}_{\\vec{r} + \\frac{1}{2}} \\\\ \\tilde{J}_{l, \\vec{r}} &amp;\\to \\tilde{J}_{\\vec{r}} \\\\ \\tilde{M}_{l - \\frac{1}{2}, \\vec{r} + \\frac{1}{2}} &amp;\\to \\tilde{M}_{\\vec{r} + \\frac{1}{2}} \\\\ \\Omega &amp;\\to \\omega \\\\ \\tilde{\\partial}_t &amp;\\to -\\imath \\omega \\\\ \\hat{\\partial}_t &amp;\\to -\\imath \\omega \\\\ \\end{aligned} \\] <p>and then</p> \\[ \\begin{aligned} \\tilde{\\nabla} \\times \\tilde{E}_{\\vec{r}} &amp;= \\imath \\omega \\hat{B}_{\\vec{r} + \\frac{1}{2}} - \\hat{M}_{\\vec{r} + \\frac{1}{2}} \\\\ \\hat{\\nabla} \\times \\hat{H}_{\\vec{r} + \\frac{1}{2}} &amp;= -\\imath \\omega \\tilde{D}_{\\vec{r}} + \\tilde{J}_{\\vec{r}} \\\\ \\end{aligned} \\] \\[ \\hat{\\nabla} \\times (\\mu^{-1}_{\\vec{r} + \\frac{1}{2}} \\cdot \\tilde{\\nabla} \\times \\tilde{E}_{\\vec{r}}) -\\omega^2 \\epsilon_{\\vec{r}} \\cdot \\tilde{E}_{\\vec{r}} = -\\imath \\omega \\tilde{J}_{\\vec{r}} \\\\ \\]"},{"location":"api/fdfd/#core-operator-layers","title":"Core operator layers","text":""},{"location":"api/fdfd/#meanas.fdfd.functional","title":"meanas.fdfd.functional","text":"<p>Functional versions of many FDFD operators. These can be useful for performing FDFD calculations without needing to construct large matrices in memory.</p> <p>The functions generated here expect <code>cfdfield_t</code> inputs with shape (3, X, Y, Z), e.g. E = [E_x, E_y, E_z] where each (complex) component has shape (X, Y, Z)</p>"},{"location":"api/fdfd/#meanas.fdfd.functional.e_full","title":"e_full","text":"<pre><code>e_full(\n omega: complex,\n dxes: dx_lists_t,\n epsilon: fdfield,\n mu: fdfield | None = None,\n) -&gt; cfdfield_updater_t\n</code></pre> <p>Wave operator for use with E-field. See <code>operators.e_full</code> for details.</p> <p>Parameters:</p> Name Type Description Default <code>omega</code> <code>complex</code> <p>Angular frequency of the simulation</p> required <code>dxes</code> <code>dx_lists_t</code> <p>Grid parameters <code>[dx_e, dx_h]</code> as described in <code>meanas.fdmath.types</code></p> required <code>epsilon</code> <code>fdfield</code> <p>Dielectric constant</p> required <code>mu</code> <code>fdfield | None</code> <p>Magnetic permeability (default 1 everywhere)</p> <code>None</code> <p>Returns:</p> Type Description <code>cfdfield_updater_t</code> <p>Function <code>f</code> implementing the wave operator</p> <code>cfdfield_updater_t</code> <p><code>f(E)</code> -&gt; <code>-i * omega * J</code></p>"},{"location":"api/fdfd/#meanas.fdfd.functional.eh_full","title":"eh_full","text":"<pre><code>eh_full(\n omega: complex,\n dxes: dx_lists_t,\n epsilon: fdfield,\n mu: fdfield | None = None,\n) -&gt; Callable[\n [cfdfield, cfdfield], tuple[cfdfield_t, cfdfield_t]\n]\n</code></pre> <p>Wave operator for full (both E and H) field representation. See <code>operators.eh_full</code>.</p> <p>Parameters:</p> Name Type Description Default <code>omega</code> <code>complex</code> <p>Angular frequency of the simulation</p> required <code>dxes</code> <code>dx_lists_t</code> <p>Grid parameters <code>[dx_e, dx_h]</code> as described in <code>meanas.fdmath.types</code></p> required <code>epsilon</code> <code>fdfield</code> <p>Dielectric constant</p> required <code>mu</code> <code>fdfield | None</code> <p>Magnetic permeability (default 1 everywhere)</p> <code>None</code> <p>Returns:</p> Type Description <code>Callable[[cfdfield, cfdfield], tuple[cfdfield_t, cfdfield_t]]</code> <p>Function <code>f</code> implementing the wave operator</p> <code>Callable[[cfdfield, cfdfield], tuple[cfdfield_t, cfdfield_t]]</code> <p><code>f(E, H)</code> -&gt; <code>(J, -M)</code></p>"},{"location":"api/fdfd/#meanas.fdfd.functional.e2h","title":"e2h","text":"<pre><code>e2h(\n omega: complex,\n dxes: dx_lists_t,\n mu: fdfield | None = None,\n) -&gt; cfdfield_updater_t\n</code></pre> <p>Utility operator for converting the <code>E</code> field into the <code>H</code> field. For use with <code>e_full</code> -- assumes that there is no magnetic current <code>M</code>.</p> <p>Parameters:</p> Name Type Description Default <code>omega</code> <code>complex</code> <p>Angular frequency of the simulation</p> required <code>dxes</code> <code>dx_lists_t</code> <p>Grid parameters <code>[dx_e, dx_h]</code> as described in <code>meanas.fdmath.types</code></p> required <code>mu</code> <code>fdfield | None</code> <p>Magnetic permeability (default 1 everywhere)</p> <code>None</code> <p>Returns:</p> Type Description <code>cfdfield_updater_t</code> <p>Function <code>f</code> for converting <code>E</code> to <code>H</code>,</p> <code>cfdfield_updater_t</code> <p><code>f(E)</code> -&gt; <code>H</code></p>"},{"location":"api/fdfd/#meanas.fdfd.functional.m2j","title":"m2j","text":"<pre><code>m2j(\n omega: complex,\n dxes: dx_lists_t,\n mu: fdfield | None = None,\n) -&gt; cfdfield_updater_t\n</code></pre> <p>Utility operator for converting magnetic current <code>M</code> distribution into equivalent electric current distribution <code>J</code>. For use with e.g. <code>e_full</code>.</p> <p>Parameters:</p> Name Type Description Default <code>omega</code> <code>complex</code> <p>Angular frequency of the simulation</p> required <code>dxes</code> <code>dx_lists_t</code> <p>Grid parameters <code>[dx_e, dx_h]</code> as described in <code>meanas.fdmath.types</code></p> required <code>mu</code> <code>fdfield | None</code> <p>Magnetic permeability (default 1 everywhere)</p> <code>None</code> <p>Returns:</p> Type Description <code>cfdfield_updater_t</code> <p>Function <code>f</code> for converting <code>M</code> to <code>J</code>,</p> <code>cfdfield_updater_t</code> <p><code>f(M)</code> -&gt; <code>J</code></p>"},{"location":"api/fdfd/#meanas.fdfd.functional.e_tfsf_source","title":"e_tfsf_source","text":"<pre><code>e_tfsf_source(\n TF_region: fdfield,\n omega: complex,\n dxes: dx_lists_t,\n epsilon: fdfield,\n mu: fdfield | None = None,\n) -&gt; cfdfield_updater_t\n</code></pre> <p>Operator that turns an E-field distribution into a total-field/scattered-field (TFSF) source.</p> <p>If <code>A</code> is the full wave operator from <code>e_full(...)</code> and <code>Q</code> is the diagonal mask selecting the total-field region, then the TFSF source is the commutator</p> \\[ \\frac{A Q - Q A}{-i \\omega} E. \\] <p>This vanishes in the interior of the total-field and scattered-field regions and is supported only at their shared boundary, where the mask discontinuity makes <code>A</code> and <code>Q</code> fail to commute. The returned current is therefore the distributed source needed to inject the desired total field without also forcing the scattered-field region.</p> <p>Parameters:</p> Name Type Description Default <code>TF_region</code> <code>fdfield</code> <p>mask which is set to 1 in the total-field region, and 0 elsewhere (i.e. in the scattered-field region). Should have the same shape as the simulation grid, e.g. <code>epsilon[0].shape</code>.</p> required <code>omega</code> <code>complex</code> <p>Angular frequency of the simulation</p> required <code>dxes</code> <code>dx_lists_t</code> <p>Grid parameters <code>[dx_e, dx_h]</code> as described in <code>meanas.fdmath.types</code></p> required <code>epsilon</code> <code>fdfield</code> <p>Dielectric constant distribution</p> required <code>mu</code> <code>fdfield | None</code> <p>Magnetic permeability (default 1 everywhere)</p> <code>None</code> <p>Returns:</p> Type Description <code>cfdfield_updater_t</code> <p>Function <code>f</code> which takes an E field and returns a current distribution,</p> <code>cfdfield_updater_t</code> <p><code>f(E)</code> -&gt; <code>J</code></p>"},{"location":"api/fdfd/#meanas.fdfd.functional.poynting_e_cross_h","title":"poynting_e_cross_h","text":"<pre><code>poynting_e_cross_h(\n dxes: dx_lists_t,\n) -&gt; Callable[[cfdfield, cfdfield], cfdfield_t]\n</code></pre> <p>Generates a function that takes the single-frequency <code>E</code> and <code>H</code> fields and calculates the cross product <code>E</code> x <code>H</code> = \\(E \\times H\\) as required for the Poynting vector, \\(S = E \\times H\\).</p> <p>On the Yee grid, the electric and magnetic components are not stored at the same locations. This helper therefore applies the same one-cell electric-field shifts used by the sparse <code>operators.poynting_e_cross(...)</code> construction so that the discrete cross product matches the face-centered energy flux used in <code>meanas.fdtd.energy.poynting(...)</code>.</p> Note <p>This function also shifts the input <code>E</code> field by one cell as required for computing the Poynting cross product (see <code>meanas.fdfd</code> module docs).</p> Note <p>If <code>E</code> and <code>H</code> are peak amplitudes as assumed elsewhere in this code, the time-average of the poynting vector is <code>&lt;S&gt; = Re(S)/2 = Re(E x H*) / 2</code>. The factor of <code>1/2</code> can be omitted if root-mean-square quantities are used instead.</p> <p>Parameters:</p> Name Type Description Default <code>dxes</code> <code>dx_lists_t</code> <p>Grid parameters <code>[dx_e, dx_h]</code> as described in <code>meanas.fdmath.types</code></p> required <p>Returns:</p> Type Description <code>Callable[[cfdfield, cfdfield], cfdfield_t]</code> <p>Function <code>f</code> that returns the staggered-grid cross product <code>E \\times H</code>.</p> <code>Callable[[cfdfield, cfdfield], cfdfield_t]</code> <p>For time-average power, call it as <code>f(E, H.conj())</code> and take <code>Re(...) / 2</code>.</p>"},{"location":"api/fdfd/#meanas.fdfd.operators","title":"meanas.fdfd.operators","text":"<p>Sparse matrix operators for use with electromagnetic wave equations.</p> <p>These functions return sparse-matrix (<code>scipy.sparse.sparray</code>) representations of a variety of operators, intended for use with E and H fields vectorized using the <code>meanas.fdmath.vectorization.vec()</code> and <code>meanas.fdmath.vectorization.unvec()</code> functions.</p> <p>E- and H-field values are defined on a Yee cell; <code>epsilon</code> values should be calculated for cells centered at each E component (<code>mu</code> at each H component).</p> <p>Many of these functions require a <code>dxes</code> parameter, of type <code>dx_lists_t</code>; see the <code>meanas.fdmath.types</code> submodule for details.</p> <p>The following operators are included:</p> <ul> <li>E-only wave operator</li> <li>H-only wave operator</li> <li>EH wave operator</li> <li>Curl for use with E, H fields</li> <li>E to H conversion</li> <li>M to J conversion</li> <li>Poynting cross products</li> <li>Circular shifts</li> <li>Discrete derivatives</li> <li>Averaging operators</li> <li>Cross product matrices</li> </ul>"},{"location":"api/fdfd/#meanas.fdfd.operators.e_full","title":"e_full","text":"<pre><code>e_full(\n omega: complex,\n dxes: dx_lists_t,\n epsilon: vfdfield | vcfdfield,\n mu: vfdfield | None = None,\n pec: vfdfield | None = None,\n pmc: vfdfield | None = None,\n) -&gt; sparse.sparray\n</code></pre> <p>Wave operator \\[ \\nabla \\times (\\frac{1}{\\mu} \\nabla \\times) - \\Omega^2 \\epsilon \\] </p> <pre><code>del x (1/mu * del x) - omega**2 * epsilon\n</code></pre> <p>for use with the E-field, with wave equation \\[ (\\nabla \\times (\\frac{1}{\\mu} \\nabla \\times) - \\Omega^2 \\epsilon) E = -\\imath \\omega J \\] </p> <pre><code>(del x (1/mu * del x) - omega**2 * epsilon) E = -i * omega * J\n</code></pre> <p>To make this matrix symmetric, use the preconditioners from <code>e_full_preconditioners()</code>.</p> <p>Parameters:</p> Name Type Description Default <code>omega</code> <code>complex</code> <p>Angular frequency of the simulation</p> required <code>dxes</code> <code>dx_lists_t</code> <p>Grid parameters <code>[dx_e, dx_h]</code> as described in <code>meanas.fdmath.types</code></p> required <code>epsilon</code> <code>vfdfield | vcfdfield</code> <p>Vectorized dielectric constant</p> required <code>mu</code> <code>vfdfield | None</code> <p>Vectorized magnetic permeability (default 1 everywhere).</p> <code>None</code> <code>pec</code> <code>vfdfield | None</code> <p>Vectorized mask specifying PEC cells. Any cells where <code>pec != 0</code> are interpreted as containing a perfect electrical conductor (PEC). The PEC is applied per-field-component (i.e. <code>pec.size == epsilon.size</code>)</p> <code>None</code> <code>pmc</code> <code>vfdfield | None</code> <p>Vectorized mask specifying PMC cells. Any cells where <code>pmc != 0</code> are interpreted as containing a perfect magnetic conductor (PMC). The PMC is applied per-field-component (i.e. <code>pmc.size == epsilon.size</code>)</p> <code>None</code> <p>Returns:</p> Type Description <code>sparray</code> <p>Sparse matrix containing the wave operator.</p>"},{"location":"api/fdfd/#meanas.fdfd.operators.e_full_preconditioners","title":"e_full_preconditioners","text":"<pre><code>e_full_preconditioners(\n dxes: dx_lists_t,\n) -&gt; tuple[sparse.sparray, sparse.sparray]\n</code></pre> <p>Left and right preconditioners <code>(Pl, Pr)</code> for symmetrizing the <code>e_full</code> wave operator.</p> <p>The preconditioned matrix <code>A_symm = (Pl @ A @ Pr)</code> is complex-symmetric (non-Hermitian unless there is no loss or PMLs).</p> <p>The preconditioner matrices are diagonal and complex, with <code>Pr = 1 / Pl</code></p> <p>Parameters:</p> Name Type Description Default <code>dxes</code> <code>dx_lists_t</code> <p>Grid parameters <code>[dx_e, dx_h]</code> as described in <code>meanas.fdmath.types</code></p> required <p>Returns:</p> Type Description <code>tuple[sparray, sparray]</code> <p>Preconditioner matrices <code>(Pl, Pr)</code>.</p>"},{"location":"api/fdfd/#meanas.fdfd.operators.h_full","title":"h_full","text":"<pre><code>h_full(\n omega: complex,\n dxes: dx_lists_t,\n epsilon: vfdfield,\n mu: vfdfield | None = None,\n pec: vfdfield | None = None,\n pmc: vfdfield | None = None,\n) -&gt; sparse.sparray\n</code></pre> <p>Wave operator \\[ \\nabla \\times (\\frac{1}{\\epsilon} \\nabla \\times) - \\omega^2 \\mu \\] </p> <pre><code>del x (1/epsilon * del x) - omega**2 * mu\n</code></pre> <p>for use with the H-field, with wave equation \\[ (\\nabla \\times (\\frac{1}{\\epsilon} \\nabla \\times) - \\omega^2 \\mu) E = \\imath \\omega M \\] </p> <pre><code>(del x (1/epsilon * del x) - omega**2 * mu) E = i * omega * M\n</code></pre> <p>Parameters:</p> Name Type Description Default <code>omega</code> <code>complex</code> <p>Angular frequency of the simulation</p> required <code>dxes</code> <code>dx_lists_t</code> <p>Grid parameters <code>[dx_e, dx_h]</code> as described in <code>meanas.fdmath.types</code></p> required <code>epsilon</code> <code>vfdfield</code> <p>Vectorized dielectric constant</p> required <code>mu</code> <code>vfdfield | None</code> <p>Vectorized magnetic permeability (default 1 everywhere)</p> <code>None</code> <code>pec</code> <code>vfdfield | None</code> <p>Vectorized mask specifying PEC cells. Any cells where <code>pec != 0</code> are interpreted as containing a perfect electrical conductor (PEC). The PEC is applied per-field-component (i.e. <code>pec.size == epsilon.size</code>)</p> <code>None</code> <code>pmc</code> <code>vfdfield | None</code> <p>Vectorized mask specifying PMC cells. Any cells where <code>pmc != 0</code> are interpreted as containing a perfect magnetic conductor (PMC). The PMC is applied per-field-component (i.e. <code>pmc.size == epsilon.size</code>)</p> <code>None</code> <p>Returns:</p> Type Description <code>sparray</code> <p>Sparse matrix containing the wave operator.</p>"},{"location":"api/fdfd/#meanas.fdfd.operators.eh_full","title":"eh_full","text":"<pre><code>eh_full(\n omega: complex,\n dxes: dx_lists_t,\n epsilon: vfdfield,\n mu: vfdfield | None = None,\n pec: vfdfield | None = None,\n pmc: vfdfield | None = None,\n) -&gt; sparse.sparray\n</code></pre> <p>Wave operator for <code>[E, H]</code> field representation. This operator implements Maxwell's equations without cancelling out either E or H. The operator is</p> \\[ \\begin{bmatrix} -\\imath \\omega \\epsilon &amp; \\nabla \\times \\\\ \\nabla \\times &amp; \\imath \\omega \\mu \\end{bmatrix} \\] <pre><code>[[-i * omega * epsilon, del x ],\n [del x, i * omega * mu]]\n</code></pre> <p>for use with a field vector of the form <code>cat(vec(E), vec(H))</code>:</p> \\[ \\begin{bmatrix} -\\imath \\omega \\epsilon &amp; \\nabla \\times \\\\ \\nabla \\times &amp; \\imath \\omega \\mu \\end{bmatrix} \\begin{bmatrix} E \\\\ H \\end{bmatrix} = \\begin{bmatrix} J \\\\ -M \\end{bmatrix} \\] <p>Parameters:</p> Name Type Description Default <code>omega</code> <code>complex</code> <p>Angular frequency of the simulation</p> required <code>dxes</code> <code>dx_lists_t</code> <p>Grid parameters <code>[dx_e, dx_h]</code> as described in <code>meanas.fdmath.types</code></p> required <code>epsilon</code> <code>vfdfield</code> <p>Vectorized dielectric constant</p> required <code>mu</code> <code>vfdfield | None</code> <p>Vectorized magnetic permeability (default 1 everywhere)</p> <code>None</code> <code>pec</code> <code>vfdfield | None</code> <p>Vectorized mask specifying PEC cells. Any cells where <code>pec != 0</code> are interpreted as containing a perfect electrical conductor (PEC). The PEC is applied per-field-component (i.e. <code>pec.size == epsilon.size</code>)</p> <code>None</code> <code>pmc</code> <code>vfdfield | None</code> <p>Vectorized mask specifying PMC cells. Any cells where <code>pmc != 0</code> are interpreted as containing a perfect magnetic conductor (PMC). The PMC is applied per-field-component (i.e. <code>pmc.size == epsilon.size</code>)</p> <code>None</code> <p>Returns:</p> Type Description <code>sparray</code> <p>Sparse matrix containing the wave operator.</p>"},{"location":"api/fdfd/#meanas.fdfd.operators.e2h","title":"e2h","text":"<pre><code>e2h(\n omega: complex,\n dxes: dx_lists_t,\n mu: vfdfield | None = None,\n pmc: vfdfield | None = None,\n) -&gt; sparse.sparray\n</code></pre> <p>Utility operator for converting the E field into the H field. For use with <code>e_full()</code> -- assumes that there is no magnetic current M.</p> <p>Parameters:</p> Name Type Description Default <code>omega</code> <code>complex</code> <p>Angular frequency of the simulation</p> required <code>dxes</code> <code>dx_lists_t</code> <p>Grid parameters <code>[dx_e, dx_h]</code> as described in <code>meanas.fdmath.types</code></p> required <code>mu</code> <code>vfdfield | None</code> <p>Vectorized magnetic permeability (default 1 everywhere)</p> <code>None</code> <code>pmc</code> <code>vfdfield | None</code> <p>Vectorized mask specifying PMC cells. Any cells where <code>pmc != 0</code> are interpreted as containing a perfect magnetic conductor (PMC). The PMC is applied per-field-component (i.e. <code>pmc.size == epsilon.size</code>)</p> <code>None</code> <p>Returns:</p> Type Description <code>sparray</code> <p>Sparse matrix for converting E to H.</p>"},{"location":"api/fdfd/#meanas.fdfd.operators.m2j","title":"m2j","text":"<pre><code>m2j(\n omega: complex,\n dxes: dx_lists_t,\n mu: vfdfield | None = None,\n) -&gt; sparse.sparray\n</code></pre> <p>Operator for converting a magnetic current M into an electric current J. For use with eg. <code>e_full()</code>.</p> <p>Parameters:</p> Name Type Description Default <code>omega</code> <code>complex</code> <p>Angular frequency of the simulation</p> required <code>dxes</code> <code>dx_lists_t</code> <p>Grid parameters <code>[dx_e, dx_h]</code> as described in <code>meanas.fdmath.types</code></p> required <code>mu</code> <code>vfdfield | None</code> <p>Vectorized magnetic permeability (default 1 everywhere)</p> <code>None</code> <p>Returns:</p> Type Description <code>sparray</code> <p>Sparse matrix for converting M to J.</p>"},{"location":"api/fdfd/#meanas.fdfd.operators.poynting_e_cross","title":"poynting_e_cross","text":"<pre><code>poynting_e_cross(\n e: vcfdfield, dxes: dx_lists_t\n) -&gt; sparse.sparray\n</code></pre> <p>Operator for computing the staggered-grid <code>(E \\times)</code> part of the Poynting vector.</p> <p>On the Yee grid the E and H components live on different edges, so the electric field must be shifted by one cell in the appropriate direction before forming the discrete cross product. This sparse operator encodes that shifted cross product directly and is the matrix equivalent of <code>functional.poynting_e_cross_h(...)</code>.</p> <p>Parameters:</p> Name Type Description Default <code>e</code> <code>vcfdfield</code> <p>Vectorized E-field for the ExH cross product</p> required <code>dxes</code> <code>dx_lists_t</code> <p>Grid parameters <code>[dx_e, dx_h]</code> as described in <code>meanas.fdmath.types</code></p> required <p>Returns:</p> Type Description <code>sparray</code> <p>Sparse matrix containing the <code>(E \\times)</code> part of the staggered Poynting</p> <code>sparray</code> <p>cross product.</p>"},{"location":"api/fdfd/#meanas.fdfd.operators.poynting_h_cross","title":"poynting_h_cross","text":"<pre><code>poynting_h_cross(\n h: vcfdfield, dxes: dx_lists_t\n) -&gt; sparse.sparray\n</code></pre> <p>Operator for computing the staggered-grid <code>(H \\times)</code> part of the Poynting vector.</p> <p>Together with <code>poynting_e_cross(...)</code>, this provides the matrix form of the Yee-grid cross product used in the flux helpers. The two are related by the usual antisymmetry of the cross product,</p> \\[ H \\times E = -(E \\times H), \\] <p>once the same staggered field placement is used on both sides.</p> <p>Parameters:</p> Name Type Description Default <code>h</code> <code>vcfdfield</code> <p>Vectorized H-field for the HxE cross product</p> required <code>dxes</code> <code>dx_lists_t</code> <p>Grid parameters <code>[dx_e, dx_h]</code> as described in <code>meanas.fdmath.types</code></p> required <p>Returns:</p> Type Description <code>sparray</code> <p>Sparse matrix containing the <code>(H \\times)</code> part of the staggered Poynting</p> <code>sparray</code> <p>cross product.</p>"},{"location":"api/fdfd/#meanas.fdfd.operators.e_tfsf_source","title":"e_tfsf_source","text":"<pre><code>e_tfsf_source(\n TF_region: vfdfield,\n omega: complex,\n dxes: dx_lists_t,\n epsilon: vfdfield,\n mu: vfdfield | None = None,\n) -&gt; sparse.sparray\n</code></pre> <p>Operator that turns a desired E-field distribution into a total-field/scattered-field (TFSF) source.</p> <p>Let <code>A</code> be the full wave operator from <code>e_full(...)</code>, and let <code>Q = \\mathrm{diag}(TF_region)</code> be the projector onto the total-field region. Then the TFSF current operator is the commutator</p> \\[ \\frac{A Q - Q A}{-i \\omega}. \\] <p>Inside regions where <code>Q</code> is locally constant, <code>A</code> and <code>Q</code> commute and the source vanishes. Only cells at the TF/SF boundary contribute nonzero current, which is exactly the desired distributed source for injecting the chosen field into the total-field region without directly forcing the scattered-field region.</p> <p>Parameters:</p> Name Type Description Default <code>TF_region</code> <code>vfdfield</code> <p>Mask, which is set to 1 inside the total-field region and 0 in the scattered-field region</p> required <code>omega</code> <code>complex</code> <p>Angular frequency of the simulation</p> required <code>dxes</code> <code>dx_lists_t</code> <p>Grid parameters <code>[dx_e, dx_h]</code> as described in <code>meanas.fdmath.types</code></p> required <code>epsilon</code> <code>vfdfield</code> <p>Vectorized dielectric constant</p> required <code>mu</code> <code>vfdfield | None</code> <p>Vectorized magnetic permeability (default 1 everywhere).</p> <code>None</code> <p>Returns:</p> Type Description <code>sparray</code> <p>Sparse matrix that turns an E-field into a current (J) distribution.</p>"},{"location":"api/fdfd/#meanas.fdfd.operators.e_boundary_source","title":"e_boundary_source","text":"<pre><code>e_boundary_source(\n mask: vfdfield,\n omega: complex,\n dxes: dx_lists_t,\n epsilon: vfdfield,\n mu: vfdfield | None = None,\n periodic_mask_edges: bool = False,\n) -&gt; sparse.sparray\n</code></pre> <p>Operator that turns an E-field distrubtion into a current (J) distribution along the edges (external and internal) of the provided mask. This is just an <code>e_tfsf_source()</code> with an additional masking step.</p> <p>Equivalently, this helper first constructs the TFSF commutator source for the full mask and then zeroes out all cells except the mask boundary. The boundary is defined as the set of cells whose mask value changes under a one-cell shift in any Cartesian direction. With <code>periodic_mask_edges=False</code> the shifts mirror at the domain boundary; with <code>True</code> they wrap periodically.</p> <p>Parameters:</p> Name Type Description Default <code>mask</code> <code>vfdfield</code> <p>The current distribution is generated at the edges of the mask, i.e. any points where shifting the mask by one cell in any direction would change its value.</p> required <code>omega</code> <code>complex</code> <p>Angular frequency of the simulation</p> required <code>dxes</code> <code>dx_lists_t</code> <p>Grid parameters <code>[dx_e, dx_h]</code> as described in <code>meanas.fdmath.types</code></p> required <code>epsilon</code> <code>vfdfield</code> <p>Vectorized dielectric constant</p> required <code>mu</code> <code>vfdfield | None</code> <p>Vectorized magnetic permeability (default 1 everywhere).</p> <code>None</code> <p>Returns:</p> Type Description <code>sparray</code> <p>Sparse matrix that turns an E-field into a current (J) distribution.</p>"},{"location":"api/fdfd/#meanas.fdfd.solvers","title":"meanas.fdfd.solvers","text":"<p>Solvers and solver interface for FDFD problems.</p>"},{"location":"api/fdfd/#meanas.fdfd.solvers.generic","title":"generic","text":"<pre><code>generic(\n omega: complex,\n dxes: dx_lists_t,\n J: vcfdfield,\n epsilon: vfdfield,\n mu: vfdfield | None = None,\n *,\n pec: vfdfield | None = None,\n pmc: vfdfield | None = None,\n adjoint: bool = False,\n matrix_solver: Callable[..., ArrayLike] = _scipy_qmr,\n matrix_solver_opts: dict[str, Any] | None = None,\n E_guess: vcfdfield | None = None,\n) -&gt; vcfdfield_t\n</code></pre> <p>Conjugate gradient FDFD solver using CSR sparse matrices.</p> <p>All ndarray arguments should be 1D arrays, as returned by <code>meanas.fdmath.vectorization.vec()</code>.</p> <p>Parameters:</p> Name Type Description Default <code>omega</code> <code>complex</code> <p>Complex frequency to solve at.</p> required <code>dxes</code> <code>dx_lists_t</code> <p><code>[[dx_e, dy_e, dz_e], [dx_h, dy_h, dz_h]]</code> (complex cell sizes) as discussed in <code>meanas.fdmath.types</code></p> required <code>J</code> <code>vcfdfield</code> <p>Electric current distribution (at E-field locations)</p> required <code>epsilon</code> <code>vfdfield</code> <p>Dielectric constant distribution (at E-field locations)</p> required <code>mu</code> <code>vfdfield | None</code> <p>Magnetic permeability distribution (at H-field locations)</p> <code>None</code> <code>pec</code> <code>vfdfield | None</code> <p>Perfect electric conductor distribution (at E-field locations; non-zero value indicates PEC is present)</p> <code>None</code> <code>pmc</code> <code>vfdfield | None</code> <p>Perfect magnetic conductor distribution (at H-field locations; non-zero value indicates PMC is present)</p> <code>None</code> <code>adjoint</code> <code>bool</code> <p>If true, solves the adjoint problem.</p> <code>False</code> <code>matrix_solver</code> <code>Callable[..., ArrayLike]</code> <p>Called as <code>matrix_solver(A, b, **matrix_solver_opts) -&gt; x</code>, where <code>A</code>: <code>scipy.sparse.csr_array</code>; <code>b</code>: <code>ArrayLike</code>; <code>x</code>: <code>ArrayLike</code>; Default is a wrapped version of <code>scipy.sparse.linalg.qmr()</code> which doesn't return convergence info and logs the residual every 100 iterations.</p> <code>_scipy_qmr</code> <code>matrix_solver_opts</code> <code>dict[str, Any] | None</code> <p>Passed as kwargs to <code>matrix_solver(...)</code></p> <code>None</code> <code>E_guess</code> <code>vcfdfield | None</code> <p>Guess at the solution E-field. <code>matrix_solver</code> must accept an <code>x0</code> argument with the same purpose.</p> <code>None</code> <p>Returns:</p> Type Description <code>vcfdfield_t</code> <p>E-field which solves the system.</p>"},{"location":"api/fdfd/#meanas.fdfd.scpml","title":"meanas.fdfd.scpml","text":"<p>Functions for creating stretched coordinate perfectly matched layer (PML) absorbers.</p>"},{"location":"api/fdfd/#meanas.fdfd.scpml.s_function_t","title":"s_function_t <code>module-attribute</code>","text":"<pre><code>s_function_t = Callable[\n [NDArray[float64]], NDArray[float64]\n]\n</code></pre> <p>Typedef for s-functions, see <code>prepare_s_function()</code></p>"},{"location":"api/fdfd/#meanas.fdfd.scpml.prepare_s_function","title":"prepare_s_function","text":"<pre><code>prepare_s_function(\n ln_R: float = -16, m: float = 4\n) -&gt; s_function_t\n</code></pre> <p>Create an s_function to pass to the SCPML functions. This is used when you would like to customize the PML parameters.</p> <p>Parameters:</p> Name Type Description Default <code>ln_R</code> <code>float</code> <p>Natural logarithm of the desired reflectance</p> <code>-16</code> <code>m</code> <code>float</code> <p>Polynomial order for the PML (imaginary part increases as distance ** m)</p> <code>4</code> <p>Returns:</p> Type Description <code>s_function_t</code> <p>An s_function, which takes an ndarray (distances) and returns an ndarray (complex part</p> <code>s_function_t</code> <p>of the cell width; needs to be divided by <code>sqrt(epilon_effective) * real(omega))</code></p> <code>s_function_t</code> <p>before use.</p>"},{"location":"api/fdfd/#meanas.fdfd.scpml.uniform_grid_scpml","title":"uniform_grid_scpml","text":"<pre><code>uniform_grid_scpml(\n shape: Sequence[int],\n thicknesses: Sequence[int],\n omega: float,\n epsilon_effective: float = 1.0,\n s_function: s_function_t | None = None,\n) -&gt; list[list[NDArray[numpy.float64]]]\n</code></pre> <p>Create dx arrays for a uniform grid with a cell width of 1 and a pml.</p> <p>If you want something more fine-grained, check out <code>stretch_with_scpml(...)</code>.</p> <p>Parameters:</p> Name Type Description Default <code>shape</code> <code>Sequence[int]</code> <p>Shape of the grid, including the PMLs (which are 2*thicknesses thick)</p> required <code>thicknesses</code> <code>Sequence[int]</code> <p><code>[th_x, th_y, th_z]</code> Thickness of the PML in each direction. Both polarities are added. Each th_ of pml is applied twice, once on each edge of the grid along the given axis. <code>th_*</code> may be zero, in which case no pml is added.</p> required <code>omega</code> <code>float</code> <p>Angular frequency for the simulation</p> required <code>epsilon_effective</code> <code>float</code> <p>Effective epsilon of the PML. Match this to the material at the edge of your grid. Default 1.</p> <code>1.0</code> <code>s_function</code> <code>s_function_t | None</code> <p>created by <code>prepare_s_function(...)</code>, allowing customization of pml parameters. Default uses <code>prepare_s_function()</code> with no parameters.</p> <code>None</code> <p>Returns:</p> Type Description <code>list[list[NDArray[float64]]]</code> <p>Complex cell widths (dx_lists_mut) as discussed in <code>meanas.fdmath.types</code>.</p>"},{"location":"api/fdfd/#meanas.fdfd.scpml.stretch_with_scpml","title":"stretch_with_scpml","text":"<pre><code>stretch_with_scpml(\n dxes: list[list[NDArray[float64]]],\n axis: int,\n polarity: int,\n omega: float,\n epsilon_effective: float = 1.0,\n thickness: int = 10,\n s_function: s_function_t | None = None,\n) -&gt; list[list[NDArray[numpy.float64]]]\n</code></pre> <p>Stretch dxes to contain a stretched-coordinate PML (SCPML) in one direction along one axis.</p> <p>Parameters:</p> Name Type Description Default <code>dxes</code> <code>list[list[NDArray[float64]]]</code> <p>Grid parameters <code>[dx_e, dx_h]</code> as described in <code>meanas.fdmath.types</code></p> required <code>axis</code> <code>int</code> <p>axis to stretch (0=x, 1=y, 2=z)</p> required <code>polarity</code> <code>int</code> <p>direction to stretch (-1 for -ve, +1 for +ve)</p> required <code>omega</code> <code>float</code> <p>Angular frequency for the simulation</p> required <code>epsilon_effective</code> <code>float</code> <p>Effective epsilon of the PML. Match this to the material at the edge of your grid. Default 1.</p> <code>1.0</code> <code>thickness</code> <code>int</code> <p>number of cells to use for pml (default 10)</p> <code>10</code> <code>s_function</code> <code>s_function_t | None</code> <p>Created by <code>prepare_s_function(...)</code>, allowing customization of pml parameters. Default uses <code>prepare_s_function()</code> with no parameters.</p> <code>None</code> <p>Returns:</p> Type Description <code>list[list[NDArray[float64]]]</code> <p>Complex cell widths (dx_lists_mut) as discussed in <code>meanas.fdmath.types</code>.</p> <code>list[list[NDArray[float64]]]</code> <p>Multiple calls to this function may be necessary if multiple absorpbing boundaries are needed.</p>"},{"location":"api/fdfd/#meanas.fdfd.farfield","title":"meanas.fdfd.farfield","text":"<p>Functions for performing near-to-farfield transformation (and the reverse).</p>"},{"location":"api/fdfd/#meanas.fdfd.farfield.near_to_farfield","title":"near_to_farfield","text":"<pre><code>near_to_farfield(\n E_near: transverse_slice_pair,\n H_near: transverse_slice_pair,\n dx: float,\n dy: float,\n padded_size: Sequence[int] | int | None = None,\n) -&gt; dict[str, Any]\n</code></pre> <p>Compute the farfield, i.e. the distribution of the fields after propagation through several wavelengths of uniform medium.</p> <p>The input fields should be complex phasors.</p> <p>Parameters:</p> Name Type Description Default <code>E_near</code> <code>transverse_slice_pair</code> <p>List of 2 ndarrays containing the 2D phasor field slices for the transverse E fields (e.g. [Ex, Ey] for calculating the farfield toward the z-direction).</p> required <code>H_near</code> <code>transverse_slice_pair</code> <p>List of 2 ndarrays containing the 2D phasor field slices for the transverse H fields (e.g. [Hx, hy] for calculating the farfield towrad the z-direction).</p> required <code>dx</code> <code>float</code> <p>Cell size along x-dimension, in units of wavelength.</p> required <code>dy</code> <code>float</code> <p>Cell size along y-dimension, in units of wavelength.</p> required <code>padded_size</code> <code>Sequence[int] | int | None</code> <p>Shape of the output. A single integer <code>n</code> will be expanded to <code>(n, n)</code>. Powers of 2 are most efficient for FFT computation. Default is the smallest power of 2 larger than the input, for each axis.</p> <code>None</code> <p>Returns:</p> Type Description <code>dict[str, Any]</code> <p>Dict with keys</p> <code>dict[str, Any]</code> <ul> <li><code>E_far</code>: Normalized E-field farfield; multiply by (i k exp(-i k r) / (4 pi r)) to get the actual field value.</li> </ul> <code>dict[str, Any]</code> <ul> <li><code>H_far</code>: Normalized H-field farfield; multiply by (i k exp(-i k r) / (4 pi r)) to get the actual field value.</li> </ul> <code>dict[str, Any]</code> <ul> <li><code>kx</code>, <code>ky</code>: Wavevector values corresponding to the x- and y- axes in E_far and H_far, normalized to wavelength (dimensionless).</li> </ul> <code>dict[str, Any]</code> <ul> <li><code>dkx</code>, <code>dky</code>: step size for kx and ky, normalized to wavelength.</li> </ul> <code>dict[str, Any]</code> <ul> <li><code>theta</code>: arctan2(ky, kx) corresponding to each (kx, ky). This is the angle in the x-y plane, counterclockwise from above, starting from +x.</li> </ul> <code>dict[str, Any]</code> <ul> <li><code>phi</code>: arccos(kz / k) corresponding to each (kx, ky). This is the angle away from +z.</li> </ul>"},{"location":"api/fdfd/#meanas.fdfd.farfield.far_to_nearfield","title":"far_to_nearfield","text":"<pre><code>far_to_nearfield(\n E_far: transverse_slice_pair,\n H_far: transverse_slice_pair,\n dkx: float,\n dky: float,\n padded_size: Sequence[int] | int | None = None,\n) -&gt; dict[str, Any]\n</code></pre> <p>Compute the farfield, i.e. the distribution of the fields after propagation through several wavelengths of uniform medium.</p> <p>The input fields should be complex phasors.</p> <p>Parameters:</p> Name Type Description Default <code>E_far</code> <code>transverse_slice_pair</code> <p>List of 2 ndarrays containing the 2D phasor field slices for the transverse E fields (e.g. [Ex, Ey] for calculating the nearfield toward the z-direction). Fields should be normalized so that E_far = E_far_actual / (i k exp(-i k r) / (4 pi r))</p> required <code>H_far</code> <code>transverse_slice_pair</code> <p>List of 2 ndarrays containing the 2D phasor field slices for the transverse H fields (e.g. [Hx, hy] for calculating the nearfield toward the z-direction). Fields should be normalized so that H_far = H_far_actual / (i k exp(-i k r) / (4 pi r))</p> required <code>dkx</code> <code>float</code> <p>kx discretization, in units of wavelength.</p> required <code>dky</code> <code>float</code> <p>ky discretization, in units of wavelength.</p> required <code>padded_size</code> <code>Sequence[int] | int | None</code> <p>Shape of the output. A single integer <code>n</code> will be expanded to <code>(n, n)</code>. Powers of 2 are most efficient for FFT computation. Default is the smallest power of 2 larger than the input, for each axis.</p> <code>None</code> <p>Returns:</p> Type Description <code>dict[str, Any]</code> <p>Dict with keys</p> <code>dict[str, Any]</code> <ul> <li><code>E</code>: E-field nearfield</li> </ul> <code>dict[str, Any]</code> <ul> <li><code>H</code>: H-field nearfield</li> </ul> <code>dict[str, Any]</code> <ul> <li><code>dx</code>, <code>dy</code>: spatial discretization, normalized to wavelength (dimensionless)</li> </ul>"},{"location":"api/fdmath/","title":"fdmath","text":""},{"location":"api/fdmath/#meanas.fdmath","title":"meanas.fdmath","text":"<p>Basic discrete calculus for finite difference (fd) simulations.</p>"},{"location":"api/fdmath/#meanas.fdmath--fields-functions-and-operators","title":"Fields, Functions, and Operators","text":"<p>Discrete fields are stored in one of two forms:</p> <ul> <li>The <code>fdfield_t</code> form is a multidimensional <code>numpy.NDArray</code><ul> <li>For a scalar field, this is just <code>U[m, n, p]</code>, where <code>m</code>, <code>n</code>, and <code>p</code> are discrete indices referring to positions on the x, y, and z axes respectively.</li> <li>For a vector field, the first index specifies which vector component is accessed: <code>E[:, m, n, p] = [Ex[m, n, p], Ey[m, n, p], Ez[m, n, p]]</code>.</li> </ul> </li> <li>The <code>vfdfield_t</code> form is simply a vectorzied (i.e. 1D) version of the <code>fdfield_t</code>, as obtained by <code>meanas.fdmath.vectorization.vec</code> (effectively just <code>numpy.ravel</code>)</li> </ul> Operators which act on fields also come in two forms <ul> <li>Python functions, created by the functions in <code>meanas.fdmath.functional</code>. The generated functions act on fields in the <code>fdfield_t</code> form.</li> <li>Linear operators, usually 2D sparse matrices using <code>scipy.sparse</code>, created by <code>meanas.fdmath.operators</code>. These operators act on vectorized fields in the <code>vfdfield_t</code> form.</li> </ul> <p>The operations performed should be equivalent: <code>functional.op(*args)(E)</code> should be equivalent to <code>unvec(operators.op(*args) @ vec(E), E.shape[1:])</code>.</p> <p>Generally speaking the <code>field_t</code> form is easier to work with, but can be harder or less efficient to compose (e.g. it is easy to generate a single matrix by multiplying a series of other matrices).</p>"},{"location":"api/fdmath/#meanas.fdmath--discrete-calculus","title":"Discrete calculus","text":"<p>This documentation and approach is roughly based on W.C. Chew's excellent \"Electromagnetic Theory on a Lattice\" (doi:10.1063/1.355770), which covers a superset of this material with similar notation and more detail.</p>"},{"location":"api/fdmath/#meanas.fdmath--scalar-derivatives-and-cell-shifts","title":"Scalar derivatives and cell shifts","text":"<p>Define the discrete forward derivative as \\[ [\\tilde{\\partial}_x f]_{m + \\frac{1}{2}} = \\frac{1}{\\Delta_{x, m}} (f_{m + 1} - f_m) \\]</p> <p>where \\(f\\) is a function defined at discrete locations on the x-axis (labeled using \\(m\\)). The value at \\(m\\) occupies a length \\(\\Delta_{x, m}\\) along the x-axis. Note that \\(m\\) is an index along the x-axis, not necessarily an x-coordinate, since each length \\(\\Delta_{x, m}, \\Delta_{x, m+1}, ...\\) is independently chosen.</p> <p>If we treat <code>f</code> as a 1D array of values, with the <code>i</code>-th value <code>f[i]</code> taking up a length <code>dx[i]</code> along the x-axis, the forward derivative is</p> <pre><code>deriv_forward(f)[i] = (f[i + 1] - f[i]) / dx[i]\n</code></pre> <p>Likewise, discrete reverse derivative is \\[ [\\hat{\\partial}_x f ]_{m - \\frac{1}{2}} = \\frac{1}{\\Delta_{x, m}} (f_{m} - f_{m - 1}) \\]</p> <p>or</p> <pre><code>deriv_back(f)[i] = (f[i] - f[i - 1]) / dx[i]\n</code></pre> <p>The derivatives' values are shifted by a half-cell relative to the original function, and will have different cell widths if all the <code>dx[i]</code> ( \\(\\Delta_{x, m}\\) ) are not identical:</p> <pre><code>[figure: derivatives and cell sizes]\n dx0 dx1 dx2 dx3 cell sizes for function\n ----- ----- ----------- -----\n ______________________________\n | | | |\n f0 | f1 | f2 | f3 | function\n _____|_____|___________|_____|\n | | | |\n | Df0 | Df1 | Df2 | Df3 forward derivative (periodic boundary)\n __|_____|________|________|___\n\n dx'3] dx'0 dx'1 dx'2 [dx'3 cell sizes for forward derivative\n -- ----- -------- -------- ---\n dx'0] dx'1 dx'2 dx'3 [dx'0 cell sizes for reverse derivative\n ______________________________\n | | | |\n | df1 | df2 | df3 | df0 reverse derivative (periodic boundary)\n __|_____|________|________|___\n\nPeriodic boundaries are used here and elsewhere unless otherwise noted.\n</code></pre> <p>In the above figure, <code>f0 =</code> \\(f_0\\), <code>f1 =</code> \\(f_1\\) <code>Df0 =</code> \\([\\tilde{\\partial}f]_{0 + \\frac{1}{2}}\\) <code>Df1 =</code> \\([\\tilde{\\partial}f]_{1 + \\frac{1}{2}}\\) <code>df0 =</code> \\([\\hat{\\partial}f]_{0 - \\frac{1}{2}}\\) etc.</p> <p>The fractional subscript \\(m + \\frac{1}{2}\\) is used to indicate values defined at shifted locations relative to the original \\(m\\), with corresponding lengths \\[ \\Delta_{x, m + \\frac{1}{2}} = \\frac{1}{2} * (\\Delta_{x, m} + \\Delta_{x, m + 1}) \\] </p> <p>Just as \\(m\\) is not itself an x-coordinate, neither is \\(m + \\frac{1}{2}\\); carefully note the positions of the various cells in the above figure vs their labels. If the positions labeled with \\(m\\) are considered the \"base\" or \"original\" grid, the positions labeled with \\(m + \\frac{1}{2}\\) are said to lie on a \"dual\" or \"derived\" grid.</p> <p>For the remainder of the <code>Discrete calculus</code> section, all figures will show constant-length cells in order to focus on the vector derivatives themselves. See the <code>Grid description</code> section below for additional information on this topic and generalization to three dimensions.</p>"},{"location":"api/fdmath/#meanas.fdmath--gradients-and-fore-vectors","title":"Gradients and fore-vectors","text":"<p>Expanding to three dimensions, we can define two gradients \\[ [\\tilde{\\nabla} f]_{m,n,p} = \\vec{x} [\\tilde{\\partial}_x f]_{m + \\frac{1}{2},n,p} + \\vec{y} [\\tilde{\\partial}_y f]_{m,n + \\frac{1}{2},p} + \\vec{z} [\\tilde{\\partial}_z f]_{m,n,p + \\frac{1}{2}} \\]</p> \\[ [\\hat{\\nabla} f]_{m,n,p} = \\vec{x} [\\hat{\\partial}_x f]_{m + \\frac{1}{2},n,p} + \\vec{y} [\\hat{\\partial}_y f]_{m,n + \\frac{1}{2},p} + \\vec{z} [\\hat{\\partial}_z f]_{m,n,p + \\frac{1}{2}} \\] <p>or</p> <pre><code>[code: gradients]\ngrad_forward(f)[i,j,k] = [Dx_forward(f)[i, j, k],\n Dy_forward(f)[i, j, k],\n Dz_forward(f)[i, j, k]]\n = [(f[i + 1, j, k] - f[i, j, k]) / dx[i],\n (f[i, j + 1, k] - f[i, j, k]) / dy[i],\n (f[i, j, k + 1] - f[i, j, k]) / dz[i]]\n\ngrad_back(f)[i,j,k] = [Dx_back(f)[i, j, k],\n Dy_back(f)[i, j, k],\n Dz_back(f)[i, j, k]]\n = [(f[i, j, k] - f[i - 1, j, k]) / dx[i],\n (f[i, j, k] - f[i, j - 1, k]) / dy[i],\n (f[i, j, k] - f[i, j, k - 1]) / dz[i]]\n</code></pre> <p>The three derivatives in the gradient cause shifts in different directions, so the x/y/z components of the resulting \"vector\" are defined at different points: the x-component is shifted in the x-direction, y in y, and z in z.</p> <p>We call the resulting object a \"fore-vector\" or \"back-vector\", depending on the direction of the shift. We write it as \\[ \\tilde{g}_{m,n,p} = \\vec{x} g^x_{m + \\frac{1}{2},n,p} + \\vec{y} g^y_{m,n + \\frac{1}{2},p} + \\vec{z} g^z_{m,n,p + \\frac{1}{2}} \\]</p> \\[ \\hat{g}_{m,n,p} = \\vec{x} g^x_{m - \\frac{1}{2},n,p} + \\vec{y} g^y_{m,n - \\frac{1}{2},p} + \\vec{z} g^z_{m,n,p - \\frac{1}{2}} \\] <pre><code>[figure: gradient / fore-vector]\n (m, n+1, p+1) ______________ (m+1, n+1, p+1)\n /: /|\n / : / |\n / : / |\n (m, n, p+1)/_____________/ | The forward derivatives are defined\n | : | | at the Dx, Dy, Dz points,\n | :.........|...| but the forward-gradient fore-vector\n z y Dz / | / is the set of all three\n |/_x | Dy | / and is said to be \"located\" at (m,n,p)\n |/ |/\n (m, n, p)|_____Dx______| (m+1, n, p)\n</code></pre>"},{"location":"api/fdmath/#meanas.fdmath--divergences","title":"Divergences","text":"<p>There are also two divergences,</p> \\[ d_{n,m,p} = [\\tilde{\\nabla} \\cdot \\hat{g}]_{n,m,p} = [\\tilde{\\partial}_x g^x]_{m,n,p} + [\\tilde{\\partial}_y g^y]_{m,n,p} + [\\tilde{\\partial}_z g^z]_{m,n,p} \\] \\[ d_{n,m,p} = [\\hat{\\nabla} \\cdot \\tilde{g}]_{n,m,p} = [\\hat{\\partial}_x g^x]_{m,n,p} + [\\hat{\\partial}_y g^y]_{m,n,p} + [\\hat{\\partial}_z g^z]_{m,n,p} \\] <p>or</p> <pre><code>[code: divergences]\ndiv_forward(g)[i,j,k] = Dx_forward(gx)[i, j, k] +\n Dy_forward(gy)[i, j, k] +\n Dz_forward(gz)[i, j, k]\n = (gx[i + 1, j, k] - gx[i, j, k]) / dx[i] +\n (gy[i, j + 1, k] - gy[i, j, k]) / dy[i] +\n (gz[i, j, k + 1] - gz[i, j, k]) / dz[i]\n\ndiv_back(g)[i,j,k] = Dx_back(gx)[i, j, k] +\n Dy_back(gy)[i, j, k] +\n Dz_back(gz)[i, j, k]\n = (gx[i, j, k] - gx[i - 1, j, k]) / dx[i] +\n (gy[i, j, k] - gy[i, j - 1, k]) / dy[i] +\n (gz[i, j, k] - gz[i, j, k - 1]) / dz[i]\n</code></pre> <p>where <code>g = [gx, gy, gz]</code> is a fore- or back-vector field.</p> <p>Since we applied the forward divergence to the back-vector (and vice-versa), the resulting scalar value is defined at the back-vector's (fore-vector's) location \\((m,n,p)\\) and not at the locations of its components \\((m \\pm \\frac{1}{2},n,p)\\) etc.</p> <pre><code>[figure: divergence]\n ^^\n (m-1/2, n+1/2, p+1/2) _____||_______ (m+1/2, n+1/2, p+1/2)\n /: || ,, /|\n / : || // / | The divergence at (m, n, p) (the center\n / : // / | of this cube) of a fore-vector field\n (m-1/2, n-1/2, p+1/2)/_____________/ | is the sum of the outward-pointing\n | : | | fore-vector components, which are\n z y &lt;==|== :.........|.====&gt; located at the face centers.\n |/_x | / | /\n | / // | / Note that in a nonuniform grid, each\n |/ // || |/ dimension is normalized by the cell width.\n (m-1/2, n-1/2, p-1/2)|____//_______| (m+1/2, n-1/2, p-1/2)\n '' ||\n VV\n</code></pre>"},{"location":"api/fdmath/#meanas.fdmath--curls","title":"Curls","text":"<p>The two curls are then</p> \\[ \\begin{aligned} \\hat{h}_{m + \\frac{1}{2}, n + \\frac{1}{2}, p + \\frac{1}{2}} &amp;= \\\\ [\\tilde{\\nabla} \\times \\tilde{g}]_{m + \\frac{1}{2}, n + \\frac{1}{2}, p + \\frac{1}{2}} &amp;= \\vec{x} (\\tilde{\\partial}_y g^z_{m,n,p + \\frac{1}{2}} - \\tilde{\\partial}_z g^y_{m,n + \\frac{1}{2},p}) \\\\ &amp;+ \\vec{y} (\\tilde{\\partial}_z g^x_{m + \\frac{1}{2},n,p} - \\tilde{\\partial}_x g^z_{m,n,p + \\frac{1}{2}}) \\\\ &amp;+ \\vec{z} (\\tilde{\\partial}_x g^y_{m,n + \\frac{1}{2},p} - \\tilde{\\partial}_y g^z_{m + \\frac{1}{2},n,p}) \\end{aligned} \\] <p>and</p> \\[ \\tilde{h}_{m - \\frac{1}{2}, n - \\frac{1}{2}, p - \\frac{1}{2}} = [\\hat{\\nabla} \\times \\hat{g}]_{m - \\frac{1}{2}, n - \\frac{1}{2}, p - \\frac{1}{2}} \\] <p>where \\(\\hat{g}\\) and \\(\\tilde{g}\\) are located at \\((m,n,p)\\) with components at \\((m \\pm \\frac{1}{2},n,p)\\) etc., while \\(\\hat{h}\\) and \\(\\tilde{h}\\) are located at \\((m \\pm \\frac{1}{2}, n \\pm \\frac{1}{2}, p \\pm \\frac{1}{2})\\) with components at \\((m, n \\pm \\frac{1}{2}, p \\pm \\frac{1}{2})\\) etc.</p> <pre><code>[code: curls]\ncurl_forward(g)[i,j,k] = [Dy_forward(gz)[i, j, k] - Dz_forward(gy)[i, j, k],\n Dz_forward(gx)[i, j, k] - Dx_forward(gz)[i, j, k],\n Dx_forward(gy)[i, j, k] - Dy_forward(gx)[i, j, k]]\n\ncurl_back(g)[i,j,k] = [Dy_back(gz)[i, j, k] - Dz_back(gy)[i, j, k],\n Dz_back(gx)[i, j, k] - Dx_back(gz)[i, j, k],\n Dx_back(gy)[i, j, k] - Dy_back(gx)[i, j, k]]\n</code></pre> <p>For example, consider the forward curl, at (m, n, p), of a back-vector field <code>g</code>, defined on a grid containing (m + 1/2, n + 1/2, p + 1/2). The curl will be a fore-vector, so its z-component will be defined at (m, n, p + 1/2). Take the nearest x- and y-components of <code>g</code> in the xy plane where the curl's z-component is located; these are</p> <pre><code>[curl components]\n(m, n + 1/2, p + 1/2) : x-component of back-vector at (m + 1/2, n + 1/2, p + 1/2)\n(m + 1, n + 1/2, p + 1/2) : x-component of back-vector at (m + 3/2, n + 1/2, p + 1/2)\n(m + 1/2, n , p + 1/2) : y-component of back-vector at (m + 1/2, n + 1/2, p + 1/2)\n(m + 1/2, n + 1 , p + 1/2) : y-component of back-vector at (m + 1/2, n + 3/2, p + 1/2)\n</code></pre> <p>These four xy-components can be used to form a loop around the curl's z-component; its magnitude and sign is set by their loop-oriented sum (i.e. two have their signs flipped to complete the loop).</p> <pre><code>[figure: z-component of curl]\n : |\n z y : ^^ |\n |/_x :....||.&lt;.....| (m+1, n+1, p+1/2)\n / || /\n | v || | ^\n |/ |/\n (m, n, p+1/2) |_____&gt;______| (m+1, n, p+1/2)\n</code></pre>"},{"location":"api/fdmath/#meanas.fdmath--maxwells-equations","title":"Maxwell's Equations","text":"<p>If we discretize both space (m,n,p) and time (l), Maxwell's equations become</p> \\[ \\begin{aligned} \\tilde{\\nabla} \\times \\tilde{E}_{l,\\vec{r}} &amp;= -\\tilde{\\partial}_t \\hat{B}_{l-\\frac{1}{2}, \\vec{r} + \\frac{1}{2}} - \\hat{M}_{l, \\vec{r} + \\frac{1}{2}} \\\\ \\hat{\\nabla} \\times \\hat{H}_{l-\\frac{1}{2},\\vec{r} + \\frac{1}{2}} &amp;= \\hat{\\partial}_t \\tilde{D}_{l, \\vec{r}} + \\tilde{J}_{l-\\frac{1}{2},\\vec{r}} \\\\ \\tilde{\\nabla} \\cdot \\hat{B}_{l-\\frac{1}{2}, \\vec{r} + \\frac{1}{2}} &amp;= 0 \\\\ \\hat{\\nabla} \\cdot \\tilde{D}_{l,\\vec{r}} &amp;= \\rho_{l,\\vec{r}} \\end{aligned} \\] <p>with</p> \\[ \\begin{aligned} \\hat{B}_{\\vec{r}} &amp;= \\mu_{\\vec{r} + \\frac{1}{2}} \\cdot \\hat{H}_{\\vec{r} + \\frac{1}{2}} \\\\ \\tilde{D}_{\\vec{r}} &amp;= \\epsilon_{\\vec{r}} \\cdot \\tilde{E}_{\\vec{r}} \\end{aligned} \\] <p>where the spatial subscripts are abbreviated as \\(\\vec{r} = (m, n, p)\\) and \\(\\vec{r} + \\frac{1}{2} = (m + \\frac{1}{2}, n + \\frac{1}{2}, p + \\frac{1}{2})\\), \\(\\tilde{E}\\) and \\(\\hat{H}\\) are the electric and magnetic fields, \\(\\tilde{J}\\) and \\(\\hat{M}\\) are the electric and magnetic current distributions, and \\(\\epsilon\\) and \\(\\mu\\) are the dielectric permittivity and magnetic permeability.</p> <p>The above is Yee's algorithm, written in a form analogous to Maxwell's equations. The time derivatives can be expanded to form the update equations:</p> <pre><code>[code: Maxwell's equations updates]\nH[i, j, k] -= dt * (curl_forward(E)[i, j, k] + M[t, i, j, k]) / mu[i, j, k]\nE[i, j, k] += dt * (curl_back( H)[i, j, k] + J[t, i, j, k]) / epsilon[i, j, k]\n</code></pre> <p>Note that the E-field fore-vector and H-field back-vector are offset by a half-cell, resulting in distinct locations for all six E- and H-field components:</p> <pre><code>[figure: Field components]\n\n (m - 1/2,=&gt; ____________Hx__________[H] &lt;= r + 1/2 = (m + 1/2,\n n + 1/2, /: /: /| n + 1/2,\n z y p + 1/2) / : / : / | p + 1/2)\n |/_x / : / : / |\n / : Ez__________Hy | Locations of the E- and\n / : : : /| | H-field components for the\n (m - 1/2, / : : Ey...../.|..Hz [E] fore-vector at r = (m,n,p)\n n - 1/2, =&gt;/________________________/ | /| (the large cube's center)\n p + 1/2) | : : / | | / | and [H] back-vector at r + 1/2\n | : :/ | |/ | (the top right corner)\n | : [E].......|.Ex |\n | :.................|......| &lt;= (m + 1/2, n + 1/2, p + 1/2)\n | / | /\n | / | /\n | / | / This is the Yee discretization\n | / | / scheme (\"Yee cell\").\nr - 1/2 = | / | /\n (m - 1/2, |/ |/\n n - 1/2,=&gt; |________________________| &lt;= (m + 1/2, n - 1/2, p - 1/2)\n p - 1/2)\n</code></pre> <p>Each component forms its own grid, offset from the others:</p> <pre><code>[figure: E-fields for adjacent cells]\n\n H1__________Hx0_________H0\n z y /: /|\n |/_x / : / | This figure shows H back-vector locations\n / : / | H0, H1, etc. and their associated components\n Hy1 : Hy0 | H0 = (Hx0, Hy0, Hz0) etc.\n / : / |\n / Hz1 / Hz0\n H2___________Hx3_________H3 | The equivalent drawing for E would have\n | : | | fore-vectors located at the cube's\n | : | | center (and the centers of adjacent cubes),\n | : | | with components on the cube's faces.\n | H5..........Hx4...|......H4\n | / | /\n Hz2 / Hz2 /\n | / | /\n | Hy6 | Hy4\n | / | /\n |/ |/\n H6__________Hx7__________H7\n</code></pre> <p>The divergence equations can be derived by taking the divergence of the curl equations and combining them with charge continuity, \\[ \\hat{\\nabla} \\cdot \\tilde{J} + \\hat{\\partial}_t \\rho = 0 \\]</p> <p>implying that the discrete Maxwell's equations do not produce spurious charges.</p>"},{"location":"api/fdmath/#meanas.fdmath--wave-equation","title":"Wave equation","text":"<p>Taking the backward curl of the \\(\\tilde{\\nabla} \\times \\tilde{E}\\) equation and replacing the resulting \\(\\hat{\\nabla} \\times \\hat{H}\\) term using its respective equation, and setting \\(\\hat{M}\\) to zero, we can form the discrete wave equation:</p> \\[ \\begin{aligned} \\tilde{\\nabla} \\times \\tilde{E}_{l,\\vec{r}} &amp;= -\\tilde{\\partial}_t \\hat{B}_{l-\\frac{1}{2}, \\vec{r} + \\frac{1}{2}} - \\hat{M}_{l-1, \\vec{r} + \\frac{1}{2}} \\\\ \\mu^{-1}_{\\vec{r} + \\frac{1}{2}} \\cdot \\tilde{\\nabla} \\times \\tilde{E}_{l,\\vec{r}} &amp;= -\\tilde{\\partial}_t \\hat{H}_{l-\\frac{1}{2}, \\vec{r} + \\frac{1}{2}} \\\\ \\hat{\\nabla} \\times (\\mu^{-1}_{\\vec{r} + \\frac{1}{2}} \\cdot \\tilde{\\nabla} \\times \\tilde{E}_{l,\\vec{r}}) &amp;= \\hat{\\nabla} \\times (-\\tilde{\\partial}_t \\hat{H}_{l-\\frac{1}{2}, \\vec{r} + \\frac{1}{2}}) \\\\ \\hat{\\nabla} \\times (\\mu^{-1}_{\\vec{r} + \\frac{1}{2}} \\cdot \\tilde{\\nabla} \\times \\tilde{E}_{l,\\vec{r}}) &amp;= -\\tilde{\\partial}_t \\hat{\\nabla} \\times \\hat{H}_{l-\\frac{1}{2}, \\vec{r} + \\frac{1}{2}} \\\\ \\hat{\\nabla} \\times (\\mu^{-1}_{\\vec{r} + \\frac{1}{2}} \\cdot \\tilde{\\nabla} \\times \\tilde{E}_{l,\\vec{r}}) &amp;= -\\tilde{\\partial}_t \\hat{\\partial}_t \\epsilon_{\\vec{r}} \\tilde{E}_{l, \\vec{r}} + \\hat{\\partial}_t \\tilde{J}_{l-\\frac{1}{2},\\vec{r}} \\\\ \\hat{\\nabla} \\times (\\mu^{-1}_{\\vec{r} + \\frac{1}{2}} \\cdot \\tilde{\\nabla} \\times \\tilde{E}_{l,\\vec{r}}) + \\tilde{\\partial}_t \\hat{\\partial}_t \\epsilon_{\\vec{r}} \\cdot \\tilde{E}_{l, \\vec{r}} &amp;= \\tilde{\\partial}_t \\tilde{J}_{l - \\frac{1}{2}, \\vec{r}} \\end{aligned} \\]"},{"location":"api/fdmath/#meanas.fdmath--frequency-domain","title":"Frequency domain","text":"<p>We can substitute in a time-harmonic fields</p> \\[ \\begin{aligned} \\tilde{E}_{l, \\vec{r}} &amp;= \\tilde{E}_{\\vec{r}} e^{-\\imath \\omega l \\Delta_t} \\\\ \\tilde{J}_{l, \\vec{r}} &amp;= \\tilde{J}_{\\vec{r}} e^{-\\imath \\omega (l - \\frac{1}{2}) \\Delta_t} \\end{aligned} \\] <p>resulting in</p> \\[ \\begin{aligned} \\tilde{\\partial}_t &amp;\\Rightarrow (e^{ \\imath \\omega \\Delta_t} - 1) / \\Delta_t = \\frac{-2 \\imath}{\\Delta_t} \\sin(\\omega \\Delta_t / 2) e^{-\\imath \\omega \\Delta_t / 2} = -\\imath \\Omega e^{-\\imath \\omega \\Delta_t / 2}\\\\ \\hat{\\partial}_t &amp;\\Rightarrow (1 - e^{-\\imath \\omega \\Delta_t}) / \\Delta_t = \\frac{-2 \\imath}{\\Delta_t} \\sin(\\omega \\Delta_t / 2) e^{ \\imath \\omega \\Delta_t / 2} = -\\imath \\Omega e^{ \\imath \\omega \\Delta_t / 2}\\\\ \\Omega &amp;= 2 \\sin(\\omega \\Delta_t / 2) / \\Delta_t \\end{aligned} \\] <p>This gives the frequency-domain wave equation,</p> \\[ \\hat{\\nabla} \\times (\\mu^{-1}_{\\vec{r} + \\frac{1}{2}} \\cdot \\tilde{\\nabla} \\times \\tilde{E}_{\\vec{r}}) -\\Omega^2 \\epsilon_{\\vec{r}} \\cdot \\tilde{E}_{\\vec{r}} = -\\imath \\Omega \\tilde{J}_{\\vec{r}} e^{\\imath \\omega \\Delta_t / 2} \\\\ \\]"},{"location":"api/fdmath/#meanas.fdmath--plane-waves-and-dispersion-relation","title":"Plane waves and Dispersion relation","text":"<p>With uniform material distribution and no sources</p> \\[ \\begin{aligned} \\mu_{\\vec{r} + \\frac{1}{2}} &amp;= \\mu \\\\ \\epsilon_{\\vec{r}} &amp;= \\epsilon \\\\ \\tilde{J}_{\\vec{r}} &amp;= 0 \\\\ \\end{aligned} \\] <p>the frequency domain wave equation simplifies to</p> \\[ \\hat{\\nabla} \\times \\tilde{\\nabla} \\times \\tilde{E}_{\\vec{r}} - \\Omega^2 \\epsilon \\mu \\tilde{E}_{\\vec{r}} = 0 \\] <p>Since \\(\\hat{\\nabla} \\cdot \\tilde{E}_{\\vec{r}} = 0\\), we can simplify</p> \\[ \\begin{aligned} \\hat{\\nabla} \\times \\tilde{\\nabla} \\times \\tilde{E}_{\\vec{r}} &amp;= \\tilde{\\nabla}(\\hat{\\nabla} \\cdot \\tilde{E}_{\\vec{r}}) - \\hat{\\nabla} \\cdot \\tilde{\\nabla} \\tilde{E}_{\\vec{r}} \\\\ &amp;= - \\hat{\\nabla} \\cdot \\tilde{\\nabla} \\tilde{E}_{\\vec{r}} \\\\ &amp;= - \\tilde{\\nabla}^2 \\tilde{E}_{\\vec{r}} \\end{aligned} \\] <p>and we get</p> \\[ \\tilde{\\nabla}^2 \\tilde{E}_{\\vec{r}} + \\Omega^2 \\epsilon \\mu \\tilde{E}_{\\vec{r}} = 0 \\] <p>We can convert this to three scalar-wave equations of the form</p> \\[ (\\tilde{\\nabla}^2 + K^2) \\phi_{\\vec{r}} = 0 \\] <p>with \\(K^2 = \\Omega^2 \\mu \\epsilon\\). Now we let</p> \\[ \\phi_{\\vec{r}} = A e^{\\imath (k_x m \\Delta_x + k_y n \\Delta_y + k_z p \\Delta_z)} \\] <p>resulting in</p> \\[ \\begin{aligned} \\tilde{\\partial}_x &amp;\\Rightarrow (e^{ \\imath k_x \\Delta_x} - 1) / \\Delta_t = \\frac{-2 \\imath}{\\Delta_x} \\sin(k_x \\Delta_x / 2) e^{ \\imath k_x \\Delta_x / 2} = \\imath K_x e^{ \\imath k_x \\Delta_x / 2}\\\\ \\hat{\\partial}_x &amp;\\Rightarrow (1 - e^{-\\imath k_x \\Delta_x}) / \\Delta_t = \\frac{-2 \\imath}{\\Delta_x} \\sin(k_x \\Delta_x / 2) e^{-\\imath k_x \\Delta_x / 2} = \\imath K_x e^{-\\imath k_x \\Delta_x / 2}\\\\ K_x &amp;= 2 \\sin(k_x \\Delta_x / 2) / \\Delta_x \\\\ \\end{aligned} \\] <p>with similar expressions for the y and z dimnsions (and \\(K_y, K_z\\)).</p> <p>This implies</p> \\[ \\tilde{\\nabla}^2 = -(K_x^2 + K_y^2 + K_z^2) \\phi_{\\vec{r}} \\\\ K_x^2 + K_y^2 + K_z^2 = \\Omega^2 \\mu \\epsilon = \\Omega^2 / c^2 \\] <p>where \\(c = \\sqrt{\\mu \\epsilon}\\).</p> <p>Assuming real \\((k_x, k_y, k_z), \\omega\\) will be real only if</p> \\[ c^2 \\Delta_t^2 = \\frac{\\Delta_t^2}{\\mu \\epsilon} &lt; 1/(\\frac{1}{\\Delta_x^2} + \\frac{1}{\\Delta_y^2} + \\frac{1}{\\Delta_z^2}) \\] <p>If \\(\\Delta_x = \\Delta_y = \\Delta_z\\), this simplifies to \\(c \\Delta_t &lt; \\Delta_x / \\sqrt{3}\\). This last form can be interpreted as enforcing causality; the distance that light travels in one timestep (i.e., \\(c \\Delta_t\\)) must be less than the diagonal of the smallest cell ( \\(\\Delta_x / \\sqrt{3}\\) when on a uniform cubic grid).</p>"},{"location":"api/fdmath/#meanas.fdmath--grid-description","title":"Grid description","text":"<p>As described in the section on scalar discrete derivatives above, cell widths (<code>dx[i]</code>, <code>dy[j]</code>, <code>dz[k]</code>) along each axis can be arbitrary and independently defined. Moreover, all field components are actually defined at \"derived\" or \"dual\" positions, in-between the \"base\" grid points on one or more axes.</p> <p>To get a better sense of how this works, let's start by drawing a grid with uniform <code>dy</code> and <code>dz</code> and nonuniform <code>dx</code>. We will only draw one cell in the y and z dimensions to make the illustration simpler; we need at least two cells in the x dimension to demonstrate how nonuniform <code>dx</code> affects the various components.</p> <p>Place the E fore-vectors at integer indices \\(r = (m, n, p)\\) and the H back-vectors at fractional indices \\(r + \\frac{1}{2} = (m + \\frac{1}{2}, n + \\frac{1}{2}, p + \\frac{1}{2})\\). Remember that these are indices and not coordinates; they can correspond to arbitrary (monotonically increasing) coordinates depending on the cell widths.</p> <p>Draw lines to denote the planes on which the H components and back-vectors are defined. For simplicity, don't draw the equivalent planes for the E components and fore-vectors, except as necessary to show their locations -- it's easiest to just connect them to their associated H-equivalents.</p> <p>The result looks something like this:</p> <pre><code>[figure: Component centers]\n p=\n [H]__________Hx___________[H]_____Hx______[H] __ +1/2\n z y /: /: /: /: /| | |\n |/_x / : / : / : / : / | | |\n / : / : / : / : / | | |\n Hy : Ez...........Hy : Ez......Hy | | |\n /: : : : /: : : : /| | | |\n / : Hz : Ey....../.:..Hz : Ey./.|..Hz __ 0 | dz[0]\n / : /: : / / : /: : / / | /| | |\n /_________________________/_______________/ | / | | |\n | :/ : :/ | :/ : :/ | |/ | | |\n | Ex : [E].......|..Ex : [E]..|..Ex | | |\n | : | : | | | |\n | [H]..........Hx....|......[H].....H|x.....[H] __ --------- (n=+1/2, p=-1/2)\n | / | / | / / /\n Hz / Hz / Hz / / /\n | / | / | / / /\n | Hy | Hy | Hy __ 0 / dy[0]\n | / | / | / / /\n | / | / | / / /\n |/ |/ |/ / /\n [H]__________Hx___________[H]_____Hx______[H] __ -1/2 /\n =n\n |------------|------------|-------|-------|\n -1/2 0 +1/2 +1 +3/2 = m\n\n ------------------------- ----------------\n dx[0] dx[1]\n\n Part of a nonuniform \"base grid\", with labels specifying\n positions of the various field components. [E] fore-vectors\n are at the cell centers, and [H] back-vectors are at the\n vertices. H components along the near (-y) top (+z) edge\n have been omitted to make the insides of the cubes easier\n to visualize.\n</code></pre> <p>The above figure shows where all the components are located; however, it is also useful to show what volumes those components correspond to. Consider the Ex component at <code>m = +1/2</code>: it is shifted in the x-direction by a half-cell from the E fore-vector at <code>m = 0</code> (labeled <code>[E]</code> in the figure). It corresponds to a volume between <code>m = 0</code> and <code>m = +1</code> (the other dimensions are not shifted, i.e. they are still bounded by <code>n, p = +-1/2</code>). (See figure below). Since <code>m</code> is an index and not an x-coordinate, the Ex component is not necessarily at the center of the volume it represents, and the x-length of its volume is the derived quantity <code>dx'[0] = (dx[0] + dx[1]) / 2</code> rather than the base <code>dx</code>. (See also <code>Scalar derivatives and cell shifts</code>).</p> <pre><code>[figure: Ex volumes]\n p=\n &lt;_________________________________________&gt; __ +1/2\n z y &lt;&lt; /: / /: &gt;&gt; | |\n |/_x &lt; &lt; / : / / : &gt; &gt; | |\n &lt; &lt; / : / / : &gt; &gt; | |\n &lt; &lt; / : / / : &gt; &gt; | |\n &lt;: &lt; / : : / : &gt;: &gt; | |\n &lt; : &lt; / : : / : &gt; : &gt; __ 0 | dz[0]\n &lt; : &lt; / : : / :&gt; : &gt; | |\n &lt;____________/____________________/_______&gt; : &gt; | |\n &lt; : &lt; | : : | &gt; : &gt; | |\n &lt; Ex &lt; | : Ex | &gt; Ex &gt; | |\n &lt; : &lt; | : : | &gt; : &gt; | |\n &lt; : &lt;....|.......:........:...|.......&gt;...:...&gt; __ --------- (n=+1/2, p=-1/2)\n &lt; : &lt; | / : /| /&gt; : &gt; / /\n &lt; : &lt; | / : / | / &gt; : &gt; / /\n &lt; :&lt; | / :/ | / &gt; :&gt; / /\n &lt; &lt; | / : | / &gt; &gt; _ 0 / dy[0]\n &lt; &lt; | / | / &gt; &gt; / /\n &lt; &lt; | / | / &gt; &gt; / /\n &lt;&lt; |/ |/ &gt;&gt; / /\n &lt;____________|____________________|_______&gt; __ -1/2 /\n =n\n |------------|------------|-------|-------|\n -1/2 0 +1/2 +1 +3/2 = m\n\n ~------------ -------------------- -------~\n dx'[-1] dx'[0] dx'[1]\n\n The Ex values are positioned on the x-faces of the base\n grid. They represent the Ex field in volumes shifted by\n a half-cell in the x-dimension, as shown here. Only the\n center cell (with width dx'[0]) is fully shown; the\n other two are truncated (shown using &gt;&lt; markers).\n\n Note that the Ex positions are the in the same positions\n as the previous figure; only the cell boundaries have moved.\n Also note that the points at which Ex is defined are not\n necessarily centered in the volumes they represent; non-\n uniform cell sizes result in off-center volumes like the\n center cell here.\n</code></pre> <p>The next figure shows the volumes corresponding to the Hy components, which are shifted in two dimensions (x and z) compared to the base grid.</p> <pre><code>[figure: Hy volumes]\n p=\n z y mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm __ +1/2 s\n |/_x &lt;&lt; m: m: &gt;&gt; | |\n &lt; &lt; m : m : &gt; &gt; | | dz'[1]\n &lt; &lt; m : m : &gt; &gt; | |\n Hy........... m........Hy...........m......Hy &gt; | |\n &lt; &lt; m : m : &gt; &gt; | |\n &lt; ______ m_____:_______________m_____:_&gt;______ __ 0\n &lt; &lt; m /: m / &gt; &gt; | |\n mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm &gt; | |\n &lt; &lt; | / : | / &gt; &gt; | | dz'[0]\n &lt; &lt; | / : | / &gt; &gt; | |\n &lt; &lt; | / : | / &gt; &gt; | |\n &lt; wwwww|w/wwwwwwwwwwwwwwwwwww|w/wwwww&gt;wwwwwwww __ s\n &lt; &lt; |/ w |/ w&gt; &gt; / /\n _____________|_____________________|________ &gt; / /\n &lt; &lt; | w | w &gt; &gt; / /\n &lt; Hy........|...w........Hy.......|...w...&gt;..Hy _ 0 / dy[0]\n &lt; &lt; | w | w &gt; &gt; / /\n &lt;&lt; | w | w &gt; &gt; / /\n &lt; |w |w &gt;&gt; / /\n wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww __ -1/2 /\n\n |------------|------------|--------|-------|\n-1/2 0 +1/2 +1 +3/2 = m\n\n ~------------ --------------------- -------~\n dx'[-1] dx'[0] dx'[1]\n\n The Hy values are positioned on the y-edges of the base\n grid. Again here, the 'Hy' labels represent the same points\n as in the basic grid figure above; the edges have shifted\n by a half-cell along the x- and z-axes.\n\n The grid lines _|:/ are edges of the area represented by\n each Hy value, and the lines drawn using &lt;m&gt;.w represent\n edges where a cell's faces extend beyond the drawn area\n (i.e. where the drawing is truncated in the x- or z-\n directions).\n</code></pre>"},{"location":"api/fdmath/#meanas.fdmath--datastructure-dx_lists_t","title":"Datastructure: dx_lists_t","text":"<p>In this documentation, the E fore-vectors are placed on the base grid. An equivalent formulation could place the H back-vectors on the base grid instead. However, in the case of a non-uniform grid, the operation to get from the \"base\" cell widths to \"derived\" ones is not its own inverse.</p> <p>The base grid's cell sizes could be fully described by a list of three 1D arrays, specifying the cell widths along all three axes:</p> <pre><code>[dx, dy, dz] = [[dx[0], dx[1], ...], [dy[0], ...], [dz[0], ...]]\n</code></pre> <p>Note that this is a list-of-arrays rather than a 2D array, as the simulation domain may have a different number of cells along each axis.</p> <p>Knowing the base grid's cell widths and the boundary conditions (periodic unless otherwise noted) is enough information to calculate the cell widths <code>dx'</code>, <code>dy'</code>, and <code>dz'</code> for the derived grids.</p> <p>However, since most operations are trivially generalized to allow either E or H to be defined on the base grid, they are written to take the a full set of base and derived cell widths, distinguished by which field they apply to rather than their \"base\" or \"derived\" status. This removes the need for each function to generate the derived widths, and makes the \"base\" vs \"derived\" distinction unnecessary in the code.</p> <p>The resulting data structure containing all the cell widths takes the form of a list-of-lists-of-arrays. The first list-of-arrays provides the cell widths for the E-field fore-vectors, while the second list-of-arrays does the same for the H-field back-vectors:</p> <pre><code> [[[dx_e[0], dx_e[1], ...], [dy_e[0], ...], [dz_e[0], ...]],\n [[dx_h[0], dx_h[1], ...], [dy_h[0], ...], [dz_h[0], ...]]]\n</code></pre> <p>where <code>dx_e[0]</code> is the x-width of the <code>m=0</code> cells, as used when calculating dE/dx, and <code>dy_h[0]</code> is the y-width of the <code>n=0</code> cells, as used when calculating dH/dy, etc.</p>"},{"location":"api/fdmath/#meanas.fdmath--permittivity-and-permeability","title":"Permittivity and Permeability","text":"<p>Since each vector component of E and H is defined in a different location and represents a different volume, the value of the spatially-discrete <code>epsilon</code> and <code>mu</code> can also be different for all three field components, even when representing a simple planar interface between two isotropic materials.</p> <p>As a result, <code>epsilon</code> and <code>mu</code> are taken to have the same dimensions as the field, and composed of the three diagonal tensor components:</p> <pre><code>[equations: epsilon_and_mu]\nepsilon = [epsilon_xx, epsilon_yy, epsilon_zz]\nmu = [mu_xx, mu_yy, mu_zz]\n</code></pre> <p>or</p> \\[ \\epsilon = \\begin{bmatrix} \\epsilon_{xx} &amp; 0 &amp; 0 \\\\ 0 &amp; \\epsilon_{yy} &amp; 0 \\\\ 0 &amp; 0 &amp; \\epsilon_{zz} \\end{bmatrix} \\] \\[ \\mu = \\begin{bmatrix} \\mu_{xx} &amp; 0 &amp; 0 \\\\ 0 &amp; \\mu_{yy} &amp; 0 \\\\ 0 &amp; 0 &amp; \\mu_{zz} \\end{bmatrix} \\] <p>where the off-diagonal terms (e.g. <code>epsilon_xy</code>) are assumed to be zero.</p> <p>High-accuracy volumetric integration of shapes on multiple grids can be performed by the gridlock module.</p> <p>The values of the vacuum permittivity and permability effectively become scaling factors that appear in several locations (e.g. between the E and H fields). In order to limit floating-point inaccuracy and simplify calculations, they are often set to 1 and relative permittivities and permeabilities are used in their places; the true values can be multiplied back in after the simulation is complete if non- normalized results are needed.</p>"},{"location":"api/fdmath/#functional-and-sparse-operators","title":"Functional and sparse operators","text":""},{"location":"api/fdmath/#meanas.fdmath.functional","title":"meanas.fdmath.functional","text":"<p>Math functions for finite difference simulations</p> <p>Basic discrete calculus etc.</p>"},{"location":"api/fdmath/#meanas.fdmath.functional.deriv_forward","title":"deriv_forward","text":"<pre><code>deriv_forward(\n dx_e: Sequence[NDArray[floating | complexfloating]]\n | None = None,\n) -&gt; tuple[\n fdfield_updater_t, fdfield_updater_t, fdfield_updater_t\n]\n</code></pre> <p>Utility operators for taking discretized derivatives (backward variant).</p> <p>Parameters:</p> Name Type Description Default <code>dx_e</code> <code>Sequence[NDArray[floating | complexfloating]] | None</code> <p>Lists of cell sizes for all axes <code>[[dx_0, dx_1, ...], [dy_0, dy_1, ...], ...]</code>.</p> <code>None</code> <p>Returns:</p> Type Description <code>tuple[fdfield_updater_t, fdfield_updater_t, fdfield_updater_t]</code> <p>List of functions for taking forward derivatives along each axis.</p>"},{"location":"api/fdmath/#meanas.fdmath.functional.deriv_back","title":"deriv_back","text":"<pre><code>deriv_back(\n dx_h: Sequence[NDArray[floating | complexfloating]]\n | None = None,\n) -&gt; tuple[\n fdfield_updater_t, fdfield_updater_t, fdfield_updater_t\n]\n</code></pre> <p>Utility operators for taking discretized derivatives (forward variant).</p> <p>Parameters:</p> Name Type Description Default <code>dx_h</code> <code>Sequence[NDArray[floating | complexfloating]] | None</code> <p>Lists of cell sizes for all axes <code>[[dx_0, dx_1, ...], [dy_0, dy_1, ...], ...]</code>.</p> <code>None</code> <p>Returns:</p> Type Description <code>tuple[fdfield_updater_t, fdfield_updater_t, fdfield_updater_t]</code> <p>List of functions for taking forward derivatives along each axis.</p>"},{"location":"api/fdmath/#meanas.fdmath.functional.curl_forward","title":"curl_forward","text":"<pre><code>curl_forward(\n dx_e: Sequence[NDArray[floating | complexfloating]]\n | None = None,\n) -&gt; Callable[[TT], TT]\n</code></pre> <p>Curl operator for use with the E field.</p> <p>Parameters:</p> Name Type Description Default <code>dx_e</code> <code>Sequence[NDArray[floating | complexfloating]] | None</code> <p>Lists of cell sizes for all axes <code>[[dx_0, dx_1, ...], [dy_0, dy_1, ...], ...]</code>.</p> <code>None</code> <p>Returns:</p> Type Description <code>Callable[[TT], TT]</code> <p>Function <code>f</code> for taking the discrete forward curl of a field,</p> <code>Callable[[TT], TT]</code> <p><code>f(E)</code> -&gt; curlE \\(= \\nabla_f \\times E\\)</p>"},{"location":"api/fdmath/#meanas.fdmath.functional.curl_back","title":"curl_back","text":"<pre><code>curl_back(\n dx_h: Sequence[NDArray[floating | complexfloating]]\n | None = None,\n) -&gt; Callable[[TT], TT]\n</code></pre> <p>Create a function which takes the backward curl of a field.</p> <p>Parameters:</p> Name Type Description Default <code>dx_h</code> <code>Sequence[NDArray[floating | complexfloating]] | None</code> <p>Lists of cell sizes for all axes <code>[[dx_0, dx_1, ...], [dy_0, dy_1, ...], ...]</code>.</p> <code>None</code> <p>Returns:</p> Type Description <code>Callable[[TT], TT]</code> <p>Function <code>f</code> for taking the discrete backward curl of a field,</p> <code>Callable[[TT], TT]</code> <p><code>f(H)</code> -&gt; curlH \\(= \\nabla_b \\times H\\)</p>"},{"location":"api/fdmath/#meanas.fdmath.operators","title":"meanas.fdmath.operators","text":"<p>Matrix operators for finite difference simulations</p> <p>Basic discrete calculus etc.</p>"},{"location":"api/fdmath/#meanas.fdmath.operators.shift_circ","title":"shift_circ","text":"<pre><code>shift_circ(\n axis: int, shape: Sequence[int], shift_distance: int = 1\n) -&gt; sparse.sparray\n</code></pre> <p>Utility operator for performing a circular shift along a specified axis by a specified number of elements.</p> <p>Parameters:</p> Name Type Description Default <code>axis</code> <code>int</code> <p>Axis to shift along. x=0, y=1, z=2</p> required <code>shape</code> <code>Sequence[int]</code> <p>Shape of the grid being shifted</p> required <code>shift_distance</code> <code>int</code> <p>Number of cells to shift by. May be negative. Default 1.</p> <code>1</code> <p>Returns:</p> Type Description <code>sparray</code> <p>Sparse matrix for performing the circular shift.</p>"},{"location":"api/fdmath/#meanas.fdmath.operators.shift_with_mirror","title":"shift_with_mirror","text":"<pre><code>shift_with_mirror(\n axis: int, shape: Sequence[int], shift_distance: int = 1\n) -&gt; sparse.sparray\n</code></pre> <p>Utility operator for performing an n-element shift along a specified axis, with mirror boundary conditions applied to the cells beyond the receding edge.</p> <p>Parameters:</p> Name Type Description Default <code>axis</code> <code>int</code> <p>Axis to shift along. x=0, y=1, z=2</p> required <code>shape</code> <code>Sequence[int]</code> <p>Shape of the grid being shifted</p> required <code>shift_distance</code> <code>int</code> <p>Number of cells to shift by. May be negative. Default 1.</p> <code>1</code> <p>Returns:</p> Type Description <code>sparray</code> <p>Sparse matrix for performing the shift-with-mirror.</p>"},{"location":"api/fdmath/#meanas.fdmath.operators.deriv_forward","title":"deriv_forward","text":"<pre><code>deriv_forward(\n dx_e: Sequence[NDArray[floating | complexfloating]],\n) -&gt; list[sparse.sparray]\n</code></pre> <p>Utility operators for taking discretized derivatives (forward variant).</p> <p>Parameters:</p> Name Type Description Default <code>dx_e</code> <code>Sequence[NDArray[floating | complexfloating]]</code> <p>Lists of cell sizes for all axes <code>[[dx_0, dx_1, ...], [dy_0, dy_1, ...], ...]</code>.</p> required <p>Returns:</p> Type Description <code>list[sparray]</code> <p>List of operators for taking forward derivatives along each axis.</p>"},{"location":"api/fdmath/#meanas.fdmath.operators.deriv_back","title":"deriv_back","text":"<pre><code>deriv_back(\n dx_h: Sequence[NDArray[floating | complexfloating]],\n) -&gt; list[sparse.sparray]\n</code></pre> <p>Utility operators for taking discretized derivatives (backward variant).</p> <p>Parameters:</p> Name Type Description Default <code>dx_h</code> <code>Sequence[NDArray[floating | complexfloating]]</code> <p>Lists of cell sizes for all axes <code>[[dx_0, dx_1, ...], [dy_0, dy_1, ...], ...]</code>.</p> required <p>Returns:</p> Type Description <code>list[sparray]</code> <p>List of operators for taking forward derivatives along each axis.</p>"},{"location":"api/fdmath/#meanas.fdmath.operators.cross","title":"cross","text":"<pre><code>cross(B: Sequence[sparray]) -&gt; sparse.sparray\n</code></pre> <p>Cross product operator</p> <p>Parameters:</p> Name Type Description Default <code>B</code> <code>Sequence[sparray]</code> <p>List <code>[Bx, By, Bz]</code> of sparse matrices corresponding to the x, y, z portions of the operator on the left side of the cross product.</p> required <p>Returns:</p> Type Description <code>sparray</code> <p>Sparse matrix corresponding to (B x), where x is the cross product.</p>"},{"location":"api/fdmath/#meanas.fdmath.operators.vec_cross","title":"vec_cross","text":"<pre><code>vec_cross(b: vfdfield) -&gt; sparse.sparray\n</code></pre> <p>Vector cross product operator</p> <p>Parameters:</p> Name Type Description Default <code>b</code> <code>vfdfield</code> <p>Vector on the left side of the cross product.</p> required <p>Returns:</p> <pre><code>Sparse matrix corresponding to (b x), where x is the cross product.\n</code></pre>"},{"location":"api/fdmath/#meanas.fdmath.operators.avg_forward","title":"avg_forward","text":"<pre><code>avg_forward(\n axis: int, shape: Sequence[int]\n) -&gt; sparse.sparray\n</code></pre> <p>Forward average operator <code>(x4 = (x4 + x5) / 2)</code></p> <p>Parameters:</p> Name Type Description Default <code>axis</code> <code>int</code> <p>Axis to average along (x=0, y=1, z=2)</p> required <code>shape</code> <code>Sequence[int]</code> <p>Shape of the grid to average</p> required <p>Returns:</p> Type Description <code>sparray</code> <p>Sparse matrix for forward average operation.</p>"},{"location":"api/fdmath/#meanas.fdmath.operators.avg_back","title":"avg_back","text":"<pre><code>avg_back(axis: int, shape: Sequence[int]) -&gt; sparse.sparray\n</code></pre> <p>Backward average operator <code>(x4 = (x4 + x3) / 2)</code></p> <p>Parameters:</p> Name Type Description Default <code>axis</code> <code>int</code> <p>Axis to average along (x=0, y=1, z=2)</p> required <code>shape</code> <code>Sequence[int]</code> <p>Shape of the grid to average</p> required <p>Returns:</p> Type Description <code>sparray</code> <p>Sparse matrix for backward average operation.</p>"},{"location":"api/fdmath/#meanas.fdmath.operators.curl_forward","title":"curl_forward","text":"<pre><code>curl_forward(\n dx_e: Sequence[NDArray[floating | complexfloating]],\n) -&gt; sparse.sparray\n</code></pre> <p>Curl operator for use with the E field.</p> <p>Parameters:</p> Name Type Description Default <code>dx_e</code> <code>Sequence[NDArray[floating | complexfloating]]</code> <p>Lists of cell sizes for all axes <code>[[dx_0, dx_1, ...], [dy_0, dy_1, ...], ...]</code>.</p> required <p>Returns:</p> Type Description <code>sparray</code> <p>Sparse matrix for taking the discretized curl of the E-field</p>"},{"location":"api/fdmath/#meanas.fdmath.operators.curl_back","title":"curl_back","text":"<pre><code>curl_back(\n dx_h: Sequence[NDArray[floating | complexfloating]],\n) -&gt; sparse.sparray\n</code></pre> <p>Curl operator for use with the H field.</p> <p>Parameters:</p> Name Type Description Default <code>dx_h</code> <code>Sequence[NDArray[floating | complexfloating]]</code> <p>Lists of cell sizes for all axes <code>[[dx_0, dx_1, ...], [dy_0, dy_1, ...], ...]</code>.</p> required <p>Returns:</p> Type Description <code>sparray</code> <p>Sparse matrix for taking the discretized curl of the H-field</p>"},{"location":"api/fdmath/#meanas.fdmath.vectorization","title":"meanas.fdmath.vectorization","text":"<p>Functions for moving between a vector field (list of 3 ndarrays, <code>[f_x, f_y, f_z]</code>) and a 1D array representation of that field <code>[f_x0, f_x1, f_x2,... f_y0,... f_z0,...]</code>. Vectorized versions of the field use row-major (ie., C-style) ordering.</p>"},{"location":"api/fdmath/#meanas.fdmath.vectorization.vec","title":"vec","text":"<pre><code>vec(f: None) -&gt; None\n</code></pre><pre><code>vec(f: fdfield_t) -&gt; vfdfield_t\n</code></pre><pre><code>vec(f: cfdfield_t) -&gt; vcfdfield_t\n</code></pre><pre><code>vec(f: fdfield2_t) -&gt; vfdfield2_t\n</code></pre><pre><code>vec(f: cfdfield2_t) -&gt; vcfdfield2_t\n</code></pre><pre><code>vec(f: fdslice_t) -&gt; vfdslice_t\n</code></pre><pre><code>vec(f: cfdslice_t) -&gt; vcfdslice_t\n</code></pre><pre><code>vec(f: ArrayLike) -&gt; NDArray\n</code></pre> <pre><code>vec(\n f: fdfield_t\n | cfdfield_t\n | fdfield2_t\n | cfdfield2_t\n | fdslice_t\n | cfdslice_t\n | ArrayLike\n | None,\n) -&gt; (\n vfdfield_t\n | vcfdfield_t\n | vfdfield2_t\n | vcfdfield2_t\n | vfdslice_t\n | vcfdslice_t\n | NDArray\n | None\n)\n</code></pre> <p>Create a 1D ndarray from a vector field which spans a 1-3D region.</p> <p>Returns <code>None</code> if called with <code>f=None</code>.</p> <p>Parameters:</p> Name Type Description Default <code>f</code> <code>fdfield_t | cfdfield_t | fdfield2_t | cfdfield2_t | fdslice_t | cfdslice_t | ArrayLike | None</code> <p>A vector field, e.g. <code>[f_x, f_y, f_z]</code> where each <code>f_</code> component is a 1- to 3-D ndarray (<code>f_*</code> should all be the same size). Doesn't fail with <code>f=None</code>.</p> required <p>Returns:</p> Type Description <code>vfdfield_t | vcfdfield_t | vfdfield2_t | vcfdfield2_t | vfdslice_t | vcfdslice_t | NDArray | None</code> <p>1D ndarray containing the linearized field (or <code>None</code>)</p>"},{"location":"api/fdmath/#meanas.fdmath.vectorization.unvec","title":"unvec","text":"<pre><code>unvec(\n v: None, shape: Sequence[int], nvdim: int = 3\n) -&gt; None\n</code></pre><pre><code>unvec(\n v: vfdfield_t, shape: Sequence[int], nvdim: int = 3\n) -&gt; fdfield_t\n</code></pre><pre><code>unvec(\n v: vcfdfield_t, shape: Sequence[int], nvdim: int = 3\n) -&gt; cfdfield_t\n</code></pre><pre><code>unvec(\n v: vfdfield2_t, shape: Sequence[int], nvdim: int = 3\n) -&gt; fdfield2_t\n</code></pre><pre><code>unvec(\n v: vcfdfield2_t, shape: Sequence[int], nvdim: int = 3\n) -&gt; cfdfield2_t\n</code></pre><pre><code>unvec(\n v: vfdslice_t, shape: Sequence[int], nvdim: int = 3\n) -&gt; fdslice_t\n</code></pre><pre><code>unvec(\n v: vcfdslice_t, shape: Sequence[int], nvdim: int = 3\n) -&gt; cfdslice_t\n</code></pre><pre><code>unvec(\n v: ArrayLike, shape: Sequence[int], nvdim: int = 3\n) -&gt; NDArray\n</code></pre> <pre><code>unvec(\n v: vfdfield_t\n | vcfdfield_t\n | vfdfield2_t\n | vcfdfield2_t\n | vfdslice_t\n | vcfdslice_t\n | ArrayLike\n | None,\n shape: Sequence[int],\n nvdim: int = 3,\n) -&gt; (\n fdfield_t\n | cfdfield_t\n | fdfield2_t\n | cfdfield2_t\n | fdslice_t\n | cfdslice_t\n | NDArray\n | None\n)\n</code></pre> <p>Perform the inverse of vec(): take a 1D ndarray and output an <code>nvdim</code>-component field of form e.g. <code>[f_x, f_y, f_z]</code> (<code>nvdim=3</code>) where each of <code>f_*</code> is a len(shape)-dimensional ndarray.</p> <p>Returns <code>None</code> if called with <code>v=None</code>.</p> <p>Parameters:</p> Name Type Description Default <code>v</code> <code>vfdfield_t | vcfdfield_t | vfdfield2_t | vcfdfield2_t | vfdslice_t | vcfdslice_t | ArrayLike | None</code> <p>1D ndarray representing a vector field of shape shape (or None)</p> required <code>shape</code> <code>Sequence[int]</code> <p>shape of the vector field</p> required <code>nvdim</code> <code>int</code> <p>Number of components in each vector</p> <code>3</code> <p>Returns:</p> Type Description <code>fdfield_t | cfdfield_t | fdfield2_t | cfdfield2_t | fdslice_t | cfdslice_t | NDArray | None</code> <p><code>[f_x, f_y, f_z]</code> where each <code>f_</code> is a <code>len(shape)</code> dimensional ndarray (or <code>None</code>)</p>"},{"location":"api/fdmath/#meanas.fdmath.types","title":"meanas.fdmath.types","text":"<p>Types shared across multiple submodules</p>"},{"location":"api/fdmath/#meanas.fdmath.types.dx_lists_t","title":"dx_lists_t <code>module-attribute</code>","text":"<pre><code>dx_lists_t = Sequence[\n Sequence[NDArray[floating | complexfloating]]\n]\n</code></pre> <p>'dxes' datastructure which contains grid cell width information in the following format:</p> <pre><code>[[[dx_e[0], dx_e[1], ...], [dy_e[0], ...], [dz_e[0], ...]],\n [[dx_h[0], dx_h[1], ...], [dy_h[0], ...], [dz_h[0], ...]]]\n</code></pre> <p>where <code>dx_e[0]</code> is the x-width of the <code>x=0</code> cells, as used when calculating dE/dx, and <code>dy_h[0]</code> is the y-width of the <code>y=0</code> cells, as used when calculating dH/dy, etc.</p>"},{"location":"api/fdmath/#meanas.fdmath.types.dx_lists2_t","title":"dx_lists2_t <code>module-attribute</code>","text":"<pre><code>dx_lists2_t = Sequence[\n Sequence[NDArray[floating | complexfloating]]\n]\n</code></pre> <p>2D 'dxes' datastructure which contains grid cell width information in the following format:</p> <pre><code>[[[dx_e[0], dx_e[1], ...], [dy_e[0], ...]],\n [[dx_h[0], dx_h[1], ...], [dy_h[0], ...]]]\n</code></pre> <p>where <code>dx_e[0]</code> is the x-width of the <code>x=0</code> cells, as used when calculating dE/dx, and <code>dy_h[0]</code> is the y-width of the <code>y=0</code> cells, as used when calculating dH/dy, etc.</p>"},{"location":"api/fdmath/#meanas.fdmath.types.dx_lists_mut","title":"dx_lists_mut <code>module-attribute</code>","text":"<pre><code>dx_lists_mut = MutableSequence[\n MutableSequence[NDArray[floating | complexfloating]]\n]\n</code></pre> <p>Mutable version of <code>dx_lists_t</code></p>"},{"location":"api/fdmath/#meanas.fdmath.types.dx_lists2_mut","title":"dx_lists2_mut <code>module-attribute</code>","text":"<pre><code>dx_lists2_mut = MutableSequence[\n MutableSequence[NDArray[floating | complexfloating]]\n]\n</code></pre> <p>Mutable version of <code>dx_lists2_t</code></p>"},{"location":"api/fdmath/#meanas.fdmath.types.fdfield_updater_t","title":"fdfield_updater_t <code>module-attribute</code>","text":"<pre><code>fdfield_updater_t = Callable[..., fdfield]\n</code></pre> <p>Convenience type for functions which take and return a real <code>fdfield</code></p>"},{"location":"api/fdmath/#meanas.fdmath.types.cfdfield_updater_t","title":"cfdfield_updater_t <code>module-attribute</code>","text":"<pre><code>cfdfield_updater_t = Callable[..., cfdfield]\n</code></pre> <p>Convenience type for functions which take and return a complex <code>cfdfield</code></p>"},{"location":"api/fdmath/#meanas.fdmath.types.fdfield","title":"fdfield","text":"<pre><code>fdfield = fdfield_t | NDArray[floating]\n</code></pre> <p>Vector field with shape (3, X, Y, Z) (e.g. <code>[E_x, E_y, E_z]</code>)</p>"},{"location":"api/fdmath/#meanas.fdmath.types.vfdfield","title":"vfdfield","text":"<pre><code>vfdfield = vfdfield_t | NDArray[floating]\n</code></pre> <p>Linearized vector field (single vector of length 3XY*Z)</p>"},{"location":"api/fdmath/#meanas.fdmath.types.cfdfield","title":"cfdfield","text":"<pre><code>cfdfield = cfdfield_t | NDArray[complexfloating]\n</code></pre> <p>Complex vector field with shape (3, X, Y, Z) (e.g. <code>[E_x, E_y, E_z]</code>)</p>"},{"location":"api/fdmath/#meanas.fdmath.types.vcfdfield","title":"vcfdfield","text":"<pre><code>vcfdfield = vcfdfield_t | NDArray[complexfloating]\n</code></pre> <p>Linearized complex vector field (single vector of length 3XY*Z)</p>"},{"location":"api/fdmath/#meanas.fdmath.types.fdslice","title":"fdslice","text":"<pre><code>fdslice = fdslice_t | NDArray[floating]\n</code></pre> <p>Vector field slice with shape (3, X, Y) (e.g. <code>[E_x, E_y, E_z]</code> at a single Z position)</p>"},{"location":"api/fdmath/#meanas.fdmath.types.vfdslice","title":"vfdslice","text":"<pre><code>vfdslice = vfdslice_t | NDArray[floating]\n</code></pre> <p>Linearized vector field slice (single vector of length 3XY)</p>"},{"location":"api/fdmath/#meanas.fdmath.types.cfdslice","title":"cfdslice","text":"<pre><code>cfdslice = cfdslice_t | NDArray[complexfloating]\n</code></pre> <p>Complex vector field slice with shape (3, X, Y) (e.g. <code>[E_x, E_y, E_z]</code> at a single Z position)</p>"},{"location":"api/fdmath/#meanas.fdmath.types.vcfdslice","title":"vcfdslice","text":"<pre><code>vcfdslice = vcfdslice_t | NDArray[complexfloating]\n</code></pre> <p>Linearized complex vector field slice (single vector of length 3XY)</p>"},{"location":"api/fdmath/#meanas.fdmath.types.fdfield2","title":"fdfield2","text":"<pre><code>fdfield2 = fdfield2_t | NDArray[floating]\n</code></pre> <p>2D Vector field with shape (2, X, Y) (e.g. <code>[E_x, E_y]</code>)</p>"},{"location":"api/fdmath/#meanas.fdmath.types.vfdfield2","title":"vfdfield2","text":"<pre><code>vfdfield2 = vfdfield2_t | NDArray[floating]\n</code></pre> <p>2D Linearized vector field (single vector of length 2XY)</p>"},{"location":"api/fdmath/#meanas.fdmath.types.cfdfield2","title":"cfdfield2","text":"<pre><code>cfdfield2 = cfdfield2_t | NDArray[complexfloating]\n</code></pre> <p>2D Complex vector field with shape (2, X, Y) (e.g. <code>[E_x, E_y]</code>)</p>"},{"location":"api/fdmath/#meanas.fdmath.types.vcfdfield2","title":"vcfdfield2","text":"<pre><code>vcfdfield2 = vcfdfield2_t | NDArray[complexfloating]\n</code></pre> <p>2D Linearized complex vector field (single vector of length 2XY)</p>"},{"location":"api/fdtd/","title":"fdtd","text":""},{"location":"api/fdtd/#meanas.fdtd","title":"meanas.fdtd","text":"<p>Utilities for running finite-difference time-domain (FDTD) simulations</p> <p>See the discussion of <code>Maxwell's Equations</code> in <code>meanas.fdmath</code> for basic mathematical background.</p>"},{"location":"api/fdtd/#meanas.fdtd--timestep","title":"Timestep","text":"<p>From the discussion of \"Plane waves and the Dispersion relation\" in <code>meanas.fdmath</code>, we have</p> \\[ c^2 \\Delta_t^2 = \\frac{\\Delta_t^2}{\\mu \\epsilon} &lt; 1/(\\frac{1}{\\Delta_x^2} + \\frac{1}{\\Delta_y^2} + \\frac{1}{\\Delta_z^2}) \\] <p>or, if \\(\\Delta_x = \\Delta_y = \\Delta_z\\), then \\(c \\Delta_t &lt; \\frac{\\Delta_x}{\\sqrt{3}}\\).</p> <p>Based on this, we can set</p> <pre><code>dt = sqrt(mu.min() * epsilon.min()) / sqrt(1/dx_min**2 + 1/dy_min**2 + 1/dz_min**2)\n</code></pre> <p>The <code>dx_min</code>, <code>dy_min</code>, <code>dz_min</code> should be the minimum value across both the base and derived grids.</p>"},{"location":"api/fdtd/#meanas.fdtd--poynting-vector-and-energy-conservation","title":"Poynting Vector and Energy Conservation","text":"<p>Let</p> \\[ \\begin{aligned} \\tilde{S}_{l, l', \\vec{r}} &amp;=&amp; &amp;\\tilde{E}_{l, \\vec{r}} \\otimes \\hat{H}_{l', \\vec{r} + \\frac{1}{2}} \\\\ &amp;=&amp; &amp;\\vec{x} (\\tilde{E}^y_{l,m+1,n,p} \\hat{H}^z_{l',\\vec{r} + \\frac{1}{2}} - \\tilde{E}^z_{l,m+1,n,p} \\hat{H}^y_{l', \\vec{r} + \\frac{1}{2}}) \\\\ &amp; &amp;+ &amp;\\vec{y} (\\tilde{E}^z_{l,m,n+1,p} \\hat{H}^x_{l',\\vec{r} + \\frac{1}{2}} - \\tilde{E}^x_{l,m,n+1,p} \\hat{H}^z_{l', \\vec{r} + \\frac{1}{2}}) \\\\ &amp; &amp;+ &amp;\\vec{z} (\\tilde{E}^x_{l,m,n,p+1} \\hat{H}^y_{l',\\vec{r} + \\frac{1}{2}} - \\tilde{E}^y_{l,m,n,p+1} \\hat{H}^z_{l', \\vec{r} + \\frac{1}{2}}) \\end{aligned} \\] <p>where \\(\\vec{r} = (m, n, p)\\) and \\(\\otimes\\) is a modified cross product in which the \\(\\tilde{E}\\) terms are shifted as indicated.</p> <p>By taking the divergence and rearranging terms, we can show that</p> \\[ \\begin{aligned} \\hat{\\nabla} \\cdot \\tilde{S}_{l, l', \\vec{r}} &amp;= \\hat{\\nabla} \\cdot (\\tilde{E}_{l, \\vec{r}} \\otimes \\hat{H}_{l', \\vec{r} + \\frac{1}{2}}) \\\\ &amp;= \\hat{H}_{l', \\vec{r} + \\frac{1}{2}} \\cdot \\tilde{\\nabla} \\times \\tilde{E}_{l, \\vec{r}} - \\tilde{E}_{l, \\vec{r}} \\cdot \\hat{\\nabla} \\times \\hat{H}_{l', \\vec{r} + \\frac{1}{2}} \\\\ &amp;= \\hat{H}_{l', \\vec{r} + \\frac{1}{2}} \\cdot (-\\tilde{\\partial}_t \\mu_{\\vec{r} + \\frac{1}{2}} \\hat{H}_{l - \\frac{1}{2}, \\vec{r} + \\frac{1}{2}} - \\hat{M}_{l, \\vec{r} + \\frac{1}{2}}) - \\tilde{E}_{l, \\vec{r}} \\cdot (\\hat{\\partial}_t \\tilde{\\epsilon}_{\\vec{r}} \\tilde{E}_{l'+\\frac{1}{2}, \\vec{r}} + \\tilde{J}_{l', \\vec{r}}) \\\\ &amp;= \\hat{H}_{l'} \\cdot (-\\mu / \\Delta_t)(\\hat{H}_{l + \\frac{1}{2}} - \\hat{H}_{l - \\frac{1}{2}}) - \\tilde{E}_l \\cdot (\\epsilon / \\Delta_t )(\\tilde{E}_{l'+\\frac{1}{2}} - \\tilde{E}_{l'-\\frac{1}{2}}) - \\hat{H}_{l'} \\cdot \\hat{M}_{l} - \\tilde{E}_l \\cdot \\tilde{J}_{l'} \\\\ \\end{aligned} \\] <p>where in the last line the spatial subscripts have been dropped to emphasize the time subscripts \\(l, l'\\), i.e.</p> \\[ \\begin{aligned} \\tilde{E}_l &amp;= \\tilde{E}_{l, \\vec{r}} \\\\ \\hat{H}_l &amp;= \\tilde{H}_{l, \\vec{r} + \\frac{1}{2}} \\\\ \\tilde{\\epsilon} &amp;= \\tilde{\\epsilon}_{\\vec{r}} \\\\ \\end{aligned} \\] <p>etc. For \\(l' = l + \\frac{1}{2}\\) we get</p> \\[ \\begin{aligned} \\hat{\\nabla} \\cdot \\tilde{S}_{l, l + \\frac{1}{2}} &amp;= \\hat{H}_{l + \\frac{1}{2}} \\cdot (-\\mu / \\Delta_t)(\\hat{H}_{l + \\frac{1}{2}} - \\hat{H}_{l - \\frac{1}{2}}) - \\tilde{E}_l \\cdot (\\epsilon / \\Delta_t)(\\tilde{E}_{l+1} - \\tilde{E}_l) - \\hat{H}_{l'} \\cdot \\hat{M}_l - \\tilde{E}_l \\cdot \\tilde{J}_{l + \\frac{1}{2}} \\\\ &amp;= (-\\mu / \\Delta_t)(\\hat{H}^2_{l + \\frac{1}{2}} - \\hat{H}_{l + \\frac{1}{2}} \\cdot \\hat{H}_{l - \\frac{1}{2}}) - (\\epsilon / \\Delta_t)(\\tilde{E}_{l+1} \\cdot \\tilde{E}_l - \\tilde{E}^2_l) - \\hat{H}_{l'} \\cdot \\hat{M}_l - \\tilde{E}_l \\cdot \\tilde{J}_{l + \\frac{1}{2}} \\\\ &amp;= -(\\mu \\hat{H}^2_{l + \\frac{1}{2}} +\\epsilon \\tilde{E}_{l+1} \\cdot \\tilde{E}_l) / \\Delta_t \\\\ +(\\mu \\hat{H}_{l + \\frac{1}{2}} \\cdot \\hat{H}_{l - \\frac{1}{2}} +\\epsilon \\tilde{E}^2_l) / \\Delta_t \\\\ - \\hat{H}_{l+\\frac{1}{2}} \\cdot \\hat{M}_l \\\\ - \\tilde{E}_l \\cdot \\tilde{J}_{l+\\frac{1}{2}} \\\\ \\end{aligned} \\] <p>and for \\(l' = l - \\frac{1}{2}\\),</p> \\[ \\begin{aligned} \\hat{\\nabla} \\cdot \\tilde{S}_{l, l - \\frac{1}{2}} &amp;= (\\mu \\hat{H}^2_{l - \\frac{1}{2}} +\\epsilon \\tilde{E}_{l-1} \\cdot \\tilde{E}_l) / \\Delta_t \\\\ -(\\mu \\hat{H}_{l + \\frac{1}{2}} \\cdot \\hat{H}_{l - \\frac{1}{2}} +\\epsilon \\tilde{E}^2_l) / \\Delta_t \\\\ - \\hat{H}_{l-\\frac{1}{2}} \\cdot \\hat{M}_l \\\\ - \\tilde{E}_l \\cdot \\tilde{J}_{l-\\frac{1}{2}} \\\\ \\end{aligned} \\] <p>These two results form the discrete time-domain analogue to Poynting's theorem. They hint at the expressions for the energy, which can be calculated at the same time-index as either the E or H field:</p> \\[ \\begin{aligned} U_l &amp;= \\epsilon \\tilde{E}^2_l + \\mu \\hat{H}_{l + \\frac{1}{2}} \\cdot \\hat{H}_{l - \\frac{1}{2}} \\\\ U_{l + \\frac{1}{2}} &amp;= \\epsilon \\tilde{E}_l \\cdot \\tilde{E}_{l + 1} + \\mu \\hat{H}^2_{l + \\frac{1}{2}} \\\\ \\end{aligned} \\] <p>Rewriting the Poynting theorem in terms of the energy expressions,</p> \\[ \\begin{aligned} (U_{l+\\frac{1}{2}} - U_l) / \\Delta_t &amp;= -\\hat{\\nabla} \\cdot \\tilde{S}_{l, l + \\frac{1}{2}} \\\\ - \\hat{H}_{l+\\frac{1}{2}} \\cdot \\hat{M}_l \\\\ - \\tilde{E}_l \\cdot \\tilde{J}_{l+\\frac{1}{2}} \\\\ (U_l - U_{l-\\frac{1}{2}}) / \\Delta_t &amp;= -\\hat{\\nabla} \\cdot \\tilde{S}_{l, l - \\frac{1}{2}} \\\\ - \\hat{H}_{l-\\frac{1}{2}} \\cdot \\hat{M}_l \\\\ - \\tilde{E}_l \\cdot \\tilde{J}_{l-\\frac{1}{2}} \\\\ \\end{aligned} \\] <p>This result is exact and should practically hold to within numerical precision. No time- or spatial-averaging is necessary.</p> <p>Note that each value of \\(J\\) contributes to the energy twice (i.e. once per field update) despite only causing the value of \\(E\\) to change once (same for \\(M\\) and \\(H\\)).</p>"},{"location":"api/fdtd/#meanas.fdtd--sources","title":"Sources","text":"<p>It is often useful to excite the simulation with an arbitrary broadband pulse and then extract the frequency-domain response by performing an on-the-fly Fourier transform of the time-domain fields.</p> <p><code>accumulate_phasor</code> in <code>meanas.fdtd.phasor</code> performs the phase accumulation for one or more target frequencies, while leaving source normalization and simulation-loop policy to the caller. <code>temporal_phasor(...)</code> and <code>temporal_phasor_scale(...)</code> apply the same Fourier sum to a scalar waveform, which is useful when a pulsed source envelope must be normalized before being applied to a point source or mode source. <code>real_injection_scale(...)</code> is the corresponding helper for the common real-valued injection pattern <code>numpy.real(scale * waveform)</code>. Convenience wrappers <code>accumulate_phasor_e</code>, <code>accumulate_phasor_h</code>, and <code>accumulate_phasor_j</code> apply the usual Yee time offsets. <code>reconstruct_real(...)</code> and the corresponding <code>reconstruct_real_e/h/j(...)</code> wrappers perform the inverse operation, converting phasors back into real-valued field snapshots at explicit Yee-aligned times. For scalar <code>omega</code>, the reconstruction helpers accept either a plain field phasor or the batched <code>(1, *sample_shape)</code> form used by the accumulator helpers. The helpers accumulate</p> \\[ \\Delta_t \\sum_l w_l e^{-i \\omega t_l} f_l \\] <p>with caller-provided sample times and weights. In this codebase the matching electric-current convention is typically <code>E -= dt * J / epsilon</code> in FDTD and <code>-i \\omega J</code> on the right-hand side of the FDFD wave equation.</p> <p>For FDTD/FDFD equivalence, this phasor path is the primary comparison workflow. It isolates the guided <code>+\\omega</code> response that the frequency-domain solver targets directly, regardless of whether the underlying FDTD run used real- or complex-valued fields.</p> <p>For exact pulsed FDTD/FDFD equivalence it is often simplest to keep the injected source, fields, and CPML auxiliary state complex-valued. The <code>real_injection_scale(...)</code> helper is instead for the more ordinary one-run real-valued source path, where the intended positive-frequency waveform is injected through <code>numpy.real(scale * waveform)</code> and any remaining negative- frequency leakage is controlled by the pulse bandwidth and run length.</p> <p><code>reconstruct_real(...)</code> is for a different question: given a phasor, what late real-valued field snapshot should it produce? That raw-snapshot comparison is stricter and noisier because a monitor plane generally contains both the guided field and the remaining orthogonal content,</p> \\[ E_{\\text{monitor}} = E_{\\text{guided}} + E_{\\text{residual}} . \\] <p>Phasor/modal comparisons mostly validate the guided <code>+\\omega</code> term. Raw real-field comparisons expose both terms at once, so they should be treated as secondary diagnostics rather than the main solver-equivalence benchmark.</p> <p>The Ricker wavelet (normalized second derivative of a Gaussian) is commonly used for the pulse shape. It can be written</p> \\[ f_r(t) = (1 - \\frac{1}{2} (\\omega (t - \\tau))^2) e^{-(\\frac{\\omega (t - \\tau)}{2})^2} \\] <p>with \\(\\tau &gt; \\frac{2 * \\pi}{\\omega}\\) as a minimum delay to avoid a discontinuity at t=0 (assuming the source is off for t&lt;0 this gives \\(\\sim 10^{-3}\\) error at t=0).</p>"},{"location":"api/fdtd/#meanas.fdtd--boundary-conditions","title":"Boundary conditions","text":"<p><code>meanas.fdtd</code> exposes two boundary-related building blocks:</p> <ul> <li><code>conducting_boundary(...)</code> for simple perfect-electric-conductor style field clamping at one face of the domain.</li> <li><code>cpml_params(...)</code> and <code>updates_with_cpml(...)</code> for convolutional perfectly matched layers (CPMLs) attached to one or more faces of the Yee grid.</li> </ul> <p><code>updates_with_cpml(...)</code> accepts a three-by-two table of CPML parameter blocks:</p> <pre><code>cpml_params[axis][polarity_index]\n</code></pre> <p>where <code>axis</code> is <code>0</code>, <code>1</code>, or <code>2</code> and <code>polarity_index</code> corresponds to <code>(-1, +1)</code>. Passing <code>None</code> for one entry disables CPML on that face while leaving the other directions unchanged. This is how mixed boundary setups such as \"absorbing in x, periodic in y/z\" are expressed.</p> <p>When comparing an FDTD run against an FDFD solve, use the same stretched coordinate system in both places:</p> <ol> <li>Build the FDTD update with the desired CPML parameters.</li> <li>Stretch the FDFD <code>dxes</code> with the matching SCPML transform.</li> <li>Compare the extracted phasor against the FDFD field or residual on those stretched <code>dxes</code>.</li> </ol> <p>The electric-current sign convention used throughout the examples and tests is</p> \\[ E \\leftarrow E - \\Delta_t J / \\epsilon \\] <p>which matches the FDFD right-hand side</p> \\[ -i \\omega J. \\]"},{"location":"api/fdtd/#core-update-and-analysis-helpers","title":"Core update and analysis helpers","text":""},{"location":"api/fdtd/#meanas.fdtd.base","title":"meanas.fdtd.base","text":"<p>Basic FDTD field updates</p>"},{"location":"api/fdtd/#meanas.fdtd.base.maxwell_e","title":"maxwell_e","text":"<pre><code>maxwell_e(\n dt: float, dxes: dx_lists_t | None = None\n) -&gt; fdfield_updater_t\n</code></pre> <p>Build a function which performs a portion the time-domain E-field update,</p> <pre><code>E += curl_back(H[t]) / epsilon\n</code></pre> <p>The full update should be</p> <pre><code>E += (curl_back(H[t]) + J) / epsilon\n</code></pre> <p>which requires an additional step of <code>E += J / epsilon</code> which is not performed by the generated function.</p> <p>See <code>meanas.fdmath</code> for descriptions of</p> <ul> <li>This update step: \"Maxwell's equations\" section</li> <li><code>dxes</code>: \"Datastructure: dx_lists_t\" section</li> <li><code>epsilon</code>: \"Permittivity and Permeability\" section</li> </ul> <p>Also see the \"Timestep\" section of <code>meanas.fdtd</code> for a discussion of the <code>dt</code> parameter.</p> <p>Parameters:</p> Name Type Description Default <code>dt</code> <code>float</code> <p>Timestep. See <code>meanas.fdtd</code> for details.</p> required <code>dxes</code> <code>dx_lists_t | None</code> <p>Grid description; see <code>meanas.fdmath</code>.</p> <code>None</code> <p>Returns:</p> Type Description <code>fdfield_updater_t</code> <p>Function <code>f(E_old, H_old, epsilon) -&gt; E_new</code>.</p>"},{"location":"api/fdtd/#meanas.fdtd.base.maxwell_h","title":"maxwell_h","text":"<pre><code>maxwell_h(\n dt: float, dxes: dx_lists_t | None = None\n) -&gt; fdfield_updater_t\n</code></pre> <p>Build a function which performs part of the time-domain H-field update,</p> <pre><code>H -= curl_forward(E[t]) / mu\n</code></pre> <p>The full update should be</p> <pre><code>H -= (curl_forward(E[t]) + M) / mu\n</code></pre> <p>which requires an additional step of <code>H -= M / mu</code> which is not performed by the generated function; this step can be omitted if there is no magnetic current <code>M</code>.</p> <p>See <code>meanas.fdmath</code> for descriptions of</p> <ul> <li>This update step: \"Maxwell's equations\" section</li> <li><code>dxes</code>: \"Datastructure: dx_lists_t\" section</li> <li><code>mu</code>: \"Permittivity and Permeability\" section</li> </ul> <p>Also see the \"Timestep\" section of <code>meanas.fdtd</code> for a discussion of the <code>dt</code> parameter.</p> <p>Parameters:</p> Name Type Description Default <code>dt</code> <code>float</code> <p>Timestep. See <code>meanas.fdtd</code> for details.</p> required <code>dxes</code> <code>dx_lists_t | None</code> <p>Grid description; see <code>meanas.fdmath</code>.</p> <code>None</code> <p>Returns:</p> Type Description <code>fdfield_updater_t</code> <p>Function <code>f(E_old, H_old, epsilon) -&gt; E_new</code>.</p>"},{"location":"api/fdtd/#meanas.fdtd.pml","title":"meanas.fdtd.pml","text":"<p>Convolutional perfectly matched layer (CPML) support for FDTD updates.</p> <p>The helpers in this module construct per-face CPML parameters and then wrap the standard Yee updates with the additional auxiliary <code>psi</code> fields needed by the CPML recurrence.</p> <p>The intended call pattern is:</p> <ol> <li>Build a <code>cpml_params[axis][polarity_index]</code> table with <code>cpml_params(...)</code>.</li> <li>Pass that table into <code>updates_with_cpml(...)</code> together with <code>dt</code>, <code>dxes</code>, and <code>epsilon</code>.</li> <li>Advance the returned <code>update_E</code> / <code>update_H</code> closures in the simulation loop.</li> </ol> <p>Each face can be enabled or disabled independently by replacing one table entry with <code>None</code>.</p>"},{"location":"api/fdtd/#meanas.fdtd.pml.cpml_params","title":"cpml_params","text":"<pre><code>cpml_params(\n axis: int,\n polarity: int,\n dt: float,\n thickness: int = 8,\n ln_R_per_layer: float = -1.6,\n epsilon_eff: float = 1,\n mu_eff: float = 1,\n m: float = 3.5,\n ma: float = 1,\n cfs_alpha: float = 0,\n) -&gt; dict[str, Any]\n</code></pre> <p>Construct the parameter block for one CPML face.</p> <p>Parameters:</p> Name Type Description Default <code>axis</code> <code>int</code> <p>Which Cartesian axis the CPML is normal to (<code>0</code>, <code>1</code>, or <code>2</code>).</p> required <code>polarity</code> <code>int</code> <p>Which face along that axis (<code>-1</code> for the low-index face, <code>+1</code> for the high-index face).</p> required <code>dt</code> <code>float</code> <p>Timestep used by the Yee update.</p> required <code>thickness</code> <code>int</code> <p>Number of Yee cells occupied by the CPML region.</p> <code>8</code> <code>ln_R_per_layer</code> <code>float</code> <p>Logarithmic attenuation target per layer.</p> <code>-1.6</code> <code>epsilon_eff</code> <code>float</code> <p>Effective permittivity used when choosing the CPML scaling.</p> <code>1</code> <code>mu_eff</code> <code>float</code> <p>Effective permeability used when choosing the CPML scaling.</p> <code>1</code> <code>m</code> <code>float</code> <p>Polynomial grading exponent for <code>sigma</code> and <code>kappa</code>.</p> <code>3.5</code> <code>ma</code> <code>float</code> <p>Polynomial grading exponent for the complex-frequency shift <code>alpha</code>.</p> <code>1</code> <code>cfs_alpha</code> <code>float</code> <p>Maximum complex-frequency shift parameter.</p> <code>0</code> <p>Returns:</p> Type Description <code>dict[str, Any]</code> <p>Dictionary with:</p> <code>dict[str, Any]</code> <ul> <li><code>param_e</code>: <code>(p0, p1, p2)</code> arrays for the E update</li> </ul> <code>dict[str, Any]</code> <ul> <li><code>param_h</code>: <code>(p0, p1, p2)</code> arrays for the H update</li> </ul> <code>dict[str, Any]</code> <ul> <li><code>region</code>: slice tuple selecting the CPML cells on that face</li> </ul>"},{"location":"api/fdtd/#meanas.fdtd.pml.updates_with_cpml","title":"updates_with_cpml","text":"<pre><code>updates_with_cpml(\n cpml_params: Sequence[Sequence[dict[str, Any] | None]],\n dt: float,\n dxes: dx_lists_t,\n epsilon: fdfield,\n *,\n dtype: DTypeLike = numpy.float32,\n) -&gt; tuple[Callable[..., None], Callable[..., None]]\n</code></pre> <p>Build Yee-step update closures augmented with CPML terms.</p> <p>Parameters:</p> Name Type Description Default <code>cpml_params</code> <code>Sequence[Sequence[dict[str, Any] | None]]</code> <p>Three-by-two sequence indexed as <code>[axis][polarity_index]</code>. Entries are the dictionaries returned by <code>cpml_params(...)</code>; use <code>None</code> to disable CPML on one face.</p> required <code>dt</code> <code>float</code> <p>Timestep.</p> required <code>dxes</code> <code>dx_lists_t</code> <p>Yee-grid spacing lists <code>[dx_e, dx_h]</code>.</p> required <code>epsilon</code> <code>fdfield</code> <p>Electric material distribution used by the E update.</p> required <code>dtype</code> <code>DTypeLike</code> <p>Storage dtype for the auxiliary CPML state arrays.</p> <code>float32</code> <p>Returns:</p> Type Description <code>Callable[..., None]</code> <p><code>(update_E, update_H)</code> closures with the same call shape as the basic</p> <code>Callable[..., None]</code> <p>Yee updates:</p> <code>tuple[Callable[..., None], Callable[..., None]]</code> <ul> <li><code>update_E(e, h, epsilon)</code></li> </ul> <code>tuple[Callable[..., None], Callable[..., None]]</code> <ul> <li><code>update_H(e, h, mu)</code></li> </ul> <code>tuple[Callable[..., None], Callable[..., None]]</code> <p>The closures retain the CPML auxiliary state internally.</p>"},{"location":"api/fdtd/#meanas.fdtd.boundaries","title":"meanas.fdtd.boundaries","text":"<p>Boundary conditions</p>"},{"location":"api/fdtd/#meanas.fdtd.boundaries--todo-conducting-boundary-documentation","title":"TODO conducting boundary documentation","text":""},{"location":"api/fdtd/#meanas.fdtd.energy","title":"meanas.fdtd.energy","text":""},{"location":"api/fdtd/#meanas.fdtd.energy.poynting","title":"poynting","text":"<pre><code>poynting(\n e: fdfield, h: fdfield, dxes: dx_lists_t | None = None\n) -&gt; fdfield_t\n</code></pre> <p>Calculate the poynting vector <code>S</code> (\\(S\\)).</p> <p>This is the energy transfer rate (amount of energy <code>U</code> per <code>dt</code> transferred between adjacent cells) in each direction that happens during the half-step bounded by the two provided fields.</p> <p>The returned vector field <code>S</code> is the energy flow across +x, +y, and +z boundaries of the corresponding <code>U</code> cell. For example,</p> <pre><code> mx = numpy.roll(mask, -1, axis=0)\n my = numpy.roll(mask, -1, axis=1)\n mz = numpy.roll(mask, -1, axis=2)\n\n u_hstep = fdtd.energy_hstep(e0=es[ii - 1], h1=hs[ii], e2=es[ii], **args)\n u_estep = fdtd.energy_estep(h0=hs[ii], e1=es[ii], h2=hs[ii + 1], **args)\n delta_j_B = fdtd.delta_energy_j(j0=js[ii], e1=es[ii], dxes=dxes)\n du_half_h2e = u_estep - u_hstep - delta_j_B\n\n s_h2e = -fdtd.poynting(e=es[ii], h=hs[ii], dxes=dxes) * dt\n planes = [s_h2e[0, mask].sum(), -s_h2e[0, mx].sum(),\n s_h2e[1, mask].sum(), -s_h2e[1, my].sum(),\n s_h2e[2, mask].sum(), -s_h2e[2, mz].sum()]\n\n assert_close(sum(planes), du_half_h2e[mask])\n</code></pre> <p>(see <code>meanas.tests.test_fdtd.test_poynting_planes</code>)</p> <p>The full relationship is</p> \\[ \\begin{aligned} (U_{l+\\frac{1}{2}} - U_l) / \\Delta_t &amp;= -\\hat{\\nabla} \\cdot \\tilde{S}_{l, l + \\frac{1}{2}} \\\\ - \\hat{H}_{l+\\frac{1}{2}} \\cdot \\hat{M}_l \\\\ - \\tilde{E}_l \\cdot \\tilde{J}_{l+\\frac{1}{2}} \\\\ (U_l - U_{l-\\frac{1}{2}}) / \\Delta_t &amp;= -\\hat{\\nabla} \\cdot \\tilde{S}_{l, l - \\frac{1}{2}} \\\\ - \\hat{H}_{l-\\frac{1}{2}} \\cdot \\hat{M}_l \\\\ - \\tilde{E}_l \\cdot \\tilde{J}_{l-\\frac{1}{2}} \\\\ \\end{aligned} \\] <p>These equalities are exact and should practically hold to within numerical precision. No time- or spatial-averaging is necessary. (See <code>meanas.fdtd</code> docs for derivation.)</p> <p>Parameters:</p> Name Type Description Default <code>e</code> <code>fdfield</code> <p>E-field</p> required <code>h</code> <code>fdfield</code> <p>H-field (one half-timestep before or after <code>e</code>)</p> required <code>dxes</code> <code>dx_lists_t | None</code> <p>Grid description; see <code>meanas.fdmath</code>.</p> <code>None</code> <p>Returns:</p> Name Type Description <code>s</code> <code>fdfield_t</code> <p>Vector field. Components indicate the energy transfer rate from the corresponding energy cell into its +x, +y, and +z neighbors during the half-step from the time of the earlier input field until the time of later input field.</p>"},{"location":"api/fdtd/#meanas.fdtd.energy.poynting_divergence","title":"poynting_divergence","text":"<pre><code>poynting_divergence(\n s: fdfield | None = None,\n *,\n e: fdfield | None = None,\n h: fdfield | None = None,\n dxes: dx_lists_t | None = None,\n) -&gt; fdfield_t\n</code></pre> <p>Calculate the divergence of the poynting vector.</p> <p>This is the net energy flow for each cell, i.e. the change in energy <code>U</code> per <code>dt</code> caused by transfer of energy to nearby cells (rather than absorption/emission by currents <code>J</code> or <code>M</code>).</p> <p>See <code>poynting</code> and <code>meanas.fdtd</code> for more details. Args: s: Poynting vector, as calculated with <code>poynting</code>. Optional; caller can provide <code>e</code> and <code>h</code> instead. e: E-field (optional; need either <code>s</code> or both <code>e</code> and <code>h</code>) h: H-field (optional; need either <code>s</code> or both <code>e</code> and <code>h</code>) dxes: Grid description; see <code>meanas.fdmath</code>.</p> <p>Returns:</p> Name Type Description <code>ds</code> <code>fdfield_t</code> <p>Divergence of the poynting vector. Entries indicate the net energy flow out of the corresponding energy cell.</p>"},{"location":"api/fdtd/#meanas.fdtd.energy.energy_hstep","title":"energy_hstep","text":"<pre><code>energy_hstep(\n e0: fdfield,\n h1: fdfield,\n e2: fdfield,\n epsilon: fdfield | None = None,\n mu: fdfield | None = None,\n dxes: dx_lists_t | None = None,\n) -&gt; fdfield_t\n</code></pre> <p>Calculate energy <code>U</code> at the time of the provided H-field <code>h1</code>.</p> <p>TODO: Figure out what this means spatially.</p> <p>Parameters:</p> Name Type Description Default <code>e0</code> <code>fdfield</code> <p>E-field one half-timestep before the energy.</p> required <code>h1</code> <code>fdfield</code> <p>H-field (at the same timestep as the energy).</p> required <code>e2</code> <code>fdfield</code> <p>E-field one half-timestep after the energy.</p> required <code>epsilon</code> <code>fdfield | None</code> <p>Dielectric constant distribution.</p> <code>None</code> <code>mu</code> <code>fdfield | None</code> <p>Magnetic permeability distribution.</p> <code>None</code> <code>dxes</code> <code>dx_lists_t | None</code> <p>Grid description; see <code>meanas.fdmath</code>.</p> <code>None</code> <p>Returns:</p> Type Description <code>fdfield_t</code> <p>Energy, at the time of the H-field <code>h1</code>.</p>"},{"location":"api/fdtd/#meanas.fdtd.energy.energy_estep","title":"energy_estep","text":"<pre><code>energy_estep(\n h0: fdfield,\n e1: fdfield,\n h2: fdfield,\n epsilon: fdfield | None = None,\n mu: fdfield | None = None,\n dxes: dx_lists_t | None = None,\n) -&gt; fdfield_t\n</code></pre> <p>Calculate energy <code>U</code> at the time of the provided E-field <code>e1</code>.</p> <p>TODO: Figure out what this means spatially.</p> <p>Parameters:</p> Name Type Description Default <code>h0</code> <code>fdfield</code> <p>H-field one half-timestep before the energy.</p> required <code>e1</code> <code>fdfield</code> <p>E-field (at the same timestep as the energy).</p> required <code>h2</code> <code>fdfield</code> <p>H-field one half-timestep after the energy.</p> required <code>epsilon</code> <code>fdfield | None</code> <p>Dielectric constant distribution.</p> <code>None</code> <code>mu</code> <code>fdfield | None</code> <p>Magnetic permeability distribution.</p> <code>None</code> <code>dxes</code> <code>dx_lists_t | None</code> <p>Grid description; see <code>meanas.fdmath</code>.</p> <code>None</code> <p>Returns:</p> Type Description <code>fdfield_t</code> <p>Energy, at the time of the E-field <code>e1</code>.</p>"},{"location":"api/fdtd/#meanas.fdtd.energy.delta_energy_h2e","title":"delta_energy_h2e","text":"<pre><code>delta_energy_h2e(\n dt: float,\n e0: fdfield,\n h1: fdfield,\n e2: fdfield,\n h3: fdfield,\n epsilon: fdfield | None = None,\n mu: fdfield | None = None,\n dxes: dx_lists_t | None = None,\n) -&gt; fdfield_t\n</code></pre> <p>Change in energy during the half-step from <code>h1</code> to <code>e2</code>.</p> <p>This is just from (e2 * e2 + h3 * h1) - (h1 * h1 + e0 * e2)</p> <p>Parameters:</p> Name Type Description Default <code>e0</code> <code>fdfield</code> <p>E-field one half-timestep before the start of the energy delta.</p> required <code>h1</code> <code>fdfield</code> <p>H-field at the start of the energy delta.</p> required <code>e2</code> <code>fdfield</code> <p>E-field at the end of the energy delta (one half-timestep after <code>h1</code>).</p> required <code>h3</code> <code>fdfield</code> <p>H-field one half-timestep after the end of the energy delta.</p> required <code>epsilon</code> <code>fdfield | None</code> <p>Dielectric constant distribution.</p> <code>None</code> <code>mu</code> <code>fdfield | None</code> <p>Magnetic permeability distribution.</p> <code>None</code> <code>dxes</code> <code>dx_lists_t | None</code> <p>Grid description; see <code>meanas.fdmath</code>.</p> <code>None</code> <p>Returns:</p> Type Description <code>fdfield_t</code> <p>Change in energy from the time of <code>h1</code> to the time of <code>e2</code>.</p>"},{"location":"api/fdtd/#meanas.fdtd.energy.delta_energy_e2h","title":"delta_energy_e2h","text":"<pre><code>delta_energy_e2h(\n dt: float,\n h0: fdfield,\n e1: fdfield,\n h2: fdfield,\n e3: fdfield,\n epsilon: fdfield | None = None,\n mu: fdfield | None = None,\n dxes: dx_lists_t | None = None,\n) -&gt; fdfield_t\n</code></pre> <p>Change in energy during the half-step from <code>e1</code> to <code>h2</code>.</p> <p>This is just from (h2 * h2 + e3 * e1) - (e1 * e1 + h0 * h2)</p> <p>Parameters:</p> Name Type Description Default <code>h0</code> <code>fdfield</code> <p>E-field one half-timestep before the start of the energy delta.</p> required <code>e1</code> <code>fdfield</code> <p>H-field at the start of the energy delta.</p> required <code>h2</code> <code>fdfield</code> <p>E-field at the end of the energy delta (one half-timestep after <code>e1</code>).</p> required <code>e3</code> <code>fdfield</code> <p>H-field one half-timestep after the end of the energy delta.</p> required <code>epsilon</code> <code>fdfield | None</code> <p>Dielectric constant distribution.</p> <code>None</code> <code>mu</code> <code>fdfield | None</code> <p>Magnetic permeability distribution.</p> <code>None</code> <code>dxes</code> <code>dx_lists_t | None</code> <p>Grid description; see <code>meanas.fdmath</code>.</p> <code>None</code> <p>Returns:</p> Type Description <code>fdfield_t</code> <p>Change in energy from the time of <code>e1</code> to the time of <code>h2</code>.</p>"},{"location":"api/fdtd/#meanas.fdtd.energy.delta_energy_j","title":"delta_energy_j","text":"<pre><code>delta_energy_j(\n j0: fdfield, e1: fdfield, dxes: dx_lists_t | None = None\n) -&gt; fdfield_t\n</code></pre> <p>Calculate the electric-current work term \\(J \\cdot E\\) on the Yee grid.</p> <p>This is the source contribution that appears beside the flux divergence in the discrete Poynting identities documented in <code>meanas.fdtd</code>.</p> <p>Note that each value of <code>J</code> contributes twice in a full Yee cycle (once per half-step energy balance) even though it directly changes <code>E</code> only once.</p> <p>Parameters:</p> Name Type Description Default <code>j0</code> <code>fdfield</code> <p>Electric-current density sampled at the same half-step as the current work term.</p> required <code>e1</code> <code>fdfield</code> <p>Electric field sampled at the matching integer timestep.</p> required <code>dxes</code> <code>dx_lists_t | None</code> <p>Grid description; defaults to unit spacing.</p> <code>None</code> <p>Returns:</p> Type Description <code>fdfield_t</code> <p>Per-cell source-work contribution with the scalar field shape.</p>"},{"location":"api/fdtd/#meanas.fdtd.energy.dxmul","title":"dxmul","text":"<pre><code>dxmul(\n ee: fdfield,\n hh: fdfield,\n epsilon: fdfield | float | None = None,\n mu: fdfield | float | None = None,\n dxes: dx_lists_t | None = None,\n) -&gt; fdfield_t\n</code></pre> <p>Multiply E- and H-like field products by material weights and cell volumes.</p> <p>Parameters:</p> Name Type Description Default <code>ee</code> <code>fdfield</code> <p>Three-component electric-field product, such as <code>e0 * e2</code>.</p> required <code>hh</code> <code>fdfield</code> <p>Three-component magnetic-field product, such as <code>h1 * h1</code>.</p> required <code>epsilon</code> <code>fdfield | float | None</code> <p>Electric material weight; defaults to <code>1</code>.</p> <code>None</code> <code>mu</code> <code>fdfield | float | None</code> <p>Magnetic material weight; defaults to <code>1</code>.</p> <code>None</code> <code>dxes</code> <code>dx_lists_t | None</code> <p>Grid description; defaults to unit spacing.</p> <code>None</code> <p>Returns:</p> Type Description <code>fdfield_t</code> <p>Scalar field containing the weighted electric plus magnetic contribution</p> <code>fdfield_t</code> <p>for each Yee cell.</p>"},{"location":"api/fdtd/#meanas.fdtd.phasor","title":"meanas.fdtd.phasor","text":"<p>Helpers for extracting single- or multi-frequency phasors from FDTD samples.</p> <p>These helpers are intentionally low-level: callers own the accumulator arrays and the sampling policy. The accumulated quantity is</p> <pre><code>dt * sum(weight * exp(-1j * omega * t_step) * sample_step)\n</code></pre> <p>where <code>t_step = (step + offset_steps) * dt</code>.</p> <p>The usual Yee offsets are:</p> <ul> <li><code>accumulate_phasor_e(..., step=l)</code> for <code>E_l</code></li> <li><code>accumulate_phasor_h(..., step=l)</code> for <code>H_{l + 1/2}</code></li> <li><code>accumulate_phasor_j(..., step=l)</code> for <code>J_{l + 1/2}</code></li> </ul> <p><code>temporal_phasor(...)</code> and <code>temporal_phasor_scale(...)</code> apply the same Fourier sum to a 1D scalar waveform. They are useful for normalizing a pulsed source before that scalar waveform is applied to a point source or spatial mode source. <code>real_injection_scale(...)</code> is a companion helper for the common real-valued injection pattern <code>numpy.real(scale * waveform)</code>, where <code>waveform</code> is the analytic positive-frequency signal and the injected real current should still produce a desired phasor response. <code>reconstruct_real(...)</code> and its <code>E/H/J</code> wrappers perform the inverse operation: they turn one or more phasors back into real-valued field snapshots at explicit Yee-aligned sample times. For a scalar target frequency they accept either a plain field phasor or the batched <code>(1, *sample_shape)</code> form used elsewhere in this module.</p> <p>These helpers do not choose warmup/accumulation windows or pulse-envelope normalization. They also do not impose a current sign convention. In this codebase, electric-current injection normally appears as <code>E -= dt * J / epsilon</code>, which matches the FDFD right-hand side <code>-1j * omega * J</code>.</p>"},{"location":"api/fdtd/#meanas.fdtd.phasor.accumulate_phasor","title":"accumulate_phasor","text":"<pre><code>accumulate_phasor(\n accumulator: NDArray[complexfloating],\n omegas: float\n | complex\n | Sequence[float | complex]\n | NDArray,\n dt: float,\n sample: ArrayLike,\n step: int,\n *,\n offset_steps: float = 0.0,\n weight: ArrayLike = 1.0,\n) -&gt; NDArray[numpy.complexfloating]\n</code></pre> <p>Add one time-domain sample into a phasor accumulator.</p> <p>The added quantity is</p> <pre><code>dt * weight * exp(-1j * omega * t_step) * sample\n</code></pre> <p>where <code>t_step = (step + offset_steps) * dt</code>.</p> Note <p>This helper already multiplies by <code>dt</code>. If the caller's normalization factor was derived from a discrete sum that already includes <code>dt</code>, pass <code>weight / dt</code> here.</p>"},{"location":"api/fdtd/#meanas.fdtd.phasor.temporal_phasor","title":"temporal_phasor","text":"<pre><code>temporal_phasor(\n samples: ArrayLike,\n omegas: float\n | complex\n | Sequence[float | complex]\n | NDArray,\n dt: float,\n *,\n start_step: int = 0,\n offset_steps: float = 0.0,\n) -&gt; NDArray[numpy.complexfloating]\n</code></pre> <p>Fourier-project a 1D temporal waveform onto one or more angular frequencies.</p> <p>The returned quantity is</p> <pre><code>dt * sum(exp(-1j * omega * t_step) * samples[step_index])\n</code></pre> <p>where <code>t_step = (start_step + step_index + offset_steps) * dt</code>.</p>"},{"location":"api/fdtd/#meanas.fdtd.phasor.temporal_phasor_scale","title":"temporal_phasor_scale","text":"<pre><code>temporal_phasor_scale(\n samples: ArrayLike,\n omegas: float\n | complex\n | Sequence[float | complex]\n | NDArray,\n dt: float,\n *,\n start_step: int = 0,\n offset_steps: float = 0.0,\n target: ArrayLike = 1.0,\n) -&gt; NDArray[numpy.complexfloating]\n</code></pre> <p>Return the scalar multiplier that gives a desired temporal phasor response.</p> <p>The returned scale satisfies</p> <pre><code>temporal_phasor(scale * samples, omegas, dt, ...) == target\n</code></pre> <p>for each target frequency. The result keeps a leading frequency axis even when <code>omegas</code> is scalar.</p>"},{"location":"api/fdtd/#meanas.fdtd.phasor.real_injection_scale","title":"real_injection_scale","text":"<pre><code>real_injection_scale(\n samples: ArrayLike,\n omegas: float\n | complex\n | Sequence[float | complex]\n | NDArray,\n dt: float,\n *,\n start_step: int = 0,\n offset_steps: float = 0.0,\n target: ArrayLike = 1.0,\n) -&gt; NDArray[numpy.complexfloating]\n</code></pre> <p>Return the scale for a real-valued injection built from an analytic waveform.</p> <p>If the time-domain source is applied as</p> <pre><code>numpy.real(scale * samples[step])\n</code></pre> <p>then the desired positive-frequency phasor is obtained by compensating for the 1/2 factor between the real-valued source and its analytic component:</p> <pre><code>scale = 2 * target / temporal_phasor(samples, ...)\n</code></pre> <p>This helper normalizes only the intended positive-frequency component. Any residual negative-frequency leakage is controlled by the waveform design and the accumulation window.</p>"},{"location":"api/fdtd/#meanas.fdtd.phasor.reconstruct_real","title":"reconstruct_real","text":"<pre><code>reconstruct_real(\n phasors: ArrayLike,\n omegas: float\n | complex\n | Sequence[float | complex]\n | NDArray,\n dt: float,\n step: int,\n *,\n offset_steps: float = 0.0,\n) -&gt; NDArray[numpy.floating]\n</code></pre> <p>Reconstruct a real-valued field snapshot from one or more phasors.</p> <p>The returned quantity is</p> <pre><code>real(phasor * exp(1j * omega * t_step))\n</code></pre> <p>where <code>t_step = (step + offset_steps) * dt</code>.</p> <p>For multi-frequency inputs, the leading frequency axis is preserved. For a scalar <code>omega</code>, callers may pass either <code>(1, *sample_shape)</code> or <code>sample_shape</code>; the return shape matches that choice.</p>"},{"location":"api/fdtd/#meanas.fdtd.phasor.accumulate_phasor_e","title":"accumulate_phasor_e","text":"<pre><code>accumulate_phasor_e(\n accumulator: NDArray[complexfloating],\n omegas: float\n | complex\n | Sequence[float | complex]\n | NDArray,\n dt: float,\n sample: ArrayLike,\n step: int,\n *,\n weight: ArrayLike = 1.0,\n) -&gt; NDArray[numpy.complexfloating]\n</code></pre> <p>Accumulate an E-field sample taken at integer timestep <code>step</code>.</p>"},{"location":"api/fdtd/#meanas.fdtd.phasor.accumulate_phasor_h","title":"accumulate_phasor_h","text":"<pre><code>accumulate_phasor_h(\n accumulator: NDArray[complexfloating],\n omegas: float\n | complex\n | Sequence[float | complex]\n | NDArray,\n dt: float,\n sample: ArrayLike,\n step: int,\n *,\n weight: ArrayLike = 1.0,\n) -&gt; NDArray[numpy.complexfloating]\n</code></pre> <p>Accumulate an H-field sample corresponding to <code>H_{step + 1/2}</code>.</p>"},{"location":"api/fdtd/#meanas.fdtd.phasor.accumulate_phasor_j","title":"accumulate_phasor_j","text":"<pre><code>accumulate_phasor_j(\n accumulator: NDArray[complexfloating],\n omegas: float\n | complex\n | Sequence[float | complex]\n | NDArray,\n dt: float,\n sample: ArrayLike,\n step: int,\n *,\n weight: ArrayLike = 1.0,\n) -&gt; NDArray[numpy.complexfloating]\n</code></pre> <p>Accumulate a current sample corresponding to <code>J_{step + 1/2}</code>.</p>"},{"location":"api/fdtd/#meanas.fdtd.phasor.reconstruct_real_e","title":"reconstruct_real_e","text":"<pre><code>reconstruct_real_e(\n phasors: ArrayLike,\n omegas: float\n | complex\n | Sequence[float | complex]\n | NDArray,\n dt: float,\n step: int,\n) -&gt; NDArray[numpy.floating]\n</code></pre> <p>Reconstruct a real E-field snapshot taken at integer timestep <code>step</code>.</p>"},{"location":"api/fdtd/#meanas.fdtd.phasor.reconstruct_real_h","title":"reconstruct_real_h","text":"<pre><code>reconstruct_real_h(\n phasors: ArrayLike,\n omegas: float\n | complex\n | Sequence[float | complex]\n | NDArray,\n dt: float,\n step: int,\n) -&gt; NDArray[numpy.floating]\n</code></pre> <p>Reconstruct a real H-field snapshot corresponding to <code>H_{step + 1/2}</code>.</p>"},{"location":"api/fdtd/#meanas.fdtd.phasor.reconstruct_real_j","title":"reconstruct_real_j","text":"<pre><code>reconstruct_real_j(\n phasors: ArrayLike,\n omegas: float\n | complex\n | Sequence[float | complex]\n | NDArray,\n dt: float,\n step: int,\n) -&gt; NDArray[numpy.floating]\n</code></pre> <p>Reconstruct a real current snapshot corresponding to <code>J_{step + 1/2}</code>.</p>"},{"location":"api/meanas/","title":"meanas","text":""},{"location":"api/meanas/#meanas","title":"meanas","text":"<p>Electromagnetic simulation tools</p> <p>See the tracked examples for end-to-end workflows, and <code>help(meanas)</code> for the toolbox overview and API derivations.</p>"},{"location":"api/waveguides/","title":"waveguides","text":""},{"location":"api/waveguides/#meanas.fdfd.waveguide_2d","title":"meanas.fdfd.waveguide_2d","text":"<p>Operators and helper functions for waveguides with unchanging cross-section.</p> <p>The propagation direction is chosen to be along the z axis, and all fields are given an implicit z-dependence of the form <code>exp(-1 * wavenumber * z)</code>.</p> <p>As the z-dependence is known, all the functions in this file assume a 2D grid (i.e. <code>dxes = [[[dx_e[0], dx_e[1], ...], [dy_e[0], ...]], [[dx_h[0], ...], [dy_h[0], ...]]]</code>).</p> <p>===============</p> <p>Consider Maxwell's equations in continuous space, in the frequency domain. Assuming a structure with some (x, y) cross-section extending uniformly into the z dimension, with a diagonal \\(\\epsilon\\) tensor, we have</p> \\[ \\begin{aligned} \\nabla \\times \\vec{E}(x, y, z) &amp;= -\\imath \\omega \\mu \\vec{H} \\\\ \\nabla \\times \\vec{H}(x, y, z) &amp;= \\imath \\omega \\epsilon \\vec{E} \\\\ \\vec{E}(x,y,z) &amp;= (\\vec{E}_t(x, y) + E_z(x, y)\\vec{z}) e^{-\\imath \\beta z} \\\\ \\vec{H}(x,y,z) &amp;= (\\vec{H}_t(x, y) + H_z(x, y)\\vec{z}) e^{-\\imath \\beta z} \\\\ \\end{aligned} \\] <p>Expanding the first two equations into vector components, we get</p> \\[ \\begin{aligned} -\\imath \\omega \\mu_{xx} H_x &amp;= \\partial_y E_z - \\partial_z E_y \\\\ -\\imath \\omega \\mu_{yy} H_y &amp;= \\partial_z E_x - \\partial_x E_z \\\\ -\\imath \\omega \\mu_{zz} H_z &amp;= \\partial_x E_y - \\partial_y E_x \\\\ \\imath \\omega \\epsilon_{xx} E_x &amp;= \\partial_y H_z - \\partial_z H_y \\\\ \\imath \\omega \\epsilon_{yy} E_y &amp;= \\partial_z H_x - \\partial_x H_z \\\\ \\imath \\omega \\epsilon_{zz} E_z &amp;= \\partial_x H_y - \\partial_y H_x \\\\ \\end{aligned} \\] <p>Substituting in our expressions for \\(\\vec{E}\\), \\(\\vec{H}\\) and discretizing:</p> \\[ \\begin{aligned} -\\imath \\omega \\mu_{xx} H_x &amp;= \\tilde{\\partial}_y E_z + \\imath \\beta E_y \\\\ -\\imath \\omega \\mu_{yy} H_y &amp;= -\\imath \\beta E_x - \\tilde{\\partial}_x E_z \\\\ -\\imath \\omega \\mu_{zz} H_z &amp;= \\tilde{\\partial}_x E_y - \\tilde{\\partial}_y E_x \\\\ \\imath \\omega \\epsilon_{xx} E_x &amp;= \\hat{\\partial}_y H_z + \\imath \\beta H_y \\\\ \\imath \\omega \\epsilon_{yy} E_y &amp;= -\\imath \\beta H_x - \\hat{\\partial}_x H_z \\\\ \\imath \\omega \\epsilon_{zz} E_z &amp;= \\hat{\\partial}_x H_y - \\hat{\\partial}_y H_x \\\\ \\end{aligned} \\] <p>Rewrite the last three equations as</p> \\[ \\begin{aligned} \\imath \\beta H_y &amp;= \\imath \\omega \\epsilon_{xx} E_x - \\hat{\\partial}_y H_z \\\\ \\imath \\beta H_x &amp;= -\\imath \\omega \\epsilon_{yy} E_y - \\hat{\\partial}_x H_z \\\\ \\imath \\omega E_z &amp;= \\frac{1}{\\epsilon_{zz}} \\hat{\\partial}_x H_y - \\frac{1}{\\epsilon_{zz}} \\hat{\\partial}_y H_x \\\\ \\end{aligned} \\] <p>Now apply \\(\\imath \\beta \\tilde{\\partial}_x\\) to the last equation, then substitute in for \\(\\imath \\beta H_x\\) and \\(\\imath \\beta H_y\\):</p> \\[ \\begin{aligned} \\imath \\beta \\tilde{\\partial}_x \\imath \\omega E_z &amp;= \\imath \\beta \\tilde{\\partial}_x \\frac{1}{\\epsilon_{zz}} \\hat{\\partial}_x H_y - \\imath \\beta \\tilde{\\partial}_x \\frac{1}{\\epsilon_{zz}} \\hat{\\partial}_y H_x \\\\ &amp;= \\tilde{\\partial}_x \\frac{1}{\\epsilon_{zz}} \\hat{\\partial}_x ( \\imath \\omega \\epsilon_{xx} E_x - \\hat{\\partial}_y H_z) - \\tilde{\\partial}_x \\frac{1}{\\epsilon_{zz}} \\hat{\\partial}_y (-\\imath \\omega \\epsilon_{yy} E_y - \\hat{\\partial}_x H_z) \\\\ &amp;= \\tilde{\\partial}_x \\frac{1}{\\epsilon_{zz}} \\hat{\\partial}_x ( \\imath \\omega \\epsilon_{xx} E_x) - \\tilde{\\partial}_x \\frac{1}{\\epsilon_{zz}} \\hat{\\partial}_y (-\\imath \\omega \\epsilon_{yy} E_y) \\\\ \\imath \\beta \\tilde{\\partial}_x E_z &amp;= \\tilde{\\partial}_x \\frac{1}{\\epsilon_{zz}} \\hat{\\partial}_x (\\epsilon_{xx} E_x) + \\tilde{\\partial}_x \\frac{1}{\\epsilon_{zz}} \\hat{\\partial}_y (\\epsilon_{yy} E_y) \\\\ \\end{aligned} \\] <p>With a similar approach (but using \\(\\imath \\beta \\tilde{\\partial}_y\\) instead), we can get</p> \\[ \\begin{aligned} \\imath \\beta \\tilde{\\partial}_y E_z &amp;= \\tilde{\\partial}_y \\frac{1}{\\epsilon_{zz}} \\hat{\\partial}_x (\\epsilon_{xx} E_x) + \\tilde{\\partial}_y \\frac{1}{\\epsilon_{zz}} \\hat{\\partial}_y (\\epsilon_{yy} E_y) \\\\ \\end{aligned} \\] <p>We can combine this equation for \\(\\imath \\beta \\tilde{\\partial}_y E_z\\) with the unused \\(\\imath \\omega \\mu_{xx} H_x\\) and \\(\\imath \\omega \\mu_{yy} H_y\\) equations to get</p> \\[ \\begin{aligned} -\\imath \\omega \\mu_{xx} \\imath \\beta H_x &amp;= -\\beta^2 E_y + \\imath \\beta \\tilde{\\partial}_y E_z \\\\ -\\imath \\omega \\mu_{xx} \\imath \\beta H_x &amp;= -\\beta^2 E_y + \\tilde{\\partial}_y ( \\frac{1}{\\epsilon_{zz}} \\hat{\\partial}_x (\\epsilon_{xx} E_x) + \\frac{1}{\\epsilon_{zz}} \\hat{\\partial}_y (\\epsilon_{yy} E_y) )\\\\ \\end{aligned} \\] <p>and</p> \\[ \\begin{aligned} -\\imath \\omega \\mu_{yy} \\imath \\beta H_y &amp;= \\beta^2 E_x - \\imath \\beta \\tilde{\\partial}_x E_z \\\\ -\\imath \\omega \\mu_{yy} \\imath \\beta H_y &amp;= \\beta^2 E_x - \\tilde{\\partial}_x ( \\frac{1}{\\epsilon_{zz}} \\hat{\\partial}_x (\\epsilon_{xx} E_x) + \\frac{1}{\\epsilon_{zz}} \\hat{\\partial}_y (\\epsilon_{yy} E_y) )\\\\ \\end{aligned} \\] <p>However, based on our rewritten equation for \\(\\imath \\beta H_x\\) and the so-far unused equation for \\(\\imath \\omega \\mu_{zz} H_z\\) we can also write</p> \\[ \\begin{aligned} -\\imath \\omega \\mu_{xx} (\\imath \\beta H_x) &amp;= -\\imath \\omega \\mu_{xx} (-\\imath \\omega \\epsilon_{yy} E_y - \\hat{\\partial}_x H_z) \\\\ &amp;= -\\omega^2 \\mu_{xx} \\epsilon_{yy} E_y + \\imath \\omega \\mu_{xx} \\hat{\\partial}_x ( \\frac{1}{-\\imath \\omega \\mu_{zz}} (\\tilde{\\partial}_x E_y - \\tilde{\\partial}_y E_x)) \\\\ &amp;= -\\omega^2 \\mu_{xx} \\epsilon_{yy} E_y -\\mu_{xx} \\hat{\\partial}_x \\frac{1}{\\mu_{zz}} (\\tilde{\\partial}_x E_y - \\tilde{\\partial}_y E_x) \\\\ \\end{aligned} \\] <p>and, similarly,</p> \\[ \\begin{aligned} -\\imath \\omega \\mu_{yy} (\\imath \\beta H_y) &amp;= \\omega^2 \\mu_{yy} \\epsilon_{xx} E_x +\\mu_{yy} \\hat{\\partial}_y \\frac{1}{\\mu_{zz}} (\\tilde{\\partial}_x E_y - \\tilde{\\partial}_y E_x) \\\\ \\end{aligned} \\] <p>By combining both pairs of expressions, we get</p> \\[ \\begin{aligned} \\beta^2 E_x - \\tilde{\\partial}_x ( \\frac{1}{\\epsilon_{zz}} \\hat{\\partial}_x (\\epsilon_{xx} E_x) + \\frac{1}{\\epsilon_{zz}} \\hat{\\partial}_y (\\epsilon_{yy} E_y) ) &amp;= \\omega^2 \\mu_{yy} \\epsilon_{xx} E_x +\\mu_{yy} \\hat{\\partial}_y \\frac{1}{\\mu_{zz}} (\\tilde{\\partial}_x E_y - \\tilde{\\partial}_y E_x) \\\\ -\\beta^2 E_y + \\tilde{\\partial}_y ( \\frac{1}{\\epsilon_{zz}} \\hat{\\partial}_x (\\epsilon_{xx} E_x) + \\frac{1}{\\epsilon_{zz}} \\hat{\\partial}_y (\\epsilon_{yy} E_y) ) &amp;= -\\omega^2 \\mu_{xx} \\epsilon_{yy} E_y -\\mu_{xx} \\hat{\\partial}_x \\frac{1}{\\mu_{zz}} (\\tilde{\\partial}_x E_y - \\tilde{\\partial}_y E_x) \\\\ \\end{aligned} \\] <p>Using these, we can construct the eigenvalue problem</p> \\[ \\beta^2 \\begin{bmatrix} E_x \\\\ E_y \\end{bmatrix} = (\\omega^2 \\begin{bmatrix} \\mu_{yy} \\epsilon_{xx} &amp; 0 \\\\ 0 &amp; \\mu_{xx} \\epsilon_{yy} \\end{bmatrix} + \\begin{bmatrix} -\\mu_{yy} \\hat{\\partial}_y \\\\ \\mu_{xx} \\hat{\\partial}_x \\end{bmatrix} \\mu_{zz}^{-1} \\begin{bmatrix} -\\tilde{\\partial}_y &amp; \\tilde{\\partial}_x \\end{bmatrix} + \\begin{bmatrix} \\tilde{\\partial}_x \\\\ \\tilde{\\partial}_y \\end{bmatrix} \\epsilon_{zz}^{-1} \\begin{bmatrix} \\hat{\\partial}_x \\epsilon_{xx} &amp; \\hat{\\partial}_y \\epsilon_{yy} \\end{bmatrix}) \\begin{bmatrix} E_x \\\\ E_y \\end{bmatrix} \\] <p>In the literature, \\(\\beta\\) is usually used to denote the lossless/real part of the propagation constant, but in <code>meanas</code> it is allowed to be complex.</p> <p>An equivalent eigenvalue problem can be formed using the \\(H_x\\) and \\(H_y\\) fields, if those are more convenient.</p> <p>Note that \\(E_z\\) was never discretized, so \\(\\beta\\) will need adjustment to account for numerical dispersion if the result is introduced into a space with a discretized z-axis.</p>"},{"location":"api/waveguides/#meanas.fdfd.waveguide_2d.operator_e","title":"operator_e","text":"<pre><code>operator_e(\n omega: complex,\n dxes: dx_lists2_t,\n epsilon: vfdslice,\n mu: vfdslice | None = None,\n) -&gt; sparse.sparray\n</code></pre> <p>Waveguide operator of the form</p> <pre><code>omega**2 * mu * epsilon +\nmu * [[-Dy], [Dx]] / mu * [-Dy, Dx] +\n[[Dx], [Dy]] / epsilon * [Dx, Dy] * epsilon\n</code></pre> <p>for use with a field vector of the form <code>cat([E_x, E_y])</code>.</p> <p>More precisely, the operator is</p> \\[ \\omega^2 \\begin{bmatrix} \\mu_{yy} \\epsilon_{xx} &amp; 0 \\\\ 0 &amp; \\mu_{xx} \\epsilon_{yy} \\end{bmatrix} + \\begin{bmatrix} -\\mu_{yy} \\hat{\\partial}_y \\\\ \\mu_{xx} \\hat{\\partial}_x \\end{bmatrix} \\mu_{zz}^{-1} \\begin{bmatrix} -\\tilde{\\partial}_y &amp; \\tilde{\\partial}_x \\end{bmatrix} + \\begin{bmatrix} \\tilde{\\partial}_x \\\\ \\tilde{\\partial}_y \\end{bmatrix} \\epsilon_{zz}^{-1} \\begin{bmatrix} \\hat{\\partial}_x \\epsilon_{xx} &amp; \\hat{\\partial}_y \\epsilon_{yy} \\end{bmatrix} \\] <p>\\(\\tilde{\\partial}_x\\) and \\(\\hat{\\partial}_x\\) are the forward and backward derivatives along x, and each \\(\\epsilon_{xx}\\), \\(\\mu_{yy}\\), etc. is a diagonal matrix containing the vectorized material property distribution.</p> <p>This operator can be used to form an eigenvalue problem of the form <code>operator_e(...) @ [E_x, E_y] = wavenumber**2 * [E_x, E_y]</code></p> <p>which can then be solved for the eigenmodes of the system (an <code>exp(-i * wavenumber * z)</code> z-dependence is assumed for the fields).</p> <p>Parameters:</p> Name Type Description Default <code>omega</code> <code>complex</code> <p>The angular frequency of the system.</p> required <code>dxes</code> <code>dx_lists2_t</code> <p>Grid parameters <code>[dx_e, dx_h]</code> as described in <code>meanas.fdmath.types</code> (2D)</p> required <code>epsilon</code> <code>vfdslice</code> <p>Vectorized dielectric constant grid</p> required <code>mu</code> <code>vfdslice | None</code> <p>Vectorized magnetic permeability grid (default 1 everywhere)</p> <code>None</code> <p>Returns:</p> Type Description <code>sparray</code> <p>Sparse matrix representation of the operator.</p>"},{"location":"api/waveguides/#meanas.fdfd.waveguide_2d.operator_h","title":"operator_h","text":"<pre><code>operator_h(\n omega: complex,\n dxes: dx_lists2_t,\n epsilon: vfdslice,\n mu: vfdslice | None = None,\n) -&gt; sparse.sparray\n</code></pre> <p>Waveguide operator of the form</p> <pre><code>omega**2 * epsilon * mu +\nepsilon * [[-Dy], [Dx]] / epsilon * [-Dy, Dx] +\n[[Dx], [Dy]] / mu * [Dx, Dy] * mu\n</code></pre> <p>for use with a field vector of the form <code>cat([H_x, H_y])</code>.</p> <p>More precisely, the operator is</p> \\[ \\omega^2 \\begin{bmatrix} \\epsilon_{yy} \\mu_{xx} &amp; 0 \\\\ 0 &amp; \\epsilon_{xx} \\mu_{yy} \\end{bmatrix} + \\begin{bmatrix} -\\epsilon_{yy} \\tilde{\\partial}_y \\\\ \\epsilon_{xx} \\tilde{\\partial}_x \\end{bmatrix} \\epsilon_{zz}^{-1} \\begin{bmatrix} -\\hat{\\partial}_y &amp; \\hat{\\partial}_x \\end{bmatrix} + \\begin{bmatrix} \\hat{\\partial}_x \\\\ \\hat{\\partial}_y \\end{bmatrix} \\mu_{zz}^{-1} \\begin{bmatrix} \\tilde{\\partial}_x \\mu_{xx} &amp; \\tilde{\\partial}_y \\mu_{yy} \\end{bmatrix} \\] <p>\\(\\tilde{\\partial}_x\\) and \\(\\hat{\\partial}_x\\) are the forward and backward derivatives along x, and each \\(\\epsilon_{xx}\\), \\(\\mu_{yy}\\), etc. is a diagonal matrix containing the vectorized material property distribution.</p> <p>This operator can be used to form an eigenvalue problem of the form <code>operator_h(...) @ [H_x, H_y] = wavenumber**2 * [H_x, H_y]</code></p> <p>which can then be solved for the eigenmodes of the system (an <code>exp(-i * wavenumber * z)</code> z-dependence is assumed for the fields).</p> <p>Parameters:</p> Name Type Description Default <code>omega</code> <code>complex</code> <p>The angular frequency of the system.</p> required <code>dxes</code> <code>dx_lists2_t</code> <p>Grid parameters <code>[dx_e, dx_h]</code> as described in <code>meanas.fdmath.types</code> (2D)</p> required <code>epsilon</code> <code>vfdslice</code> <p>Vectorized dielectric constant grid</p> required <code>mu</code> <code>vfdslice | None</code> <p>Vectorized magnetic permeability grid (default 1 everywhere)</p> <code>None</code> <p>Returns:</p> Type Description <code>sparray</code> <p>Sparse matrix representation of the operator.</p>"},{"location":"api/waveguides/#meanas.fdfd.waveguide_2d.normalized_fields_e","title":"normalized_fields_e","text":"<pre><code>normalized_fields_e(\n e_xy: vcfdfield2,\n wavenumber: complex,\n omega: complex,\n dxes: dx_lists2_t,\n epsilon: vfdslice,\n mu: vfdslice | None = None,\n prop_phase: float = 0,\n) -&gt; tuple[vcfdslice_t, vcfdslice_t]\n</code></pre> <p>Given a vector <code>e_xy</code> containing the vectorized E_x and E_y fields, returns normalized, vectorized E and H fields for the system.</p> <p>Parameters:</p> Name Type Description Default <code>e_xy</code> <code>vcfdfield2</code> <p>Vector containing E_x and E_y fields</p> required <code>wavenumber</code> <code>complex</code> <p>Wavenumber assuming fields have z-dependence of <code>exp(-i * wavenumber * z)</code>. It should satisfy <code>operator_e() @ e_xy == wavenumber**2 * e_xy</code></p> required <code>omega</code> <code>complex</code> <p>The angular frequency of the system</p> required <code>dxes</code> <code>dx_lists2_t</code> <p>Grid parameters <code>[dx_e, dx_h]</code> as described in <code>meanas.fdmath.types</code> (2D)</p> required <code>epsilon</code> <code>vfdslice</code> <p>Vectorized dielectric constant grid</p> required <code>mu</code> <code>vfdslice | None</code> <p>Vectorized magnetic permeability grid (default 1 everywhere)</p> <code>None</code> <code>prop_phase</code> <code>float</code> <p>Phase shift <code>(dz * corrected_wavenumber)</code> over 1 cell in propagation direction. Default 0 (continuous propagation direction, i.e. dz-&gt;0).</p> <code>0</code> <p>Returns:</p> Type Description <code>vcfdslice_t</code> <p><code>(e, h)</code>, where each field is vectorized, normalized,</p> <code>vcfdslice_t</code> <p>and contains all three vector components.</p> Notes <p><code>e_xy</code> is only the transverse electric eigenvector. This helper first reconstructs the full three-component <code>E</code> and <code>H</code> fields with <code>exy2e(...)</code> and <code>exy2h(...)</code>, then normalizes them to unit forward power using <code>_normalized_fields(...)</code>.</p> <p>The normalization target is</p> \\[ \\Re\\left[\\mathrm{inner\\_product}(e, h, \\mathrm{conj\\_h}=True)\\right] = 1, \\] <p>so the returned fields represent a unit-power forward mode under the discrete Yee-grid Poynting inner product.</p>"},{"location":"api/waveguides/#meanas.fdfd.waveguide_2d.normalized_fields_h","title":"normalized_fields_h","text":"<pre><code>normalized_fields_h(\n h_xy: vcfdfield2,\n wavenumber: complex,\n omega: complex,\n dxes: dx_lists2_t,\n epsilon: vfdslice,\n mu: vfdslice | None = None,\n prop_phase: float = 0,\n) -&gt; tuple[vcfdslice_t, vcfdslice_t]\n</code></pre> <p>Given a vector <code>h_xy</code> containing the vectorized H_x and H_y fields, returns normalized, vectorized E and H fields for the system.</p> <p>Parameters:</p> Name Type Description Default <code>h_xy</code> <code>vcfdfield2</code> <p>Vector containing H_x and H_y fields</p> required <code>wavenumber</code> <code>complex</code> <p>Wavenumber assuming fields have z-dependence of <code>exp(-i * wavenumber * z)</code>. It should satisfy <code>operator_h() @ h_xy == wavenumber**2 * h_xy</code></p> required <code>omega</code> <code>complex</code> <p>The angular frequency of the system</p> required <code>dxes</code> <code>dx_lists2_t</code> <p>Grid parameters <code>[dx_e, dx_h]</code> as described in <code>meanas.fdmath.types</code> (2D)</p> required <code>epsilon</code> <code>vfdslice</code> <p>Vectorized dielectric constant grid</p> required <code>mu</code> <code>vfdslice | None</code> <p>Vectorized magnetic permeability grid (default 1 everywhere)</p> <code>None</code> <code>prop_phase</code> <code>float</code> <p>Phase shift <code>(dz * corrected_wavenumber)</code> over 1 cell in propagation direction. Default 0 (continuous propagation direction, i.e. dz-&gt;0).</p> <code>0</code> <p>Returns:</p> Type Description <code>vcfdslice_t</code> <p><code>(e, h)</code>, where each field is vectorized, normalized,</p> <code>vcfdslice_t</code> <p>and contains all three vector components.</p> Notes <p>This is the <code>H_x/H_y</code> analogue of <code>normalized_fields_e(...)</code>. The final normalized mode should describe the same physical solution, but because the overall complex phase and sign are chosen heuristically, <code>normalized_fields_e(...)</code> and <code>normalized_fields_h(...)</code> need not return identical representatives for nearly symmetric modes.</p>"},{"location":"api/waveguides/#meanas.fdfd.waveguide_2d.exy2h","title":"exy2h","text":"<pre><code>exy2h(\n wavenumber: complex,\n omega: complex,\n dxes: dx_lists2_t,\n epsilon: vfdslice,\n mu: vfdslice | None = None,\n) -&gt; sparse.sparray\n</code></pre> <p>Operator which transforms the vector <code>e_xy</code> containing the vectorized E_x and E_y fields, into a vectorized H containing all three H components</p> <p>Parameters:</p> Name Type Description Default <code>wavenumber</code> <code>complex</code> <p>Wavenumber assuming fields have z-dependence of <code>exp(-i * wavenumber * z)</code>. It should satisfy <code>operator_e() @ e_xy == wavenumber**2 * e_xy</code></p> required <code>omega</code> <code>complex</code> <p>The angular frequency of the system</p> required <code>dxes</code> <code>dx_lists2_t</code> <p>Grid parameters <code>[dx_e, dx_h]</code> as described in <code>meanas.fdmath.types</code> (2D)</p> required <code>epsilon</code> <code>vfdslice</code> <p>Vectorized dielectric constant grid</p> required <code>mu</code> <code>vfdslice | None</code> <p>Vectorized magnetic permeability grid (default 1 everywhere)</p> <code>None</code> <p>Returns:</p> Type Description <code>sparray</code> <p>Sparse matrix representing the operator.</p>"},{"location":"api/waveguides/#meanas.fdfd.waveguide_2d.hxy2e","title":"hxy2e","text":"<pre><code>hxy2e(\n wavenumber: complex,\n omega: complex,\n dxes: dx_lists2_t,\n epsilon: vfdslice,\n mu: vfdslice | None = None,\n) -&gt; sparse.sparray\n</code></pre> <p>Operator which transforms the vector <code>h_xy</code> containing the vectorized H_x and H_y fields, into a vectorized E containing all three E components</p> <p>Parameters:</p> Name Type Description Default <code>wavenumber</code> <code>complex</code> <p>Wavenumber assuming fields have z-dependence of <code>exp(-i * wavenumber * z)</code>. It should satisfy <code>operator_h() @ h_xy == wavenumber**2 * h_xy</code></p> required <code>omega</code> <code>complex</code> <p>The angular frequency of the system</p> required <code>dxes</code> <code>dx_lists2_t</code> <p>Grid parameters <code>[dx_e, dx_h]</code> as described in <code>meanas.fdmath.types</code> (2D)</p> required <code>epsilon</code> <code>vfdslice</code> <p>Vectorized dielectric constant grid</p> required <code>mu</code> <code>vfdslice | None</code> <p>Vectorized magnetic permeability grid (default 1 everywhere)</p> <code>None</code> <p>Returns:</p> Type Description <code>sparray</code> <p>Sparse matrix representing the operator.</p>"},{"location":"api/waveguides/#meanas.fdfd.waveguide_2d.hxy2h","title":"hxy2h","text":"<pre><code>hxy2h(\n wavenumber: complex,\n dxes: dx_lists2_t,\n mu: vfdslice | None = None,\n) -&gt; sparse.sparray\n</code></pre> <p>Operator which transforms the vector <code>h_xy</code> containing the vectorized H_x and H_y fields, into a vectorized H containing all three H components</p> <p>Parameters:</p> Name Type Description Default <code>wavenumber</code> <code>complex</code> <p>Wavenumber assuming fields have z-dependence of <code>exp(-i * wavenumber * z)</code>. It should satisfy <code>operator_h() @ h_xy == wavenumber**2 * h_xy</code></p> required <code>dxes</code> <code>dx_lists2_t</code> <p>Grid parameters <code>[dx_e, dx_h]</code> as described in <code>meanas.fdmath.types</code> (2D)</p> required <code>mu</code> <code>vfdslice | None</code> <p>Vectorized magnetic permeability grid (default 1 everywhere)</p> <code>None</code> <p>Returns:</p> Type Description <code>sparray</code> <p>Sparse matrix representing the operator.</p>"},{"location":"api/waveguides/#meanas.fdfd.waveguide_2d.exy2e","title":"exy2e","text":"<pre><code>exy2e(\n wavenumber: complex,\n dxes: dx_lists2_t,\n epsilon: vfdslice,\n) -&gt; sparse.sparray\n</code></pre> <p>Operator which transforms the vector <code>e_xy</code> containing the vectorized E_x and E_y fields, into a vectorized E containing all three E components</p> <p>From the operator derivation (see module docs), we have</p> \\[ \\imath \\omega \\epsilon_{zz} E_z = \\hat{\\partial}_x H_y - \\hat{\\partial}_y H_x \\\\ \\] <p>as well as the intermediate equations</p> \\[ \\begin{aligned} \\imath \\beta H_y &amp;= \\imath \\omega \\epsilon_{xx} E_x - \\hat{\\partial}_y H_z \\\\ \\imath \\beta H_x &amp;= -\\imath \\omega \\epsilon_{yy} E_y - \\hat{\\partial}_x H_z \\\\ \\end{aligned} \\] <p>Combining these, we get</p> \\[ \\begin{aligned} E_z &amp;= \\frac{1}{- \\omega \\beta \\epsilon_{zz}} (( \\hat{\\partial}_y \\hat{\\partial}_x H_z -\\hat{\\partial}_x \\hat{\\partial}_y H_z) + \\imath \\omega (\\hat{\\partial}_x \\epsilon_{xx} E_x + \\hat{\\partial}_y \\epsilon{yy} E_y)) &amp;= \\frac{1}{\\imath \\beta \\epsilon_{zz}} (\\hat{\\partial}_x \\epsilon_{xx} E_x + \\hat{\\partial}_y \\epsilon{yy} E_y) \\end{aligned} \\] <p>Parameters:</p> Name Type Description Default <code>wavenumber</code> <code>complex</code> <p>Wavenumber assuming fields have z-dependence of <code>exp(-i * wavenumber * z)</code> It should satisfy <code>operator_e() @ e_xy == wavenumber**2 * e_xy</code></p> required <code>dxes</code> <code>dx_lists2_t</code> <p>Grid parameters <code>[dx_e, dx_h]</code> as described in <code>meanas.fdmath.types</code> (2D)</p> required <code>epsilon</code> <code>vfdslice</code> <p>Vectorized dielectric constant grid</p> required <p>Returns:</p> Type Description <code>sparray</code> <p>Sparse matrix representing the operator.</p>"},{"location":"api/waveguides/#meanas.fdfd.waveguide_2d.e2h","title":"e2h","text":"<pre><code>e2h(\n wavenumber: complex,\n omega: complex,\n dxes: dx_lists2_t,\n mu: vfdslice | None = None,\n) -&gt; sparse.sparray\n</code></pre> <p>Returns an operator which, when applied to a vectorized E eigenfield, produces the vectorized H eigenfield slice.</p> <p>Parameters:</p> Name Type Description Default <code>wavenumber</code> <code>complex</code> <p>Wavenumber assuming fields have z-dependence of <code>exp(-i * wavenumber * z)</code></p> required <code>omega</code> <code>complex</code> <p>The angular frequency of the system</p> required <code>dxes</code> <code>dx_lists2_t</code> <p>Grid parameters <code>[dx_e, dx_h]</code> as described in <code>meanas.fdmath.types</code> (2D)</p> required <code>mu</code> <code>vfdslice | None</code> <p>Vectorized magnetic permeability grid (default 1 everywhere)</p> <code>None</code> <p>Returns:</p> Type Description <code>sparray</code> <p>Sparse matrix representation of the operator.</p>"},{"location":"api/waveguides/#meanas.fdfd.waveguide_2d.h2e","title":"h2e","text":"<pre><code>h2e(\n wavenumber: complex,\n omega: complex,\n dxes: dx_lists2_t,\n epsilon: vfdslice,\n) -&gt; sparse.sparray\n</code></pre> <p>Returns an operator which, when applied to a vectorized H eigenfield, produces the vectorized E eigenfield slice.</p> <p>Parameters:</p> Name Type Description Default <code>wavenumber</code> <code>complex</code> <p>Wavenumber assuming fields have z-dependence of <code>exp(-i * wavenumber * z)</code></p> required <code>omega</code> <code>complex</code> <p>The angular frequency of the system</p> required <code>dxes</code> <code>dx_lists2_t</code> <p>Grid parameters <code>[dx_e, dx_h]</code> as described in <code>meanas.fdmath.types</code> (2D)</p> required <code>epsilon</code> <code>vfdslice</code> <p>Vectorized dielectric constant grid</p> required <p>Returns:</p> Type Description <code>sparray</code> <p>Sparse matrix representation of the operator.</p>"},{"location":"api/waveguides/#meanas.fdfd.waveguide_2d.curl_e","title":"curl_e","text":"<pre><code>curl_e(\n wavenumber: complex, dxes: dx_lists2_t\n) -&gt; sparse.sparray\n</code></pre> <p>Discretized curl operator for use with the waveguide E field slice.</p> <p>Parameters:</p> Name Type Description Default <code>wavenumber</code> <code>complex</code> <p>Wavenumber assuming fields have z-dependence of <code>exp(-i * wavenumber * z)</code></p> required <code>dxes</code> <code>dx_lists2_t</code> <p>Grid parameters <code>[dx_e, dx_h]</code> as described in <code>meanas.fdmath.types</code> (2D)</p> required <p>Returns:</p> Type Description <code>sparray</code> <p>Sparse matrix representation of the operator.</p>"},{"location":"api/waveguides/#meanas.fdfd.waveguide_2d.curl_h","title":"curl_h","text":"<pre><code>curl_h(\n wavenumber: complex, dxes: dx_lists2_t\n) -&gt; sparse.sparray\n</code></pre> <p>Discretized curl operator for use with the waveguide H field slice.</p> <p>Parameters:</p> Name Type Description Default <code>wavenumber</code> <code>complex</code> <p>Wavenumber assuming fields have z-dependence of <code>exp(-i * wavenumber * z)</code></p> required <code>dxes</code> <code>dx_lists2_t</code> <p>Grid parameters <code>[dx_e, dx_h]</code> as described in <code>meanas.fdmath.types</code> (2D)</p> required <p>Returns:</p> Type Description <code>sparray</code> <p>Sparse matrix representation of the operator.</p>"},{"location":"api/waveguides/#meanas.fdfd.waveguide_2d.h_err","title":"h_err","text":"<pre><code>h_err(\n h: vcfdslice,\n wavenumber: complex,\n omega: complex,\n dxes: dx_lists2_t,\n epsilon: vfdslice,\n mu: vfdslice | None = None,\n) -&gt; float\n</code></pre> <p>Calculates the relative error in the H field</p> <p>Parameters:</p> Name Type Description Default <code>h</code> <code>vcfdslice</code> <p>Vectorized H field</p> required <code>wavenumber</code> <code>complex</code> <p>Wavenumber assuming fields have z-dependence of <code>exp(-i * wavenumber * z)</code></p> required <code>omega</code> <code>complex</code> <p>The angular frequency of the system</p> required <code>dxes</code> <code>dx_lists2_t</code> <p>Grid parameters <code>[dx_e, dx_h]</code> as described in <code>meanas.fdmath.types</code> (2D)</p> required <code>epsilon</code> <code>vfdslice</code> <p>Vectorized dielectric constant grid</p> required <code>mu</code> <code>vfdslice | None</code> <p>Vectorized magnetic permeability grid (default 1 everywhere)</p> <code>None</code> <p>Returns:</p> Type Description <code>float</code> <p>Relative error <code>norm(A_h @ h) / norm(h)</code>.</p>"},{"location":"api/waveguides/#meanas.fdfd.waveguide_2d.e_err","title":"e_err","text":"<pre><code>e_err(\n e: vcfdslice,\n wavenumber: complex,\n omega: complex,\n dxes: dx_lists2_t,\n epsilon: vfdslice,\n mu: vfdslice | None = None,\n) -&gt; float\n</code></pre> <p>Calculates the relative error in the E field</p> <p>Parameters:</p> Name Type Description Default <code>e</code> <code>vcfdslice</code> <p>Vectorized E field</p> required <code>wavenumber</code> <code>complex</code> <p>Wavenumber assuming fields have z-dependence of <code>exp(-i * wavenumber * z)</code></p> required <code>omega</code> <code>complex</code> <p>The angular frequency of the system</p> required <code>dxes</code> <code>dx_lists2_t</code> <p>Grid parameters <code>[dx_e, dx_h]</code> as described in <code>meanas.fdmath.types</code> (2D)</p> required <code>epsilon</code> <code>vfdslice</code> <p>Vectorized dielectric constant grid</p> required <code>mu</code> <code>vfdslice | None</code> <p>Vectorized magnetic permeability grid (default 1 everywhere)</p> <code>None</code> <p>Returns:</p> Type Description <code>float</code> <p>Relative error <code>norm(A_e @ e) / norm(e)</code>.</p>"},{"location":"api/waveguides/#meanas.fdfd.waveguide_2d.sensitivity","title":"sensitivity","text":"<pre><code>sensitivity(\n e_norm: vcfdslice,\n h_norm: vcfdslice,\n wavenumber: complex,\n omega: complex,\n dxes: dx_lists2_t,\n epsilon: vfdslice,\n mu: vfdslice | None = None,\n) -&gt; vcfdslice_t\n</code></pre> <p>Given a waveguide structure (<code>dxes</code>, <code>epsilon</code>, <code>mu</code>) and mode fields (<code>e_norm</code>, <code>h_norm</code>, <code>wavenumber</code>, <code>omega</code>), calculates the sensitivity of the wavenumber \\(\\beta\\) to changes in the dielectric structure \\(\\epsilon\\).</p> <p>The output is a vector of the same size as <code>vec(epsilon)</code>, with each element specifying the sensitivity of <code>wavenumber</code> to changes in the corresponding element in <code>vec(epsilon)</code>, i.e.</p> \\[ sens_{i} = \\frac{\\partial\\beta}{\\partial\\epsilon_i} \\] <p>An adjoint approach is used to calculate the sensitivity; the derivation is provided here:</p> <p>Starting with the eigenvalue equation</p> \\[ \\beta^2 E_{xy} = A_E E_{xy} \\] <p>where \\(A_E\\) is the waveguide operator from <code>operator_e()</code>, and \\(E_{xy} = \\begin{bmatrix} E_x \\\\ E_y \\end{bmatrix}\\), we can differentiate with respect to one of the \\(\\epsilon\\) elements (i.e. at one Yee grid point), \\(\\epsilon_i\\):</p> \\[ (2 \\beta) \\partial_{\\epsilon_i}(\\beta) E_{xy} + \\beta^2 \\partial_{\\epsilon_i} E_{xy} = \\partial_{\\epsilon_i}(A_E) E_{xy} + A_E \\partial_{\\epsilon_i} E_{xy} \\] <p>We then multiply by \\(H_{yx}^\\star = \\begin{bmatrix}H_y^\\star \\\\ -H_x^\\star \\end{bmatrix}\\) from the left:</p> \\[ (2 \\beta) \\partial_{\\epsilon_i}(\\beta) H_{yx}^\\star E_{xy} + \\beta^2 H_{yx}^\\star \\partial_{\\epsilon_i} E_{xy} = H_{yx}^\\star \\partial_{\\epsilon_i}(A_E) E_{xy} + H_{yx}^\\star A_E \\partial_{\\epsilon_i} E_{xy} \\] <p>However, \\(H_{yx}^\\star\\) is actually a left-eigenvector of \\(A_E\\). This can be verified by inspecting the form of <code>operator_h</code> (\\(A_H\\)) and comparing its conjugate transpose to <code>operator_e</code> (\\(A_E\\)). Also, note \\(H_{yx}^\\star \\cdot E_{xy} = H^\\star \\times E\\) recalls the mode orthogonality relation. See doi:10.5194/ars-9-85-201 for a similar approach. Therefore,</p> \\[ H_{yx}^\\star A_E \\partial_{\\epsilon_i} E_{xy} = \\beta^2 H_{yx}^\\star \\partial_{\\epsilon_i} E_{xy} \\] <p>and we can simplify to</p> \\[ \\partial_{\\epsilon_i}(\\beta) = \\frac{1}{2 \\beta} \\frac{H_{yx}^\\star \\partial_{\\epsilon_i}(A_E) E_{xy} }{H_{yx}^\\star E_{xy}} \\] <p>This expression can be quickly calculated for all \\(i\\) by writing out the various terms of \\(\\partial_{\\epsilon_i} A_E\\) and recognizing that the vector-matrix-vector products (i.e. scalars) \\(sens_i = \\vec{v}_{left} \\partial_{\\epsilon_i} (\\epsilon_{xyz}) \\vec{v}_{right}\\), indexed by \\(i\\), can be expressed as elementwise multiplications \\(\\vec{sens} = \\vec{v}_{left} \\star \\vec{v}_{right}\\)</p> <p>Parameters:</p> Name Type Description Default <code>e_norm</code> <code>vcfdslice</code> <p>Normalized, vectorized E_xyz field for the mode. E.g. as returned by <code>normalized_fields_e</code>.</p> required <code>h_norm</code> <code>vcfdslice</code> <p>Normalized, vectorized H_xyz field for the mode. E.g. as returned by <code>normalized_fields_e</code>.</p> required <code>wavenumber</code> <code>complex</code> <p>Propagation constant for the mode. The z-axis is assumed to be continuous (i.e. without numerical dispersion).</p> required <code>omega</code> <code>complex</code> <p>The angular frequency of the system.</p> required <code>dxes</code> <code>dx_lists2_t</code> <p>Grid parameters <code>[dx_e, dx_h]</code> as described in <code>meanas.fdmath.types</code> (2D)</p> required <code>epsilon</code> <code>vfdslice</code> <p>Vectorized dielectric constant grid</p> required <code>mu</code> <code>vfdslice | None</code> <p>Vectorized magnetic permeability grid (default 1 everywhere)</p> <code>None</code> <p>Returns:</p> Type Description <code>vcfdslice_t</code> <p>Sparse matrix representation of the operator.</p>"},{"location":"api/waveguides/#meanas.fdfd.waveguide_2d.solve_modes","title":"solve_modes","text":"<pre><code>solve_modes(\n mode_numbers: Sequence[int],\n omega: complex,\n dxes: dx_lists2_t,\n epsilon: vfdslice,\n mu: vfdslice | None = None,\n mode_margin: int = 2,\n) -&gt; tuple[\n NDArray[numpy.complex128], NDArray[numpy.complex128]\n]\n</code></pre> <p>Given a 2D region, attempts to solve for the eigenmode with the specified mode numbers.</p> <p>Parameters:</p> Name Type Description Default <code>mode_numbers</code> <code>Sequence[int]</code> <p>List of 0-indexed mode numbers to solve for</p> required <code>omega</code> <code>complex</code> <p>Angular frequency of the simulation</p> required <code>dxes</code> <code>dx_lists2_t</code> <p>Grid parameters <code>[dx_e, dx_h]</code> as described in <code>meanas.fdmath.types</code></p> required <code>epsilon</code> <code>vfdslice</code> <p>Dielectric constant</p> required <code>mu</code> <code>vfdslice | None</code> <p>Magnetic permeability (default 1 everywhere)</p> <code>None</code> <code>mode_margin</code> <code>int</code> <p>The eigensolver will actually solve for <code>(max(mode_number) + mode_margin)</code> modes, but only return the target mode. Increasing this value can improve the solver's ability to find the correct mode. Default 2.</p> <code>2</code> <p>Returns:</p> Name Type Description <code>e_xys</code> <code>NDArray[complex128]</code> <p>NDArray of vfdfield_t specifying fields. First dimension is mode number.</p> <code>wavenumbers</code> <code>NDArray[complex128]</code> <p>list of wavenumbers</p>"},{"location":"api/waveguides/#meanas.fdfd.waveguide_2d.solve_mode","title":"solve_mode","text":"<pre><code>solve_mode(\n mode_number: int, *args: Any, **kwargs: Any\n) -&gt; tuple[vcfdfield2_t, complex]\n</code></pre> <p>Wrapper around <code>solve_modes()</code> that solves for a single mode.</p> <p>Parameters:</p> Name Type Description Default <code>mode_number</code> <code>int</code> <p>0-indexed mode number to solve for</p> required <code>*args</code> <code>Any</code> <p>passed to <code>solve_modes()</code></p> <code>()</code> <code>**kwargs</code> <code>Any</code> <p>passed to <code>solve_modes()</code></p> <code>{}</code> <p>Returns:</p> Type Description <code>tuple[vcfdfield2_t, complex]</code> <p>(e_xy, wavenumber)</p>"},{"location":"api/waveguides/#meanas.fdfd.waveguide_2d.inner_product","title":"inner_product","text":"<pre><code>inner_product(\n e1: vcfdfield2,\n h2: vcfdfield2,\n dxes: dx_lists2_t,\n prop_phase: float = 0,\n conj_h: bool = False,\n trapezoid: bool = False,\n) -&gt; complex\n</code></pre> <p>Compute the discrete waveguide overlap / Poynting inner product.</p> <p>This is the 2D transverse integral corresponding to the time-averaged longitudinal Poynting flux,</p> \\[ \\frac{1}{2}\\int (E_x H_y - E_y H_x) \\, dx \\, dy \\] <p>with the Yee-grid staggering and optional propagation-phase adjustment used by the waveguide helpers in this module.</p> <p>Parameters:</p> Name Type Description Default <code>e1</code> <code>vcfdfield2</code> <p>Vectorized electric field, typically from <code>exy2e(...)</code> or <code>normalized_fields_e(...)</code>.</p> required <code>h2</code> <code>vcfdfield2</code> <p>Vectorized magnetic field, typically from <code>hxy2h(...)</code>, <code>exy2h(...)</code>, or one of the normalization helpers.</p> required <code>dxes</code> <code>dx_lists2_t</code> <p>Two-dimensional Yee-grid spacing lists <code>[dx_e, dx_h]</code>.</p> required <code>prop_phase</code> <code>float</code> <p>Phase advance over one propagation cell. This is used to shift the H field into the same longitudinal reference plane as the E field.</p> <code>0</code> <code>conj_h</code> <code>bool</code> <p>Whether to conjugate <code>h2</code> before forming the overlap. Use <code>True</code> for the usual time-averaged power normalization.</p> <code>False</code> <code>trapezoid</code> <code>bool</code> <p>Whether to use trapezoidal quadrature instead of the default rectangular Yee-cell sum.</p> <code>False</code> <p>Returns:</p> Type Description <code>complex</code> <p>Complex overlap / longitudinal power integral.</p>"},{"location":"api/waveguides/#meanas.fdfd.waveguide_3d","title":"meanas.fdfd.waveguide_3d","text":"<p>Tools for working with waveguide modes in 3D domains.</p> <p>This module relies heavily on <code>waveguide_2d</code> and mostly just transforms its parameters into 2D equivalents and expands the results back into 3D.</p> <p>The intended workflow is:</p> <ol> <li>Select a single-cell slice normal to the propagation axis.</li> <li>Solve the corresponding 2D mode problem with <code>solve_mode(...)</code>.</li> <li>Turn that mode into a one-sided source with <code>compute_source(...)</code>.</li> <li>Build an overlap window with <code>compute_overlap_e(...)</code> for port readout.</li> </ol> <p><code>polarity</code> is part of the public convention throughout this module:</p> <ul> <li><code>+1</code> means forward propagation toward increasing index along <code>axis</code></li> <li><code>-1</code> means backward propagation toward decreasing index along <code>axis</code></li> </ul> <p>That same convention controls which side of the selected slice is used for the overlap window and how the expanded field is phased.</p>"},{"location":"api/waveguides/#meanas.fdfd.waveguide_3d.solve_mode","title":"solve_mode","text":"<pre><code>solve_mode(\n mode_number: int,\n omega: complex,\n dxes: dx_lists_t,\n axis: int,\n polarity: int,\n slices: Sequence[slice],\n epsilon: fdfield,\n mu: fdfield | None = None,\n) -&gt; Waveguide3DMode\n</code></pre> <p>Given a 3D grid, selects a slice from the grid and attempts to solve for an eigenmode propagating through that slice.</p> <p>Parameters:</p> Name Type Description Default <code>mode_number</code> <code>int</code> <p>Number of the mode, 0-indexed</p> required <code>omega</code> <code>complex</code> <p>Angular frequency of the simulation</p> required <code>dxes</code> <code>dx_lists_t</code> <p>Grid parameters <code>[dx_e, dx_h]</code> as described in <code>meanas.fdmath.types</code></p> required <code>axis</code> <code>int</code> <p>Propagation axis (0=x, 1=y, 2=z)</p> required <code>polarity</code> <code>int</code> <p>Propagation direction (+1 for +ve, -1 for -ve)</p> required <code>slices</code> <code>Sequence[slice]</code> <p><code>epsilon[tuple(slices)]</code> is used to select the portion of the grid to use as the waveguide cross-section. <code>slices[axis]</code> must select exactly one item.</p> required <code>epsilon</code> <code>fdfield</code> <p>Dielectric constant</p> required <code>mu</code> <code>fdfield | None</code> <p>Magnetic permeability (default 1 everywhere)</p> <code>None</code> <p>Returns:</p> Type Description <code>Waveguide3DMode</code> <p>Dictionary containing:</p> <code>Waveguide3DMode</code> <ul> <li><code>E</code>: full-grid electric field for the solved mode</li> </ul> <code>Waveguide3DMode</code> <ul> <li><code>H</code>: full-grid magnetic field for the solved mode</li> </ul> <code>Waveguide3DMode</code> <ul> <li><code>wavenumber</code>: propagation constant corrected for the discretized propagation axis</li> </ul> <code>Waveguide3DMode</code> <ul> <li><code>wavenumber_2d</code>: propagation constant of the reduced 2D eigenproblem</li> </ul> Notes <p>The returned fields are normalized through the <code>waveguide_2d</code> normalization convention before being expanded back to 3D.</p>"},{"location":"api/waveguides/#meanas.fdfd.waveguide_3d.compute_source","title":"compute_source","text":"<pre><code>compute_source(\n E: cfdfield,\n wavenumber: complex,\n omega: complex,\n dxes: dx_lists_t,\n axis: int,\n polarity: int,\n slices: Sequence[slice],\n epsilon: fdfield,\n mu: fdfield | None = None,\n) -&gt; cfdfield_t\n</code></pre> <p>Given an eigenmode obtained by <code>solve_mode</code>, returns the current source distribution necessary to position a unidirectional source at the slice location.</p> <p>Parameters:</p> Name Type Description Default <code>E</code> <code>cfdfield</code> <p>E-field of the mode</p> required <code>wavenumber</code> <code>complex</code> <p>Wavenumber of the mode</p> required <code>omega</code> <code>complex</code> <p>Angular frequency of the simulation</p> required <code>dxes</code> <code>dx_lists_t</code> <p>Grid parameters <code>[dx_e, dx_h]</code> as described in <code>meanas.fdmath.types</code></p> required <code>axis</code> <code>int</code> <p>Propagation axis (0=x, 1=y, 2=z)</p> required <code>polarity</code> <code>int</code> <p>Propagation direction (+1 for +ve, -1 for -ve)</p> required <code>slices</code> <code>Sequence[slice]</code> <p><code>epsilon[tuple(slices)]</code> is used to select the portion of the grid to use as the waveguide cross-section. <code>slices[axis]</code> should select only one item.</p> required <code>mu</code> <code>fdfield | None</code> <p>Magnetic permeability (default 1 everywhere)</p> <code>None</code> <p>Returns:</p> Type Description <code>cfdfield_t</code> <p><code>J</code> distribution for a one-sided electric-current source.</p> Notes <p>The source is built from the expanded mode field and a boundary-source operator. The resulting current is intended to be injected with the same sign convention used elsewhere in the package:</p> <p><code>E -= dt * J / epsilon</code></p>"},{"location":"api/waveguides/#meanas.fdfd.waveguide_3d.compute_overlap_e","title":"compute_overlap_e","text":"<pre><code>compute_overlap_e(\n E: cfdfield,\n wavenumber: complex,\n dxes: dx_lists_t,\n axis: int,\n polarity: int,\n slices: Sequence[slice],\n _omega: float,\n) -&gt; cfdfield_t\n</code></pre> <p>Build an overlap field for projecting another 3D electric field onto a mode.</p> <p>The returned field is intended for the discrete overlap expression</p> \\[ \\sum \\mathrm{overlap\\_e} \\; E_\\mathrm{other}^* \\] <p>where the sum is over the full Yee-grid field storage.</p> <p>The construction uses a two-cell window immediately upstream of the selected slice:</p> <ul> <li>for <code>polarity=+1</code>, the two cells just before <code>slices[axis].start</code></li> <li>for <code>polarity=-1</code>, the two cells just after <code>slices[axis].stop</code></li> </ul> <p>The window is clipped to the simulation domain if necessary. A clipped but non-empty window raises <code>RuntimeWarning</code>; an empty window raises <code>ValueError</code>.</p> <p>The derivation below assumes reflection symmetry and the standard waveguide overlap relation involving</p> \\[ \\int ((E \\times H_\\mathrm{mode}) + (E_\\mathrm{mode} \\times H)) \\cdot dn. \\] <p>E x H_mode + E_mode x H -&gt; Ex Hmy - EyHmx + Emx Hy - Emy Hx (Z-prop) Ex we/B Emx + Ex i/B dy Hmz - Ey (-we/B Emy) - Ey i/B dx Hmz we/B (Ex Emx + Ey Emy) + i/B (Ex dy Hmz - Ey dx Hmz) we/B (Ex Emx + Ey Emy) + i/B (Ex dy (dx Emy - dy Emx) - Ey dx (dx Emy - dy Emx)) we/B (Ex Emx + Ey Emy) + i/B (Ex dy dx Emy - Ex dy dy Emx - Ey dx dx Emy - Ey dx dy Emx)</p> <p>Ex j/wu (-jB Emx - dx Emz) - Ey j/wu (dy Emz + jB Emy) B/wu (Ex Emx + Ey Emy) - j/wu (Ex dx Emz + Ey dy Emz)</p> <p>Parameters:</p> Name Type Description Default <code>E</code> <code>cfdfield</code> <p>E-field of the mode</p> required <code>wavenumber</code> <code>complex</code> <p>Wavenumber of the mode</p> required <code>dxes</code> <code>dx_lists_t</code> <p>Grid parameters <code>[dx_e, dx_h]</code> as described in <code>meanas.fdmath.types</code></p> required <code>axis</code> <code>int</code> <p>Propagation axis (0=x, 1=y, 2=z)</p> required <code>polarity</code> <code>int</code> <p>Propagation direction (+1 for +ve, -1 for -ve)</p> required <code>slices</code> <code>Sequence[slice]</code> <p><code>epsilon[tuple(slices)]</code> is used to select the portion of the grid to use as the waveguide cross-section. slices[axis] should select only one item.</p> required <p>Returns:</p> Type Description <code>cfdfield_t</code> <p><code>overlap_e</code> normalized so that <code>numpy.sum(overlap_e * E.conj()) == 1</code></p> <code>cfdfield_t</code> <p>over the retained overlap window.</p>"},{"location":"api/waveguides/#meanas.fdfd.waveguide_3d.expand_e","title":"expand_e","text":"<pre><code>expand_e(\n E: cfdfield,\n wavenumber: complex,\n dxes: dx_lists_t,\n axis: int,\n polarity: int,\n slices: Sequence[slice],\n) -&gt; cfdfield_t\n</code></pre> <p>Given an eigenmode obtained by <code>solve_mode</code>, expands the E-field from the 2D slice where the mode was calculated to the entire domain (along the propagation axis). This assumes the epsilon cross-section remains constant throughout the entire domain; it is up to the caller to truncate the expansion to any regions where it is valid.</p> <p>Parameters:</p> Name Type Description Default <code>E</code> <code>cfdfield</code> <p>E-field of the mode</p> required <code>wavenumber</code> <code>complex</code> <p>Wavenumber of the mode</p> required <code>dxes</code> <code>dx_lists_t</code> <p>Grid parameters <code>[dx_e, dx_h]</code> as described in <code>meanas.fdmath.types</code></p> required <code>axis</code> <code>int</code> <p>Propagation axis (0=x, 1=y, 2=z)</p> required <code>polarity</code> <code>int</code> <p>Propagation direction (+1 for +ve, -1 for -ve)</p> required <code>slices</code> <code>Sequence[slice]</code> <p><code>epsilon[tuple(slices)]</code> is used to select the portion of the grid to use as the waveguide cross-section. slices[axis] should select only one item.</p> required <p>Returns:</p> Type Description <code>cfdfield_t</code> <p><code>E</code>, with the original field expanded along the specified <code>axis</code>.</p> Notes <p>This helper assumes that the waveguide cross-section remains constant along the propagation axis and applies the phase factor</p> \\[ e^{-i \\, \\mathrm{polarity} \\, wavenumber \\, \\Delta z} \\] <p>to each copied slice.</p>"},{"location":"api/waveguides/#meanas.fdfd.waveguide_cyl","title":"meanas.fdfd.waveguide_cyl","text":"<p>Operators and helper functions for cylindrical waveguides with unchanging cross-section.</p> <p>Waveguide operator is derived according to 10.1364/OL.33.001848.</p> <p>As in <code>waveguide_2d</code>, the propagation dependence is separated from the transverse solve. Here the propagation coordinate is the bend angle <code>\\theta</code>, and the fields are assumed to have the form</p> \\[ \\vec{E}(r, y, \\theta), \\vec{H}(r, y, \\theta) \\propto e^{-\\imath m \\theta}, \\] <p>where <code>m</code> is the angular wavenumber returned by <code>solve_mode(s)</code>. It is often convenient to introduce the corresponding linear wavenumber</p> \\[ \\beta = \\frac{m}{r_{\\min}}, \\] <p>so that the cylindrical problem resembles the straight-waveguide problem with additional metric factors.</p> <p>Those metric factors live on the staggered radial Yee grids. If the left edge of the computational window is at <code>r = r_{\\min}</code>, define the electric-grid and magnetic-grid radial sample locations by</p> \\[ \\begin{aligned} r_a(n) &amp;= r_{\\min} + \\sum_{j \\le n} \\Delta r_{e, j}, \\\\ r_b\\!\\left(n + \\tfrac{1}{2}\\right) &amp;= r_{\\min} + \\tfrac{1}{2}\\Delta r_{e, n} + \\sum_{j &lt; n} \\Delta r_{h, j}, \\end{aligned} \\] <p>and from them the diagonal metric matrices</p> \\[ \\begin{aligned} T_a &amp;= \\operatorname{diag}(r_a / r_{\\min}), \\\\ T_b &amp;= \\operatorname{diag}(r_b / r_{\\min}). \\end{aligned} \\] <p>With the same forward/backward derivative notation used in <code>waveguide_2d</code>, the coordinate-transformed discrete curl equations used here are</p> \\[ \\begin{aligned} -\\imath \\omega \\mu_{rr} H_r &amp;= \\tilde{\\partial}_y E_z + \\imath \\beta T_a^{-1} E_y, \\\\ -\\imath \\omega \\mu_{yy} H_y &amp;= -\\imath \\beta T_b^{-1} E_r - T_b^{-1} \\tilde{\\partial}_r (T_a E_z), \\\\ -\\imath \\omega \\mu_{zz} H_z &amp;= \\tilde{\\partial}_r E_y - \\tilde{\\partial}_y E_r, \\\\ \\imath \\beta H_y &amp;= -\\imath \\omega T_b \\epsilon_{rr} E_r - T_b \\hat{\\partial}_y H_z, \\\\ \\imath \\beta H_r &amp;= \\imath \\omega T_a \\epsilon_{yy} E_y - T_b T_a^{-1} \\hat{\\partial}_r (T_b H_z), \\\\ \\imath \\omega E_z &amp;= T_a \\epsilon_{zz}^{-1} \\left(\\hat{\\partial}_r H_y - \\hat{\\partial}_y H_r\\right). \\end{aligned} \\] <p>The first three equations are the cylindrical analogue of the straight-guide relations for <code>H_r</code>, <code>H_y</code>, and <code>H_z</code>. The next two are the metric-weighted versions of the straight-guide identities for <code>\\imath \\beta H_y</code> and <code>\\imath \\beta H_r</code>, and the last equation plays the same role as the longitudinal <code>E_z</code> reconstruction in <code>waveguide_2d</code>.</p> <p>Following the same elimination steps as in <code>waveguide_2d</code>, apply <code>\\imath \\beta \\tilde{\\partial}_r</code> and <code>\\imath \\beta \\tilde{\\partial}_y</code> to the equation for <code>E_z</code>, substitute for <code>\\imath \\beta H_r</code> and <code>\\imath \\beta H_y</code>, and then eliminate <code>H_z</code> with</p> \\[ H_z = \\frac{1}{-\\imath \\omega \\mu_{zz}} \\left(\\tilde{\\partial}_r E_y - \\tilde{\\partial}_y E_r\\right). \\] <p>This yields the transverse electric eigenproblem implemented by <code>cylindrical_operator(...)</code>:</p> \\[ \\beta^2 \\begin{bmatrix} E_r \\\\ E_y \\end{bmatrix} = \\left( \\omega^2 \\begin{bmatrix} T_b^2 \\mu_{yy} \\epsilon_{xx} &amp; 0 \\\\ 0 &amp; T_a^2 \\mu_{xx} \\epsilon_{yy} \\end{bmatrix} + \\begin{bmatrix} -T_b \\mu_{yy} \\hat{\\partial}_y \\\\ T_a \\mu_{xx} \\hat{\\partial}_x \\end{bmatrix} T_b \\mu_{zz}^{-1} \\begin{bmatrix} -\\tilde{\\partial}_y &amp; \\tilde{\\partial}_x \\end{bmatrix} + \\begin{bmatrix} \\tilde{\\partial}_x \\\\ \\tilde{\\partial}_y \\end{bmatrix} T_a \\epsilon_{zz}^{-1} \\begin{bmatrix} \\hat{\\partial}_x T_b \\epsilon_{xx} &amp; \\hat{\\partial}_y T_a \\epsilon_{yy} \\end{bmatrix} \\right) \\begin{bmatrix} E_r \\\\ E_y \\end{bmatrix}. \\] <p>Since <code>\\beta = m / r_{\\min}</code>, the solver implemented in this file returns the angular wavenumber <code>m</code>, while the operator itself is most naturally written in terms of the linear quantity <code>\\beta</code>. The helpers below reconstruct the full field components from the solved transverse eigenvector and then normalize the mode to unit forward power with the same discrete longitudinal Poynting inner product used by <code>waveguide_2d</code>.</p> <p>As in the straight-waveguide case, all functions here assume a 2D grid:</p> <p><code>dxes = [[[dr_e_0, dr_e_1, ...], [dy_e_0, ...]], [[dr_h_0, ...], [dy_h_0, ...]]]</code>.</p>"},{"location":"api/waveguides/#meanas.fdfd.waveguide_cyl.cylindrical_operator","title":"cylindrical_operator","text":"<pre><code>cylindrical_operator(\n omega: float,\n dxes: dx_lists2_t,\n epsilon: vfdslice,\n rmin: float,\n) -&gt; sparse.sparray\n</code></pre> <p>Cylindrical coordinate waveguide operator of the form</p> \\[ (\\omega^2 \\begin{bmatrix} T_b T_b \\mu_{yy} \\epsilon_{xx} &amp; 0 \\\\ 0 &amp; T_a T_a \\mu_{xx} \\epsilon_{yy} \\end{bmatrix} + \\begin{bmatrix} -T_b \\mu_{yy} \\hat{\\partial}_y \\\\ T_a \\mu_{xx} \\hat{\\partial}_x \\end{bmatrix} T_b \\mu_{zz}^{-1} \\begin{bmatrix} -\\tilde{\\partial}_y &amp; \\tilde{\\partial}_x \\end{bmatrix} + \\begin{bmatrix} \\tilde{\\partial}_x \\\\ \\tilde{\\partial}_y \\end{bmatrix} T_a \\epsilon_{zz}^{-1} \\begin{bmatrix} \\hat{\\partial}_x T_b \\epsilon_{xx} &amp; \\hat{\\partial}_y T_a \\epsilon_{yy} \\end{bmatrix}) \\begin{bmatrix} E_r \\\\ E_y \\end{bmatrix} \\] <p>for use with a field vector of the form <code>[E_r, E_y]</code>.</p> <p>This operator can be used to form an eigenvalue problem of the form A @ [E_r, E_y] = beta**2 * [E_r, E_y]</p> <p>which can then be solved for the eigenmodes of the system (an <code>exp(-i * angular_wavenumber * theta)</code> theta-dependence is assumed for the fields, with <code>beta = angular_wavenumber / rmin</code>).</p> <p>(NOTE: See module docs and 10.1364/OL.33.001848)</p> <p>Parameters:</p> Name Type Description Default <code>omega</code> <code>float</code> <p>The angular frequency of the system</p> required <code>dxes</code> <code>dx_lists2_t</code> <p>Grid parameters <code>[dx_e, dx_h]</code> as described in <code>meanas.fdmath.types</code> (2D)</p> required <code>epsilon</code> <code>vfdslice</code> <p>Vectorized dielectric constant grid</p> required <code>rmin</code> <code>float</code> <p>Radius at the left edge of the simulation domain (at minimum 'x')</p> required <p>Returns:</p> Type Description <code>sparray</code> <p>Sparse matrix representation of the operator</p>"},{"location":"api/waveguides/#meanas.fdfd.waveguide_cyl.solve_modes","title":"solve_modes","text":"<pre><code>solve_modes(\n mode_numbers: Sequence[int],\n omega: float,\n dxes: dx_lists2_t,\n epsilon: vfdslice,\n rmin: float,\n mode_margin: int = 2,\n) -&gt; tuple[\n NDArray[numpy.complex128], NDArray[numpy.complex128]\n]\n</code></pre> <p>Given a 2d (r, y) slice of epsilon, attempts to solve for the eigenmode of the bent waveguide with the specified mode number.</p> <p>Parameters:</p> Name Type Description Default <code>mode_numbers</code> <code>Sequence[int]</code> <p>Mode numbers to solve, 0-indexed.</p> required <code>omega</code> <code>float</code> <p>Angular frequency of the simulation</p> required <code>dxes</code> <code>dx_lists2_t</code> <p>Grid parameters [dx_e, dx_h] as described in meanas.fdmath.types. The first coordinate is assumed to be r, the second is y.</p> required <code>epsilon</code> <code>vfdslice</code> <p>Dielectric constant</p> required <code>rmin</code> <code>float</code> <p>Radius of curvature for the simulation. This should be the minimum value of r within the simulation domain.</p> required <p>Returns:</p> Name Type Description <code>e_xys</code> <code>NDArray[complex128]</code> <p>NDArray of vfdfield_t specifying fields. First dimension is mode number.</p> <code>angular_wavenumbers</code> <code>NDArray[complex128]</code> <p>list of wavenumbers in 1/rad units.</p>"},{"location":"api/waveguides/#meanas.fdfd.waveguide_cyl.solve_mode","title":"solve_mode","text":"<pre><code>solve_mode(\n mode_number: int, *args: Any, **kwargs: Any\n) -&gt; tuple[vcfdfield2, complex]\n</code></pre> <p>Wrapper around <code>solve_modes()</code> that solves for a single mode.</p> <p>Parameters:</p> Name Type Description Default <code>mode_number</code> <code>int</code> <p>0-indexed mode number to solve for</p> required <code>*args</code> <code>Any</code> <p>passed to <code>solve_modes()</code></p> <code>()</code> <code>**kwargs</code> <code>Any</code> <p>passed to <code>solve_modes()</code></p> <code>{}</code> <p>Returns:</p> Type Description <code>tuple[vcfdfield2, complex]</code> <p>(e_xy, angular_wavenumber)</p>"},{"location":"api/waveguides/#meanas.fdfd.waveguide_cyl.linear_wavenumbers","title":"linear_wavenumbers","text":"<pre><code>linear_wavenumbers(\n e_xys: Sequence[vcfdfield2] | NDArray[complex128],\n angular_wavenumbers: ArrayLike,\n epsilon: vfdslice,\n dxes: dx_lists2_t,\n rmin: float,\n) -&gt; NDArray[numpy.complex128]\n</code></pre> <p>Calculate linear wavenumbers (1/distance) based on angular wavenumbers (1/rad) and the mode's energy distribution.</p> <p>Parameters:</p> Name Type Description Default <code>e_xys</code> <code>Sequence[vcfdfield2] | NDArray[complex128]</code> <p>Vectorized mode fields with shape (num_modes, 2 * x *y)</p> required <code>angular_wavenumbers</code> <code>ArrayLike</code> <p>Wavenumbers assuming fields have theta-dependence of <code>exp(-i * angular_wavenumber * theta)</code>. They should satisfy <code>operator_e() @ e_xy == (angular_wavenumber / rmin) ** 2 * e_xy</code></p> required <code>epsilon</code> <code>vfdslice</code> <p>Vectorized dielectric constant grid with shape (3, x, y)</p> required <code>dxes</code> <code>dx_lists2_t</code> <p>Grid parameters <code>[dx_e, dx_h]</code> as described in <code>meanas.fdmath.types</code> (2D)</p> required <code>rmin</code> <code>float</code> <p>Radius at the left edge of the simulation domain (at minimum 'x')</p> required <p>Returns:</p> Type Description <code>NDArray[complex128]</code> <p>NDArray containing the calculated linear (1/distance) wavenumbers</p>"},{"location":"api/waveguides/#meanas.fdfd.waveguide_cyl.exy2h","title":"exy2h","text":"<pre><code>exy2h(\n angular_wavenumber: complex,\n omega: float,\n dxes: dx_lists2_t,\n rmin: float,\n epsilon: vfdslice,\n mu: vfdslice | None = None,\n) -&gt; sparse.sparray\n</code></pre> <p>Operator which transforms the vector <code>e_xy</code> containing the vectorized E_r and E_y fields, into a vectorized H containing all three H components</p> <p>Parameters:</p> Name Type Description Default <code>angular_wavenumber</code> <code>complex</code> <p>Wavenumber assuming fields have theta-dependence of <code>exp(-i * angular_wavenumber * theta)</code>. It should satisfy <code>operator_e() @ e_xy == (angular_wavenumber / rmin) ** 2 * e_xy</code></p> required <code>omega</code> <code>float</code> <p>The angular frequency of the system</p> required <code>dxes</code> <code>dx_lists2_t</code> <p>Grid parameters <code>[dx_e, dx_h]</code> as described in <code>meanas.fdmath.types</code> (2D)</p> required <code>rmin</code> <code>float</code> <p>Radius at the left edge of the simulation domain (at minimum 'x')</p> required <code>epsilon</code> <code>vfdslice</code> <p>Vectorized dielectric constant grid</p> required <code>mu</code> <code>vfdslice | None</code> <p>Vectorized magnetic permeability grid (default 1 everywhere)</p> <code>None</code> <p>Returns:</p> Type Description <code>sparray</code> <p>Sparse matrix representing the operator.</p>"},{"location":"api/waveguides/#meanas.fdfd.waveguide_cyl.exy2e","title":"exy2e","text":"<pre><code>exy2e(\n angular_wavenumber: complex,\n omega: float,\n dxes: dx_lists2_t,\n rmin: float,\n epsilon: vfdslice,\n) -&gt; sparse.sparray\n</code></pre> <p>Operator which transforms the vector <code>e_xy</code> containing the vectorized E_r and E_y fields, into a vectorized E containing all three E components</p> <p>Unlike the straight waveguide case, the H_z components do not cancel and must be calculated from E_r and E_y in order to then calculate E_z.</p> <p>Parameters:</p> Name Type Description Default <code>angular_wavenumber</code> <code>complex</code> <p>Wavenumber assuming fields have theta-dependence of <code>exp(-i * angular_wavenumber * theta)</code>. It should satisfy <code>operator_e() @ e_xy == (angular_wavenumber / rmin) ** 2 * e_xy</code></p> required <code>omega</code> <code>float</code> <p>The angular frequency of the system</p> required <code>dxes</code> <code>dx_lists2_t</code> <p>Grid parameters <code>[dx_e, dx_h]</code> as described in <code>meanas.fdmath.types</code> (2D)</p> required <code>rmin</code> <code>float</code> <p>Radius at the left edge of the simulation domain (at minimum 'x')</p> required <code>epsilon</code> <code>vfdslice</code> <p>Vectorized dielectric constant grid</p> required <p>Returns:</p> Type Description <code>sparray</code> <p>Sparse matrix representing the operator.</p>"},{"location":"api/waveguides/#meanas.fdfd.waveguide_cyl.e2h","title":"e2h","text":"<pre><code>e2h(\n angular_wavenumber: complex,\n omega: float,\n dxes: dx_lists2_t,\n rmin: float,\n mu: vfdslice | None = None,\n) -&gt; sparse.sparray\n</code></pre> <p>Returns an operator which, when applied to a vectorized E eigenfield, produces the vectorized H eigenfield.</p> <p>This operator is created directly from the initial coordinate-transformed equations:</p> \\[ \\begin{aligned} -\\imath \\omega \\mu_{rr} H_r &amp;= \\tilde{\\partial}_y E_z + \\imath \\beta T_a^{-1} E_y, \\\\ -\\imath \\omega \\mu_{yy} H_y &amp;= -\\imath \\beta T_b^{-1} E_r - T_b^{-1} \\tilde{\\partial}_r (T_a E_z), \\\\ -\\imath \\omega \\mu_{zz} H_z &amp;= \\tilde{\\partial}_r E_y - \\tilde{\\partial}_y E_r, \\end{aligned} \\] <p>Parameters:</p> Name Type Description Default <code>angular_wavenumber</code> <code>complex</code> <p>Wavenumber assuming fields have theta-dependence of <code>exp(-i * angular_wavenumber * theta)</code>. It should satisfy <code>operator_e() @ e_xy == (angular_wavenumber / rmin) ** 2 * e_xy</code></p> required <code>omega</code> <code>float</code> <p>The angular frequency of the system</p> required <code>dxes</code> <code>dx_lists2_t</code> <p>Grid parameters <code>[dx_e, dx_h]</code> as described in <code>meanas.fdmath.types</code> (2D)</p> required <code>rmin</code> <code>float</code> <p>Radius at the left edge of the simulation domain (at minimum 'x')</p> required <code>mu</code> <code>vfdslice | None</code> <p>Vectorized magnetic permeability grid (default 1 everywhere)</p> <code>None</code> <p>Returns:</p> Type Description <code>sparray</code> <p>Sparse matrix representation of the operator.</p>"},{"location":"api/waveguides/#meanas.fdfd.waveguide_cyl.dxes2T","title":"dxes2T","text":"<pre><code>dxes2T(\n dxes: dx_lists2_t, rmin: float\n) -&gt; tuple[NDArray[numpy.float64], NDArray[numpy.float64]]\n</code></pre> <p>Construct the cylindrical metric matrices \\(T_a\\) and \\(T_b\\).</p> <p><code>T_a</code> is sampled on the E-grid radial locations, while <code>T_b</code> is sampled on the staggered H-grid radial locations. These are the diagonal matrices that convert the straight-waveguide algebra into its cylindrical counterpart.</p> <p>Parameters:</p> Name Type Description Default <code>dxes</code> <code>dx_lists2_t</code> <p>Grid parameters <code>[dx_e, dx_h]</code> as described in <code>meanas.fdmath.types</code> (2D)</p> required <code>rmin</code> <code>float</code> <p>Radius at the left edge of the simulation domain (at minimum 'x')</p> required <p>Returns:</p> Type Description <code>tuple[NDArray[float64], NDArray[float64]]</code> <p>Sparse diagonal matrices <code>(T_a, T_b)</code>.</p>"},{"location":"api/waveguides/#meanas.fdfd.waveguide_cyl.normalized_fields_e","title":"normalized_fields_e","text":"<pre><code>normalized_fields_e(\n e_xy: vcfdfield2,\n angular_wavenumber: complex,\n omega: float,\n dxes: dx_lists2_t,\n rmin: float,\n epsilon: vfdslice,\n mu: vfdslice | None = None,\n prop_phase: float = 0,\n) -&gt; tuple[vcfdslice_t, vcfdslice_t]\n</code></pre> <p>Given a vector <code>e_xy</code> containing the vectorized E_r and E_y fields, returns normalized, vectorized E and H fields for the system.</p> <p>Parameters:</p> Name Type Description Default <code>e_xy</code> <code>vcfdfield2</code> <p>Vector containing E_r and E_y fields</p> required <code>angular_wavenumber</code> <code>complex</code> <p>Wavenumber assuming fields have theta-dependence of <code>exp(-i * angular_wavenumber * theta)</code>. It should satisfy <code>operator_e() @ e_xy == (angular_wavenumber / rmin) ** 2 * e_xy</code></p> required <code>omega</code> <code>float</code> <p>The angular frequency of the system</p> required <code>dxes</code> <code>dx_lists2_t</code> <p>Grid parameters <code>[dx_e, dx_h]</code> as described in <code>meanas.fdmath.types</code> (2D)</p> required <code>rmin</code> <code>float</code> <p>Radius at the left edge of the simulation domain (at minimum 'x')</p> required <code>epsilon</code> <code>vfdslice</code> <p>Vectorized dielectric constant grid</p> required <code>mu</code> <code>vfdslice | None</code> <p>Vectorized magnetic permeability grid (default 1 everywhere)</p> <code>None</code> <code>prop_phase</code> <code>float</code> <p>Phase shift <code>(dz * corrected_wavenumber)</code> over 1 cell in propagation direction. Default 0 (continuous propagation direction, i.e. dz-&gt;0).</p> <code>0</code> <p>Returns:</p> Type Description <code>vcfdslice_t</code> <p><code>(e, h)</code>, where each field is vectorized, normalized,</p> <code>vcfdslice_t</code> <p>and contains all three vector components.</p> Notes <p>The normalization step is delegated to <code>_normalized_fields(...)</code>, which enforces unit forward power under the discrete inner product</p> \\[ \\frac{1}{2}\\int (E_r H_y^* - E_y H_r^*) \\, dr \\, dy. \\] <p>The angular wavenumber <code>m</code> is first converted into the full three-component fields, then the overall complex phase and sign are fixed so the result is reproducible for symmetric modes.</p>"}]}