﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
5065	[NF] Conditions in IF equations are wrongly marked as structural parameters	Adrian Pop	Per Östlund	"
In NFInst we have:
https://github.com/OpenModelica/OMCompiler/blob/master/Compiler/NFFrontEnd/NFInst.mo#L3054

{{{#!mo
    case Equation.IF()
      algorithm
        all_params := true;

        for branch in eq.branches loop
          () := match branch
            case Equation.Branch.BRANCH()
              algorithm
                if all_params and Expression.variability(branch.condition) == Variability.PARAMETER then
                  markStructuralParamsExp(branch.condition);
                else
                  all_params := false;
                end if;

                updateImplicitVariabilityEql(branch.body);
              then
                ();
          end match;
        end for;
      then
        ();
}}}

If the condition is parameter it doesn't mean they are structural parameters. 

The specification says this:
{{{
If-equations in equation sections which do not have exclusively 
parameter expressions as switching conditions shall have the 
same number of equations in each branch.
}}}

This marking of IF conditions as structural make some models to fail, for example: Modelica.Blocks.Continuous.PID.

In this case we mark as structural:
{{{
set structural: I.initType/initType
set structural: initType/initType
set structural: D.initType/initType
set structural: D.zeroGain/zeroGain
set structural: D.k/k
set structural: Td/Td
}}}

D.zeroGain is selected as structural parameter because is a parameter and is an IF condition.

D.zeroGain depends on PID.Td which is also marked as structural.
Td in PID has no binding, just a start value and the NFCeval fails.
Now, we could use the start value because Td doesn't have fixed=false but I'm not sure if that is correct.

{{{
""[C:/home/adrpo33/dev/OMTesting/nf/pid.mo:176:9-176:92:writable] Notification: From here:
[C:/home/adrpo33/dev/OMTesting/nf/pid.mo:185:40-185:57:writable] Error: Constant Td is used without having been given a value.
[C:/home/adrpo33/dev/OpenModelica/OMCompiler/Compiler/NFFrontEnd/NFCeval.mo:720:9-720:67:writable] Error: Internal error NFCeval.evalBinaryDiv failed to evaluate ‘Td / 1.0‘
}}}

How should we fix this? Do we just use the start value?

In general thou', I think we cannot decide on structural parameters for IF equations until we type everything, expand the equations and we check that the number of equations are different in the branches. If the number of equations are different in the branches and the IF conditions depends on parameters that have no bindings, then we can issue an error.
"	defect	closed	high	2.0.0	New Instantiation		fixed		
