### 4.4.3. Metric Expressions

The metric for an optimization is an expression which can be combination of constants, variables and built-in functions. Optimizations will always attempt to drive the metric value to the Metric > Target(GHz) parameter in the algorithm.

The most common function found in metric expressions is cellvalue. The arguments for the cellvalue function are measurement label, row index, column index and default value. If the cell is not found in the measurement, the default value will be used instead.

Is is common to assign variables to expressions using cellvalue functions and then use those variables in the metric itself.

• Example 1

Description: Target resonant frequencies of the first 2 modes of a cavity.

Prerequisites: An eigenmode simulation with two modes shall be run prior to specifying the metric. A measurement of the mode summary table must exist so that the cell value functions can be used.

Variables:

• F1 = cellvalue('Measurement_1', 0, 0, '0Hz') (this is the mode 1 frequency)

• F2 = cellvalue('Measurement_1', 0, 1, '0Hz') (this is the mode 2 frequency)

Metric: abs(F1 - 0.45GHz) + abs(F2 - 0.80GHz)

Notes: In this case, set the Metric > Target(GHz) parameter in the algorithm to 0 GHz.

• Example 2

Description: Target a specific emission current and minimize beam ripple for a MICHELLE simulation.

Prerequisites: A MICHELLE simulation shall be run prior to specifying the metric. A measurement of the summary of results table must exist so that the cell value functions can be used.

Variables:

• C = cellvalue('Measurement_1', 0, 0, '0A') (this is the emitted current)

• BR = cellvalue('Measurement_1', 0, 9, '0') (this is the beam ripple)

Metric: abs(C - 0.1A) + BR