Simulating Behaviors in Functions or Logical Components Using EKL Scripting, and Retrieving the Results

You can use EKL (Engineering Knowledge Language) to simulate any type of behavior in a function or a logical component, and then retrieve the results for further use in scripting.

In this scenario you use the EKL scripting to simulate a logical component with a Dymola behavior in the first part of the scenario, and in the second part you retrieve results for further use in scripting.

Note: In this scenario, you work with a Dymola behavior in a logical component. It is possible to do the same for any behavior in a function or a logical component, the scenario is similar.

This task shows you how to:


Before you begin: Do the following to create a logical component with a Dymola behavior to simulate:
  1. Create a logical component with a Dymola behavior and open it to edit it. See Create a Logical Component with a Behavior.
  2. In the MainModel, create a new model MyModelTest. See Dymola Behavior Modeling Users Guide: Managing Classes: Creating a Class: Creating an Empty Class or Extending for an Existing Class.
  3. Open the model and use the Modelica Editor to insert the following Modelica text:
    Real x(start=7);
    equation
    der(x)=-x;
    For working with the Modelica Editor, see Dymola Behavior Modeling Users Guide: Managing Classes: Displaying and Editing Modelica Text: Working with the Modelica Editor: Displaying and Editing Modelica Text..
  4. Instantiate MyModelTest in MainModel. See Dymola Behavior Modeling Users Guide: Managing Components: Instantiating a Component.
  5. Set up the virtual execution, for example, what algorithm, start time, and stop time to use in the simulation. See Setting up a Simulation.
    Note: You can override the start time and stop time in the script.

Simulate a Function or Logical Component Containing a Dymola Behavior Using EKL Scripting

You can simulate behavior in a function or logical component using Enterprise Knowledge Language (EKL) scripts. You use the global function SimulateBehaviorModel.

In this task you create an action to simulate a logical component with a Dymola behavior, and you test that the simulation was performed.

Note: To be able to use an object that is located in the same PLM object as the action, we use an RFLVPMLogicalReference input in this scenario.

  1. From the Compass, click 3D Modeling Apps , and select Engineering Rules Capture.
  2. From the action bar, click Action .

    For full information about actions, see Engineering Rules Capture Users Guide: Working with Actions: Creating an Action.

  3. In the Knowledge Engineering Specification Logical dialog box that appears, click OK.
    In the tree, a Knowledge Engineering Specification Logical node appears.
  4. In the Action Editor that appears, do the following:
    1. To create the input variable to use, In the Argument list, the Name column, double-click <Add new argument> and type myLogicalInput.
    2. Click the Type box and select, from the list, RFLVPMLogicalReference.
    3. Click the text pane to enter it.
    4. Press Enter to go to a new line.
    5. Type myLogicalInput->SimulateBehaviorModel(0,6)

      You have now selected start time 0 and stop time 6 for the simulation.

      Note: You can select to use the start time and stop time defined for the model in the simulation setup in Dymola Behavior Modeling. See General Tab.

      Important: To select the start time and stop time defined in the simulation setup, you must make sure that the bracket contains nothing, that is, it must be ()

      The full text for this task is now:
      myLogicalInput->SimulateBehaviorModel(0,6)
    6. Click OK.
    The result is:
    • The action is created.
    • In the tree, under the Relations.1 node, the action is displayed with an icon .
  5. In the tree, under the Relations.1 node, right-click Action.1 and select Action.1 object > Run.
  6. In the Insert Object dialog box:
    1. To select reference for the selected myLogicalInput, from the Compass, click the Logical Reference node.
    2. Click OK.
    The result is:
    • The action is executed, MyModelTest is simulated with start time 0 and stop time 6.
    • The Signal Monitor appears to display the result of the simulation.
  7. To check the result, in the Signal Monitor, right-click a signal and select Add to Plot > New Plot.
  8. From the Compass, click 3D Modeling Apps , and select Functional & Logical Design.

Note: You can now edit and run the action directly without changing app. You can edit the action by double-clicking the action in the tree.

Retrieving the Simulation Results for Further Scripting

You can retrieve the simulation results for further scripting.

In this task, you retrieve the simulation results from the previous simulation, and check that the results were retrieved. You retrieve the simulation results by enhancing the action from previous task.

Before you begin: Do the previous talk.
  1. To open the action to enhance it, double-click it in the tree.

    Tip: You can also right-click the action in the tree and select Action1.object > Definition.

  2. In the Action Editor, do the following:
    1. Press Enter to go to a new line.
    2. To define a EKL variable result of type List where the retrieved simulation results are stored, enter the line let result(List)
    3. On a new line, type myLogicalInput->GetSimulationResult("MainModel.myModelTest.x",result)

      The first parameter is the path to the variable to retrieve the simulation result for, the second parameter is the variable holding the retrieved result.

      Tip: You can copy the path from the Signal Monitor, right-click the variable you want to copy the path for, and select Copy Path to Clipboard. You can then paste the path into the bracket of the function.

    4. To see all values in the result as a message on the screen, add the line Message("AllValues",result)
      The full text for this scenario is now:
      myLogicalInput->SimulateBehaviorModel(0,6)
      let result(List)
      myLogicalInput->GetSimulationResult("MainModel.myModelTest.x",result)
      Message("AllValues",result)
      
    5. Click OK.
    The action is enhanced.
  3. In the tree, under the Relations.1 node, right-click Action.1 and select Action.1 object > Run.
  4. In the Insert Object dialog box:
    1. To select reference for the selected myLogicalInput, from the Compass, click the Logical Reference node.
    2. Click OK.
    The result is:
    • The model is again simulated according to the task above.
    • The simulation result of the variable x is retrieved and stored in result for further scripting.
    • A message appears displaying the content in result.