Quickly Accessing Component Properties in Scripts

Categories:

In large networks, time to process and transfer data may have an impact on solve time. Scripts are a commonly used for accessing component properties to dictate operating conditions or simulate controls. In this blog post, we will be exploring how to reduce operating time when accessing component properties via script. We will also walk through an example of how to access internal identifiers and component type names, as well as how to use them in a script. We will be using a quick script that accesses various component properties during each pressure iteration. For the networks in this blog, I will be using version 8.14.1.4845.

Introduction

First, we are going to take a look at how to directly reference component properties in a script. This a relatively straightforward process of using the GUI to determine a component’s type and property names.  We will use that information to assign references to properties of components in a control system as an alternative to using data transfer links and DCS components (using a process similar to a previous post). Finally, we will take a look at some tradeoffs between explicitly referencing component properties and using a method to retrieve them.

Network

Consider a simple network, where 3 variable speed pumps are regulated by a PID controller and a quick script. The recruitment and deactivation of pumps and pump speed rate limits are controlled using a quick script. Below is an image of the network .

The pump activation can be seen by adjusting the setpoint manually using a slide bar (right).

Accessing Properties

In a previous post, we discussed how to retrieve variable references using a function, using the GetPropertyFromFullDisplayName() method.

Alternatively, the output may be accessed using internal identifiers. This requires a bit more legwork, but we will see that it offers a significant reduction in script runtime. We will start our code with our component reference. We can paste the component identifier into the GetComponent() method. For this example, we are passing this in though a script input.

For this example PIDComponentID will return “PID” in the code below.

//Identify PID Component – Setting references for future operations
//Setting Component Reference
IPS.Core.Component PID = Project.GetComponent(PIDComponentID.ToString()); 

The next step is to determine the type of the component. We can retrieve this by right clicking on the component and selecting “Copy Type Name”.

This should return:

DCS.Components.Analog.Controllers.PID

We can use this to create a reference to the Flownex
component using the copied Type.

//Setting PID Component Reference
DCS.Components.Analog.Controllers.PID PID = PIDComponent as DCS.Components.Analog.Controllers.PID;

Now we can right click on property in the PID that we would like to reference and select Copy internal identifiers to clipboard.

This will copy the following property name to the clipboard:

Output

Now we can make a reference to the Output property of our
PID Controller component.

//Setting PID Output Reference
PIDOutput = PID.Output;

Putting our code together results in the following:

//Identify PID Component – Setting references for future operations
//Setting Component Reference
IPS.Core.Component PID = Project.GetComponent(PIDComponentID.ToString());
// IPS.Core.Component
//Setting PID Component Reference

DCS.Components.Analog.Controllers.PID PID = PIDComponent as DCS.Components.Analog.Controllers.PID;
//Setting PID Output Reference
PIDOutput = PID.Output;

This approach takes a few clicks and an extra line of code
for each component type, but it decreases the runtime of script components and
permits the same functionality as the GetPropertyFromFullDisplayName() method.

Testing Solve Speed

Now that we know how to access internal properties of
Flownex components, we can compare two functionally identical network solutions
solve speeds. One uses GetPropertyFromFullDisplayName() to access properties
and the other uses internal identifiers to access properties.

We will be running a 10 minute simulation with 100 ms
timesteps. All pumps are initially set to 1200rpm (125.7 rad/s) and the
setpoint remains at 10kg/s. The resulting graphs for pump speeds, PID Output,
Number of active pumps in this simulation is shown below: