Skip to content

An extension to PowSyBl Open Load Flow to solve the load flow equations with the non-linear solver Knitro

License

Notifications You must be signed in to change notification settings

powsybl/powsybl-open-loadflow-knitro-solver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

PowSyBl Open Load Flow - Knitro Solver

Actions Status Snapshot Status Coverage Status Quality Gate MPL-2.0 License Slack

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.

PowSyBl Logo

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 vs PowSyBl Open Load Flow Knitro Solver

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).

Getting Started

To use the PowSyBl Open Load Flow Knitro Solver extension, a valid Knitro installation is required.

Platform compatibility

Knitro supports Linux, Windows, and macOS; however, its Java bindings are currently available only on Linux and Windows.

Installing Knitro

  1. Obtain the installation kit and trial license from the Artelys website.
  2. 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

Installing Knitro Java Bindings

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

Running a Load Flow with Knitro Solver

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);

Features

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.

Configuration

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);

Knitro Parameters

  1. 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
  2. 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 the KnitroLoadFlowParameters extension.
  3. Jacobian Sparsity:

    • Default: Sparse form (highly recommended, improves calculation as load flow problems are highly sparse problems).
    • To specify dense form:
      • Use setGradientUserRoutineKnitro in the KnitroLoadFlowParameters extension.
    • 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).
  4. Maximum Iterations:

    • Default: 200
    • Modify using setMaxIterations.

Constraint Handling

Constraints are categorized into two types:

  1. Linear and Quadratic Constraints:

    • Explicitly passed to the solver.
  2. Non-linear (Non-quadratic) Constraints:

    • Evaluated during each iteration by a callback class, based on the current state.

About

An extension to PowSyBl Open Load Flow to solve the load flow equations with the non-linear solver Knitro

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages