# Example: two control functions from a function description, bound to devices
# in the two ways CTL supports. Made-up building; names are illustrative.
#
#  1. Binding by role: one outdoor-temperature curve sets the minimum position
#     of every radiator valve at the facade (downdraught compensation).
#  2. Binding by instance: one CO2 curve, copied per room, sets each room's
#     VAV damper from that room's own CO2 sensor.

@prefix bot: <https://w3id.org/bot#> .
@prefix brick: <https://brickschema.org/schema/Brick#> .
@prefix ctl: <https://hamborg.github.io/ctl-ontology#> .
@prefix ex: <https://example.org/building/> .
@prefix prov: <http://www.w3.org/ns/prov#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix s223: <http://data.ashrae.org/standard223#> .
@prefix unit: <http://qudt.org/vocab/unit/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

# --- The source document --------------------------------------------------

ex:FunctionDescription a prov:Entity ;
    rdfs:label "Function description, room control, ground floor" .

ex:Scope a ctl:ApplicabilityScope ;
    ctl:scopeDescription "Room control, ground floor offices and meeting rooms" .

# --- 1. Downdraught compensation, bound by role ---------------------------

ex:Curve_Downdraught a ctl:Curve ;
    prov:wasDerivedFrom ex:FunctionDescription ;
    ctl:sourceLabel "Downdraught" ;
    ctl:xQuantityLabel "Outdoor temperature (°C)" ;
    ctl:xUnit unit:DEG_C ;
    ctl:yQuantityLabel "Valve position (%)" ;
    ctl:yUnit unit:PERCENT ;
    ctl:interpolation ctl:Linear ;
    ctl:hasBreakpoint [ a ctl:Breakpoint ; ctl:x "0.0"^^xsd:decimal ; ctl:y "10.0"^^xsd:decimal ] ,
                      [ a ctl:Breakpoint ; ctl:x "6.0"^^xsd:decimal ; ctl:y "0.0"^^xsd:decimal ] .

ex:Fn_Downdraught a ctl:CompensationCurve ;
    rdfs:label "Downdraught compensation: minimum position of facade radiator valves" ;
    prov:wasDerivedFrom ex:FunctionDescription ;
    ctl:textDescription "Below 6 °C outdoors, radiator valves at the facades take a minimum position, rising from 0 % to 10 % as the outdoor temperature falls to 0 °C." ;
    ctl:activationCondition "Outdoor temperature below 6 °C" ;
    ctl:intent ex:Intent_Downdraught ;
    ctl:role ctl:MinimumPosition ;
    ctl:remainsActiveInMode ex:Mode_Stop ;
    ctl:appliesTo ex:Scope ;
    ctl:usesCurve ex:Curve_Downdraught ;
    s223:hasInput ex:Prop_OutdoorTemp ;
    s223:hasOutput ex:Prop_FacadeValveMinPos .

ex:Intent_Downdraught a ctl:Intent ; rdfs:label "Compensate for cold downdraught from windows" .
ex:Mode_Stop a ctl:OperatingMode ; rdfs:label "Stop" .

# The documented input, and the installed sensor that fills it
ex:Prop_OutdoorTemp a s223:QuantifiableObservableProperty ;
    rdfs:label "Outdoor temperature" .
ex:OutdoorTempSensor a brick:Outside_Air_Temperature_Sensor ;
    ctl:fillsSlot ex:Prop_OutdoorTemp .

# The output acts on a role; the valves that meet the role's criterion fill it
ex:Prop_FacadeValveMinPos a s223:QuantifiableActuatableProperty ;
    rdfs:label "Minimum position of facade radiator valves" ;
    ctl:actuates ex:Role_FacadeValve .

ex:Role_RadiatorValve a ctl:DeviceRole ;
    rdfs:label "Radiator valve" ;
    ctl:withinScope ex:Scope .
ex:Role_FacadeValve a ctl:DeviceRole ;
    rdfs:label "Radiator valve at the facade" ;
    ctl:selectionCriterion "valves at the facades" ;
    ctl:specialises ex:Role_RadiatorValve ;
    ctl:withinScope ex:Scope .

ex:Radiator_101 a brick:Hot_Water_Radiator ; ctl:hasPlacement "beneath facade window" .
ex:Valve_101 a brick:Hot_Water_Valve ; ctl:fillsRole ex:Role_FacadeValve .
ex:Valve_102 a brick:Hot_Water_Valve ; ctl:fillsRole ex:Role_FacadeValve .
ex:Valve_105 a brick:Hot_Water_Valve ; ctl:fillsRole ex:Role_RadiatorValve .   # inner wall: not compensated

# --- 2. CO2 compensation, bound by instance --------------------------------

ex:Curve_CO2 a ctl:Curve ;
    prov:wasDerivedFrom ex:FunctionDescription ;
    ctl:sourceLabel "Air quality" ;
    ctl:xQuantityLabel "CO2 level (ppm)" ;
    ctl:xUnit unit:PPM ;
    ctl:yQuantityLabel "Damper position (%)" ;
    ctl:yUnit unit:PERCENT ;
    ctl:interpolation ctl:Linear ;
    ctl:hasBreakpoint [ a ctl:Breakpoint ; ctl:x "800"^^xsd:decimal ; ctl:y "0"^^xsd:decimal ] ,
                      [ a ctl:Breakpoint ; ctl:x "1200"^^xsd:decimal ; ctl:y "100"^^xsd:decimal ] .

# The template, as the document states it once for all rooms
ex:Fn_CO2 a ctl:CompensationCurve ;
    rdfs:label "CO2 compensation of the room's VAV damper" ;
    prov:wasDerivedFrom ex:FunctionDescription ;
    ctl:intent ex:Intent_ReduceCO2 ;
    ctl:role ctl:PositionDemand ;
    ctl:priorityStatement "CO2 compensation has the highest priority in the room." ;
    ctl:appliesTo ex:Scope ;
    ctl:usesCurve ex:Curve_CO2 .

ex:Intent_ReduceCO2 a ctl:Intent ; rdfs:label "Reduce the CO2 level in the room" .

# One copy per room, with the room's own sensor and damper
ex:Room_101 a bot:Space .
ex:Room_101_CO2 a brick:CO2_Sensor .
ex:Room_101_VAV a brick:Variable_Air_Volume_Box ;
    s223:hasProperty ex:Room_101_DamperDemand .
ex:Room_101_DamperDemand a s223:QuantifiableActuatableProperty .

ex:Fn_CO2_Room_101 a ctl:CompensationCurve ;
    ctl:instanceOf ex:Fn_CO2 ;
    ctl:usesCurve ex:Curve_CO2 ;
    s223:hasInput ex:Room_101_CO2 ;
    s223:hasOutput ex:Room_101_DamperDemand .
