// Independent worked listings. Load this chapter with vocabulary.sysml, not with other chapters. package Lappendixa_01 { private import CoffeeVocabulary::*; private import ScalarValues::Real; // ANCHOR: listing-1 part def MachineBase { attribute waterTemp : Real; part components : Grinder[*]; part sensors : CupSensor[1..*]; } part def EspressoUnit :> MachineBase { part grinder : Grinder :> components; attribute espressoBrewTemp :>> waterTemp; ref primarySensor ::> sensors; port waterReturn : ~WaterPort; attribute maxTemp : Real = 96.0; attribute currentTemp : Real := 20.0; attribute targetTemp : Real default = 93.0; } // ANCHOR_END: listing-1 } package Lappendixa_02 { private import CoffeeVocabulary::*; part def Station { // ANCHOR: listing-2 // Two sensors, exactly part sensors : CupSensor [2]; // Optional steam wand part steamWand : SteamWand [0..1]; // Any number of logged events item events : LogEvent [*]; // ANCHOR_END: listing-2 } } package Lappendixa_03 { private import CoffeeVocabulary::*; private import ScalarValues::Real; part def Station { // ANCHOR: listing-3 // Abstract part: every concrete machine must specialize this abstract part def Machine; // Input parameter action def SetPressure { in attribute targetPressure : Real; } // Derived attribute computed from sub-parts derived attribute totalMass : Real; // Ordered list of brew steps (`ordered` follows the multiplicity) ref action brewSteps : BrewStep [*] ordered; // ANCHOR_END: listing-3 } } package Lappendixa_04 { private import CoffeeVocabulary::*; // ANCHOR: listing-4 package CoffeeMachineDomain { public part def CoffeeMachine; // visible outside private part def InternalBoard; // hidden from importers } // ANCHOR_END: listing-4 } package Lappendixa_05 { private import CoffeeVocabulary::*; // ANCHOR: listing-5 // Line note -- discarded by the parser //* Block note, also discarded. It runs to the closing marker, so always close it. */ /* A bare block comment IS model data: it becomes a Comment element whose body is this text */ doc /* Documentation attached to the owning element as model data */ comment about CoffeeMachine /* Standalone annotating comment -- can target any element */ // ANCHOR_END: listing-5 } package Lappendixa_06 { private import CoffeeVocabulary::*; // ANCHOR: listing-6 part def Assembly { part components : Grinder[*]; part grinder : Grinder :> components; } part def EspressoAssembly :> Assembly { part espressoGrinder :>> grinder; port waterReturn : ~WaterPort; } // ANCHOR_END: listing-6 } package Lappendixa_07 { private import CoffeeVocabulary::*; private import ScalarValues::Real; // ANCHOR: listing-7 attribute def Temperature :> Real; attribute waterTemp : Temperature = 93.0; // ANCHOR_END: listing-7 } package Lappendixa_08 { private import CoffeeVocabulary::*; // ANCHOR: listing-8 enum def DrinkSize { small; medium; large; } // ANCHOR_END: listing-8 } package Lappendixa_09 { private import CoffeeVocabulary::*; // ANCHOR: listing-9 item def Water; item def BrewedCoffee; item waterSupply : Water [1]; // ANCHOR_END: listing-9 } package Lappendixa_10 { private import CoffeeVocabulary::*; // ANCHOR: listing-10 part def CoffeeMachine { part grinder : Grinder [1]; part brewer : Brewer [1]; } part myCoffeeMachine : CoffeeMachine; // ANCHOR_END: listing-10 } package Lappendixa_11 { private import CoffeeVocabulary::*; // ANCHOR: listing-11 port def WaterPort { out item waterOut : Water; } part def WaterTank { port waterOut : WaterPort; } part def Brewer { port waterInlet : ~WaterPort; // conjugated: receives water } // ANCHOR_END: listing-11 } package Lappendixa_12 { private import CoffeeVocabulary::*; private import Connections::BinaryConnection; part def Station { part waterTank : WaterTank; part brewer : Brewer; part controlPanel : Panel; // ANCHOR: listing-12 connection def WaterLine :> BinaryConnection; connect waterTank.waterOut to brewer.waterInlet; bind brewer.targetTemp = controlPanel.setTemp; // ANCHOR_END: listing-12 } } package Lappendixa_13 { private import CoffeeVocabulary::*; part def Station { part waterTank : WaterTank; part brewer : Brewer; // ANCHOR: listing-13 interface def WaterInterface { end supply : WaterPort; end demand : ~WaterPort; } interface waterLine : WaterInterface connect waterTank.waterOut to brewer.waterInlet; // ANCHOR_END: listing-13 } } package Lappendixa_14 { private import CoffeeVocabulary::*; part def Station { action brewCycle : BrewCycle; action heatAction : HeatWater; part brewer : Brewer; // ANCHOR: listing-14 allocate brewCycle to brewer; allocation heatingAlloc allocate heatAction to brewer.heatingElement; // ANCHOR_END: listing-14 } } package Lappendixa_15 { private import CoffeeVocabulary::*; // ANCHOR: listing-15 action def BrewCycle { in beanType : BeanType; out coffee : BrewedCoffee; action grind : GrindBeans; action heat : HeatWater; action extract : Extract; first grind then heat; first heat then extract; } action brewCycle : BrewCycle; // ANCHOR_END: listing-15 } package Lappendixa_16 { private import CoffeeVocabulary::*; private import ScalarValues::Boolean; // ANCHOR: listing-16 state def MachineStates { attribute cupDetected : Boolean; state idle; state brewing; state cleaning; transition T1 first idle accept StartBrewEvent if cupDetected then brewing; transition T2 first brewing accept BrewCompleteEvent then idle; } state machineStates : MachineStates; // ANCHOR_END: listing-16 } package Lappendixa_17 { private import CoffeeVocabulary::*; state def Controller { state idle; state brewing; part cupSensor : CupSensor; // ANCHOR: listing-17 transition T1 first idle accept StartBrewEvent if cupSensor.cupDetected then brewing; // ANCHOR_END: listing-17 } } package Lappendixa_18 { private import CoffeeVocabulary::*; part def Station { part waterTank : WaterTank; part brewer : Brewer; // ANCHOR: listing-18 flow def WaterFlow { end source : WaterSupplyPort; end sink : WaterPort; } flow of Water from waterTank.waterOut.water to brewer.waterInlet.water; // ANCHOR_END: listing-18 } } package Lappendixa_19 { private import CoffeeVocabulary::*; private import ScalarValues::Real; // ANCHOR: listing-19 calc def BrewTime { in volume : Real; in pressure : Real; return t : Real = volume / pressure * 60.0; } // ANCHOR_END: listing-19 } package Lappendixa_20 { private import CoffeeVocabulary::*; // ANCHOR: listing-20 constraint def BrewTempInRange { in brewer : Brewer; brewer.waterTemp >= 90.0 and brewer.waterTemp <= 96.0 } part def TestStation { part sample : Brewer; assert constraint inRange : BrewTempInRange { in :>> brewer = sample; } } // ANCHOR_END: listing-20 } package Lappendixa_21 { private import CoffeeVocabulary::*; // ANCHOR: listing-21 requirement def BrewTimeRequirement { subject machine : CoffeeMachine; require constraint { machine.brewTime <= 60.0 } } requirement brewTime : BrewTimeRequirement; // ANCHOR_END: listing-21 } package Lappendixa_22 { private import CoffeeVocabulary::*; part myCoffeeMachine : CoffeeMachine; // ANCHOR: listing-22 satisfy requirement : BrewTimeReq by myCoffeeMachine; // ANCHOR_END: listing-22 } package Lappendixa_23 { private import CoffeeVocabulary::*; private import StandardViewDefinitions::InterconnectionView; // ANCHOR: listing-23 view def StructuralView :> InterconnectionView { filter @SysML::PartUsage; render rendering asTree : Views::GraphicalRendering; } view structuralView : StructuralView { expose CoffeeMachineDomain::*; } view scratch { expose CoffeeMachine; } // anonymous // ANCHOR_END: listing-23 } package Lappendixa_24 { private import CoffeeVocabulary::*; private import ScalarValues::Boolean; private import ScalarValues::String; // ANCHOR: listing-24 metadata def ReviewStatus { attribute reviewer : String; attribute approved : Boolean; } part def CoffeeMachine { // Without an `about` clause, a metadata usage annotates its // containing element -- so this attaches to CoffeeMachine @ReviewStatus { :>> reviewer = "Alice"; :>> approved = true; } } // ANCHOR_END: listing-24 } package Lappendixa_25 { private import CoffeeVocabulary::*; part def Station { // ANCHOR: listing-25 individual part myEspressoMachine : EspressoMachine { snapshot part machineAtStartup; timeslice part machineInOperation; } // ANCHOR_END: listing-25 } }