Skip to content

Commit 330e28f

Browse files
authored
Merge pull request #441 from ie3-institute/ck/#440-impedanceWeightedGraph
Add impedance weighted graph
2 parents bd31239 + 8493071 commit 330e28f

File tree

13 files changed

+391
-44
lines changed

13 files changed

+391
-44
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
### Added
1010
- SQL time series sources (`SqlTimeSeriesSource` and `SqlTimeSeriesMappingSource`) [#467](https://github.com/ie3-institute/PowerSystemDataModel/issues/467)
11+
- Graph with impedance weighted edges including facilities to create it [#440](https://github.com/ie3-institute/PowerSystemDataModel/issues/440)
1112

1213
### Fixed
1314
- Reduced code smells [#492](https://github.com/ie3-institute/PowerSystemDataModel/issues/492)

docs/readthedocs/models/ValidationUtils.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ Validation Utils
44
This page gives an overview about the ValidationUtils in the *PowerSystemDataModel*.
55

66
What are the ValidationUtils?
7-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7+
=============================
88
The methods in ValidationUtils and subclasses can be used to check that objects are valid, meaning their parameters have valid values and they are correctly connected.
99

1010
What is checked?
11-
^^^^^^^^^^^^^^^^
11+
================
1212
- The check methods include checks that assigned values are valid, e.g. lines are not allowed to have negative lengths or the rated power factor of any unit must be between 0 and 1.
1313
- Furthermore, several connections are checked, e.g. that lines only connect nodes of the same voltage level or that the voltage levels indicated for the transformer sides match the voltage levels of the nodes they are connected to.
1414

1515
How does it work?
16-
^^^^^^^^^^^^^^^^^
16+
=================
1717
- The method :code:`ValidationUtils.check(Object)` is the only method that should be called by the user.
1818
- This check method identifies the object class and forwards it to a specific check method for the given object
1919
- The overall structure of the ValidationUtils methods follows a cascading scheme, orientated along the class tree
@@ -26,7 +26,7 @@ How does it work?
2626
- ValidationUtils furthermore contains several utils methods used in the subclasses
2727

2828
Which objects are checked?
29-
^^^^^^^^^^^^^^^^^^^^^^^^^^
29+
==========================
3030
The ValidationUtils include validation checks for...
3131

3232
- NodeValidationUtils
@@ -81,7 +81,7 @@ The ValidationUtils include validation checks for...
8181
- SystemParticipants
8282

8383
What should be considered?
84-
^^^^^^^^^^^^^^^^^^^^^^^^^^
84+
==========================
8585
- Due to many checks with if-conditions, the usage of the ValidationUtils for many objects might be runtime relevant.
8686
- The check for a GridContainer includes the interplay of the contained entities as well as the checks of all contained entities.
8787
- If new classes are introduced to the *PowerSystemDataModel*, make sure to follow the forwarding structure of the ValidationUtils methods when writing the check methods!

docs/readthedocs/models/input/grid/line.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ Entity Model
4949
| nodeB | -- | |
5050
+-------------------+------+--------------------------------------------------------+
5151
| parallelDevices | -- | | overall amount of parallel lines to automatically |
52-
| | -- | | construct (e.g. parallelDevices = 2 will build a |
53-
| | -- | | total of two lines using the specified parameters) |
52+
| | | | construct (e.g. parallelDevices = 2 will build a |
53+
| | | | total of two lines using the specified parameters) |
5454
+-------------------+------+--------------------------------------------------------+
5555
| type | -- | |
5656
+-------------------+------+--------------------------------------------------------+

docs/readthedocs/models/input/grid/transformer2w.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ Entity Model
6666
| nodeB | -- | Lower voltage node |
6767
+-----------------+------+------------------------------------------------------------+
6868
| parallelDevices | -- | | overall amount of parallel transformers to automatically |
69-
| | -- | | construct (e.g. parallelDevices = 2 will build a |
70-
| | -- | | total of two transformers using the specified parameters)|
69+
| | | | construct (e.g. parallelDevices = 2 will build a |
70+
| | | | total of two transformers using the specified parameters)|
7171
+-----------------+------+------------------------------------------------------------+
7272
| type | -- | |
7373
+-----------------+------+------------------------------------------------------------+

docs/readthedocs/models/input/grid/transformer3w.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ Entity Model
8888
| nodeC | -- | Lowest voltage node |
8989
+-----------------+------+------------------------------------------------------------+
9090
| parallelDevices | -- | | overall amount of parallel transformers to automatically |
91-
| | -- | | construct (e.g. parallelDevices = 2 will build a |
92-
| | -- | | total of two transformers using the specified parameters)|
91+
| | | | construct (e.g. parallelDevices = 2 will build a |
92+
| | | | total of two transformers using the specified parameters)|
9393
+-----------------+------+------------------------------------------------------------+
9494
| type | -- | |
9595
+-----------------+------+------------------------------------------------------------+

docs/readthedocs/models/models.rst

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -54,31 +54,32 @@ Equality Checks
5454
instances is not as trivial as it might seem, because there might be different understandings about the equality of
5555
quantities (e.g. there is a big difference between two instances being equal or equivalent). After long discussions how to
5656
treat quantities in the entity :code:`equals()` method, we agreed on the following rules to be applied:
57-
- equality check is done by calling :code:`Objects.equals(<QuantityInstanceA>, <QuantityInstanceB>)` or
58-
:code:`<QuantityInstanceA>.equals(<QuantityInstanceB>)`.
59-
Using :code:`Objects.equals(<QuantityInstanceA>, <QuantityInstanceB>)` is necessary especially for time series data.
60-
As in contrast to all other places, quantity time series from real world data sometimes are not complete and
61-
hence contain missing values. To represent missing values this is the only place where the usage of :code:`null`
62-
is a valid choice and hence needs to be treated accordingly. Please remember that his is only allowed in very few
63-
places and you should try to avoid using :code:`null` for quantities or any other constructor parameter whenever possible!
64-
- equality is given if, and only if, the quantities value object and unit are exactly equal. Value objects can become
65-
e.g. :code:`BigDecimal` or :code:`Double` instances. It is important, that the object type is also the same, otherwise
66-
the entities :code:`equals()` method returns false. This behavior is in sync with the equals implementation
67-
of the indriya library. Hence, you should ensure that your code always pass in the same kind of a quantity instance
68-
with the same underlying number format and type. For this purpose you should especially be aware of the unit conversion
69-
method :code:`AbstractQuantity.to(Quantity)` which may return seemingly unexpected types, e.g. if called on a quantity
70-
with a :code:`double` typed value, it may return a quantity with a value of either :code:`Double` type or :code:`BigDecimal` type.
71-
- for now, there is no default way to compare entities in a 'number equality' way provided. E.g. a line with a length
72-
of 1km compared to a line with a length of 1000m is actually of the same length, but calling :code:`LineA.equals(LineB)`
73-
would return :code:`false` as the equality check does NOT convert units. If you want to compare two entity instances
74-
based on their equivalence you have (for now) check for each quantity manually using their :code:`isEquivalentTo()`
75-
method. If you think you would benefit from a standard method that allows entity equivalence check, please consider
76-
handing in an issue `here <https://github.com/ie3-institute/PowerSystemDataModel/issues>`_.
77-
Furthermore, the current existing implementation of :code:`isEquivalentTo()` in indriya does not allow the provision of
78-
a tolerance threshold that might be necessary when comparing values from floating point operations. We consider
79-
providing such a method in our `PowerSystemUtils <https://github.com/ie3-institute/PowerSystemUtils>`_ library.
80-
If you think you would benefit from such a method, please consider handing in an issue
81-
`here <https://github.com/ie3-institute/PowerSystemUtils/issues>`_.
57+
58+
- equality check is done by calling :code:`Objects.equals(<QuantityInstanceA>, <QuantityInstanceB>)` or
59+
:code:`<QuantityInstanceA>.equals(<QuantityInstanceB>)`.
60+
Using :code:`Objects.equals(<QuantityInstanceA>, <QuantityInstanceB>)` is necessary especially for time series data.
61+
As in contrast to all other places, quantity time series from real world data sometimes are not complete and
62+
hence contain missing values. To represent missing values this is the only place where the usage of :code:`null`
63+
is a valid choice and hence needs to be treated accordingly. Please remember that his is only allowed in very few
64+
places and you should try to avoid using :code:`null` for quantities or any other constructor parameter whenever possible!
65+
- equality is given if, and only if, the quantities value object and unit are exactly equal. Value objects can become
66+
e.g. :code:`BigDecimal` or :code:`Double` instances. It is important, that the object type is also the same, otherwise
67+
the entities :code:`equals()` method returns false. This behavior is in sync with the equals implementation
68+
of the indriya library. Hence, you should ensure that your code always pass in the same kind of a quantity instance
69+
with the same underlying number format and type. For this purpose you should especially be aware of the unit conversion
70+
method :code:`AbstractQuantity.to(Quantity)` which may return seemingly unexpected types, e.g. if called on a quantity
71+
with a :code:`double` typed value, it may return a quantity with a value of either :code:`Double` type or :code:`BigDecimal` type.
72+
- for now, there is no default way to compare entities in a 'number equality' way provided. E.g. a line with a length
73+
of 1km compared to a line with a length of 1000m is actually of the same length, but calling :code:`LineA.equals(LineB)`
74+
would return :code:`false` as the equality check does NOT convert units. If you want to compare two entity instances
75+
based on their equivalence you have (for now) check for each quantity manually using their :code:`isEquivalentTo()`
76+
method. If you think you would benefit from a standard method that allows entity equivalence check, please consider
77+
handing in an issue `here <https://github.com/ie3-institute/PowerSystemDataModel/issues>`_.
78+
Furthermore, the current existing implementation of :code:`isEquivalentTo()` in indriya does not allow the provision of
79+
a tolerance threshold that might be necessary when comparing values from floating point operations. We consider
80+
providing such a method in our `PowerSystemUtils <https://github.com/ie3-institute/PowerSystemUtils>`_ library.
81+
If you think you would benefit from such a method, please consider handing in an issue
82+
`here <https://github.com/ie3-institute/PowerSystemUtils/issues>`_.
8283

8384
Conditional Parameters
8485
Some of the models have conditional parameters. When reading model data from a data source, their respective factories for building these

gradle/scripts/tests.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ test {
44
events "skipped", "failed"
55
}
66

7+
// Improve logging for failed Spock tests
78
testLogging {
89
exceptionFormat "Full"
910
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* © 2021. TU Dortmund University,
3+
* Institute of Energy Systems, Energy Efficiency and Energy Economics,
4+
* Research group Distribution grid planning and operation
5+
*/
6+
package edu.ie3.datamodel.graph;
7+
8+
import static tech.units.indriya.unit.Units.OHM;
9+
10+
import javax.measure.Quantity;
11+
import javax.measure.Unit;
12+
import javax.measure.quantity.ElectricResistance;
13+
import org.jgrapht.graph.DefaultWeightedEdge;
14+
import tech.units.indriya.quantity.Quantities;
15+
16+
/**
17+
* A default implementation for edges in a {@link ImpedanceWeightedGraph}. All access to the weight
18+
* of an edge must go through the graph interface, which is why this class doesn't expose any public
19+
* methods.
20+
*
21+
* @version 0.1
22+
* @since 04.06.20
23+
*/
24+
public class ImpedanceWeightedEdge extends DefaultWeightedEdge {
25+
private static final long serialVersionUID = -3331046813188425729L;
26+
27+
protected static final Unit<ElectricResistance> DEFAULT_IMPEDANCE_UNIT = OHM;
28+
29+
public Quantity<ElectricResistance> getImpedance() {
30+
return Quantities.getQuantity(getWeight(), DEFAULT_IMPEDANCE_UNIT);
31+
}
32+
33+
@Override
34+
public String toString() {
35+
return "ImpedanceWeightedEdge{" + "impedance=" + getImpedance() + "} " + super.toString();
36+
}
37+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* © 2021. TU Dortmund University,
3+
* Institute of Energy Systems, Energy Efficiency and Energy Economics,
4+
* Research group Distribution grid planning and operation
5+
*/
6+
package edu.ie3.datamodel.graph;
7+
8+
import edu.ie3.datamodel.models.input.NodeInput;
9+
import java.util.function.Supplier;
10+
import javax.measure.Quantity;
11+
import javax.measure.quantity.ElectricResistance;
12+
import org.jgrapht.graph.SimpleWeightedGraph;
13+
import tech.units.indriya.ComparableQuantity;
14+
15+
/** An impedance weighted graph that uses {@link ImpedanceWeightedEdge}s as edge type. */
16+
public class ImpedanceWeightedGraph extends SimpleWeightedGraph<NodeInput, ImpedanceWeightedEdge> {
17+
18+
private static final long serialVersionUID = -2797654003980753342L;
19+
20+
public ImpedanceWeightedGraph() {
21+
super(ImpedanceWeightedEdge.class);
22+
}
23+
24+
public ImpedanceWeightedGraph(
25+
Supplier<NodeInput> vertexSupplier, Supplier<ImpedanceWeightedEdge> edgeSupplier) {
26+
super(vertexSupplier, edgeSupplier);
27+
}
28+
29+
/**
30+
* Assigns a {@link Quantity} of type {@link ElectricResistance} to an instance of edge {@link
31+
* ImpedanceWeightedEdge}
32+
*
33+
* @param edge edge whose weight should be altered
34+
* @param weight the weight of the {@link ImpedanceWeightedEdge}
35+
*/
36+
public void setEdgeWeightQuantity(
37+
ImpedanceWeightedEdge edge, ComparableQuantity<ElectricResistance> weight) {
38+
double weightDouble =
39+
weight.to(ImpedanceWeightedEdge.DEFAULT_IMPEDANCE_UNIT).getValue().doubleValue();
40+
super.setEdgeWeight(edge, weightDouble);
41+
}
42+
43+
/**
44+
* The only purpose for overriding this method is to provide a better indication of the unit that
45+
* is expected to be passed in. It is highly advised to use the {@link
46+
* ImpedanceWeightedGraph#setEdgeWeightQuantity(ImpedanceWeightedEdge, ComparableQuantity)} for
47+
* safety purposes that the provided edge weight is correct.
48+
*
49+
* @param edge the edge whose weight should be altered
50+
* @param impedanceInOhm the weight of the {@link ImpedanceWeightedEdge} in ohm
51+
* @deprecated Use {@link ImpedanceWeightedGraph#setEdgeWeightQuantity(ImpedanceWeightedEdge,
52+
* ComparableQuantity)} instead, as it provides means for proper unit handling
53+
*/
54+
@Override
55+
@Deprecated
56+
public void setEdgeWeight(ImpedanceWeightedEdge edge, double impedanceInOhm) {
57+
super.setEdgeWeight(edge, impedanceInOhm);
58+
}
59+
}

src/main/java/edu/ie3/datamodel/io/connectors/InfluxDbConnector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class InfluxDbConnector implements DataConnector {
5050
* @param databaseName the name of the database the session should be set to
5151
* @param createDb true if the connector should create the database if it doesn't exist yet, false
5252
* otherwise
53-
* @param logLevel log level of the {@link InfluxDB.LogLevel} logger
53+
* @param logLevel log level of the {@link org.influxdb.InfluxDB.LogLevel} logger
5454
* @param batchOptions write options to write batch operations
5555
*/
5656
public InfluxDbConnector(

0 commit comments

Comments
 (0)