Project Setup

Project Setup defines the first project in the Getting Started section. The following pages parameterize the project, repeat the project for multiple 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.

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

from matplotlib import pyplot as plt

import jcmsuite

# Solve the Project
results = jcmsuite.solve("mie2D.jcmp")

# Access the results of the first postprocess and export it to a dictionary
scattering_postprocess = results.postprocesses[0]
scattering_export = scattering_postprocess.to_dict()
cross_section = scattering_export["ElectromagneticFieldEnergyFlux"][0][0].real

print(f"scattering cross section: {cross_section}")

# Access the field export of the second postprocess
field_export = results.postprocesses[1].fields

# Select the first field intensity and export it to an xarray Dataset
xarray_export = field_export.select(0).intensity.to_xarray()

xx = xarray_export["X"]
yy = xarray_export["Y"]
intensity = xarray_export["field"]

plt.pcolor(xx, yy, intensity)
plt.show()

solve creates the mesh, runs the project, and returns a SolveResult. The first postprocess is available through result.postprocesses[0]. The script exports the postprocess data with to_dict() as a dictionary. The script reads the ElectromagneticFieldEnergyFlux value and prints its real part.

The second postprocess is available through result.postprocesses[1]. The script selects the first exported field and uses intensity to calculate the squared norm. Then the script uses 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.

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 view to open the fieldbag in JCMview:

jcmsuite.view(results.file)

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:

import jcmsuite

# Create the mesh and view it
results = jcmsuite.geo(".", show=True)

Project Files

run.py
from matplotlib import pyplot as plt

import jcmsuite

# Solve the Project
results = jcmsuite.solve("mie2D.jcmp")

# Access the results of the first postprocess and export it to a dictionary
scattering_postprocess = results.postprocesses[0]
scattering_export = scattering_postprocess.to_dict()
cross_section = scattering_export["ElectromagneticFieldEnergyFlux"][0][0].real

print(f"scattering cross section: {cross_section}")

# Access the field export of the second postprocess
field_export = results.postprocesses[1].fields

# Select the first field intensity and export it to an xarray Dataset
xarray_export = field_export.select(0).intensity.to_xarray()

xx = xarray_export["X"]
yy = xarray_export["Y"]
intensity = xarray_export["field"]

plt.pcolor(xx, yy, intensity)
plt.show()
run_geo.py
import jcmsuite

# Create the mesh and view it
results = jcmsuite.geo(".", show=True)
layout.jcm
Layout2D {
  UnitOfLength = 1e-6

  MeshOptions {
    MaximumSideLength = 0.1
    CurvilinearDegree = 2
  }

  Objects {
    # Computational domain
    Parallelogram {
      Name = "ComputationalDomain"
      DomainId = 1
      Priority = ComputationalDomain
      Width = 4
      Height = 4

      Boundary {
        Class = Transparent
      }
    }

    # Scatterer (rod)
    Circle {
      Name = "Rod"
      DomainId = 2
      Priority = 1
      Radius = 0.5
      RefineAll = 4
    }
  }
}
materials.jcm
# material properties for the surroundings (air)
Material {
  DomainId = 1
  RelPermittivity = 1.0
  RelPermeability = 1.0
}

# material properties the glass rod
Material {
  DomainId = 2
  RelPermittivity = 2.3104 # 1.52^2
  RelPermeability = 1.0
}
mie2D.jcmp
Project {
  InfoLevel = 3
  Electromagnetics {
    TimeHarmonic {
      Scattering {
        FieldComponents = Electric
        Accuracy {
          FiniteElementDegree = 3
          Refinement {
            MaxNumberSteps = 0
            PreRefinements = 0
          }
        }
      }
    }
  }
}
# computes the energy flux of the scattered field into the exterior domain
PostProcess {
  FluxIntegration {
    FieldBagPath = "./mie2D_results/fieldbag.jcm"
    OutputFileName = "./mie2D_results/energyflux_scattered.jcm"
    OutputQuantity = ElectromagneticFieldEnergyFlux
    InterfaceType = ExteriorDomain
  }
}

# exports computed field on cartesian grid
PostProcess {
  ExportFields {
    FieldBagPath = "./mie2D_results/fieldbag.jcm"
    OutputFileName = "./mie2D_results/fieldbag_cartesian.jcm"
    Cartesian {
      NGridPointsX = 200
      NGridPointsY = 200
    }
  }
}
sources.jcm
SourceBag {
  Source {
    ElectricFieldStrength {
      PlaneWave {
        K = [1.14239732857811e7 0.0 0.0]
        Amplitude = [0 0 1]
      }
    }
  }
}

Next Step

Continue to Keyword Substitution to provide the radius as a project key.