Derivative Setup
This page shows how to configure a JCMsuite project for first-order derivatives. The example uses a two-dimensional electromagnetic project with a parameterized trapezoid.
Solver derivative support
JCMsuite computes solver derivatives only for Scattering projects.
PropagatingMode and ResonanceMode projects do not provide these derivatives.
Their eigenvalues cannot be used as solver-provided derivative data.
Declare Derivative Parameters
Declare each geometric or material quantity that must be differentiable with a
DerivativeParameter block. The Name value becomes the derivative output name. Each
TreeEntry identifies one or more values in the layout tree.
The TreeEntry can contain configuration paths and configuration object names. In this
example,
Layout2D/Objects selects the object collection. Line then selects the object whose
Name is Line. Finally, InnerAngles(2) selects the second entry of the
InnerAngles parameter.
Minimal example
This page shows only a minimal derivative-parameter setup. For complete syntax and workflows, refer to the JCMsuite solver documentation.
The example declares derivative parameters for the trapezoid width, height, side-wall angle, and corner radius:
DerivativeParameter {
Name = "width_parameter"
TreeEntry = "Layout2D/Objects/Line/Width"
}
DerivativeParameter {
Name = "height"
TreeEntry = "Layout2D/Objects/Line/Height"
}
DerivativeParameter {
Name = "swa"
TreeEntry = "Layout2D/Objects/Line/InnerAngles(1)"
TreeEntry = "Layout2D/Objects/Line/InnerAngles(2)"
}
DerivativeParameter {
Name = "radius"
TreeEntry = "Layout2D/Objects/Line/CornerRounding/Radius"
}
The derivative output name and the name of a project key do not have to match. In this
example, the solver calculates width_parameter from width. It calculates
height from h:
Height = %(h)e
Width = %(width)e
InnerAngles = [%(swa)e %(swa)e]
Radius = 8.0
Pass project keys to solve with keys=. The names
must match the template substitutions in layout.jcmt and materials.jcmt. In this
example, the project keys are h, width, swa, and permittivity. The derivative
output names are width_parameter, height, swa, and radius.
The project computes the radius derivative even though radius is not a project key.
The layout defines the base radius as 8.0. The solver evaluates the derivative at that
value. A derivative parameter can refer to a value that is fixed in the project template.
Enable Derivatives
Set the derivative order in the project file. Order = 1 requests first-order partial
derivatives. Set Order = 2 to request second-order partial derivatives.
Project {
Derivatives {
Order = 1
}
InfoLevel = 10
Electromagnetics {
TimeHarmonic {
Scattering {
FieldComponents = Electric
Accuracy {
FiniteElementDegree = 3
Precision = 0.001
}
}
}
}
}
The project contains a Fourier-transform postprocess, a scattering-matrix postprocess, and a field-export postprocess. See Derivative Export for the export workflow.
Project Files
The complete input files are included below.
run.py
import jcmsuite
results = jcmsuite.solve(
"project.jcmp",
keys={
"h": 55.0,
"width": 31.0,
"swa": 88.0,
"permittivity": 1.967 + 4.443j,
},
temporary=True,
)
flux_pp = results.postprocesses[0]
print(flux_pp)
project.jcmp
Project {
Derivatives {
Order = 1
}
InfoLevel = 10
Electromagnetics {
TimeHarmonic {
Scattering {
FieldComponents = Electric
Accuracy {
FiniteElementDegree = 3
Precision = 0.001
}
}
}
}
}
PostProcess {
FourierTransform {
FieldBagPath = "project_results/fieldbag.jcm"
OutputFileName = "project_results/fc.jcm"
NormalDirection = Y
Rotation = X:Z:-Y
Format = JCM
}
}
PostProcess {
ScatteringMatrix {
Format = JCM
InputFileName = "project_results/fc.jcm"
OutputFileName = "project_results/sm.jcm"
}
}
layout.jcmt
DerivativeParameter {
Name = "width_parameter"
TreeEntry = "Layout2D/Objects/Line/Width"
}
DerivativeParameter {
Name = "height"
TreeEntry = "Layout2D/Objects/Line/Height"
}
DerivativeParameter {
Name = "swa"
TreeEntry = "Layout2D/Objects/Line/InnerAngles(1)"
TreeEntry = "Layout2D/Objects/Line/InnerAngles(2)"
}
DerivativeParameter {
Name = "radius"
TreeEntry = "Layout2D/Objects/Line/CornerRounding/Radius"
}
Layout2D {
Name = "Line_with_derivatives"
UnitOfLength = 1e-9
MeshOptions {
MinimumMeshAngle = 25
SnapTolerance = 1e-6
MaximumSideLength = 10
}
Objects {
Parallelogram {
Name = "ComputationalDomain"
DomainId = 1
Priority = ComputationalDomain
Width = 90
Height = 100
Boundary {
Number = [1 3]
Class = TransparentBoundary
}
Boundary {
Number = [2 4]
Class = Periodic
}
}
Parallelogram {
Name = "Substrate"
DomainId = 3
Width = 90
Height = 20
Port = South
Alignment {
Parent {
Domain = "ComputationalDomain"
Port = South
}
Orientation = Parallel
}
}
Trapezoid {
Name = "Line"
DomainId = 2
Priority = 4
Height = %(h)e
Width = %(width)e
InnerAngles = [%(swa)e %(swa)e]
Port = South
Alignment {
Parent {
Domain = "Substrate"
Port = North
}
Orientation = AntiParallel
}
CornerRounding {
Point = [3 4]
Radius = 8.0
NPoints = 5
}
}
}
}
materials.jcmt
Material {
Name = "Material_1"
DomainId = 1
RelPermittivity = 1
RelPermeability = 1.0
}
Material {
Name = "Material_2"
DomainId = 2
RelPermittivity = 1.4
RelPermeability = 1.0
}
Material {
Name = "Material_3"
DomainId = 3
RelPermittivity = %(permittivity)g
RelPermeability = 1.0
}
sources.jcm
SourceBag {
Source {
ElectricFieldStrength {
PlaneWave {
3DTo2D = yes
Incidence = FromAbove
SP = [1 0]
Lambda0 = 3.65e-07
ThetaPhi = [65, 45]
}
}
}
}
SourceBag {
Source {
ElectricFieldStrength {
PlaneWave {
3DTo2D = yes
Incidence = FromAbove
SP = [0 1]
Lambda0 = 3.65e-07
ThetaPhi = [65, 45]
}
}
}
}