Skip to content

Commit 2a19a5b

Browse files
committed
Added validation cases using control structures (for use in testing).
- Also updated includes, excludes, including, excluding in SequenceFunctions library model.
1 parent fc92b5f commit 2a19a5b

8 files changed

Lines changed: 162 additions & 20 deletions

File tree

org.omg.sysml.xtext/src/org/omg/sysml/xtext/util/SysMLRepositorySaveTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class SysMLRepositorySaveTest extends SysMLRepositorySaveUtil {
3030
"02-Parts Interconnection/2a-Parts Interconnection.sysml",
3131
"03-Function-based Behavior/3a-Function-based Behavior-1.sysml",
3232
"03-Function-based Behavior/3a-Function-based Behavior-2.sysml",
33+
"03-Function-based Behavior/3a-Function-based Behavior-5.sysml",
3334
"04-Functional Allocation/4a-Functional Allocation.sysml",
3435
"05-State-based Behavior/5-State-based Behavior-1.sysml",
3536
"05-State-based Behavior/5-State-based Behavior-1a.sysml",
@@ -39,6 +40,7 @@ public class SysMLRepositorySaveTest extends SysMLRepositorySaveUtil {
3940
"09-Verification/9-Verification-simplified.sysml",
4041
"10-Analysis and Trades/10b-Trade-off Among Alternative Configurations.sysml",
4142
"10-Analysis and Trades/10c-Fuel Economy Analysis.sysml",
43+
"10-Analysis and Trades/10d-Dynamics Analysis.sysml",
4244
"11-View and Viewpoint/11a-View-Viewpoint.sysml",
4345
"11-View and Viewpoint/11b-Safety and Security Feature Views.sysml",
4446
"12-Dependency Relationships/12a-Dependency.sysml",

sysml.library/Kernel Library/SequenceFunctions.kerml

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,13 @@ package SequenceFunctions {
2121
function notEmpty(seq: Anything[0..*] nonunique): Boolean[1] {
2222
!isEmpty(seq)
2323
}
24-
function includes(seq: Anything[0..*] nonunique, value: Anything[1]): Boolean[1] {
25-
seq->exists {in x; x == value}
26-
}
27-
function includesAll(seq1: Anything[0..*] nonunique, seq2: Anything[0..*] nonunique): Boolean[1] {
24+
function includes(seq1: Anything[0..*] nonunique, seq2: Anything[0..*] nonunique): Boolean[1] {
2825
seq2->forAll {in x; seq1->includes(x)}
2926
}
3027
function includesOnly(seq1: Anything[0..*] nonunique, seq2: Anything[0..*] nonunique): Boolean[1] {
31-
seq1->includesAll(seq2) && seq2->includesAll(seq1)
32-
}
33-
function excludes(seq: Anything[0..*] nonunique, value: Anything[1]): Boolean[1] {
34-
!seq->includes(value)
28+
seq1->includes(seq2) && seq2->includes(seq1)
3529
}
36-
function excludesAll(seq1: Anything[0..*] nonunique, seq2: Anything[0..*] nonunique): Boolean[1] {
30+
function excludes(seq1: Anything[0..*] nonunique, seq2: Anything[0..*] nonunique): Boolean[1] {
3731
seq2->forAll {in x; seq1->excludes(x)}
3832
}
3933

@@ -43,11 +37,11 @@ package SequenceFunctions {
4337
function intersection(seq1: Anything[0..*] ordered nonunique, seq2: Anything[0..*] ordered nonunique): Anything[0..*] ordered nonunique {
4438
seq1->select {in x; seq2->includes(x)}
4539
}
46-
function including(seq: Anything[0..*] ordered nonunique, value : Anything[1]): Anything[0..*] ordered nonunique {
47-
(seq, value)
40+
function including(seq1: Anything[0..*] ordered nonunique, seq2: Anything[0..*] ordered nonunique): Anything[0..*] ordered nonunique {
41+
union(seq1, seq2)
4842
}
49-
function excluding(seq: Anything[0..*] ordered nonunique, value : Anything[1]): Anything[0..*] ordered nonunique {
50-
seq->reject {in x; x == value}
43+
function excluding(seq1: Anything[0..*] ordered nonunique, seq2: Anything[0..*] ordered nonunique): Anything[0..*] ordered nonunique {
44+
seq1->reject {in x; seq2->includes(x)}
5145
}
5246

5347
function subsequence(seq: Anything[0..*] ordered nonunique, startIndex: Positive[1], endIndex: Positive[1]): Anything[0..*] {

sysml/src/validation/03-Function-based Behavior/3a-Function-based Behavior-1.sysml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package '3a-Function-based Behavior-1' {
44

55
package Definitions {
66
/**
7-
* The 'TorqueValue' type is imported with the alias 'Torque'.
7+
* The 'TorqueValue' type is aliased as 'Torque'.
88
*/
99
alias Torque for ISQ::TorqueValue;
1010

@@ -19,7 +19,7 @@ package '3a-Function-based Behavior-1' {
1919
attribute def EngineOff;
2020

2121
/*
22-
* Black box specifications for activities include their inputs and outputs.
22+
* Black box definitions for actions include their inputs and outputs.
2323
*/
2424

2525
action def 'Generate Torque'(in fuelCmd: FuelCmd, out engineTorque: Torque);

sysml/src/validation/03-Function-based Behavior/3a-Function-based Behavior-2.sysml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ package '3a-Function-based Behavior-2' {
55
package Definitions {
66
alias Torque for ISQ::TorqueValue;
77

8-
// VALUE TYPES
8+
// ATTRIBUTE DEFINITIONS
99

1010
attribute def FuelCmd;
1111

1212
attribute def EngineStart;
1313
attribute def EngineOff;
1414

15-
// ACTIVITIES
15+
// ACTION DEFINITIONS
1616

1717
action def 'Generate Torque'(in fuelCmd: FuelCmd, out engineTorque: Torque);
1818
action def 'Amplify Torque'(in engineTorque: Torque, out transmissionTorque: Torque);

sysml/src/validation/03-Function-based Behavior/3a-Function-based Behavior-3.sysml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package '3a-Function-based Behavior-1' {
44

55
package Definitions {
66
/**
7-
* The 'TorqueValue' type is imported with the alias 'Torque'.
7+
* The 'TorqueValue' type is aliased as 'Torque'.
88
*/
99
alias Torque for ISQ::TorqueValue;
1010

sysml/src/validation/03-Function-based Behavior/3a-Function-based Behavior-4.sysml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ package '3a-Function-based Behavior-2' {
55
package Definitions {
66
alias Torque for ISQ::TorqueValue;
77

8-
// VALUE TYPES
8+
// ATTRIBUTE DEFINITIONS
99

1010
attribute def FuelCmd;
1111

1212
attribute def EngineStart;
1313
attribute def EngineOff;
1414

15-
// ACTIVITIES
15+
// ACTION DEFINITIONS
1616

1717
action def 'Generate Torque'(in fuelCmd: FuelCmd, out engineTorque: Torque);
1818
action def 'Amplify Torque'(in engineTorque: Torque, out transmissionTorque: Torque);
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package '3a-Function-based Behavior-5' {
2+
import Definitions::*;
3+
import Usages::*;
4+
5+
package Definitions {
6+
alias Torque for ISQ::TorqueValue;
7+
8+
// ATTRIBUTE DEFINITIONS
9+
10+
attribute def FuelCmd;
11+
12+
attribute def EngineStart;
13+
attribute def EngineOff;
14+
15+
// ACTION DEFINITIONS
16+
17+
action def 'Generate Torque'(in fuelCmd: FuelCmd, out engineTorque: Torque);
18+
action def 'Amplify Torque'(in engineTorque: Torque, out transmissionTorque: Torque);
19+
action def 'Transfer Torque'(in transmissionTorque: Torque, out driveshaftTorque: Torque);
20+
action def 'Distribute Torque'(in driveShaftTorque: Torque, out wheelTorque1: Torque, out wheelTorque2: Torque);
21+
22+
action def 'Provide Power'(in fuelCmd: FuelCmd, out wheelTorque1: Torque, out wheelTorque2: Torque);
23+
24+
}
25+
26+
package Usages {
27+
28+
action 'provide power': 'Provide Power' {
29+
// PARAMETERS
30+
31+
in fuelCmd: FuelCmd;
32+
out wheelTorque1: Torque;
33+
out wheelTorque2: Torque;
34+
35+
loop {
36+
accept engineStart : EngineStart;
37+
then action {
38+
action 'generate torque': 'Generate Torque' {
39+
in fuelCmd = 'provide power'::fuelCmd;
40+
out engineTorque: Torque;
41+
}
42+
43+
action 'amplify torque': 'Amplify Torque' {
44+
in engineTorque flow from 'generate torque'.engineTorque;
45+
out transmissionTorque;
46+
}
47+
48+
action 'transfer torque': 'Transfer Torque' {
49+
in transmissionTorque flow from 'amplify torque'.transmissionTorque;
50+
out driveshaftTorque;
51+
}
52+
53+
action 'distribute torque': 'Distribute Torque' {
54+
in driveshaftTorque flow from 'transfer torque'.driveshaftTorque;
55+
out wheelTorque1 = 'distribute torque'::wheelTorque1;
56+
out wheelTorque2 = 'distribute torque'::wheelTorque2;
57+
}
58+
}
59+
then action accept engineOff : EngineOff;
60+
}
61+
}
62+
63+
}
64+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package '10d-Dynamics Analysis' {
2+
import ISQ::*;
3+
4+
package VehicleModel {
5+
6+
part def Vehicle {
7+
attribute mass :> ISQ::mass;
8+
}
9+
10+
}
11+
12+
package DynamicsModel {
13+
14+
calc def Acceleration(p : PowerValue, m : MassValue, v : SpeedValue) : AccelerationValue =
15+
p / (m * v);
16+
17+
calc def Velocity(v0 : SpeedValue, a : AccelerationValue, dt : TimeValue) : SpeedValue =
18+
v0 + a * dt;
19+
20+
calc def Position(x0 : LengthValue, v : SpeedValue, dt : TimeValue) : LengthValue =
21+
x0 + v * dt;
22+
23+
action def StraightLineDynamics {
24+
in power : PowerValue;
25+
in mass : MassValue;
26+
in delta_t : TimeValue;
27+
in x_in : LengthValue;
28+
in v_in : SpeedValue;
29+
out x_out : LengthValue = Position(x_in, v_in, delta_t);
30+
out v_out : SpeedValue = Velocity(v_in, a_out, delta_t);
31+
out a_out : AccelerationValue = Acceleration(power, mass, v_in);
32+
}
33+
}
34+
35+
package AnalysisModel {
36+
import VehicleModel::*;
37+
import DynamicsModel::*;
38+
import SampledFunctions::*;
39+
import ScalarValues::Natural;
40+
import SequenceFunctions::*;
41+
42+
attribute def ScenarioState {
43+
position : LengthValue;
44+
velocity : SpeedValue;
45+
}
46+
47+
attribute def NominalScenario :> SampledFunction {
48+
attribute def TimeStateRecord :> SamplePair {
49+
t : TimeValue :>> domainValue;
50+
s : ScenarioState :>> rangeValue;
51+
}
52+
:>> samples : TimeStateRecord;
53+
n : Natural = size(samples);
54+
}
55+
56+
analysis def DynamicsAnalysis {
57+
subject vehicle : Vehicle;
58+
in attribute powerProfile :> ISQ::power[*];
59+
in attribute initialPosition :> ISQ::length;
60+
in attribute initialSpeed :> ISQ::speed;
61+
in attribute deltaT :> ISQ::time;
62+
return attribute accelerationProfile :> ISQ::acceleration[*] := ();
63+
64+
private attribute position := initialPosition;
65+
private attribute speed := initialSpeed;
66+
67+
for i in 1..powerProfile->size()-1 {
68+
perform action dynamics : StraightLineDynamics {
69+
in power = powerProfile[i];
70+
in mass = vehicle.mass;
71+
in delta_t = deltaT;
72+
in x_in = position;
73+
in v_in = speed;
74+
}
75+
then assign position := dynamics.x_out;
76+
then assign speed := dynamics.v_out;
77+
then assign accelerationProfile := accelerationProfile->including(dynamics.a_out);
78+
}
79+
}
80+
}
81+
82+
}

0 commit comments

Comments
 (0)