# Network

The Network object is the main workhorse of the Scripting Module.
Function/Property | Description
AddGraphicObject(Kind: Integer; X1, Y1, X2, Y2: Integer): Integer | Adds graphic object (text, image, etc., depending on the Kind) to the network. Returns Id of new object; 0, if unsuccessful.
AddNode(Kind, X, Y: Integer): Integer | Add a node to the network. Returns Id of new Node; 0, if unsuccessful. See Element Kind Constants for possible Kind values. NB: This routine was undocumented until 3.53; in previous versions of FluidFlow3, the parameter signature is: (X, Y, Kind: Integer)
AddPipe(Kind, StartNode, EndNode: Integer): Integer | Add a pipe to the network. Returns Id of new Pipe; 0, if unsuccessful. See Element Kind Constants for possible Kind values. NB: This routine was undocumented until 3.53; in previous versions of FluidFlow3, the parameter signature is: (StartNode, EndNode, Kind: Integer).
Calculate: Integer | Solve the Network.
CalculationSettings[Name: String]: Variant | Get/Set any Calculation Option's value.
Clear | Clear the contents of the Network.
Count: Integer | Get the total number of Elements (Nodes and Pipes).
Filename: String | Get the Network's filename.
FlowsheetSettings[Name: String]: Variant | Get/Set any Flowsheet Option's value.
Get(ElementId: Integer; PropertyNameOrId: Variant; [FromUnitId: Integer; ToUnitId: Integer]): Variant | Get an Element's property value. For result properties, you can optionally specify to convert the result value. If both the FromUnitId and ToUnitIds are specified the result will be converted between them. If only one is specified, this will be assumed to be the ToUnitId and the FromUnitId will be determined from how the result is stored internally.
GetAccumulatorConnectionData(ElementId: Integer; Data: TRecordList): Boolean | Given an ElementId, this will fill "Data" with information about the pipes connected to the accumulator. This function returns True if the specified ElementId is an Accumulator and has Connection Data specified. See Script | Accumulator Connection Data Record for more information about the record structure.
GetConnections(ElementId: Integer; Elements: IntegerArray): Integer | Given an ElementId, for a pipe this will fill Elements with the Ids of all connected nodes; for a node this will fill Elements with the Ids of all connected pipes. This function returns the number of Ids in Elements.
GetData(ElementId: Integer; Data: TRecord): Boolean | Given an ElementId, this will fill "Data" with the underlying equipment data for the node (if applicable).
GetElement(ElementId: Integer): Element | Get an Element object by Id. (See the Element Object.)
GetElementKindName(ElementId: Integer; [UseShortVersion: Boolean]): String | Given an Element Id return the name of the Kind associated with the Element, and any additional component-specific naming, if UseShortVersion is False.
GetElements(Elements: IntegerArray; FilterOrKind: Variant): Integer | Given a Filter (or Element Kind) this function will fill the Elements array with all the Element Ids that match, and return the total number of these as the result. Note: If neither a Filter or Kind is specified this will return all Nodes and Pipes in the Network.
GetFlowsheetExtents(var X1, Y1, X2, Y2: Integer) | Sets X1, Y1, X2, and Y2 to the values calculated as the (min/max) extents used in drawing the flowsheet on screen.
GetKindName(KindId: Integer): String | Given a KindId, returns the name associated with it.
GetNodes(Nodes: IntegerArray; FilterOrKind: Variant): Integer | Given a Filter (or Element Kind) this function will fill the Nodes array with all the Element Ids that match, and return the total number of these as the result. Note: If neither a Filter or Kind is specified this will return all the Nodes in the Network.
GetPipes(Pipes: IntegerArray; FilterOrKind: Variant): Integer | Given a Filter (or Element Kind) this will fill the Pipes array with all the Element Ids that match, and return the total number of these as the result. Note: If neither a Filter or Kind is specified this will return all the Pipes in the Network.
GetTexts(Texts: IntegerArray): Integer | Fills the Texts array with all the Ids of the "Text" strings in the Network, returning the total number of these as the result.
Load(Filename: String) | Load a Network from the file specified by Filename.
NodeCount: Integer | Get the number of nodes in the Network.
PipeCount: Integer | Get the number of pipes in the Network.
Refresh(Repaint: Boolean = False) | Refresh the user interface (i.e., the Data Report, Input Editor, etc.). Use the Repaint parameter (which defaults to False) to repaint the flowsheet.
Save(Filename: String) | Save the Network to the file specified by Filename.
SaveFlowsheetToImageFile(Filename: String) | Save the flowsheet as a PNG format image file.
SaveFlowsheetToMetafile(Filename: String) | Save the flowsheet as a metafile image file.
Set(ElementId: Integer; PropertyNameOrId: Variant; Value: Variant) | Set an Element's property value, given a PropertyName or PropertyId to Value.
TextCount: Integer | Get the number of "Text" strings in the Network.
Getting and Setting Element Properties The Network object provides two methods to get and set element properties: ▪Get(ElementId: Integer; PropertyNameOrId: Variant): Variant ▪Set(ElementId: Integer; PropertyNameOrId: Variant; Value: Variant) Get will return the value of a property for a particular element. You specify the element's identifier in the first parameter, and the name (or identifier) of the property you wish to query in the second. Example: NodePressure := Network.Get(1, 66); NodeFlow := Network.Get(1, 'Flow'); Set will update the value of a specified element's property. The first parameter is the element's id, the second is the property name or id, and the third is the value you wish to change the property to. Example: // If the flow is less than 100 then set the node's color to red. if Network.Get(1, 46) < 100 then Network.Set(1, 'BackgroundColor', clRed); Notes: ▪To see the identifiers associated with each element select the "Show or Hide Node Numbers" and the "Show or Hide Pipe Numbers" buttons on the Flowsheet Toolbar. (Alternatively, check the "Show Node Numbers" and "Show Pipe Numbers" options in the "Components" page of the Flowsheet Options dialog.) ▪See Property Constants for a full list of all available properties for each type of element. Filtering Elements On a subset of the network's elements, for example, you may wish to check how all the Flow Control Values in a network react as a Pump's speed is decreased. Three functions have been provided to filter the elements of a network: ▪GetElements(Elements: IntegerArray; FilterOrKind: Variant): Integer ▪GetNodes(Nodes: IntegerArray; FilterOrKind: Variant): Integer ▪GetPipes(Pipes: IntegerArray; FilterOrKind: Variant): Integer All functions can take two parameters: – the IntegerArray of Element Ids to be filled, and a Filter (or Kind constant). A Filter is a logical condition that will return the Ids of elements that match the condition (i.e., evaluate to True). The Kind refers to the "group" or "subgroup" that an element belongs to, e.g., a Boundary or Steel Pipe or Duct. The Filter/Kind parameter is optional; if it is not included then the routines will fill the IntegerArray with the Ids of all Elements, Nodes, or Pipes in the Network. All functions return the number of items that match the Filter/Kind. Note: GetElements is used when you do not want to distinguish between Node and Pipe Elements. When specifying a Kind instead of a Filter, you can pass in an integer value (if you know it for the Kind), or use a constant value from the FFKindConstants library. If you use a constant, then you must include FFKindConstants in the script's uses clause. uses FFKindConstants; // Required for Element Kind constants. var NodeIds; begin // Use the ekBoundaries constant to fill NodeIds with all the // Boundaries in the network. Count := Network.GetNodes(NodeIds, ekBoundaries); ShowMessage('No. Of Boundaries = ' + IntToStr(Count)); end; Note: See Element Kind Constants for a full list. (These are also listed in the "[FluidFlow3 folder]\Default\Scripts\FFKindConstants.psc" file.) When a Filter is specified only those Nodes/Pipes that meet the filter's conditions will be returned in the IntegerArray. The filter condition will normally make use of Property Names or Ids. Note: Within the filter condition the Property Names/Ids must be prefixed with the : (colon) character. const NodeFilter = '(:66 > 1)'; // Pressure greater than one var PipeIds; NodeIds; begin Count := Network.GetPipes(PipeIds); ShowMessage('Pipes in Network = ' + IntToStr(Count)); Count := Network.GetNodes(NodeIds, NodeFilter); ShowMessage('Nodes with Pressure > 1 = ' + IntToStr(Count)); end; By using combinations of comparison and logical operators, you can create fairly sophisticated filters. For example, the following statement checks that the Pressure is greater than 1 and the Flow is less than 100: const NodeFilter = '(:BoundaryPressure > 1) AND (:Flow < 100)'; var NodeIds; begin NodeCount := Network.GetNodes(NodeIds, NodeFilter); ShowMessage(NodeCount); end; Comparison and logical operators that can appear in a Filter
Operator | Meaning
< | Less than
> | Greater than
>= | Greater than or equal to
<= | Less than or equal to
= | Equal to
<> | Not equal to
AND | Tests two statements are both True
NOT | Tests that the following statement is not True
OR | Tests that at least one of two statements is True
+ | Adds numbers
- | Subtracts numbers
* | Multiplies two numbers
/ | Divides two numbers
Solving the Network Use the Calculate function to solve the network. This function will return 0 if successful; it will return an error code if the calculation fails. uses FFErrors; // Required For GetNetworkError function begin // Solve the network. ErrorCode := Network.Calculate; // If an error occurred then display its associated message. if ErrorCode <> 0 Then ShowMessage(GetNetworkError(ErrorCode)); end; Note: See the "[FluidFlow3 folder]\Default\Scripts\FFErrors.psc" file for a full list of the error messages. Using Accumulator Connection Data Example: Open the "[FluidFlow3 folder]\QA Incompressible Flow\Accumulator\Accumulator Outlet Pipe Connections.ff3" example and add the following script in the editor. var Data: TRecordList; p: TRecord; sPipeNumber: string; sBranchHeight: string; begin Network.GetAccumulatorConnectionData(1, Data); Output.Add('The full data returned for Node 1:'); Output.Add(Data.AsText); p := Data[2]; sPipeNumber := IntToStr(p['PipeNumber']); sBranchHeight := FloatToStr(p['BranchHeight']); ShowMessage('Branch Height for Pipe ' + sPipeNumber + ' is: ' + sBranchHeight); end; Network Object Examples Example: This example will go through the network 5 times, increasing the value of the first node's pressure by 1.5 each iteration. It calls a procedure to check each node's Flow result value – if it is less than 100 it will change the background color of the node to RED. uses Graphics; // Include this to get access to clRed. procedure UpdateNodeBackgroundColors; var NodeIds; // IntegerArray for holding the node ElementIds. begin NodeCount := Network.GetNodes(NodeIds); if NodeCount > 0 then begin // NOTE: NodeIds is a 0-based array so all indexing starts at 0. for NodeIndex := 0 to NodeCount – 1 do begin // If the current element's flow is less than 100 then set // it's Background color to red. if Network.Get(NodeIds[NodeIndex], 46) < 100 then Network.Set(NodeIds[NodeIndex], 'BackgroundColor', clRed); end; end; end; begin for i := 1 to 5 do begin // Get the Pressure value of Node 1 ePressure := Network.Get(1, 66); // Increase Pressure by 1.5 Network.Set(1, 66, ePressure + 1.5); // Recalculate the network. Network.Calculate; // Call the UpdateNodeBackgroundColors procedure. UpdateNodeBackgroundColors; // Update the flowsheet's user interface to reflect the changes. Network.Refresh; end; end; Example: In this example we are using a filter to get all the Nodes that have a pressure value greater than 1. uses Graphics; // Include this to get access to clRed. const NodeFilter = '(:66 > 1)'; // Pressure greater than one var NodeIds; // IntegerArray for holding the node ElementIds. begin // Get all the NodeIds that match the Filter. NodeCount := Network.GetNodes(NodeIds, NodeFilter); if NodeCount > 0 then begin // Go through each matching Node. for NodeIndex := 0 to NodeCount - 1 do begin // Get the 'current' Node. e := Network.GetElement(NodeIds[NodeIndex]); // Change its background color to green. e.Property['BackgroundColor'] := clGreen; end; end; // Update the flowsheet's user interface to reflect the changes. Network.Refresh; end;