Skip to content

Commit

Permalink
Add Tests and @doclink trial
Browse files Browse the repository at this point in the history
  • Loading branch information
nickbattle committed Jan 13, 2024
1 parent 2aaff4b commit 3cecdce
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 3 deletions.
6 changes: 4 additions & 2 deletions fmi2/rule-model/Common.vdmsl
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ functions
minMaxOfKind: Kind -> real * real
minMaxOfKind(kind) ==
cases kind:
<Integer> -> mk_(-3.402823466385288598e+38, 3.402823466385288598e+38),
<Real> -> mk_(-1.797693134862315708e+308, 1.797693134862315708e+308),
<Integer> -> mk_(-3.402823466385288598e+38, 3.402823466385288598e+38),
<Enumeration> -> mk_(-9.223372036854775808e+18, 9.223372036854775807e+18), -- xs:long = Int64
others -> undefined
end;
Expand All @@ -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 <Integer>
if is_(v, Real) or is_(v, RealType) then <Real>
elseif is_(v, Integer) or is_(v, IntegerType) then <Integer>
elseif is_(v, Boolean) or is_(v, BooleanType) then <Boolean>
elseif is_(v, String) or is_(v, StringType) then <String>
elseif is_(v, Enumeration) or is_(v, EnumerationType) then <Enumeration>
Expand Down
2 changes: 1 addition & 1 deletion fmi2/rule-model/FMIModelDescription.vdmsl
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
1 change: 1 addition & 0 deletions fmi2/rule-model/Rules/FmiModelDescription.adoc.vdmsl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ validVendorAnnotations(fmd) ==
( card { name | name in seq tools } = len tools );
----
----
-- @DocLink("<FMI3_STANDARD>#table-schema-fmiModelDescription")
validModelTypes: FmiModelDescription +> bool
validModelTypes(fmd) ==
-- @OnFail("%NAME: At least one of ModelExchange, CoSimulation or ScheduledExecution must be set")
Expand Down
1 change: 1 addition & 0 deletions fmi2/rule-model/Rules/ModelVariables.adoc.vdmsl
Original file line number Diff line number Diff line change
Expand Up @@ -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
([
Expand Down
102 changes: 102 additions & 0 deletions fmi2/rule-model/Tests/SpringMassDamper.vdmsl
Original file line number Diff line number Diff line change
@@ -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, <structured>, 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, <parameter>, <fixed>, 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, <input>, 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, <output>, 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, <output>, 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)
]
)
);

0 comments on commit 3cecdce

Please sign in to comment.