Skip to content

Commit 8b04712

Browse files
authored
Merge pull request #7 from ModelDriven/ST6RI-16
ST6RI-16 Implement Quantities and Units library (syntax)
2 parents d6bcfd2 + c572d7a commit 8b04712

10 files changed

Lines changed: 429 additions & 109 deletions

File tree

sysml/src/demonstration/2018-10-09/Parts Interconnection Demo.alf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package 'Parts Interconnection Demo' {
2-
import 'Parts Tree'::'Create Generic Hierarchical Structure'::*;
2+
import 'Parts Tree Demo'::'Create Generic Hierarchical Structure'::*;
33

44
/* DEFINITIONS */
55

@@ -50,8 +50,8 @@ package 'Parts Interconnection Demo' {
5050
}
5151

5252
assoc DriveshaftInterface {
53-
end port shaftPort_a: ShaftPort_a;
54-
end port shaftPort_d: ShaftPort_d;
53+
port shaftPort_a: ShaftPort_a;
54+
port shaftPort_d: ShaftPort_d;
5555

5656
part driveShaft: Driveshaft {
5757
port shaftPort_b: ShaftPort_b;

sysml/src/examples/Vehicle Example/VehicleDefinitions.alf

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,38 @@
22
* Example vehicle definitions model.
33
**/
44
package VehicleDefinitions {
5-
/** Import ScalarValues library **/
5+
// Import ScalarValues library
66
import ScalarValues::*;
77

8-
/** Import Quantities libraries **/
8+
// Import Quantities libraries
99
import Quantities::*;
10+
import UnitsAndScales::*;
1011
import ISQ::*;
1112

12-
/* VALUE TYPES */
13+
/* LOCALLY DEFINED VALUE TYPES */
1314

14-
/** Torque unit value type defined as a force unit times a length unit. **/
15+
/*
16+
* Torque measurement unit (and implied ratio scale) defined as a force unit times a length unit.
17+
*/
1518
class TorqueUnit specializes DerivedUnit {
16-
feature unitFactor1 subsets unitFactor {
17-
feature unit: ForceUnit redefines MeasurementUnitPowerFactor::unit;
18-
feature exponent redefines MeasurementUnitPowerFactor::exponent = 1;
19+
feature unitPowerFactor1 subsets unitPowerFactor {
20+
unit: ForceUnit redefines unit;
21+
exponent redefines exponent = 1;
1922
}
20-
feature unitFactor2 subsets unitFactor {
21-
feature unit: LengthUnit redefines MeasurementUnitPowerFactor::unit;
22-
feature exponent redefines MeasurementUnitPowerFactor::exponent = 1;
23+
unitPowerFactor2 subsets unitPowerFactor {
24+
unit: LengthUnit redefines unit;
25+
exponent redefines exponent = 1;
2326
}
2427
}
2528

26-
/** Torque quantity value type defined as a real value with a torque unit. **/
27-
class Torque specializes Quantity {
28-
feature numericValue: Real redefines Quantity::numericValue;
29-
feature unit: TorqueUnit redefines Quantity::unit;
29+
/*
30+
* Torque quantity value and feature defined as a real magnitude with a torque unit.
31+
*/
32+
class TorqueValue specializes QuantityValue {
33+
magnitude: Real redefines Quantities::QuantityValue::magnitude;
34+
scale: TorqueUnit redefines Quantities::QuantityValue::scale;
3035
}
36+
feature torque : TorqueValue;
3137

3238
/* BLOCKS */
3339

@@ -42,21 +48,21 @@ package VehicleDefinitions {
4248
class Wheel { }
4349

4450
class Lugbolt {
45-
feature tighteningTorque: Torque;
51+
tighteningTorque: torque;
4652
}
4753

4854
/* INTERFACE BLOCKS */
4955

5056
class DriveIF {
51-
feature in driveTorque: Torque;
57+
feature in driveTorque: torque;
5258
}
5359

5460
class AxleMountIF {
55-
feature out transferredTorque: Torque;
61+
feature out transferredTorque: torque;
5662
}
5763

5864
class WheelHubIF {
59-
feature in appliedTorque: Torque;
65+
feature in appliedTorque: torque;
6066
}
6167

6268
/* ASSOCIATION BLOCKS */

sysml/src/examples/Vehicle Example/VehicleUsages.alf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ package VehicleUsages {
1010

1111
'N・m': VehicleDefinitions::TorqueUnit = N * m;
1212

13-
T1: Torque = 10.0@['N・m']; // Torque(10.0, 'N・m')
14-
T2: Torque = 20.0@['N・m']; // Torque(20.0, 'N・m')
13+
T1: torque = 10.0@['N・m']; // torque(10.0, 'N・m')
14+
T2: torque = 20.0@['N・m']; // torque(20.0, 'N・m')
1515

1616
/* PARTS */
1717

@@ -26,7 +26,7 @@ package VehicleUsages {
2626
}
2727

2828
/** Basic Vehicle configuration showing a part hierarchy. **/
29-
vehicle_C1: Vehicle {
29+
vehicle_C1: torque {
3030
part frontAxleAssembly: AxleAssembly {
3131
part frontWheel[2] redefines narrowRimWheel {
3232
part lugbolt[4] redefines narrowRimWheel::lugbolt {

sysml/src/library/Base.alf

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
11
package Base {
22

3+
/*
4+
* Top level generalized type in the language.
5+
*/
36
abstract class Anything { }
47

8+
/*
9+
* Second level basic types.
10+
* Object represents a class of concepts with reference identity.
11+
* Value represents a class of concepts with value identity.
12+
*/
13+
abstract class Object specializes Anything { }
514
abstract class Value specializes Anything { }
15+
616
abstract class Enumeration specializes Value { }
717

8-
abstract class Object specializes Anything { }
9-
18+
/*
19+
* Representation of a relationship between two or more things.
20+
*/
1021
class Link specializes Object {
1122
feature participant: Anything[2..*] ordered;
1223
}
1324

25+
/*
26+
* Representation of a directed binary relationship between exactly two things, from source to target.
27+
*/
1428
assoc BinaryLink specializes Link {
1529
end sourceEnd: Anything[0..*];
1630
end targetEnd: Anything[0..*];
@@ -23,6 +37,5 @@ package Base {
2337
private connector linkage: BinaryLink
2438
(sourceEnd[1..1] => sourceParticipant,
2539
targetEnd[1..1] => targetParticipant);
26-
}
27-
40+
}
2841
}

sysml/src/library/ISQ.alf

Lines changed: 103 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,122 @@
11
package ISQ {
2+
import ScalarValues::Real;
3+
import UnitsAndScales::*;
24

3-
// Base Quantity Kinds
4-
class LengthUnit specializes Quantities::SimpleUnit { }
5-
class MassUnit specializes Quantities::SimpleUnit { }
6-
class TimeUnit specializes Quantities::SimpleUnit { }
7-
class ElectricCurrentUnit specializes Quantities::SimpleUnit { }
8-
class TemperatureUnit specializes Quantities::SimpleUnit { }
9-
class AmountOfSubstanceUnit specializes Quantities::SimpleUnit { }
10-
class LuminousIntensityUnit specializes Quantities::SimpleUnit { }
5+
// Seven base quantities defined as abstract base units that span the power space of the ISO/IEC 80000 system of quantities
6+
class LengthUnit specializes UnitsAndScales::SimpleUnit {
7+
feature unitPowerFactor redefines UnitsAndScales::SimpleUnit::unitPowerFactor {
8+
feature unit: LengthUnit redefines UnitsAndScales::UnitPowerFactor::unit;
9+
}
10+
}
11+
class MassUnit specializes UnitsAndScales::SimpleUnit {
12+
feature unitPowerFactor redefines UnitsAndScales::SimpleUnit::unitPowerFactor {
13+
feature unit: MassUnit redefines UnitsAndScales::UnitPowerFactor::unit;
14+
}
15+
}
16+
class TimeUnit specializes UnitsAndScales::SimpleUnit {
17+
feature unitPowerFactor redefines UnitsAndScales::SimpleUnit::unitPowerFactor {
18+
feature unit: TimeUnit redefines UnitsAndScales::UnitPowerFactor::unit;
19+
}
20+
}
21+
class ElectricCurrentUnit specializes UnitsAndScales::SimpleUnit {
22+
feature unitPowerFactor redefines UnitsAndScales::SimpleUnit::unitPowerFactor {
23+
feature unit: ElectricCurrentUnit redefines UnitsAndScales::UnitPowerFactor::unit;
24+
}
25+
}
26+
class TemperatureUnit specializes UnitsAndScales::SimpleUnit {
27+
feature unitPowerFactor redefines UnitsAndScales::SimpleUnit::unitPowerFactor {
28+
feature unit: TemperatureUnit redefines UnitsAndScales::UnitPowerFactor::unit;
29+
}
30+
}
31+
class AmountOfSubstanceUnit specializes UnitsAndScales::SimpleUnit {
32+
feature unitPowerFactor redefines UnitsAndScales::SimpleUnit::unitPowerFactor {
33+
feature unit: AmountOfSubstanceUnit redefines UnitsAndScales::UnitPowerFactor::unit;
34+
}
35+
}
36+
class LuminousIntensityUnit specializes UnitsAndScales::SimpleUnit {
37+
feature unitPowerFactor redefines UnitsAndScales::SimpleUnit::unitPowerFactor {
38+
feature unit: LuminousIntensityUnit redefines UnitsAndScales::UnitPowerFactor::unit;
39+
}
40+
}
1141

12-
// Derived Quantity Kinds
13-
class ForceUnit specializes Quantities::DerivedUnit {
14-
unitFactor1 subsets Quantities::DerivedUnit::unitFactor {
15-
unit: MassUnit redefines Quantities::MeasurementUnitPowerFactor::unit;
16-
exponent redefines Quantities::MeasurementUnitPowerFactor::exponent = 1;
42+
// Derived Quantity Kinds
43+
class ForceUnit specializes UnitsAndScales::DerivedUnit {
44+
feature unitPowerFactor1 subsets UnitsAndScales::MeasurementUnit::unitPowerFactor {
45+
unit: MassUnit redefines UnitsAndScales::UnitPowerFactor::unit;
46+
exponent redefines UnitsAndScales::UnitPowerFactor::exponent = 1;
1747
}
18-
unitFactor2 subsets Quantities::DerivedUnit::unitFactor {
19-
unit: LengthUnit redefines Quantities::MeasurementUnitPowerFactor::unit;
20-
exponent redefines Quantities::MeasurementUnitPowerFactor::exponent = 1;
48+
unitPowerFactor2 subsets UnitsAndScales::MeasurementUnit::unitPowerFactor {
49+
unit: LengthUnit redefines UnitsAndScales::UnitPowerFactor::unit;
50+
exponent redefines UnitsAndScales::UnitPowerFactor::exponent = 1;
2151
}
22-
unitFactor3 subsets Quantities::DerivedUnit::unitFactor {
23-
unit: TimeUnit redefines Quantities::MeasurementUnitPowerFactor::unit;
24-
exponent redefines Quantities::MeasurementUnitPowerFactor::exponent = -2;
52+
unitPowerFactor3 subsets UnitsAndScales::MeasurementUnit::unitPowerFactor {
53+
unit: TimeUnit redefines UnitsAndScales::UnitPowerFactor::unit;
54+
exponent redefines UnitsAndScales::UnitPowerFactor::exponent = -2;
2555
}
2656
}
2757

58+
class SpeedUnit specializes UnitsAndScales::DerivedUnit {
59+
feature unitPowerFactor1 subsets UnitsAndScales::MeasurementUnit::unitPowerFactor {
60+
unit: LengthUnit redefines UnitsAndScales::UnitPowerFactor::unit;
61+
exponent redefines UnitsAndScales::UnitPowerFactor::exponent = 1;
62+
}
63+
unitPowerFactor2 subsets UnitsAndScales::MeasurementUnit::unitPowerFactor {
64+
unit: TimeUnit redefines UnitsAndScales::UnitPowerFactor::unit;
65+
exponent redefines UnitsAndScales::UnitPowerFactor::exponent = -1;
66+
}
67+
}
68+
2869
// ...
2970

3071
// Base Quantities
31-
class Length specializes Quantities::Quantity {
32-
unit: LengthUnit redefines Quantities::Quantity::unit;
33-
}
34-
class Mass specializes Quantities::Quantity {
35-
unit: MassUnit redefines Quantities::Quantity::unit;
36-
}
37-
class Time specializes Quantities::Quantity {
38-
unit: TimeUnit redefines Quantities::Quantity::unit;
39-
}
40-
class ElectricCurrent specializes Quantities::Quantity {
41-
unit: ElectricCurrentUnit redefines Quantities::Quantity::unit;
72+
class LengthValue specializes Quantities::QuantityValue {
73+
magnitude: Real redefines Quantities::QuantityValue::magnitude;
74+
scale: LengthUnit redefines Quantities::QuantityValue::scale;
4275
}
43-
class Temperature specializes Quantities::Quantity {
44-
unit: TemperatureUnit redefines Quantities::Quantity::unit;
45-
}
46-
class AmountOfSubstance specializes Quantities::Quantity {
47-
unit: AmountOfSubstanceUnit redefines Quantities::Quantity::unit;
48-
}
49-
class LuminousIntensity specializes Quantities::Quantity {
50-
unit: LuminousIntensityUnit redefines Quantities::Quantity::unit;
76+
feature length: LengthValue;
77+
78+
class MassValue specializes Quantities::QuantityValue {
79+
magnitude: Real redefines Quantities::QuantityValue::magnitude;
80+
scale: MassUnit redefines Quantities::QuantityValue::scale;
81+
}
82+
feature mass: MassValue;
83+
84+
class TimeValue specializes Quantities::QuantityValue {
85+
magnitude: Real redefines Quantities::QuantityValue::magnitude;
86+
scale: TimeUnit redefines Quantities::QuantityValue::scale;
87+
}
88+
feature time: TimeValue;
89+
90+
class ElectricCurrentValue specializes Quantities::QuantityValue {
91+
magnitude: Real redefines Quantities::QuantityValue::magnitude;
92+
scale: ElectricCurrentUnit redefines Quantities::QuantityValue::scale;
93+
}
94+
feature electricCurrent: ElectricCurrentValue;
95+
96+
class TemperatureValue specializes Quantities::QuantityValue {
97+
magnitude: Real redefines Quantities::QuantityValue::magnitude;
98+
scale: TemperatureUnit redefines Quantities::QuantityValue::scale;
99+
}
100+
feature temperature: TemperatureValue;
101+
102+
class AmountOfSubstanceValue specializes Quantities::QuantityValue {
103+
magnitude: Real redefines Quantities::QuantityValue::magnitude;
104+
scale: AmountOfSubstanceUnit redefines Quantities::QuantityValue::scale;
105+
}
106+
feature amountOfSubstance: AmountOfSubstanceValue;
107+
108+
class LuminousIntensityValue specializes Quantities::QuantityValue {
109+
magnitude: Real redefines Quantities::QuantityValue::magnitude;
110+
scale: LuminousIntensityUnit redefines Quantities::QuantityValue::scale;
51111
}
112+
feature luminousIntensity: LuminousIntensityValue;
52113

53114
// Derived Quantities
54-
class Force specializes Quantities::Quantity {
55-
unit: ForceUnit redefines Quantities::Quantity::unit;
115+
class ForceValue specializes Quantities::QuantityValue {
116+
magnitude: Real redefines Quantities::QuantityValue::magnitude;
117+
scale: ForceUnit redefines Quantities::QuantityValue::scale;
56118
}
119+
feature force: ForceValue;
57120

58121
// ...
59122

sysml/src/library/Quantities.alf

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,18 @@
11
package Quantities {
22

3-
class Quantity specializes ScalarValues::Number {
4-
numericValue: ScalarValues::Number;
5-
unit: MeasurementUnit;
6-
}
7-
8-
abstract class MeasurementUnit specializes Base::Value { }
9-
10-
class SimpleUnit specializes MeasurementUnit { }
11-
12-
class DerivedUnit specializes MeasurementUnit {
13-
unitFactor: MeasurementUnitPowerFactor[1..*];
14-
}
15-
class MeasurementUnitPowerFactor specializes Base::Value {
16-
unit: MeasurementUnit;
17-
exponent: ScalarValues::Integer;
18-
}
19-
20-
abstract class ConversionBasedUnit specializes MeasurementUnit {
21-
conversionFactor: ScalarValues::Number;
22-
unit: MeasurementUnit;
3+
/*
4+
* Representation of the value of a Quantity
5+
*
6+
* The value is a tuple of a magnitude (i.e. the mathematical number value) and a reference to a MeasurementScale.
7+
* The scale may directly reference a MeasurementUnit, which implies that the scale is a ratio scale.
8+
*
9+
* TODO: Consider renaming scale to unitOrScale and MeasurementScale to MeasurementUnitOrScale for clarity.
10+
*/
11+
abstract class QuantityValue specializes ScalarValues::NumericalValue {
12+
magnitude: ScalarValues::Number;
13+
scale: UnitsAndScales::MeasurementScale;
2314
}
2415

16+
// Quantity is defined as a self-standing feature
17+
feature Quantity: QuantityValue;
2518
}

0 commit comments

Comments
 (0)