Parameter Scan
Parameter Scan repeats the parameterized project from Keyword Substitution for a range of rod radii. The scan calculates the exterior energy flux for each radius. The page displays the scattering cross section.
Define The Scan
The script uses numpy.linspace(...) to create equally spaced radii from
through
. The script then creates one set of
project keys for each radius:
# Set geometry parameter
radii = np.linspace(0.3, 0.5, 41)
keys = [{"radius": radius} for radius in radii]
Pass batched project keys to solve to run the project for each set of project keys.
The call returns a BatchSolveResult. Batch entries retain input order. The first result
corresponds to the first radius. The last result corresponds to the last radius.
Run The Scan
import numpy as np
from matplotlib import pyplot as plt
import jcmsuite
# Set geometry parameter
radii = np.linspace(0.3, 0.5, 41)
keys = [{"radius": radius} for radius in radii]
# Run the project
results = jcmsuite.solve("mie2D.jcmp", keys=keys, temporary=True, quiet=True)
# Access the results of the first postprocess and export it to a dictionary
scattering_postprocess = results.postprocesses[0]
scattering_export = scattering_postprocess.to_xarray()
cross_sections = scattering_export["ElectromagneticFieldEnergyFlux"].squeeze().real
plt.plot(radii, cross_sections, "-+")
plt.xlabel(r"radius [$\mu$ m]")
plt.ylabel("integral scattering cross section")
plt.axis("tight")
plt.show()
The script sets temporary=True. JCMsuite creates an isolated temporary working directory
for each project key entry. The isolated directories prevent one solve from overwriting
files from another solve. The quiet=True option suppresses local solver output.
The first postprocess is available through results.postprocesses[0]. The
to_xarray()
method combines energy-flux data for all batch entries. The script removes singleton
dimensions and selects the real part. Matplotlib plots the cross section against the input
radii.
Scattering cross section as a function of rod radius.
Project Files
run.py
import numpy as np
from matplotlib import pyplot as plt
import jcmsuite
# Set geometry parameter
radii = np.linspace(0.3, 0.5, 41)
keys = [{"radius": radius} for radius in radii]
# Run the project
results = jcmsuite.solve("mie2D.jcmp", keys=keys, temporary=True, quiet=True)
# Access the results of the first postprocess and export it to a dictionary
scattering_postprocess = results.postprocesses[0]
scattering_export = scattering_postprocess.to_xarray()
cross_sections = scattering_export["ElectromagneticFieldEnergyFlux"].squeeze().real
plt.plot(radii, cross_sections, "-+")
plt.xlabel(r"radius [$\mu$ m]")
plt.ylabel("integral scattering cross section")
plt.axis("tight")
plt.show()
layout.jcmt
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 = %(radius)e
}
}
}
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 Python Code Snippets to calculate template values inside project support files.