Compute Blocks¶
A compute block is a mathematical function that derives its value from an expression. Compute blocks give you the ability to calculate new tag values based on historical tag data collected from interfaces, models, or even other compute blocks.
Example
You can create a Total Wind Farm Output compute block that calculates one output (Total_Power_Output
) using two inputs (Wind_Turbine_1
and Wind_Turbine_2
).
You can use a compute block to calculate one or multiple output tags.
Guidelines¶
Review the following guidelines when building compute blocks.
Update Criteria¶
The Update Criteria for a compute block determines when the value of the output tag changes based on new values for its input tags.
Here are the options available:
On all input changed
The compute block will produce an output if all input tags change value.
For example, if a compute block has two input tags, A and B, and their last observed values are 2 and 3, respectively. The compute block will produce an output if A changes to 5 and B changes to 4. If only A changes to 5, the compute block won't produce a new output until B also changes.
On any input changed
The compute block will produce an output if any input tag changes value.
For example, if a compute block has two input tags, A and B. The compute block will produce an output if A and/or B change value, including if both A and B change at the same time.
On all input received
The compute block will produce an output if all input tags receive a new value.
For example, if a compute block has two input tags, A and B, and their last observed values are 2 and 3, respectively. The compute block will produce an output if A receives a new value of 2 and B receives a new value of 4.
On any input received
The compute block will produce an output if any input tag receives a new value.
For example, if a compute block has two input tags, A and B. The compute block will produce an output if A or B receive a new value. The compute block will also produce an output if both A and B receive a new value at the same time.
On interval
The compute block will produce an output at the specified Interval, regardless of inputs.
For example, if a compute block has two input tags, A and B, and an Interval of 1000ms
, it will produce an output every minute even if no inputs are changed or received.
On schedule
The compute block will produce an output on the specified Schedule using the latest input values. You can use a cron expression to set the scheduled run time and all times use the UTC time standard.
Historical Tag Values¶
You can access up to 20 historical values for an input tag and use these values in the expression for a compute block.
To specify the historical values to use for an input tag, select an option in the History picklist for that tag.
Example
- Select "Last value only" in History to use the latest value
- Select "20 element arrays" in History to use the last 20 values
To insert specific input tag values into an expression, enter the tag ID followed by an index [x]
. For example, the following expression calculates the value of the Difference
tag by subtracting the two latest values for the TotalLength
tag.
Difference = TotalLength.values[2] - TotalLength.values[1]
Along with a tag's value, you can also insert the following input tag attributes into an expression:
.timestamps
.epochtimes
.qualities
.lengths
Expressions¶
An expression calculates the output tag(s) for a compute block. To build an expression, you need to include the input tags for the compute block along with mathematical operators and functions.
Here's an example of an expression that calculates the efficiency for a pump:
1 2 3 4 |
|
The input tags are:
power
flow_rate
p_diff
temp
The output tag is:
efficiency
Notice how the gacc
, p_diff_m
, and sg(temperature)
values are calculated first, and then inserted into the efficiency
calculation (line 4) that determines the value for the output tag.
Building a Compute Block¶
Complete the following to build a new compute block.
- Select Compute Chain on the sidebar.
- Click Add Compute Block.
- In Name, enter a name for the compute block.
-
In Update Criteria, specify when you want the output tag to change based on its input tags.
Tip
See the Guidelines section above for more information about update criteria.
-
(Optional) In Description, enter a description of the output value of the compute block.
- In Interval, specify the interval in milliseconds at which to update the output value.
-
Under Inputs, complete the following for every input tag:
-
Select the tag to use:
- Use a tag from an interface: Select the data source in Interface and select the tag in Tag ID.
- Use an output tag from a compute block: Select Compute in Interface and select the output tag in Tag ID.
-
In Expression variable name, enter the local name to use for the tag.
- Click + Add.
- Click Edit next to the tag.
-
In History, select the value to use for the tag.
Tip
See the Guidelines section above for more information about historical tag values.
-
Click Save.
-
-
Under Outputs, complete the following for every output tag:
-
In Output Tag ID, enter a name for the tag.
Note
This is the name used to identify the tag in cloud environments and other locations where you send the tag data.
-
In Expression Variable, enter a local name to use for the tag.
Note
This is the name used to identify the tag in the expression for this compute block.
-
Click + Create.
-
-
In Define the expression, enter an expression to calculate the output tag(s).
Tips
- Include input tags in the expression by entering their Expression Variable.
- A built-in syntax checker displays alerts when you enter expression elements incorrectly.
- Visit the math.js site for more information on correct expression syntax.
- See the Guidelines section above for more information about expressions.
-
Click Save.
Viewing Compute Block Output¶
Complete the following to view the calculated outputs for compute blocks.
- Select Viewer on the sidebar.
- Open the Graph tab.
-
Move down to the Compute section.
Graphs showing the output tags for compute blocks now display.
Managing Compute Blocks¶
Editing a Compute Block
- Select Compute Chain on the sidebar.
- Locate the compute block in the list.
- Click Edit next to the compute block.
- Make changes as necessary.
- Click Update.
Editing an Input Tag
- Select Compute Chain on the sidebar.
- Locate the compute block in the list.
- Click Edit next to the compute block.
- Under Outputs, click Edit next to the tag.
- Make changes as necessary.
- Click Save.
- Click Update.
Editing an Output Tag
- Select Compute Chain on the sidebar.
- Locate the compute block in the list.
- Click Edit next to the compute block.
- Under Outputs, click Edit next to the tag.
- Make changes as necessary.
- Click Save.
- Click Update.
Deleting an Input Tag
- Select Compute Chain on the sidebar.
- Locate the compute block in the list.
- Click Edit next to the compute block.
- Under Inputs, click Delete next to the tag.
- Click Update.
Deleting an Output Tag
- Select Compute Chain on the sidebar.
- Locate the compute block in the list.
- Click Edit next to the compute block.
- Under Outputs, click Delete next to the tag.
- Click Update.
Deleting a Compute Block
- Select Compute Chain on the sidebar.
- Locate the compute block in the list.
- Click Delete next to the compute block.
- Click Delete to confirm.