Segmented Pipeline with Different Pipe Lengths Using Component Array
The model described in Segmented Pipeline Using Component Array represents a pipeline
that consists of N
identical segments. In contrast, this example
shows how you can model a segmented pipeline with segments of different lengths by using an
array of components.
This segmented pipeline model is a composite component that consists of an array of pipe segments, connected in series. Individual pipe segments are represented by the Pipe (IL) blocks from the Foundation library. The block user provides the lengths of the individual pipe segments, and the model automatically determines the size of the array based on that data.
component SegmentedPipelineDifferentLengths parameters segm_lengths = { [3 7 4 5 7 6], 'm' }; % Lengths of pipe segments end % Ports at the two ends of the pipeline nodes A = foundation.isothermal_liquid.isothermal_liquid; % A:left B = foundation.isothermal_liquid.isothermal_liquid; % B:right end % Declare array of components, size matches number of segment elements for i=1:numel(segm_lengths) components (ExternalAccess=none) pipe(i) = foundation.isothermal_liquid.elements.pipe(length = segm_lengths(i)); end end % Connect all segments in series for i=1:(numel(segm_lengths)-1) connections connect(pipe(i).B, pipe(i+1).A); end end % Connect two ends of pipeline to first and last segment, respectively connections connect(A, pipe(1).A); connect(B, pipe(numel(segm_lengths)).B); end end
The segm_lengths
(Lengths of pipe segments)
parameter is a one-dimensional array where the block user enters the lengths of the individual
pipe segments. The model automatically determines the size of the array of components by using
numel(segm_lengths)
as the upper limit for the
for
-loop iterator when it declares an array of member components:
for i=1:numel(segm_lengths) components (ExternalAccess=none) pipe(i) = foundation.isothermal_liquid.elements.pipe(length = segm_lengths(i)); end end
The length of each pipe segment specified in segm_lengths
is passed as
a parameter to the appropriate member of the component array, length =
segm_lengths(i)
.
Use another for
-loop to connect all segments in series, by connecting
node B
of each pipe segment (except the last one) to node
A
of the next segment:
for i=1:(numel(segm_lengths)-1) connections connect(pipe(i).B, pipe(i+1).A); end end
Finally, connect the internal chain of segments to the two ends of pipeline, by connecting
node A
of the composite component to node A
of the first
segment and connecting node B
of the composite component to node
B
of the last segment:
connections connect(A, pipe(1).A); connect(B, pipe(numel(segm_lengths)).B); end end
The resulting block has two isothermal liquid ports, A and B, and one modifiable parameter: Lengths of pipe segments.