Click or drag to resize

Updating CircuitElement plugins

The RelaxISPlugin_CircuitElement class remains unchanged for compatibility and should work as before. It is now marked with ObsoleteAttribute to signal that a new class is recommended for new developments.

To ignore the generated warnings, add a suppression to your code:

C#
    public class MyCircuitElement
#pragma warning disable CS0618 // Type or member is obsolete
        : RelaxISPlugin_CircuitElement
#pragma warning restore CS0618 // Type or member is obsolete

The new RelaxISPlugin_CircuitElement2 class was added with a modernized interface that is recommended for new developments. This new class mainly changes how the default parameters are defined.

The RelaxISPlugin_CircuitElement returns individual lists for parameter default names, values, lower and limits and fixed states. This requires keeping the lists in sync when changing definitions - otherwise errors could arise.

In the new class, the previous lists StandardParameterNames, StandardParameterValues, StandardParameterLowerLimits, StandardParameterUpperLimits and StandardParameterFixedStates were therefore replaced by a new property: StandardParameters.

This returns a collection of Fitparameter objects. These objects each contain properties for name, value, lower limit, upper limit and fixed state and therefore combine the previous settings into one list.

Further, the definition for the GetTightLimits function has changed. The argument type was changed to facilitate the new combined ImpedanceSpectrum class and the return type was changed. Instead of returning a jagged array with one array for the lower limits and one for the upper limits, the function now returns a collection of Limits objects.

The calculation function CalculateImpedance was not changed.

The description below shows how you would update an old RelaxISPlugin_CircuitElement to a new RelaxISPlugin_CircuitElement2 plugin.

Prerequisites

Introduce using statements for the relevant namespaces.

C#
using System.Collections.Generic;
using RelaxIS_SDK.Common;
Replacing the individual lists with a new combined list.

Perform these steps to update the plugin

  1. Find the four mandatory overridden properties StandardParameterNames, StandardParameterValues, StandardParameterLowerLimits, StandardParameterUpperLimits. Also, check if StandardParameterFixedStates was overridden.

    Do not delete the properties yet, instead use them for reference for implementing the new property.

    C#
    public override string[] StandardParameterNames
    {
        get
        {
            return new string[]
            {
                "CPE Q",
                "CPE alpha",
            };
        }
    }
    
    public override double[] StandardParameterValues
    {
        get
        {
            return new string[]
            {
                1e-6,
                0.95,
            };
        }
    }
    
    public override double[] StandardParameterLowerLimits
    {
        get
        {
            return new double[]
            {
                1e-15,
                0.15,
            };
        }
    }
    
    public override double[] StandardParameterUpperLimits
    {
        get
        {
            return new double[]
            {
                1e-1,
                1,
            };
        }
    }
    
    // Optional!
    public override bool[] StandardParameterFixedStates
    {
        get
        {
            return new bool[]
            {
                false,
                false,
            };
        }
    }

    Add a new override for StandardParameters. Note, that the property type is IReadOnlyCollection<Fitparameter>. You can simply return a List<Fitparameter>, as the list also implements this interface.

    C#
    public override IReadOnlyCollection<Fitparameter> StandardParameters
    {
        get
        {
            // Constructor arguments are:
            // (Name, Fixed?, Value, Error, Lower Limit, Upper Limit)
            // The Error argument is unused here and can be set to 0.
    
            return new List<Fitparameter>()
            {
                new Fitparameter("CPE Q", false, 1e-6, 0, 1e-15, 1e-1),
                new Fitparameter("CPE alpha", false, 0.95, 0, 0.15, 1),
            };
        }
    }

    Note, that the constructor of the Fitparameter contains an argument for the Error field. This is unused here and can be ignored.

  2. After you have added the new override with the same values for the parameters as the previous lists, delete the previous 4-5 overrides.

  3. Find if the GetTightLimits function is overridden in the plugin.

    If so, first update the argument and return type of the plugin to ImpedanceSpectrum and IReadOnlyCollectionLimits, respectively.

    The function previously generated two arrays, one with lower, and one with upper limits. These were returned as a jagged array.

    C#
    public override double[][] GetTightLimits(ImpedanceSpectrum_Fitted Spectrum)
    {
        // Some algorithm to determine tight limits.
        // Assume these were stored in the newLowerLimits and newUpperLimits arrays
    
        // Combine the arrays into a result list
        return new double[2][] { newLowerLimits, newUpperLimits };
    }

    Instead, the values must be combined into a single list of Limits objects, for example as shown here:

    C#
    public override IReadOnlyCollection<Limits> GetTightLimits(ImpedanceSpectrum Spectrum)
    {
        // Some algorithm to determine tight limits.
        // Assume these were stored in the newLowerLimits and newUpperLimits arrays
    
        // Combine the arrays into a result list
        var res = new List<Limits>();
        for (int i = 0; i < newLowerLimits.Length; i++)
        {
            res.Add(new Limits(newLowerLimits[i], newUpperLimits[i]));
        }
    
        return res;
    }

    It might be preferrable to replace the generation of the intermediate arrays completely by initially creating the list and adding to the list directly instead of first populating separate arrays.

See Also