# Project Setup Project Setup defines the first {term}`project` in the Getting Started section. The following pages parameterize the project, repeat the project for multiple {term}`project keys`, and use templates to create more complex geometries. The `mie2D` project models light scattering from an infinite glass rod. The two-dimensional layout represents the rod cross section. A plane wave travels through air in the positive x direction and illuminates the rod. ```{figure} ../_static/getting_started/project_setup/example_geometry.png :alt: An incoming plane wave scattered from an infinite glass rod. The figure shows an incoming plane wave scattered from an infinite glass rod. ``` ## Fixed Project Inputs The project uses fixed input values. The surrounding material is air. The source has a vacuum wavelength of $\lambda_0 = 550\,\mathrm{nm}$ and an electric-field amplitude of $[0, 0, 1]$. The electric field is polarized in the $z$ direction. The wave vector in `sources.jcm` is $\mathbf{k} = (k_x, 0, 0)$, where $k_x \approx 1.1424 \times 10^7\,\mathrm{m}^{-1}$. The incident electric field is: $$ \mathbf{E}_{\mathrm{illum}}(\mathbf{x}) = \begin{pmatrix} 0 \\ 0 \\ 1 \end{pmatrix} \exp\left(i\,(k_x, 0, 0)\,\mathbf{x}\right). $$ The unit of length in `layout.jcm` is $1\,\mathrm{\mu m}$. The computational domain has a width and height of $4\,\mathrm{\mu m}$. The rod has a radius of $0.5\,\mathrm{\mu m}$. The glass material has a relative permittivity of $\varepsilon_{\mathrm{rel,glass}} = 2.3104$, which corresponds to a refractive index of $n_{\mathrm{glass}} = 1.52$. The `layout.jcm` file defines the computational domain, transparent boundaries, and rod geometry. The `materials.jcm` file assigns air to domain $1$ and glass to domain $2$. The `sources.jcm` file defines the incident plane wave. The `mie2D.jcmp` project declares two postprocesses: - The first postprocess integrates the electromagnetic field energy flux at the exterior-domain interface. Up to normalization, the integrated value is the integral scattering cross section. - The second postprocess exports field data on a Cartesian grid. ## Run The Project ```{literalinclude} ../../demos/documentation_tutorials/getting_started/project_setup/run.py :language: python ``` {func}`solve ` creates the mesh, runs the project, and returns a {class}`SolveResult `. The first postprocess is available through {attr}`result.postprocesses[0] `. The script exports the postprocess data with {meth}`to_dict() ` as a dictionary. The script reads the `ElectromagneticFieldEnergyFlux` value and prints its real part. The second postprocess is available through {attr}`result.postprocesses[1] `. The script selects the first exported field and uses {attr}`intensity ` to calculate the squared norm. Then the script uses {meth}`to_xarray() ` to create an xarray data tree. The script reads the `x`, `y`, and `field` arrays. Matplotlib displays the scalar intensity as a pseudo-color plot. ```{figure} ../_static/getting_started/project_setup/intensity.png :alt: Pseudo-color field-intensity plot around the glass rod. Field intensity around the rod. ``` ## Inspect Geometry And Fields The completed project writes the solution fieldbag to the result directory. Use {func}`view ` to open the fieldbag in JCMview: ```python jcmsuite.view(results.file) ``` {attr}`results.file ` is the path to the solution fieldbag. The fieldbag must be available. JCMview requires a graphical environment. Before you solve a new project, inspect its mesh. The following script runs JCMgeo, writes `grid.jcm`, and opens the grid in JCMview. The script does not run the electromagnetic solve: ```{literalinclude} ../../demos/documentation_tutorials/getting_started/project_setup/run_geo.py :language: python ``` ## Project Files
run.py ```{literalinclude} ../../demos/documentation_tutorials/getting_started/project_setup/run.py :language: python ```
run_geo.py ```{literalinclude} ../../demos/documentation_tutorials/getting_started/project_setup/run_geo.py :language: python ```
layout.jcm ```{literalinclude} ../../demos/documentation_tutorials/getting_started/project_setup/layout.jcm :language: jcm ```
materials.jcm ```{literalinclude} ../../demos/documentation_tutorials/getting_started/project_setup/materials.jcm :language: jcm ```
mie2D.jcmp ```{literalinclude} ../../demos/documentation_tutorials/getting_started/project_setup/mie2D.jcmp :language: jcm ```
sources.jcm ```{literalinclude} ../../demos/documentation_tutorials/getting_started/project_setup/sources.jcm :language: jcm ```
## Next Step Continue to [Keyword Substitution](keyword_substitution.md) to provide the radius as a project key.