Skip to content

Commit

Permalink
New features in this commit:
Browse files Browse the repository at this point in the history
- Parameter estimation example
- Power flow model composer with test example
- Improved CMake build
- Updated documentation
  • Loading branch information
Peles, Slaven committed Jan 28, 2021
1 parent 17387c7 commit 6004c46
Show file tree
Hide file tree
Showing 100 changed files with 5,814 additions and 568 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.kdev4
.directory
*.orig
.vscode/
53 changes: 45 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# LLNL-CODE-718378.
# All rights reserved.
#
# This file is part of GridKit. For details, see github.com/LLNL/GridKit
# This file is part of GridKit. For details, see github.com/LLNL/GridKit
# Please also read the LICENSE file.
#
# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -55,12 +55,10 @@
# endorsement purposes.
#


cmake_minimum_required(VERSION 3.0)
cmake_minimum_required(VERSION 3.12)

project(gridkit)


set(component_models
#generic_model
)
Expand All @@ -69,22 +67,61 @@ set(solver_libs
# generic_solver
)

# Ipopt support is disabled by default
option(GRIDKIT_ENABLE_IPOPT "Enable Ipopt support" ON)

# SUNDIALS support is enabled by default
option(GRIDKIT_ENABLE_SUNDIALS "Enable SUNDIALS support" ON)

# Enable KLU
option(GRIDKIT_ENABLE_SUNDIALS_SPARSE "Enable SUNDIALS sparse linear solvers" OFF)


set(CMAKE_MACOSX_RPATH 1)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/config)

# TODO: Probably beter to set a debug interface target
set(CMAKE_CXX_FLAGS_DEBUG "-Wall -O0 -g")

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_INSTALL_PREFIX "/usr/local")

include_directories(${CMAKE_CURRENT_SOURCE_DIR})

option(BUILD_SHARED_LIBS:BOOL "Build shared libraries" ON)

if(GRIDKIT_ENABLE_IPOPT)
include(FindIpopt)
set(CMAKE_INSTALL_RPATH ${IPOPT_LIBRARY_DIR} ${CMAKE_INSTALL_RPATH})
endif()

include(FindSUNDIALS)
include(FindIpopt)
include(FindSuiteSparse)
set(CMAKE_INSTALL_RPATH ${SUNDIALS_LIBRARY_DIR} ${CMAKE_INSTALL_RPATH})

if(GRIDKIT_ENABLE_SUNDIALS_SPARSE)
include(FindSuiteSparse)
set(CMAKE_INSTALL_RPATH ${SUITESPARSE_LIBRARY_DIR} ${CMAKE_INSTALL_RPATH})
endif()

include_directories(${SUITESPARSE_INCLUDE_DIR} ${SUNDIALS_INCLUDE_DIR} ${IPOPT_INCLUDE_DIR})

# Set up configuration header file
# configure_file(gridkit_config.h.in gridkit_config.h)

add_subdirectory(ComponentLib)
add_subdirectory(Solver)

add_subdirectory(Examples)

# install(FILES gridkit_config.hpp DESTINATION include)

# TESTING
enable_testing()
add_test(NAME AdjointSens COMMAND $<TARGET_FILE:adjoint> )
add_test(NAME Grid3Bus COMMAND $<TARGET_FILE:grid3bus>)
if(GRIDKIT_ENABLE_IPOPT)
add_test(NAME DynamicConOpt COMMAND $<TARGET_FILE:dynconopt> )
add_test(NAME GenConstLoad COMMAND $<TARGET_FILE:genconstload>)
add_test(NAME GenInfiniteBus COMMAND $<TARGET_FILE:geninfbus> )
add_test(NAME ParameterEst COMMAND $<TARGET_FILE:paramest> ${CMAKE_SOURCE_DIR}/Examples/ParameterEstimation/lookup_table.dat)
endif()
39 changes: 28 additions & 11 deletions ComponentLib/Branch/Branch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* LLNL-CODE-718378.
* All rights reserved.
*
* This file is part of GridKit. For details, see github.com/LLNL/GridKit
* This file is part of GridKit. For details, see github.com/LLNL/GridKit
* Please also read the LICENSE file.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -77,17 +77,28 @@ namespace ModelLib {

template <class ScalarT, typename IdxT>
Branch<ScalarT, IdxT>::Branch(bus_type* bus1, bus_type* bus2)
: gL_( 100.0),
bL_(-100.0),
gL1_(0.0),
bL1_(0.01),
gL2_(0.0),
bL2_(0.01),
: R_(0.0),
X_(0.01),
G_(0.0),
B_(0.0),
bus1_(bus1),
bus2_(bus2)
{
size_ = 0;
}

template <class ScalarT, typename IdxT>
Branch<ScalarT, IdxT>::Branch(real_type R, real_type X, real_type G, real_type B, bus_type* bus1, bus_type* bus2)
: R_(R),
X_(X),
G_(G),
B_(B),
bus1_(bus1),
bus2_(bus2)
{
}


template <class ScalarT, typename IdxT>
Branch<ScalarT, IdxT>::~Branch()
{
Expand Down Expand Up @@ -126,15 +137,21 @@ int Branch<ScalarT, IdxT>::tagDifferentiable()
/**
* \brief Residual contribution of the branch is pushed to the
* two terminal buses.
*
* @todo Add and verify conductance to ground (B and G)
*/
template <class ScalarT, typename IdxT>
int Branch<ScalarT, IdxT>::evaluateResidual()
{
// std::cout << "Evaluating branch residual ...\n";
real_type b = -X_/(R_*R_ + X_*X_);
real_type g = R_/(R_*R_ + X_*X_);
ScalarT dtheta = theta1() - theta2();
P1() += V1()*V1()*(gL_ + gL1_) - V1()*V2()*(gL_*cos(dtheta) + bL_*sin(dtheta));
Q1() += -V1()*V1()*(bL_ + bL1_) - V1()*V2()*(gL_*sin(dtheta) - bL_*cos(dtheta));
P2() += V2()*V2()*(gL_ + gL2_) - V1()*V2()*(gL_*cos(dtheta) - bL_*sin(dtheta));
Q2() += -V2()*V2()*(bL_ + bL2_) + V1()*V2()*(gL_*sin(dtheta) + bL_*cos(dtheta));

P1() -= ( g + 0.5*G_)*V1()*V1() + V1()*V2()*(-g*cos(dtheta) - b*sin(dtheta));
Q1() -= (-b - 0.5*B_)*V1()*V1() + V1()*V2()*(-g*sin(dtheta) + b*cos(dtheta));
P2() -= ( g + 0.5*G_)*V2()*V2() + V1()*V2()*(-g*cos(dtheta) + b*sin(dtheta));
Q2() -= (-b - 0.5*B_)*V2()*V2() + V1()*V2()*( g*sin(dtheta) + b*cos(dtheta));

return 0;
}
Expand Down
40 changes: 17 additions & 23 deletions ComponentLib/Branch/Branch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* LLNL-CODE-718378.
* All rights reserved.
*
* This file is part of GridKit. For details, see github.com/LLNL/GridKit
* This file is part of GridKit. For details, see github.com/LLNL/GridKit
* Please also read the LICENSE file.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -96,6 +96,7 @@ namespace ModelLib

public:
Branch(bus_type* bus1, bus_type* bus2);
Branch(real_type R, real_type X, real_type G, real_type B, bus_type* bus1, bus_type* bus2);
virtual ~Branch();

int allocate();
Expand All @@ -110,35 +111,30 @@ namespace ModelLib
//int evaluateAdjointJacobian();
int evaluateAdjointIntegrand();

public:
void setGl(real_type gL)
void updateTime(real_type t, real_type a)
{
gL_ = gL;
}

void setGl1(real_type gL1)
{
gL1_ = gL1;
}

void setGl2(real_type gL2)
public:
void setR(real_type R)
{
gL2_ = gL2;
R_ = R;
}

void setBl(real_type bL)
void setX(real_type X)
{
bL_ = bL;
// std::cout << "Setting X ...\n";
X_ = X;
}

void setBl1(real_type bL1)
void setG(real_type G)
{
bL1_ = bL1;
G_ = G;
}

void setBl2(real_type bL2)
void setB(real_type B)
{
bL2_ = bL2;
B_ = B;
}

private:
Expand Down Expand Up @@ -183,12 +179,10 @@ namespace ModelLib
}

private:
real_type gL_;
real_type bL_;
real_type gL1_;
real_type bL1_;
real_type gL2_;
real_type bL2_;
real_type R_;
real_type X_;
real_type G_;
real_type B_;
bus_type* bus1_;
bus_type* bus2_;
};
Expand Down
7 changes: 4 additions & 3 deletions ComponentLib/Branch/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# LLNL-CODE-718378.
# All rights reserved.
#
# This file is part of GridKit. For details, see github.com/LLNL/GridKit
# This file is part of GridKit. For details, see github.com/LLNL/GridKit
# Please also read the LICENSE file.
#
# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -55,5 +55,6 @@
# endorsement purposes.
#

add_library(Branch Branch.cpp)
set(component_models ${component_models} Branch PARENT_SCOPE)
add_library(Branch SHARED Branch.cpp)
install(TARGETS Branch LIBRARY DESTINATION lib)
# set(component_models ${component_models} Branch PARENT_SCOPE)
130 changes: 130 additions & 0 deletions ComponentLib/Branch/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# Branch Model

Transmission lines and different types of transformers (traditional, Load Tap-Changing transformers (LTC) and Phase Angle Regulators (PARs)) can be modeled with a common branch model.

## Transmission Line Model

The most common circuit that is used to represent the transmission line model is $`\pi`$ circuit as shown in Figure 1. The nominal flow direction is from sending bus _s_ to receiving bus _r_.

<div align="center">
<img align="center" src="../../Documentation/Figures/TL.jpg">


Figure 1: Transmission line $`\pi`$ equivalent circuit
</div>

Here
``` math
Z'=R+jX
```
and
``` math
Y'=G+jB,
```
where $`R`$ is line series resistance, $`X`$ is line series reactance, $`B`$ is line shunt charging, and $`G`$ is line shunt conductance. As can be seen from Figure 1 total $`B`$ and $`G`$ are separated between two buses.
The current leaving the sending bus can be obtained from Kirchhoff's current law as
```math
I_s = y(V_s - V_r) + \frac{Y'}{2} V_s,
```
where $`V_s`$ and $`V_r`$ are voltages on sending and receiving bus, respectively, and
```math
y = \frac{1}{Z'} = \frac{R}{R^2+X^2} + j\frac{-X}{R^2+X^2} = g + jb.
```
Similarly, current leaving receiving bus is given as
```math
-I_R = y(V_r - V_s) + \frac{Y'}{2} V_r.
```
These equations can be written in a compact form as:
```math
\begin{bmatrix}
I_{s}\\
-I_{r}
\end{bmatrix}
= \mathbf{Y}_{TL}
\begin{bmatrix}
V_{s}\\
V_{r}
\end{bmatrix}
```
where:
```math
\mathbf{Y}_{TL}=\begin{bmatrix}
g + jb + \dfrac{G+jB}{2} & -(g + jb) \\
-(g + jb) & g + jb + \dfrac{G+jB}{2}
\end{bmatrix}
```

### Branch contributions to residuals for sending and receiving bus

Complex power leaving sending and receiving bus is computed as
```math
\begin{bmatrix}
S_{s}\\
S_{r}
\end{bmatrix}
=
\begin{bmatrix}
V_{s}\\
V_{r}
\end{bmatrix}
\begin{bmatrix}
I_{s}\\
-I_{r}
\end{bmatrix}^*
=
\begin{bmatrix}
V_{s}\\
V_{r}
\end{bmatrix}
\mathbf{Y}_{TL}^*
\begin{bmatrix}
V_{s}\\
V_{r}
\end{bmatrix}^*
```
After some algebra, one obtains expressions for active and reactive power that the branch takes from adjacent buses:
```math
P_{s} = \left(g + \frac{G}{2}\right) |V_{s}|^2 + [-g \cos(\theta_s - \theta_r) - b \sin(\theta_s - \theta_r)] |V_{s}| |V_{r}|
```

```math
Q_{s} = -\left(b + \frac{B}{2}\right) |V_{s}|^2 + [-g \sin(\theta_s - \theta_r) + b \cos(\theta_s - \theta_r)] |V_{s}| |V_{r}|
```

```math
P_{r} = \left(g + \frac{G}{2}\right) |V_{r}|^2 + [-g \cos(\theta_s - \theta_r) + b \sin(\theta_s - \theta_r)] |V_{s}| |V_{r}|
```

```math
Q_{r} = -\left(b + \frac{B}{2}\right) |V_{r}|^2 + [ g \sin(\theta_s - \theta_r) + b \cos(\theta_s - \theta_r)] |V_{s}| |V_{r}|
```

These quantities are treated as _loads_ and are substracted from $`P`$ and $`Q`$ residuals computed on the respective buses.

## Branch Model

**Note: Transformer model not yet implemented**

The branch model can be created by adding the ideal transformer in series with the $`\pi`$ circuit as shown in Figure 2 where $`\tau`$ is a tap ratio magnitude and $`\theta_{shift}`$is the phase shift angle.

<div align="center">
<img align="center" src="../../Documentation/Figures/branch.jpg">


Figure 2: Branch equivalent circuit
</div>


The branch admitance matrix is then:

```math
\mathbf{Y}_{BR}=
\begin{bmatrix}
\left(g + jb + \dfrac{G+jB}{2} \right)\dfrac{1}{\tau^2} & -(g + jb)\dfrac{1}{\tau e^{-j\theta_{shift}}}\\
&\\
-(g + jb)\dfrac{1}{\tau e^{j\theta_{shift}}}. & g + jb + \dfrac{G+jB}{2}
\end{bmatrix}
```
### Branch contribution to residuals for sending and receiving bus

The power flow contribution for the transformer model are obtained in a similar manner as for the $`\pi`$-model.
Loading

0 comments on commit 6004c46

Please sign in to comment.