PowSyBl (Power System Blocks) is an open source library written in Java, that makes it easy to write complex software for power systems’ simulations and analysis. Its modular approach allows developers to extend or customize its features.
PowSyBl is part of the LF Energy Foundation, a project of The Linux Foundation that supports open source innovation projects within the energy and electricity sectors.
Read more at https://www.powsybl.org !
This project and everyone participating in it is under the Linux Foundation Energy governance principles and must respect the PowSyBl Code of Conduct. By participating, you are expected to uphold this code. Please report unacceptable behavior to powsybl-tsc@lists.lfenergy.org.
PowSyBl Open Load Flow Knitro Solver is an extension to PowSyBl Open Load Flow allowing to solve the load flow equations with the non-linear solver Knitro instead of the default Newton-Raphson method.
The Knitro solver extension models the load flow problem as a constraint satisfaction problem (without an objective function).
To use the PowSyBl Open Load Flow Knitro Solver extension, a valid Knitro installation is required.
Knitro supports Linux, Windows, and macOS; however, its Java bindings are currently available only on Linux and Windows.
- Obtain the installation kit and trial license from the Artelys website.
- Configure the following environment variables:
KNITRODIR
: Path to the Knitro installation directory.ARTELYS_LICENSE
: Path to the Knitro license file or its content.
You may then validate your installation by running one of the Java examples like this (here on Linux):
cd $KNITRODIR/examples/java/examples
# compile example
javac -cp ".;../lib/*" com/artelys/knitro/examples/ExampleNLP1.java
# run example
java -cp ".;../lib/*" com.artelys.knitro.examples.ExampleNLP1
Here an example output (click to expand)
$ java -cp ".;../lib/*" com.artelys.knitro.examples.ExampleNLP1
--- snip ---
Optimal objective value = 306.5000025616414
Optimal x (with corresponding multiplier)
x1 = 0,500000 (lambda = -700,000000)
x2 = 2,000000 (lambda = -0,000000)
Optimal constraint values (with corresponding multiplier)
c[0] = 1,000000 (lambda = -700,000000)
c[1] = 4,500000 (lambda = -0,000000)
Feasibility violation = 0,000000
Optimality violation = 0,000003
Knitro Java bindings require a private JAR file that must be installed locally, as it is not available on Maven Central. Use the following command:
./mvnw install:install-file -Dfile="$KNITRODIR/examples/Java/lib/Knitro-Interfaces-2.5-KN_14.2.0.jar" -DgroupId=com.artelys -DartifactId=knitro-interfaces -Dversion=14.2.0 -Dpackaging=jar -DgeneratePom=true
To run a load flow with PowSyBl Open Load Flow Knitro Solver. We first add a few Maven dependencies to respectively have access to network model, IEEE test networks and simple logging capabilities:
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-iidm-impl</artifactId>
<version>6.6.0</version>
</dependency>
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-ieee-cdf-converter</artifactId>
<version>6.6.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.13</version>
</dependency>
We are now able to load the IEEE 14 bus test network:
Network network = IeeeCdfNetworkFactory.create14();
After adding dependency on both Open Load Flow implementation and Knitro Solver extension:
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-open-loadflow</artifactId>
<version>1.14.0</version>
</dependency>
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-open-loadflow-knitro-solver</artifactId>
<version>0.1.0</version>
</dependency>
To run the load flow with the Knitro solver, configure the
Open Load Flow parameter acSolverType
as follows:
LoadFlowParameters parameters = new LoadFlowParameters();
OpenLoadFlowParameters.create(parameters)
.setAcSolverType("KNITRO"); // Change default Open Load Flow parameter acSolverType from NEWTON_RAPHSON to KNITRO
LoadFlow.run(network, parameters);
The Knitro solver is used as a substitute for the inner loop calculations in the load flow process. The outer loops such as distributed slack, reactive limits, etc... operate identically as when using the Newton-Raphson method.
Most parameters for Knitro are configured similarly to the Newton-Raphson method.
However, specific parameters tailored to Knitro are provided through the KnitroLoadFlowParameters
extension of LoadFlowParameters
.
Here an example on how to provide Knitro solver specific parameters in Java:
LoadFlowParameters parameters = new LoadFlowParameters();
OpenLoadFlowParameters.create(parameters)
.setAcSolverType("KNITRO");
KnitroLoadFlowParameters knitroLoadFlowParameters = new KnitroLoadFlowParameters();
knitroLoadFlowParameters.setGradientComputationMode(2);
parameters.addExtension(KnitroLoadFlowParameters.class, knitroLoadFlowParameters);
-
Voltage Bounds:
- Default range: 0.5 p.u. to 1.5 p.u. : they define lower and upper bounds of voltages.
- Modify using:
setLowerVoltageBound
setUpperVoltageBound
-
Jacobian Matrix Usage:
- The solver utilizes the Jacobian matrix for solving successive linear approximations of the problem.
- Gradient Computation Modes:
1 (exact)
: Gradients computed in PowSyBl are provided to Knitro.2 (forward)
: Knitro computes gradients via forward finite differences.3 (central)
: Knitro computes gradients via central finite differences.
- Use
setGradientComputationMode
in theKnitroLoadFlowParameters
extension.
-
Jacobian Sparsity:
- Default: Sparse form (highly recommended, improves calculation as load flow problems are highly sparse problems).
- To specify dense form:
- Use
setGradientUserRoutineKnitro
in theKnitroLoadFlowParameters
extension.
- Use
- Options:
1 (dense)
: All constraints are considered as dependent of all variables.2 (sparse)
: Derivatives are computed only for variables involved in the constraints (recommended).
-
Maximum Iterations:
- Default: 200
- Modify using
setMaxIterations
.
Constraints are categorized into two types:
-
Linear and Quadratic Constraints:
- Explicitly passed to the solver.
-
Non-linear (Non-quadratic) Constraints:
- Evaluated during each iteration by a callback class, based on the current state.