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.

im1

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.

im2

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”.

im3

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.

im4

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, and number of active pumps in this simulation is shown below.

The script will access properties form the component identifiers specified above.

Speed Comparison

Each network was run five times, a summary of the runtime is
shown below:

Run

Direct
Access
time (s)

Method
Access
time (s)

% Difference

1

15.7

18.3

16.56%

2

15.5

17.9

15.48%

3

15.5

18

16.13%

4

15.6

18.1

16.03%

5

15.5

18

16.13%

Mean 15.56

18.06

16.07%

Running this network with a direct property access resulted in over 15% reduction in runtime for this network.

This difference is caused by the significant reduction in the script evaluation time. The image below shows the total simulation time when accessing properties directly.

This evaluates on the order of 1E-4s per pressure iteration.
We can compare this to retrieving properties with a method (below).

The script evaluation time is nearly an order of magnitude larger when using a script to access properties.

Conclusion

So, when most useful to access properties directly? Directly referencing properties is helpful when you are concerned about execution time and your scripts account for a significant fraction of time in your timestep. Hopefully this helped you shave some time off your simulation.

Share this post:

Upcoming Events

Dec 11
, 2024
Structural Updates (3) in Ansys 2024 R2 - Materials, Contact and Joint Elements, & HPC - Webinar
Dec 11
, 2024
Tech the Halls
Dec 11
, 2024
YesPHX Winter Social 2024
Jan 07
- Jan 10
, 2025
CES 2025
Jan 22
- Jan 25
, 2025
Arizona Photonics Days 2025
Feb 04
- Feb 06
, 2025
MD&M West 2025
Feb 04
- Feb 06
, 2025
2025 Transformative Vertical Flight
Apr 07
- Apr 10
, 2025
40th Space Symposium

Search the PADT Site

Contact Us

Most of our customers receive their support over the phone or via email. Customers who are close by can also set up a face-to-face appointment with one of our engineers.

For most locations, simply contact us: