@@ -20,6 +20,7 @@ Initially, there are only the KerML standard libraries.
2020### Import of namespaces
2121Other namespaces can be imported to simplify the notations.
2222For example, the standard package ``` ScalarValues ``` introduces standard data types like:
23+
2324- Real
2425- Boolean
2526- Integer
@@ -30,7 +31,8 @@ By importing the namespace of the package ```ScalarValues``` we can access it
3031by its simple name as follows:
3132``` SysML::kickstart
3233 private import ScalarValues::*; // Allows us shortcuts to Real, Integer, etc.
33- private import SI::*; // Allows us shortcuts to Domains
34+ private import SI::*; // Allows us shortcuts to Domains
35+ private import Ranges::*; // Allows us to specify constraints & co/contravariance
3436 attribute r: Real = oneOf(2.0 .. 3.0); // assigns r a value, constraine to the range 2 to 3.
3537 attribute i: Integer = 2; // assigns i the value 2.
3638```
@@ -53,18 +55,18 @@ It provides additional means to add constraints to numbers; the constraints can
5355``` Markdown
5456library package Ranges {
5557 // Abstract concept of a Range from which a Real is chosen
56- datatype InRange {
57- feature min: ScalarValues::Real;
58- feature max: ScalarValues::Real;
59- inv { (min <= self) and (self <= max) }
58+ abstract datatype InRange {
59+ feature range: Ranges::Range; // Models a range
60+ inv { (that.min <= self) and (that <= range.max) }
6061 }
61- datatype AllInRange :> InRange;
62+ abstract datatype AllInRange :> InRange; // ...
63+ abstract datatype QuantityInRange :> InRange; // ...
6264}
6365```
6466 These constraints are used to represent and propagate constraints, where
6567
66- - _ min _ is a known lower bound,
67- - _ max _ is a known upper bound,
68+ - _ range _ bounds the range of a Number (e.g. Integer, Real) to the given range.
69+
6870- _ AllInRange_ specifies that the constraint system shall be satisfied for all values in the range _ min .. max_ .
6971
7072Below, we give some simple examples.
@@ -84,7 +86,7 @@ part rangeExample {
8486 attribute height: Length = oneOf(10.0 .. 100.0 [cm]);
8587 attribute width: Length = oneOf(1.0 .. 1.1 [m]);
8688 attribute length: Length = oneOf(1.0 .. 1.1 [m]);
87- attribute volume: Volume = height * width * length {
89+ attribute volume: Volume, Ranges::QuantityInRange = height * width * length {
8890 :>> range = "1000.0 .. 2000.0";
8991 :>> unit = "l";
9092 }
@@ -141,10 +143,10 @@ Units are converted automatically before computations are done, and the consiste
141143the unit left of a dependency, and the unit right of it must be convertible into each other.
142144``` SysML::kickstart
143145 package unitsExample {
144- attribute t: Time [s] = 1.0 [s];
145- attribute v: Speed [m/s] = 3.0 [m/s];
146- attribute g: Acceleration [m/s^2] = 4.0 [m/s^2];
147- attribute s: Speed [m/s] = sqrt(sqr(v)+sqr(g)*sqr(t));
146+ attribute t: Time = 1.0 [s];
147+ attribute v: Speed = 3.0 [m/s];
148+ attribute g: Acceleration = 4.0 [m/s^2];
149+ attribute s: Speed = sqrt(sqr(v)+sqr(g)*sqr(t));
148150 }
149151```
150152Play with the units, e.g., by changing the unit after the type declaration or try ms instead of s.
@@ -153,7 +155,7 @@ For date and time, the ISO format is supported.
153155We can add and subtract times in this format.
154156``` SysML::kickstart::unitsExample
155157 attribute date: Time [DateTime] = DateTime("2021-10-10T03:00:00");
156- attribute time: Time [a] = 1.0 a;
158+ attribute time: Time = 1.0 a {:>> unit="a";}
157159 attribute dateResult: Time [DateTime] = date + time;
158160```
159161### Vectors
@@ -163,17 +165,17 @@ operations like the angle or cross-product.
163165Here is an example for defining vectors:
164166``` SysML::kickstart
165167package vectors {
166- attribute a: Mass(0.0.. 1.0,1.0..2.0) [kg] = (0.5,1.5) kg;
168+ attribute a: Mass = (0.5,1.5) kg {:>> range="0.0.. 1.0,1.0..2.0";}
167169 attribute b: Mass = (0.5,1.5) kg;
168- attribute c: Mass(-5.0..-1.0, -1.0..2.0, 2.0..4.0) [kg] = ( -5.0, -1.0, 3.0) kg;
170+ attribute c: Mass = (-5.0, -1.0, 3.0) kg {:>> range=" -5.0..-1.0, -1.0..2.0, 2.0..4.0";}
169171}
170172```
171173In the next example, there is a calculation with Vectors with the cross-product and angle.
172174``` SysML::kickstart::vectors
173- attribute a2: Real( 1..1,5..5,10..10);
174- attribute b2: Real( 5..5,1..1,10..10);
175+ attribute a2: Real, InRange {:>> range=" 1..1,5..5,10..10";}
176+ attribute b2: Real, InRange {:>> range=" 5..5,1..1,10..10";}
175177 attribute c2: Real = a2 cross b2;
176- attribute d2: Quantity [°] = angle(a2,b2);
178+ attribute d2: Quantity = angle(a2,b2) {:>>unit="°";}
177179```
178180## Types and Functions in Expressions
179181SysMD supports the following types:
@@ -249,13 +251,13 @@ vehicles via its path as shown in the example below.
249251``` SysML::kickstart
250252 package carParts {
251253 part def Body {
252- attribute mass: Mass( 300.0) [kg];
254+ attribute mass: Mass {:>> range=" 300.0";}
253255 }
254256 part def Engine {
255- attribute mass: Mass( 300.0) [kg];
257+ attribute mass: Mass {:>> range=" 300.0";}
256258 }
257259 part def Wheel {
258- attribute mass: Mass( 50.0) [kg];
260+ attribute mass: Mass {:>> range=" 50.0";}
259261 }
260262 }
261263```
@@ -291,14 +293,14 @@ Specializations inherit features.
291293 // We consider a vehicle to be anything that has at least one wheel.
292294 // The bySubclasses determines a consistent value for mass with min diameter.
293295 part def Vehicle {
294- attribute mass: Mass(0..1000) [kg] = bySpecializations(mass);
296+ attribute mass: Mass = bySpecializations(mass) {:>> range ="0..1000";}
295297 part wheels: carParts::Wheel[1 .. *];
296298 }
297299
298300 // A car is a vehicle with Body and Engine.
299301 // the sumOverParts determines a consistent minimal range consistent with parts.
300302 part def Car :> Vehicle {
301- attribute redefines mass: Mass(0 .. 1000)[kg] = sumOverParts(mass);
303+ attribute redefines mass: Mass = sumOverParts(mass) {:>> range ="0 .. 1000";}
302304 part wheels: carParts::Wheel[4 .. 10];
303305 part body: carParts::Body;
304306 part engine: carParts::Engine;
@@ -321,7 +323,7 @@ Boolean properties. They may also have a physical unit. Then, we specify:
321323
322324There is also a possibility to define user defined functions with any number of input variables .
323325These functions can be defined once and used multiple times.
324- ``` SysML::Global:: kickstart
326+ ``` SysML::kickstart
325327 package CalculationExample {
326328 // Definition of a Calculation
327329 calc def calcEnergy {
0 commit comments