Project Setup¶
Within this section a simple test project is defined, which will be refined in the subsequent sections to show how to do parameter scans, and to demonstrate how to define more complicated geometries.
We regard the light scattering off an infinite glass rod. The project is called mie2D. Figure “Test example” shows the setup.
Test example¶
An incoming plane wave is scattered off an infinite rod.
In this section we use fixed project parameters: The surroundings consists of air. The incoming light field has a vacuum wavelength of
and is polarized in
-direction with amplitude equal to one. Hence, the illuminating field is given as

with
. The glass rod has a cross-section diameter of
and a refractive index of
, which gives a relative permittivity of
.
The input files to this project are given below. The project file mie2D.jcmp defines two post-processes. The first post-process computes the electromagnetic energy flux of the scattered field into the exterior domain. Up to normalization this is the integral scattering cross-section. The second post-process exports the computed field onto a Cartesian mesh.
The following driver run.m shows how to run the project in Matlab:
1%% run the project
2results = jcmwave_solve('mie2D.jcmp');
3
4%% get scattering cross section
5scattering_cross_section = ...
6 results{2}.ElectromagneticFieldEnergyFlux{1};
7fprintf('\nscattering cross section: %.8g\n', ...
8 real(scattering_cross_section));
9
10
11%% plot exported cartesian grid within matlab:
12cfb = results{3};
13amplitude = cfb.field{1};
14intensity = sum(conj(amplitude).*amplitude, 3);
15pcolor(cfb.X, cfb.Y, intensity);
16shading interp; view(0, 90); axis equal;
In line 2, the project is solved. The computed data is returned as a cell array, where results{1} refers to the fieldbag and the subsequent entries refer to result data of the post-processes. This way we can extract the scattering cross-section in lines 5 and 6. With lines 12-16 we plot the computed intensity, which was exported on a regular Cartesian grid, see Figure “Intensity”.
Intensity¶
Pseudo-color intensity plot as produced by the driver run.m.
For visualization of the computed fields you may also use the JCMview-tool which is available within Matlab by the wrapper jcmwave_view.m:
jcmwave_view(results{1}.file);
Here, results{1}.file is the file path to the computed solution fieldbag.
In the above driver run.m we have used the command jcmwave_solve, which automatically created the finite element mesh, solved the problem and loaded the result data. Often, when setting up a new project, you may first want to check if the geometry has been defined properly. To do this, call the mesh generator separately (driver run_geo.m):
%% generate mesh file only
jcmwave_geo('.');
%% open grid.jcm in JCMview
jcmwave_view('grid.jcm');
The next section Keyword Substitution shows how we can parameterize our test problem.
.jcm Input Files
layout.jcm [ASCII]
1Layout2D { 2 UnitOfLength = 1e-6 3 4 MeshOptions { 5 MaximumSideLength = 0.1 6 CurvilinearDegree = 2 7 } 8 Objects { 9 10 # Computational domain 11 Parallelogram { 12 DomainId = 1 13 Width = 4 14 Height = 4 15 16 # set transparent boundary conditions 17 Boundary{ 18 Class = Transparent 19 } 20 } 21 22 # Scatterer (rod) 23 Circle { 24 DomainId = 2 25 Radius = 0.5 26 } 27 } 28} 29 30
materials.jcm [ASCII]
1 2# material properties for the surroundings (air) 3Material { 4 DomainId = 1 5 RelPermittivity = 1.0 6 RelPermeability = 1.0 7} 8 9# material properties the glass rod 10Material { 11 DomainId = 2 12 RelPermittivity = 2.3104 # 1.52^2 13 RelPermeability = 1.0 14} 15
sources.jcm [ASCII]
1SourceBag { 2 Source { 3 ElectricFieldStrength { 4 PlaneWave { 5 K = [1.14239732857811e7 0.0 0.0] 6 Amplitude = [0 0 1] 7 } 8 } 9 } 10}
mie2D.jcmp [ASCII]
1Project { 2 InfoLevel = 3 3 Electromagnetics { 4 TimeHarmonic { 5 Scattering { 6 FieldComponents = Electric 7 Accuracy { 8 FiniteElementDegree = 3 9 Refinement { 10 MaxNumberSteps = 0 11 PreRefinements = 0 12 } 13 } 14 } 15 } 16 } 17} 18 19# computes the energy flux of the scattered field into the exterior domain 20PostProcess { 21 FluxIntegration { 22 FieldBagPath = "./mie2D_results/fieldbag.jcm" 23 OutputFileName = "./mie2D_results/energyflux_scattered.jcm" 24 OutputQuantity = ElectromagneticFieldEnergyFlux 25 InterfaceType = ExteriorDomain 26 } 27} 28 29# exports computed field on cartesian grid 30PostProcess { 31 ExportFields { 32 FieldBagPath = "./mie2D_results/fieldbag.jcm" 33 OutputFileName = "./mie2D_results/fieldbag_cartesian.jcm" 34 Cartesian { 35 NGridPointsX=200 36 NGridPointsY=200 37 } 38 } 39} 40 41