description <http://ua.be/sdo2l/description/artifacts/drivetrain_hierarchical_pm#> as drivetrain_hierarchical_pm {

  uses <http://ua.be/sdo2l/vocabulary/formalisms/pm#> as pm
  uses <http://ua.be/sdo2l/vocabulary/formalisms/object_diagram#> as object_diagram
  uses <http://ua.be/sdo2l/vocabulary/formalisms/ftg#> as ftg

  extends <http://ua.be/sdo2l/description/artifacts/FTG_ftg#> as ftg_instance

  // Main hierarchical process model
  instance model : pm:Model [
    object_diagram:hasName "drivetrain_hierarchical_pm"
  ]

  instance initial : pm:Initial [ pm:hasName "initial" object_diagram:inModel model ]
  instance final : pm:Final [ pm:hasName "final" object_diagram:inModel model ]

  // --- Artifacts in Main Model ---
  instance artifact_0 : pm:Artifact [ pm:hasName "drivetrain_limitations" pm:hasType ftg_instance:f_TextDocument object_diagram:inModel model ]
  instance artifact_1 : pm:Artifact [ pm:hasName "test_requirements" pm:hasType ftg_instance:f_TextDocument object_diagram:inModel model ]
  instance artifact_2 : pm:Artifact [ pm:hasName "matlab_torque" pm:hasType ftg_instance:f_Profile object_diagram:inModel model ]
  instance artifact_3 : pm:Artifact [ pm:hasName "control_parameter_generator" pm:hasType ftg_instance:f_Script object_diagram:inModel model ]
  instance artifact_6 : pm:Artifact [ pm:hasName "drivetrain_sensor_data" pm:hasType ftg_instance:f_TabularData object_diagram:inModel model ]
  instance artifact_7 : pm:Artifact [ pm:hasName "coupling_sensor_data" pm:hasType ftg_instance:f_TabularData object_diagram:inModel model ]

  // --- Activities in Main Model ---
  instance activity_5 : pm:Activity [ pm:hasName "InputParameters" pm:isTransformation ftg_instance:t_Preparation object_diagram:inModel model ]
  instance activity_0 : pm:Activity [ pm:hasName "set_up_drivetrain_profile" pm:isTransformation ftg_instance:t_SetupProfile object_diagram:inModel model ]
  instance hierarchical_activity : pm:InvokingActivity [ pm:hasName "Conduct_Experiment" pm:invokesPM model_sub object_diagram:inModel model ]
  instance activity_4 : pm:Activity [ pm:hasName "check_properties" pm:isTransformation ftg_instance:t_VerifyData object_diagram:inModel model ]

  // --- Ports for Main Model Activities ---
  instance activity_5_port_0 : pm:CtrlInputPort [ pm:hasName "cin" pm:ofActivity activity_5 ]
  instance activity_5_port_1 : pm:CtrlOutputPort [ pm:hasName "cout" pm:ofActivity activity_5 ]
  instance activity_5_port_2 : pm:DataOutputPort [ pm:hasName "dout" pm:ofActivity activity_5 ]
  instance activity_5_port_3 : pm:DataOutputPort [ pm:hasName "dout" pm:ofActivity activity_5 ]
  instance activity_5_port_4 : pm:DataOutputPort [ pm:hasName "dout" pm:ofActivity activity_5 ]

  instance activity_0_port_0 : pm:CtrlInputPort [ pm:hasName "cin" pm:ofActivity activity_0 ]
  instance activity_0_port_2 : pm:CtrlOutputPort [ pm:hasName "cout" pm:ofActivity activity_0 ]
  instance activity_0_port_3 : pm:DataInputPort [ pm:hasName "din" pm:ofActivity activity_0 ]
  instance activity_0_port_4 : pm:DataInputPort [ pm:hasName "din" pm:ofActivity activity_0 ]
  instance activity_0_port_5 : pm:DataOutputPort [ pm:hasName "dout" pm:ofActivity activity_0 ]

  instance hierarchical_activity_port_0 : pm:CtrlInputPort [ pm:hasName "cin" pm:ofActivity hierarchical_activity ]
  instance hierarchical_activity_port_1 : pm:CtrlOutputPort [ pm:hasName "cout" pm:ofActivity hierarchical_activity ]
  //Corrected to match the actual inputs needed by the sub-process
  instance hierarchical_activity_port_2 : pm:DataInputPort [ pm:hasName "din_torque" pm:ofActivity hierarchical_activity ]
  instance hierarchical_activity_port_3 : pm:DataInputPort [ pm:hasName "din_generator" pm:ofActivity hierarchical_activity ]
  instance hierarchical_activity_port_4 : pm:DataInputPort [ pm:hasName "din_reqs" pm:ofActivity hierarchical_activity ]
  //Outputs from the sub-process
  instance hierarchical_activity_port_5 : pm:DataOutputPort [ pm:hasName "dout_drivetrain_data" pm:ofActivity hierarchical_activity ]
  instance hierarchical_activity_port_6 : pm:DataOutputPort [ pm:hasName "dout_coupling_data" pm:ofActivity hierarchical_activity ]

  instance activity_4_port_0 : pm:CtrlInputPort [ pm:hasName "cin" pm:ofActivity activity_4 ]
  instance activity_4_port_1 : pm:CtrlOutputPort [ pm:hasName "cout" pm:ofActivity activity_4 ]
  instance activity_4_port_3 : pm:DataInputPort [ pm:hasName "din" pm:ofActivity activity_4 ]
  instance activity_4_port_4 : pm:DataInputPort [ pm:hasName "din" pm:ofActivity activity_4 ]

  // --- Flows in Main Model ---
  relation instance ctrl_flow_0 : pm:CtrlFlow [ from initial to activity_5_port_0 object_diagram:inModel model ]
  relation instance ctrl_flow_1 : pm:CtrlFlow [ from activity_5_port_1 to activity_0_port_0 object_diagram:inModel model ]
  relation instance ctrl_flow_2 : pm:CtrlFlow [ from activity_0_port_2 to hierarchical_activity_port_0 object_diagram:inModel model ]
  relation instance ctrl_flow_3 : pm:CtrlFlow [ from hierarchical_activity_port_1 to activity_4_port_0 object_diagram:inModel model ]
  relation instance ctrl_flow_4 : pm:CtrlFlow [ from activity_4_port_1 to final object_diagram:inModel model ]

  relation instance data_flow_0 : pm:DataFlow [ from activity_5_port_2 to artifact_0 object_diagram:inModel model ]
  relation instance data_flow_1 : pm:DataFlow [ from artifact_0 to activity_0_port_3 object_diagram:inModel model ]
  relation instance data_flow_2 : pm:DataFlow [ from activity_5_port_3 to artifact_1 object_diagram:inModel model ]
  relation instance data_flow_3 : pm:DataFlow [ from artifact_1 to activity_0_port_4 object_diagram:inModel model ]
  relation instance data_flow_4 : pm:DataFlow [ from activity_0_port_5 to artifact_2 object_diagram:inModel model ]
  relation instance data_flow_5 : pm:DataFlow [ from activity_5_port_4 to artifact_3 object_diagram:inModel model ]
  //Data flows into the invoking activity
  relation instance data_flow_6 : pm:DataFlow [ from artifact_2 to hierarchical_activity_port_2 object_diagram:inModel model ]
  relation instance data_flow_7 : pm:DataFlow [ from artifact_3 to hierarchical_activity_port_3 object_diagram:inModel model ]
  relation instance data_flow_8 : pm:DataFlow [ from artifact_1 to hierarchical_activity_port_4 object_diagram:inModel model ]
  //Data flows out of the invoking activity
  relation instance data_flow_9 : pm:DataFlow [ from hierarchical_activity_port_5 to artifact_6 object_diagram:inModel model ]
  relation instance data_flow_10 : pm:DataFlow [ from hierarchical_activity_port_6 to artifact_7 object_diagram:inModel model ]
  //Data flows into the final check
  relation instance data_flow_11 : pm:DataFlow [ from artifact_6 to activity_4_port_3 object_diagram:inModel model ]
  relation instance data_flow_12 : pm:DataFlow [ from artifact_7 to activity_4_port_4 object_diagram:inModel model ]


  // --- Sub-Process Model for Invocation ---
  instance model_sub : pm:Model [ object_diagram:hasName "conduct_experiment_sub_pm" ]

  instance sub_initial : pm:Initial [ object_diagram:inModel model_sub ]
  instance sub_final : pm:Final [ object_diagram:inModel model_sub ]

  // Artifacts in Sub-Model
  // Input artifacts (populated by the engine from the invoking activity's inputs)
  instance sub_artifact_1 : pm:Artifact [ pm:hasName "test_requirements" pm:hasType ftg_instance:f_TextDocument object_diagram:inModel model_sub ]
  instance sub_artifact_2 : pm:Artifact [ pm:hasName "matlab_torque" pm:hasType ftg_instance:f_Profile object_diagram:inModel model_sub ]
  instance sub_artifact_3 : pm:Artifact [ pm:hasName "control_parameter_generator" pm:hasType ftg_instance:f_Script object_diagram:inModel model_sub ]
  // Internal artifacts
  instance sub_artifact_4 : pm:Artifact [ pm:hasName "matlab_control_parameters" pm:hasType ftg_instance:f_TabularData object_diagram:inModel model_sub ]
  instance sub_artifact_5 : pm:Artifact [ pm:hasName "c-code_to_be_run_on_rtt" pm:hasType ftg_instance:f_Code object_diagram:inModel model_sub ]
  // Output artifacts (read by the engine and passed to the invoking activity's outputs)
  instance sub_artifact_6 : pm:Artifact [ pm:hasName "drivetrain_sensor_data" pm:hasType ftg_instance:f_TabularData object_diagram:inModel model_sub ]
  instance sub_artifact_7 : pm:Artifact [ pm:hasName "coupling_sensor_data" pm:hasType ftg_instance:f_TabularData object_diagram:inModel model_sub ]

  // Activities in Sub-Model
  instance sub_activity_1 : pm:Activity [ pm:hasName "Generate_matlab_control_parameters" pm:isTransformation ftg_instance:t_GenerateControlParameters object_diagram:inModel model_sub ]
  instance sub_activity_2 : pm:Activity [ pm:hasName "Build_simulink_control_settings" pm:isTransformation ftg_instance:t_BuildControlSettings object_diagram:inModel model_sub ]
  instance sub_activity_3 : pm:Activity [ pm:hasName "run_experiment" pm:isTransformation ftg_instance:t_RunExperiment object_diagram:inModel model_sub ]

  // Ports for Sub-Model Activities
  instance sub_activity_1_port_0 : pm:CtrlInputPort [ pm:hasName "cin" pm:ofActivity sub_activity_1 ]
  instance sub_activity_1_port_1 : pm:CtrlOutputPort [ pm:hasName "cout" pm:ofActivity sub_activity_1 ]
  instance sub_activity_1_port_2 : pm:DataInputPort [ pm:hasName "din" pm:ofActivity sub_activity_1 ]
  instance sub_activity_1_port_3 : pm:DataInputPort [ pm:hasName "din" pm:ofActivity sub_activity_1 ]
  instance sub_activity_1_port_4 : pm:DataOutputPort [ pm:hasName "dout" pm:ofActivity sub_activity_1 ]

  instance sub_activity_2_port_0 : pm:CtrlInputPort [ pm:hasName "cin" pm:ofActivity sub_activity_2 ]
  instance sub_activity_2_port_1 : pm:CtrlOutputPort [ pm:hasName "cout" pm:ofActivity sub_activity_2 ]
  instance sub_activity_2_port_2 : pm:DataInputPort [ pm:hasName "din" pm:ofActivity sub_activity_2 ]
  instance sub_activity_2_port_3 : pm:DataInputPort [ pm:hasName "din" pm:ofActivity sub_activity_2 ]
  instance sub_activity_2_port_4 : pm:DataOutputPort [ pm:hasName "dout" pm:ofActivity sub_activity_2 ]

  instance sub_activity_3_port_0 : pm:CtrlInputPort [ pm:hasName "cin" pm:ofActivity sub_activity_3 ]
  instance sub_activity_3_port_1 : pm:CtrlOutputPort [ pm:hasName "cout" pm:ofActivity sub_activity_3 ]
  instance sub_activity_3_port_2 : pm:DataInputPort [ pm:hasName "din" pm:ofActivity sub_activity_3 ]
  instance sub_activity_3_port_3 : pm:DataOutputPort [ pm:hasName "dout" pm:ofActivity sub_activity_3 ]
  instance sub_activity_3_port_4 : pm:DataOutputPort [ pm:hasName "dout" pm:ofActivity sub_activity_3 ]

  // Flows in Sub-Model
  relation instance ctrl_flow_sub_0 : pm:CtrlFlow [ from sub_initial to sub_activity_1_port_0 object_diagram:inModel model_sub ]
  relation instance ctrl_flow_sub_1 : pm:CtrlFlow [ from sub_activity_1_port_1 to sub_activity_2_port_0 object_diagram:inModel model_sub ]
  relation instance ctrl_flow_sub_2 : pm:CtrlFlow [ from sub_activity_2_port_1 to sub_activity_3_port_0 object_diagram:inModel model_sub ]
  relation instance ctrl_flow_sub_3 : pm:CtrlFlow [ from sub_activity_3_port_1 to sub_final object_diagram:inModel model_sub ]
  
  // Note: Data flow based on flat drivetrain_pm.oml logic
  relation instance data_flow_sub_0 : pm:DataFlow [ from sub_artifact_2 to sub_activity_1_port_3 object_diagram:inModel model_sub ]
  relation instance data_flow_sub_1 : pm:DataFlow [ from sub_artifact_3 to sub_activity_1_port_2 object_diagram:inModel model_sub ]
  relation instance data_flow_sub_2 : pm:DataFlow [ from sub_activity_1_port_4 to sub_artifact_4 object_diagram:inModel model_sub ]
  relation instance data_flow_sub_3 : pm:DataFlow [ from sub_artifact_4 to sub_activity_2_port_3 object_diagram:inModel model_sub ]
  relation instance data_flow_sub_4 : pm:DataFlow [ from sub_artifact_1 to sub_activity_2_port_2 object_diagram:inModel model_sub ]
  relation instance data_flow_sub_5 : pm:DataFlow [ from sub_activity_2_port_4 to sub_artifact_5 object_diagram:inModel model_sub ]
  relation instance data_flow_sub_6 : pm:DataFlow [ from sub_artifact_5 to sub_activity_3_port_2 object_diagram:inModel model_sub ]
  relation instance data_flow_sub_7 : pm:DataFlow [ from sub_activity_3_port_3 to sub_artifact_6 object_diagram:inModel model_sub ]
  relation instance data_flow_sub_8 : pm:DataFlow [ from sub_activity_3_port_4 to sub_artifact_7 object_diagram:inModel model_sub ]
}