Layouts

A layout is the way in which the elements of a graph are arranged.

It is possible to use your own graph layout implementation, but there are also existing layouts in powsybl-diagram, ready to use.

Layouts for voltage levels

Existing implementations

PositionVoltageLevelLayout

This layout positions the different elements inside a voltage level according to the following process:

The PositionVoltageLevelLayoutFactoryParameters class

This class gathers the parameters that customize the way PositionVoltageLevelLayout behaves, from the preliminary graph cleaning (see Graph Refiner) to the block/position computation (see CellBlockDecomposer and PositionFinder):

  • feederStacked (default true): whether LegPrimaryBlock sharing the same non-bus extremity should be detected and marked as stackable, so that the corresponding feeders can later be stacked on top of each other instead of being spread out horizontally.

feederStackedDefault

feederStackedChanged

Default value (true)

Value changed (false)

  • removeUnnecessaryFictitiousNodes (default true): whether the GraphRefiner should remove the redundant FICTITIOUS nodes of the graph (i.e. nodes with only two adjacent edges that can be bypassed with a single edge). Combined with LayoutParameters.adaptCellHeightToContent, keeping these nodes makes the feeder cell taller, since each remaining fictitious node is counted as an extra block when computing the cell height.

removeUnnecessaryFictitiousNodesDefault

removeUnnecessaryFictitiousNodesChanged

Default value (true)

Value changed (false)

  • substituteSingularFictitiousByFeederNode (default true): whether the GraphRefiner should replace INTERNAL nodes having a single neighbor by a fictitious FeederNode.

substituteSingularFictitiousByFeederNodeDefault

substituteSingularFictitiousByFeederNodeChanged

Default value (true)

Value changed (false)

  • substituteInternalMiddle2wtByEquipmentNodes (default true): whether the GraphRefiner should replace, by simple EquipmentNode, the feeder/middle nodes of a two-winding transformer whose both ends are in the same voltage level, in order to avoid unnecessary snake lines.

substituteInternalMiddle2wtByEquipmentNodesDefault

substituteInternalMiddle2wtByEquipmentNodesChanged

Default value (true)

Value changed (false)

  • exceptionIfPatternNotHandled (default false): whether an exception should be thrown when the block decomposition algorithm cannot fully merge the blocks of a cell (see CellBlockDecomposer); when false, the remaining blocks are simply gathered into an UndefinedBlock and the diagram building continues.

exceptionIfPatternNotHandledDefault

PowsyblException: Blocks detection impossible for cell EXTERN null UNDEFINED [BUS bbs1 bbs1, SWITCH d1 d1, ...]

Default value (false)

Value changed (true)

  • handleShunts (default false): whether PositionFinder implementations should take ShuntCell into account when computing the List<Subsection> (see Subsection). Below, loadA and loadB are linked by a shunt jumper, while loadMid is an unrelated feeder attached in between them on the busbar. With the default false, the shunt jumper is not taken into account when ordering the feeders, so loadMid stays between loadA and loadB, and the jumper wire ends up crossing straight through loadMid’s own wire. With true, loadMid is moved out of the way (to the left of loadA), leaving a clean, crossing-free path for the jumper between loadA and loadB (at the cost of a wider diagram).

handleShuntsDefault

handleShuntsChanged

Default value (false)

Value changed (true)

  • busInfoMap (default empty): a map giving, for some BusNode ids, on which Side (LEFT/RIGHT) extra information about the bus should be displayed; this is taken into account by BlockPositionner to reserve the corresponding space. Below, two busbar sections (bbs1 and bbs2) connected by a sectionalizing breaker have bus info indicators configured on the left and right sides respectively (bbs1 -> Side.LEFT, bbs2 -> Side.RIGHT). With the default empty map, no extra space is reserved for the indicators, causing them to overlap right on top of their adjacent feeder connections and switches. With busInfoMap configured, BlockPositionner extends each busbar section by reserving a dedicated cell on the specified side, completely separating the indicators from the feeders.

busInfoMapDefault

busInfoMapChanged

Default value (empty)

Value changed (bbs1 -> Side.LEFT, bbs2 -> Side.RIGHT)

The PositionFinder class

The PositionFinder interface, and its available implementations (PositionPredefined and PositionByClustering), are described in a dedicated page: see Position of BusNodes and Cells order.

RandomVoltageLevelLayout

With this layout, the graph node coordinates are randomly fixed:

  • Between 0 and width for the x coordinate;

  • Between 0 and height for the y coordinate. The width and height variables are provided by the user.

CgmesVoltageLevelLayout

With this layout, the elements of the graph are arranged according to the data included in the CGMES DL profile.

Choosing a VoltageLevelLayout

The voltageLevelLayoutFactoryCreator attribute in the SldParameters class is the customization parameter to use to choose a specific VoltageLevelLayout.

The VoltageLevelLayoutFactoryCreator creates a VoltageLevelLayoutFactory which in turn creates a VoltageLevelLayout.

Choose a specific PositionVoltageLevelLayout

Static methods are available in the VoltageLevelLayoutFactoryCreator interface to help users manipulate those objects.

Some examples are shown below.

Example 1

PositionVoltageLevelLayout using default parameters:

VoltageLevelLayoutFactoryCreator voltageLevelLayoutFactoryCreator = VoltageLevelLayoutFactoryCreator.newPositionVoltageLevelLayoutFactoryCreator();
SldParameters sldParameters = new SldParameters().setVoltageLevelLayoutFactoryCreator(voltageLevelLayoutFactoryCreator);

Example 2

PositionVoltageLevelLayout with a chosen PositionFinder:

VoltageLevelLayoutFactoryCreator voltageLevelLayoutFactoryCreator = VoltageLevelLayoutFactoryCreator.newPositionVoltageLevelLayoutFactoryCreator(positionFinder);
SldParameters sldParameters = new SldParameters().setVoltageLevelLayoutFactoryCreator(voltageLevelLayoutFactoryCreator);

Example 3

PositionVoltageLevelLayout with chosen PositionVoltageLevelLayoutFactoryParameters:

VoltageLevelLayoutFactoryCreator voltageLevelLayoutFactoryCreator = VoltageLevelLayoutFactoryCreator.newPositionVoltageLevelLayoutFactoryCreator(positionVoltageLevelLayoutFactoryParameters);
SldParameters sldParameters = new SldParameters().setVoltageLevelLayoutFactoryCreator(voltageLevelLayoutFactoryCreator);

Example 4

PositionVoltageLevelLayout with a chosen PositionFinder and chosen PositionVoltageLevelLayoutFactoryParameters:

VoltageLevelLayoutFactoryCreator voltageLevelLayoutFactoryCreator = VoltageLevelLayoutFactoryCreator.newPositionVoltageLevelLayoutFactoryCreator(positionFinder, positionVoltageLevelLayoutFactoryParameters);
SldParameters sldParameters = new SldParameters().setVoltageLevelLayoutFactoryCreator(voltageLevelLayoutFactoryCreator);

Use the SmartVoltageLevelLayoutFactory

The SmartVoltageLevelLayoutFactory picks the “best” VoltageLevelLayout according to the information available in the network.

There is also a static method in the VoltageLevelLayoutFactoryCreator interface to help users pick the SmartVoltageLevelLayoutFactory:

VoltageLevelLayoutFactoryCreator voltageLevelLayoutFactoryCreator = VoltageLevelLayoutFactoryCreator.newSmartVoltageLevelLayoutFactoryCreator();
SldParameters sldParameters = new SldParameters().setVoltageLevelLayoutFactoryCreator(voltageLevelLayoutFactoryCreator);

Creating and using your own VoltageLevelLayout

A VoltageLevelLayout only has to implement the Layout interface, i.e. implement a run(LayoutParameters layoutParameters) method, in charge of computing the coordinates of the nodes of the VoltageLevelGraph it was built from (typically by iterating over graph.getNodes() and setting node.setX(...) / node.setY(...), as done for instance by RandomVoltageLevelLayout). The AbstractVoltageLevelLayout class can be extended to get direct access to the underlying VoltageLevelGraph (through getGraph()), but this is not mandatory.

You will also need a VoltageLevelLayoutFactory, whose only purpose is to create your VoltageLevelLayout instances from a VoltageLevelGraph:

public class MyVoltageLevelLayout implements Layout {
    // ...
    @Override
    public void run(LayoutParameters layoutParameters) {
        // compute the coordinates of the nodes of the graph
    }
}

public class MyVoltageLevelLayoutFactory implements VoltageLevelLayoutFactory {
    @Override
    public Layout create(VoltageLevelGraph graph) {
        return new MyVoltageLevelLayout(graph);
    }
}

Once your VoltageLevelLayoutFactory is ready, you can use it in the SldParameters class, either directly:

SldParameters sldParameters = new SldParameters().setVoltageLevelLayoutFactoryCreator(network -> new MyVoltageLevelLayoutFactory());

or by wrapping it into a VoltageLevelLayoutFactoryCreator, which gives you access to the Network if your factory needs it:

VoltageLevelLayoutFactoryCreator voltageLevelLayoutFactoryCreator = network -> new MyVoltageLevelLayoutFactory();
SldParameters sldParameters = new SldParameters().setVoltageLevelLayoutFactoryCreator(voltageLevelLayoutFactoryCreator);

Note

The following voltage level layout factories are available: SmartVoltageLevelLayoutFactory (the default), CgmesVoltageLevelLayoutFactory, RandomVoltageLevelLayoutFactory, PositionVoltageLevelLayoutFactory

Layouts for substations

A substation layout arranges, relative to one another, the VoltageLevelGraph of the different VoltageLevel of a substation (each one already laid out thanks to a VoltageLevelLayout), and computes the snake lines connecting them (the edges of the SubstationGraph, see Requirements for implementing a custom GraphBuilder).

Existing implementations

HorizontalSubstationLayout

With this layout, the VoltageLevelGraph are placed side by side horizontally, ordered as they were added to the SubstationGraph (by default, NetworkGraphBuilder adds them by descending nominal voltage), and vertically aligned according to the LayoutParameters.getBusbarsAlignment() parameter (aligning on the first, the last, or the middle busbar section, or without any alignment).

substationLayoutHorizontal

VerticalSubstationLayout

With this layout, the VoltageLevelGraph are stacked vertically, ordered as they appear in the SubstationGraph (i.e. by descending nominal voltage), each one below the previous one.

substationLayoutVertical

Choosing a SubstationLayout

The substationLayoutFactory attribute in the SldParameters class is the customization parameter to use to choose a specific SubstationLayout: it takes a SubstationLayoutFactory, for example a HorizontalSubstationLayoutFactory (the default) or a VerticalSubstationLayoutFactory.

SldParameters sldParameters = new SldParameters().setSubstationLayoutFactory(new VerticalSubstationLayoutFactory());

Creating and using your own SubstationLayout

Similarly, a SubstationLayout also has to implement the Layout interface. Its run(LayoutParameters layoutParameters) method is in charge of positioning the different VoltageLevelGraph of the SubstationGraph relative to one another (each of them being already laid out thanks to its own VoltageLevelLayout), and of computing the coordinates of the snake lines connecting them.

The corresponding SubstationLayoutFactory creates your SubstationLayout instances from a SubstationGraph and the VoltageLevelLayoutFactory used to lay out each VoltageLevelGraph:

public class MySubstationLayout implements Layout {
    // ...
    @Override
    public void run(LayoutParameters layoutParameters) {
        // position the voltage level graphs relative to each other and compute the snake lines
    }
}

public class MySubstationLayoutFactory implements SubstationLayoutFactory {
    @Override
    public Layout create(SubstationGraph graph, VoltageLevelLayoutFactory vLayoutFactory) {
        return new MySubstationLayout(graph, vLayoutFactory);
    }
}

Your SubstationLayoutFactory can then be set in the SldParameters class:

SldParameters sldParameters = new SldParameters().setSubstationLayoutFactory(new MySubstationLayoutFactory());

Note

The following substation layout factories are available HorizontalSubstationLayoutFactory (the default) or a VerticalSubstationLayoutFactory

Layouts for multi-substation graphs

Multi-substation graphs can use a matrix-like layout for the different substations. See Zone Matrix Layout for more details.