# Derivative Setup This page shows how to configure a JCMsuite {term}`project` for first-order derivatives. The example uses a two-dimensional electromagnetic {term}`project` with a parameterized trapezoid. ```{admonition} Solver derivative support :class: note 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. ```{admonition} Minimal example :class: note 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: ```{literalinclude} ../../demos/documentation_tutorials/derivatives/setup_and_export/setup/layout.jcmt :language: jcm :lines: 1-17 ``` The derivative output name and the name of a {term}`project key ` do not have to match. In this example, the solver calculates `width_parameter` from `width`. It calculates `height` from `h`: ```jcm Height = %(h)e Width = %(width)e InnerAngles = [%(swa)e %(swa)e] Radius = 8.0 ``` Pass {term}`project keys` to {func}`solve ` with `keys=`. The names must match the template substitutions in `layout.jcmt` and `materials.jcmt`. In this example, the {term}`project keys` are `h`, `width`, `swa`, and `permittivity`. The derivative output names are `width_parameter`, `height`, `swa`, and `radius`. The {term}`project` computes the `radius` derivative even though `radius` is not a {term}`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 {term}`project` template. ## Enable Derivatives Set the derivative order in the {term}`project` file. `Order = 1` requests first-order partial derivatives. Set `Order = 2` to request second-order partial derivatives. ```{literalinclude} ../../demos/documentation_tutorials/derivatives/setup_and_export/setup/project.jcmp :language: jcm :lines: 1-17 ``` The {term}`project` contains a Fourier-transform postprocess, a scattering-matrix postprocess, and a field-export postprocess. See [Derivative Export](export.md) for the export workflow. ## Project Files The complete input files are included below.
run.py ```{literalinclude} ../../demos/documentation_tutorials/derivatives/setup_and_export/setup/run.py :language: python ```
project.jcmp ```{literalinclude} ../../demos/documentation_tutorials/derivatives/setup_and_export/setup/project.jcmp :language: jcm ```
layout.jcmt ```{literalinclude} ../../demos/documentation_tutorials/derivatives/setup_and_export/setup/layout.jcmt :language: jcm ```
materials.jcmt ```{literalinclude} ../../demos/documentation_tutorials/derivatives/setup_and_export/setup/materials.jcmt :language: jcm ```
sources.jcm ```{literalinclude} ../../demos/documentation_tutorials/derivatives/setup_and_export/setup/sources.jcm :language: jcm ```