modelica-tools / FMUComplianceChecker

FMI Compliance Checker for validation of FMUs 1.0 and 2.0
BSD 3-Clause "New" or "Revised" License
42 stars 31 forks source link

Add check for missing initial value when using enumerations in input variables #49

Closed ghorwin closed 4 years ago

ghorwin commented 4 years ago

Hi there. I noticed a (probably) invalid modelDescription that is not yet flagged as wrong by compliance checker 2.0.4. Please see the following scalar variable definition:

<!-- Index of variable = "523" -->
<ScalarVariable
    name="Input.flowDirection"
    valueReference="20"
    description="Allowed flow direction"
    variability="fixed"
    causality="input"
    >
    <Enumeration declaredType="Modelica.Fluid.Types.PortFlowDirection"/>
</ScalarVariable>

Here, the initial value is missing and according to the table in "Functional Mock-up Interface 2.0", July 25, 2014, Page 48 of 126 the combination of fixed and input is invalid without initial variable.

From the co-simulation master point of view, the initial value is needed for initializing the input variable, so that a calculation is possible even without connected inputs.

Suggestion: as stated in the standard, "do not use fixed inputs, but rather use fixed parameters". So this may be a warning issued by the compliance checker, even if a start value is given.

IMHO, in any case, "initial"="exact" and a start value should be given in the enumeration for such cases.

nickbattle commented 4 years ago

This is picked up by VDMCheck, though I agree the error messages could be clearer:

2.2.7 Variable "Input.flowDirection" causality/variability/initial/start <input>/<fixed>/nil/nil invalid at line 20
2.2.7 Variable "Input.flowDirection" variability/causality <fixed>/<input> invalid at line 20
2.2.7 ScalarVariable "Input.flowDirection" invalid at line 20
2.2.1 ScalarVariables invalid
Errors found.

There are many cases like this that the compliance checker is missing.

ghorwin commented 4 years ago

Interesting - thanks for the link!

nickbattle commented 4 years ago

We're still working on VDMCheck, but it seems to pick up many more problems than the 2.0.4 compliance checker. If you find any issues with the tool, please raise them on the GitHub tracker.

ghorwin commented 4 years ago

A minor correction to my first post: "initial" attribute must not be given to ScalarVariables with causality "input" (this would violate standard rule on page 47 of the FMI 2.0 specs).

filip-stenstrom commented 4 years ago

I can't replicate this since I get an error message when trying to run with dummy XML on Checker 2.0.4:

[INFO][FMI2XML] [Line:32] Detected during parsing:
[ERROR][FMI2XML] Start attribute is required for this causality, variability and initial combination

Dummy XML I used:

<?xml version="1.0" encoding="UTF-8"?>
<fmiModelDescription
  fmiVersion="2.0"
  modelName="modelName"
  guid="{8c4e810f-3df3-4a00-8276-176fa3c9f9e0}"
  description="N/A"
  version="2.0"
  generationDateAndTime="2011-09-23T16:57:33Z"
  variableNamingConvention="structured">
  <ModelExchange modelIdentifier="model_identifier"/>

  <TypeDefinitions>
    <SimpleType name="Modelica.Fluid.Types.PortFlowDirection">
        <Enumeration>
            <Item name="In" value="0"/>
            <Item name="Out" value="1"/>
        </Enumeration>
    </SimpleType>
  </TypeDefinitions>

  <ModelVariables>
    <!-- Index of variable = "523" -->
    <ScalarVariable
          name="Input.flowDirection"
          valueReference="20"
          description="Allowed flow direction"
          variability="fixed"
          causality="input">
      <Enumeration declaredType="Modelica.Fluid.Types.PortFlowDirection"/>
    </ScalarVariable>
  </ModelVariables>

  <ModelStructure>
  </ModelStructure>

</fmiModelDescription>

Closing ticket since I can't replicate. Please re-open if you can provide a complete XML that it can be replicated on.

Also, regarding causality="input" variability="fixed", this has been fixed in FMI Library, so should be fixed with next Checker release.