Working with Parameters in the System of Non-Linear Equations

The System of Non-linear Equations model (SNE) supports use of parameters. Parameters set for its parent metamodel can be used in the model equations included to SNE.

This example describes use of the metamodel (that is parent to SNE) parameter in the equation of the model that is included to SNE.

The repository should contains a modeling container with the CONT_MODEL identifier. This container includes SNE, a metamodel for its calculation with the META_MODEL identifier and a model with the MODEL identifier included to SNE. The model must be calculated as a determinate equation.

To execute the example, add links to the Metabase, Ms, Db system assemblies.

    Sub UserProc;
    Var
        Mb: IMetabase;
        pMSDescr: IMetabaseObjectDescriptor;
        pMetaModel: IMsMetaModel;
        pParams: IMsModelParams;
        pParam: IMsModelParam;
        pModel: IMsModel;
        pTransf: IMsFormulaTransform;
        Varable: IMsFormulaTransformVariable;
        Slice: IMsFormulaTransformSlice;
        Term: IMsFormulaTerm;
        pFormula: IMsFormula;
        pDeterm: IMsDeterministicTransform;
    Begin
        Mb := MetabaseClass.Active;
        pMSDescr := mb.ItemById("CONT_MODEL");
        pMetaModel := Mb.ItemByIdNamespace("META_MODEL", pMSDescr.Key).Edit As IMsMetaModel;
    // Add parameter to metamodel
        pParams := pMetaModel.Params;
        pParam := pParams.Add;
        pParam.Id := "COEF_VAL";
        pParam.Name := "COEF_VAL";
        pParam.DataType := DbDataType.Float;
        pParam.DefaultValue := 0.99;
        (pMetaModel As IMetabaseObject).Save;
    // Get calculation parameters of the model included to SNE
        pModel := Mb.ItemByIdNamespace("MODEL", pMSDescr.Key).Edit As IMsModel;
        pTransf := pModel.Transform;
        pFormula := pTransf.FormulaItem(0);
        pDeterm := pFormula.Method As IMsDeterministicTransform;
    // Add parameter to the model calculation formula
        Varable := pTransf.Inputs.AddParamVariable(pParam.Id);
        Slice := Varable.Slices.Add(Null);
        Term := pDeterm.Operands.Add(Slice);
        pDeterm.Expression.AsString := "(" + pDeterm.Expression.AsString + ") + " + Term.TermToInnerText;
    // Saving the model
        If pDeterm.Expression.Valid
            Then (pModel As IMetabaseObject).Save;
            Else Debug.WriteLine(Saving the model is impossible: error in the formula!");
        End If;
    End Sub UserProc;

After executing the example the COEF_VAL parameter is added to the MODEL model calculation equation, its value can be set from the SNE that contains the given model.

See also:

Examples

IMsNonLinearEquationsTransform