diff --git a/fmi2/rule-model/Common.vdmsl b/fmi2/rule-model/Common.vdmsl index 6b75615..42d9aaa 100644 --- a/fmi2/rule-model/Common.vdmsl +++ b/fmi2/rule-model/Common.vdmsl @@ -87,7 +87,8 @@ functions minMaxOfKind: Kind -> real * real minMaxOfKind(kind) == cases kind: - -> mk_(-3.402823466385288598e+38, 3.402823466385288598e+38), + -> mk_(-1.797693134862315708e+308, 1.797693134862315708e+308), + -> mk_(-3.402823466385288598e+38, 3.402823466385288598e+38), -> mk_(-9.223372036854775808e+18, 9.223372036854775807e+18), -- xs:long = Int64 others -> undefined end; @@ -98,7 +99,8 @@ functions kindOf: Real | Integer | Boolean | String | Enumeration | RealType | IntegerType | BooleanType | StringType | EnumerationType +> Kind kindOf(v) == - if is_(v, Integer) or is_(v, IntegerType) then + if is_(v, Real) or is_(v, RealType) then + elseif is_(v, Integer) or is_(v, IntegerType) then elseif is_(v, Boolean) or is_(v, BooleanType) then elseif is_(v, String) or is_(v, StringType) then elseif is_(v, Enumeration) or is_(v, EnumerationType) then diff --git a/fmi2/rule-model/FMIModelDescription.vdmsl b/fmi2/rule-model/FMIModelDescription.vdmsl index 88641ae..79aa3cb 100644 --- a/fmi2/rule-model/FMIModelDescription.vdmsl +++ b/fmi2/rule-model/FMIModelDescription.vdmsl @@ -47,7 +47,7 @@ types rule("validModelAttributes", validModelAttributes(fmd)), rule("validVendorAnnotations", validVendorAnnotations(fmd)), rule("validGenerationDateAndTime", validGenerationDateAndTime(fmd)), - rule("validModelTypes", validModelTypes(fmd)), + validModelTypes(fmd), rule("validTypeUnits", validTypeUnits(fmd)), rule("validVariableTypes", validVariableTypes(fmd)), rule("validVariableNames", validVariableNames(fmd)), diff --git a/fmi2/rule-model/Rules/FmiModelDescription.adoc.vdmsl b/fmi2/rule-model/Rules/FmiModelDescription.adoc.vdmsl index 98d85e3..c0c8271 100644 --- a/fmi2/rule-model/Rules/FmiModelDescription.adoc.vdmsl +++ b/fmi2/rule-model/Rules/FmiModelDescription.adoc.vdmsl @@ -18,6 +18,7 @@ validVendorAnnotations(fmd) == ( card { name | name in seq tools } = len tools ); ---- ---- +-- @DocLink("#table-schema-fmiModelDescription") validModelTypes: FmiModelDescription +> bool validModelTypes(fmd) == -- @OnFail("%NAME: At least one of ModelExchange, CoSimulation or ScheduledExecution must be set") diff --git a/fmi2/rule-model/Rules/ModelVariables.adoc.vdmsl b/fmi2/rule-model/Rules/ModelVariables.adoc.vdmsl index c5fa5dc..fa1e983 100644 --- a/fmi2/rule-model/Rules/ModelVariables.adoc.vdmsl +++ b/fmi2/rule-model/Rules/ModelVariables.adoc.vdmsl @@ -14,6 +14,7 @@ validValueReferences(mvs) == validAliasNames: ModelVariables +> bool validAliasNames(mvs) == let refmap = getAliasRefMap(mvs) in + card dom refmap < len mvs => -- Must be some aliases { let aliases = refmap(ref) in allOf ([ diff --git a/fmi2/rule-model/Tests/SpringMassDamper.vdmsl b/fmi2/rule-model/Tests/SpringMassDamper.vdmsl new file mode 100644 index 0000000..f448f3a --- /dev/null +++ b/fmi2/rule-model/Tests/SpringMassDamper.vdmsl @@ -0,0 +1,102 @@ +/********************************************************************************* + * + * Copyright (c) 2017-2022, INTO-CPS Association, + * c/o Professor Peter Gorm Larsen, Department of Engineering + * Finlandsgade 22, 8200 Aarhus N. + * + * MIT Licence: + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the + * Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + * + *********************************************************************************/ + +/** + * The model definition for the Spring Mass Damper example in section 4.3.2 on p111 + */ +functions + test: () +> bool + test() == + isValidFMIConfiguration(springMassDamper, nil, nil); + +values + loc : Location = mk_Location("?", 1); -- Dummy location + + springMassDamper = mk_FmiModelDescription + ( + -- Attributes + loc, + "2.0", "MassSpringDamper", "GUID", nil, nil, nil, nil, nil, nil, nil, , nil, + + -- Model types + mk_ModelExchange(loc, "MSD", nil, nil, nil, nil, nil, nil, nil, nil), + nil, + + -- Unit definitions + nil, + + -- TypeDefinitions + [ + mk_SimpleType(loc, "Modelica.SIunits.Inertia", nil, mk_RealType(loc, nil, nil, nil, nil, 0, nil, nil, nil)), + mk_SimpleType(loc, "Modelica.SIunits.Torque", nil, mk_RealType(loc, nil, nil, nil, nil, nil, nil, nil, nil)), + mk_SimpleType(loc, "Modelica.SIunits.AngularVelocity", nil, mk_RealType(loc, nil, nil, nil, nil, nil, nil, nil, nil)), + mk_SimpleType(loc, "Modelica.SIunits.Angle", nil, mk_RealType(loc, nil, nil, nil, nil, nil, nil, nil, nil)) + ], + + -- Log categories + nil, + + -- Default experiment + nil, + + -- Vendor annotations + nil, + + -- ScalarVariables + [ +/* 1 */ mk_ScalarVariable(loc, "inertial.J", 0, nil, , , nil, nil, + mk_Real(loc, "Modelica.SIunits.Inertia", nil, nil, nil, nil, nil, nil, nil, nil, 1, nil, nil), nil), + +/* 2 */ mk_ScalarVariable(mk_Location("F", 2), "torque.tau", 1, nil, , nil, nil, nil, + mk_Real(loc, "Modelica.SIunits.Torque", nil, nil, nil, nil, nil, nil, nil, nil, 0, nil, nil), nil), + +/* 3 */ mk_ScalarVariable(mk_Location("F", 3), "inertial.phi", 2, nil, , nil, nil, nil, + mk_Real(loc, "Modelica.SIunits.Angle", nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil), nil), + +/* 4 */ mk_ScalarVariable(mk_Location("F", 4), "inertial.w", 3, nil, , nil, nil, nil, + mk_Real(loc, "Modelica.SIunits.AngularVelocity", nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil), nil) + ], + + mk_ModelStructure + ( + loc, + -- Outputs + [ + mk_Unknown(loc, 3, nil, nil), + mk_Unknown(loc, 4, nil, nil) + ], + -- Derivatives + nil, + -- InitialUnknowns + [ + mk_Unknown(loc, 3, nil, nil), + mk_Unknown(loc, 4, nil, nil) + ] + ) + ); \ No newline at end of file