diff --git a/.gitignore b/.gitignore index afc4e6a..139e99d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.kdev4 .directory *.orig +.vscode/ diff --git a/CMakeLists.txt b/CMakeLists.txt index da0ae2b..e20fb4d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 @@ -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 ) @@ -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 $ ) +add_test(NAME Grid3Bus COMMAND $) +if(GRIDKIT_ENABLE_IPOPT) + add_test(NAME DynamicConOpt COMMAND $ ) + add_test(NAME GenConstLoad COMMAND $) + add_test(NAME GenInfiniteBus COMMAND $ ) + add_test(NAME ParameterEst COMMAND $ ${CMAKE_SOURCE_DIR}/Examples/ParameterEstimation/lookup_table.dat) +endif() diff --git a/ComponentLib/Branch/Branch.cpp b/ComponentLib/Branch/Branch.cpp index 5dcc10b..b819724 100644 --- a/ComponentLib/Branch/Branch.cpp +++ b/ComponentLib/Branch/Branch.cpp @@ -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 @@ -77,17 +77,28 @@ namespace ModelLib { template Branch::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 +Branch::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 Branch::~Branch() { @@ -126,15 +137,21 @@ int Branch::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 int Branch::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; } diff --git a/ComponentLib/Branch/Branch.hpp b/ComponentLib/Branch/Branch.hpp index 18458d9..3504ed8 100644 --- a/ComponentLib/Branch/Branch.hpp +++ b/ComponentLib/Branch/Branch.hpp @@ -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 @@ -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(); @@ -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: @@ -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_; }; diff --git a/ComponentLib/Branch/CMakeLists.txt b/ComponentLib/Branch/CMakeLists.txt index 31e171c..ef558f2 100644 --- a/ComponentLib/Branch/CMakeLists.txt +++ b/ComponentLib/Branch/CMakeLists.txt @@ -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 @@ -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) diff --git a/ComponentLib/Branch/README.md b/ComponentLib/Branch/README.md new file mode 100644 index 0000000..ecfc61a --- /dev/null +++ b/ComponentLib/Branch/README.md @@ -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_. + +
+ + + + Figure 1: Transmission line $`\pi`$ equivalent circuit +
+ +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. + +
+ + + + Figure 2: Branch equivalent circuit +
+ + +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. diff --git a/ComponentLib/Bus/BaseBus.hpp b/ComponentLib/Bus/BaseBus.hpp index d3964d8..70b5eb2 100644 --- a/ComponentLib/Bus/BaseBus.hpp +++ b/ComponentLib/Bus/BaseBus.hpp @@ -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 @@ -117,6 +117,7 @@ namespace ModelLib virtual int evaluateAdjointResidual() { return 0;} //virtual int evaluateAdjointJacobian() { return 0;} virtual int evaluateAdjointIntegrand() { return 0;} + virtual void updateTime(real_type, real_type) {} // <- throw exception here // Pure virtual methods specific to Bus types virtual ScalarT& V() = 0; diff --git a/ComponentLib/Bus/BusPQ.cpp b/ComponentLib/Bus/BusPQ.cpp index 7c2a7d3..9f38384 100644 --- a/ComponentLib/Bus/BusPQ.cpp +++ b/ComponentLib/Bus/BusPQ.cpp @@ -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 @@ -106,7 +106,7 @@ BusPQ::BusPQ(ScalarT V, ScalarT theta) template BusPQ::~BusPQ() { - //std::cout << "Destroy Gen2..." << std::endl; + //std::cout << "Destroy PQ bus ..." << std::endl; } /*! @@ -115,7 +115,7 @@ BusPQ::~BusPQ() template int BusPQ::allocate() { - //std::cout << "Allocate Gen2..." << std::endl; + //std::cout << "Allocate PQ bus ..." << std::endl; f_.resize(size_); y_.resize(size_); yp_.resize(size_); @@ -163,9 +163,9 @@ int BusPQ::initialize() template int BusPQ::evaluateResidual() { + // std::cout << "Evaluating residual of a PQ bus ...\n"; f_[0] = 0.0; f_[1] = 0.0; - return 0; } diff --git a/ComponentLib/Bus/BusPQ.hpp b/ComponentLib/Bus/BusPQ.hpp index d9538a9..37fb6e5 100644 --- a/ComponentLib/Bus/BusPQ.hpp +++ b/ComponentLib/Bus/BusPQ.hpp @@ -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 diff --git a/ComponentLib/Bus/BusPV.cpp b/ComponentLib/Bus/BusPV.cpp new file mode 100644 index 0000000..e4a82f5 --- /dev/null +++ b/ComponentLib/Bus/BusPV.cpp @@ -0,0 +1,198 @@ +/* + * + * Copyright (c) 2017, Lawrence Livermore National Security, LLC. + * Produced at the Lawrence Livermore National Laboratory. + * Written by Slaven Peles . + * LLNL-CODE-718378. + * All rights reserved. + * + * 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 + * modification, are permitted provided that the following conditions are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the disclaimer (as noted below) in the + * documentation and/or other materials provided with the distribution. + * - Neither the name of the LLNS/LLNL nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL + * SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISINGIN ANY + * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + * Lawrence Livermore National Laboratory is operated by Lawrence Livermore + * National Security, LLC, for the U.S. Department of Energy, National + * Nuclear Security Administration under Contract DE-AC52-07NA27344. + * + * This document was prepared as an account of work sponsored by an agency + * of the United States government. Neither the United States government nor + * Lawrence Livermore National Security, LLC, nor any of their employees + * makes any warranty, expressed or implied, or assumes any legal liability + * or responsibility for the accuracy, completeness, or usefulness of any + * information, apparatus, product, or process disclosed, or represents that + * its use would not infringe privately owned rights. Reference herein to + * any specific commercial product, process, or service by trade name, + * trademark, manufacturer, or otherwise does not necessarily constitute or + * imply its endorsement, recommendation, or favoring by the United States + * government or Lawrence Livermore National Security, LLC. The views and + * opinions of authors expressed herein do not necessarily state or reflect + * those of the United States government or Lawrence Livermore National + * Security, LLC, and shall not be used for advertising or product + * endorsement purposes. + * + */ + +#include +#include +#include "BusPV.hpp" + +namespace ModelLib { + +/*! + * @brief Constructor for a PV bus + * + * @todo Arguments that should be passed to ModelEvaluatorImpl constructor: + * - Number of equations = 1 (size_) + * - Number of variables = 1 (size_) + * - Number of quadratures = 0 + * - Number of optimization parameters = 0 + */ +template +BusPV::BusPV() + : V_(0.0), theta0_(0.0), Pg_(0.0) +{ + //std::cout << "Create BusPV..." << std::endl; + //std::cout << "Number of equations is " << size_ << std::endl; + + size_ = 1; +} + +/*! + * @brief BusPV constructor. + * + * This constructor sets initial values for voltage and phase angle. + * + * @todo Arguments that should be passed to ModelEvaluatorImpl constructor: + * - Number of equations = 1 (size_) + * - Number of variables = 1 (size_) + * - Number of quadratures = 0 + * - Number of optimization parameters = 0 + */ +template +BusPV::BusPV(ScalarT V, ScalarT theta0, ScalarT Pg) + : V_(V), theta0_(theta0), Pg_(Pg) +{ + //std::cout << "Create BusPV ..." << std::endl; + //std::cout << "Number of equations is " << size_ << std::endl; + + size_ = 1; +} + +template +BusPV::~BusPV() +{ + //std::cout << "Destroy Gen2..." << std::endl; +} + +/*! + * @brief allocate method resizes local solution and residual vectors. + */ +template +int BusPV::allocate() +{ + //std::cout << "Allocate PV bus ..." << std::endl; + f_.resize(size_); + y_.resize(size_); + yp_.resize(size_); + tag_.resize(size_); + + fB_.resize(size_); + yB_.resize(size_); + ypB_.resize(size_); + + return 0; +} + + +template +int BusPV::tagDifferentiable() +{ + tag_[0] = false; + return 0; +} + + +/*! + * @brief initialize method sets bus variables to stored initial values. + */ +template +int BusPV::initialize() +{ + // std::cout << "Initialize BusPV..." << std::endl; + theta() = theta0_; + yp_[0] = 0.0; + + return 0; +} + +/*! + * @brief PV bus does not compute residuals, so here we just reset residual values. + * + * @warning This implementation assumes bus residuals are always evaluated + * _before_ component model residuals. + * + */ +template +int BusPV::evaluateResidual() +{ + // std::cout << "Evaluating residual of a PV bus ...\n"; + P() = Pg_; + Q() = 0.0; + + return 0; +} + + +/*! + * @brief initialize method sets bus variables to stored initial values. + */ +template +int BusPV::initializeAdjoint() +{ + // std::cout << "Initialize BusPV..." << std::endl; + yB_[0] = 0.0; + ypB_[0] = 0.0; + + return 0; +} + +template +int BusPV::evaluateAdjointResidual() +{ + fB_[0] = 0.0; + + return 0; +} + +// Available template instantiations +template class BusPV; +template class BusPV; + + +} // namespace ModelLib + diff --git a/ComponentLib/Bus/BusPV.hpp b/ComponentLib/Bus/BusPV.hpp new file mode 100644 index 0000000..0089be5 --- /dev/null +++ b/ComponentLib/Bus/BusPV.hpp @@ -0,0 +1,206 @@ +/* + * + * Copyright (c) 2017, Lawrence Livermore National Security, LLC. + * Produced at the Lawrence Livermore National Laboratory. + * Written by Slaven Peles . + * LLNL-CODE-718378. + * All rights reserved. + * + * 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 + * modification, are permitted provided that the following conditions are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the disclaimer (as noted below) in the + * documentation and/or other materials provided with the distribution. + * - Neither the name of the LLNS/LLNL nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL + * SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISINGIN ANY + * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + * Lawrence Livermore National Laboratory is operated by Lawrence Livermore + * National Security, LLC, for the U.S. Department of Energy, National + * Nuclear Security Administration under Contract DE-AC52-07NA27344. + * + * This document was prepared as an account of work sponsored by an agency + * of the United States government. Neither the United States government nor + * Lawrence Livermore National Security, LLC, nor any of their employees + * makes any warranty, expressed or implied, or assumes any legal liability + * or responsibility for the accuracy, completeness, or usefulness of any + * information, apparatus, product, or process disclosed, or represents that + * its use would not infringe privately owned rights. Reference herein to + * any specific commercial product, process, or service by trade name, + * trademark, manufacturer, or otherwise does not necessarily constitute or + * imply its endorsement, recommendation, or favoring by the United States + * government or Lawrence Livermore National Security, LLC. The views and + * opinions of authors expressed herein do not necessarily state or reflect + * those of the United States government or Lawrence Livermore National + * Security, LLC, and shall not be used for advertising or product + * endorsement purposes. + * + */ + +#ifndef _BUS_PV_HPP_ +#define _BUS_PV_HPP_ + +#include +#include "BaseBus.hpp" + +namespace ModelLib +{ + /*! + * @brief Implementation of a PV bus. + * + * Voltage _V_ and phase _theta_ are variables in PV bus model. + * Active and reactive power, _P_ and _Q_, are residual components. + * + * + */ + template + class BusPV : public BaseBus + { + using BaseBus::size_; + using BaseBus::y_; + using BaseBus::yp_; + using BaseBus::yB_; + using BaseBus::ypB_; + using BaseBus::f_; + using BaseBus::fB_; + using BaseBus::tag_; + + public: + typedef typename ModelEvaluatorImpl::real_type real_type; + + BusPV(); + BusPV(ScalarT V, ScalarT theta0, ScalarT P); + virtual ~BusPV(); + + virtual int allocate(); + virtual int tagDifferentiable(); + virtual int initialize(); + virtual int evaluateResidual(); + virtual int initializeAdjoint(); + virtual int evaluateAdjointResidual(); + + virtual ScalarT& V() + { + return V_; + } + + virtual const ScalarT& V() const + { + return V_; + } + + virtual ScalarT& theta() + { + return y_[0]; + } + + virtual const ScalarT& theta() const + { + return y_[0]; + } + + virtual ScalarT& P() + { + return f_[0]; + } + + virtual const ScalarT& P() const + { + return f_[0]; + } + + + virtual ScalarT& Q() + { + return Q_; + } + + virtual const ScalarT& Q() const + { + return Q_; + } + + virtual ScalarT& lambdaP() + { + assert(false); + return thetaB_; + } + + virtual const ScalarT& lambdaP() const + { + assert(false); + return thetaB_; + } + + virtual ScalarT& lambdaQ() + { + assert(false); + return VB_; + } + + virtual const ScalarT& lambdaQ() const + { + assert(false); + return VB_; + } + + virtual ScalarT& PB() + { + assert(false); + return PB_; + } + + virtual const ScalarT& PB() const + { + assert(false); + return PB_; + } + + virtual ScalarT& QB() + { + assert(false); + return QB_; + } + + virtual const ScalarT& QB() const + { + assert(false); + return QB_; + } + + private: + ScalarT V_; + ScalarT theta0_; ///< Default initial value for phase + ScalarT Pg_; ///< Generator injection + ScalarT Q_; + + ScalarT VB_; + ScalarT thetaB_; + ScalarT PB_; + ScalarT QB_; + }; + +} // namespace ModelLib + + +#endif // _BUS_PV_HPP_ diff --git a/ComponentLib/Bus/BusSlack.cpp b/ComponentLib/Bus/BusSlack.cpp index b3a371d..ba7070d 100644 --- a/ComponentLib/Bus/BusSlack.cpp +++ b/ComponentLib/Bus/BusSlack.cpp @@ -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 @@ -107,6 +107,7 @@ BusSlack::~BusSlack() template int BusSlack::evaluateResidual() { + // std::cout << "Evaluating residual of a slack bus ...\n"; P() = 0.0; Q() = 0.0; return 0; diff --git a/ComponentLib/Bus/BusSlack.hpp b/ComponentLib/Bus/BusSlack.hpp index 1427287..4a11931 100644 --- a/ComponentLib/Bus/BusSlack.hpp +++ b/ComponentLib/Bus/BusSlack.hpp @@ -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 @@ -138,23 +138,23 @@ namespace ModelLib /// @todo Should slack bus allow changing voltage? virtual ScalarT& lambdaP() { - return VB_; + return thetaB_; } virtual const ScalarT& lambdaP() const { - return VB_; + return thetaB_; } /// @todo Should slack bus allow changing phase? virtual ScalarT& lambdaQ() { - return thetaB_; + return VB_; } virtual const ScalarT& lambdaQ() const { - return thetaB_; + return VB_; } virtual ScalarT& PB() diff --git a/ComponentLib/Bus/CMakeLists.txt b/ComponentLib/Bus/CMakeLists.txt index 4f4c63a..f175797 100644 --- a/ComponentLib/Bus/CMakeLists.txt +++ b/ComponentLib/Bus/CMakeLists.txt @@ -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 @@ -55,5 +55,6 @@ # endorsement purposes. # -add_library(Bus BusSlack.cpp BusPQ.cpp) -set(component_models ${component_models} Bus PARENT_SCOPE) +add_library(Bus SHARED BusSlack.cpp BusPQ.cpp BusPV.cpp) +install(TARGETS Bus LIBRARY DESTINATION lib) +# set(component_models ${component_models} Bus PARENT_SCOPE) diff --git a/ComponentLib/Bus/README.md b/ComponentLib/Bus/README.md new file mode 100644 index 0000000..0e48e51 --- /dev/null +++ b/ComponentLib/Bus/README.md @@ -0,0 +1,49 @@ +# Bus Model + +A bus is a point of interconnection of electrical devices. Each bus $`i`$ has four quantities associated with it: net real power ($`P_{i}`$), net reactive power ($`Q_{i}`$), bus voltage magnitude ($`\vert`$$`V_{i}`$$`\vert`$), and bus voltage angle ($`\theta _{i}`$). +For the power flow, for each bus, two quantities are specified as input data and two variables are unknown. Depending on the available input data, there are three types of buses in the power system model: PQ (load) bus, PV (generator) bus, and a Slack (swing/reference) bus, where the following applies: + +- Load bus - $`P`$ and $`Q`$ are defined +- Generator bus - $`P`$ and $`\vert`$$`V`$$`\vert`$ are defined +- Slack bus - $`\vert`$$`V`$$`\vert`$ and $`\theta`$ are defined + + + +Type of the bus is determined based on the available input data that in return depends on what devices are attached to the bus. + +**PQ Bus** +Most of the buses in the power system are modeled as PQ buses. Those buses do not have voltage control devices such as a generator or switched shunts and are not remotely controlled by any generator. + +**PV Bus** +PV buses have some sort of controllable reactive power resource in order to maintain the voltage magnitude (voltage setpoint). Besides $`P`$ and $`\vert`$$`V`$$`\vert`$ values, $`Q_{Gimax}`$ and $`Q_{Gimin}`$ are part of the input data set as well. During the power flow solution process, PV bus can become PQ bus in the case when generator (or switched shunt) that is regulating the voltage hits the max or min $`Q_{G}`$ limits, thus it cannot longer regulate the voltage. + +**Slack Bus** +For the power system studies, only one bus is designated to be a slack bus per electrical island. The slack bus does not exist in the actual power system but it is required for solving the power flow. The location of the slack bus influences the complexity of the calculations and usually is selected to be a bus with a large dispatchable generator. The slack bus angle is set to reference value or zero degrees and all other bus angles are expressed using the slack bus voltage phasor as their reference. + +**Sign Convention** +There exist two: + +- *Load convention*: current **enters** positive terminal of the circuit element, and if P(Q) is positive that means power is **absorbed**, or if negative then it is **delivered**. +- *Generator convention*: current **leaves** positive terminal of the circuit element, and if P(Q) is positive that means power is **delivered**, or if negative then it is **absorbed**. + + +
+ + + + Figure 1: Sign convention for the power flow at the bus $`i`$ +
+ + + +Using the previously defined sign convention, real and reactive power **delivered** to bus $`i`$ are then defined as follows: + +``` math +P_{i}=P_{Gi}-P_{Li} +``` +``` math +Q_{i}=Q_{Gi}-Q_{Li} +``` + +**Other Parameters** +Buses are uniquely defined by their ID (number or name). Besides, each bus should have associated Nominal Voltage value. \ No newline at end of file diff --git a/ComponentLib/CMakeLists.txt b/ComponentLib/CMakeLists.txt index 693e76f..d7e33f4 100644 --- a/ComponentLib/CMakeLists.txt +++ b/ComponentLib/CMakeLists.txt @@ -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 @@ -60,5 +60,7 @@ add_subdirectory(Bus) add_subdirectory(Generator2) add_subdirectory(Generator4) add_subdirectory(Generator4Governor) +add_subdirectory(Generator4Param) add_subdirectory(Load) +add_subdirectory(MiniGrid) set(component_models ${component_models} PARENT_SCOPE) diff --git a/ComponentLib/Exciter/README.md b/ComponentLib/Exciter/README.md new file mode 100644 index 0000000..e32003d --- /dev/null +++ b/ComponentLib/Exciter/README.md @@ -0,0 +1,111 @@ +# **Exciter** + + +**Note: Exciter model not yet implemented** + +
+ + + + Figure 1: Exciter EXDC1 model. Fifure courtesy of [PoweWorld](https://www.powerworld.com/WebHelp/). +
+ +## Nomenclature + +### Inputs +- $`V_{REF}`$ - voltage reference set point +- $`E_{C}`$ - output from the terminal voltage transducer +- $`V_{S}`$ - power system stabilizer output signal (if present) +- $`V_{UEL}`$ and $`V_{OEL}`$ - limiters + +### States +- $`V_{t}`$ - terminal voltage (2 is sensed $`V_{t}`$) +- $`V_{B}`$ - input to a voltage regulator (3) +- $`V_{R}`$ - voltage regulator output also know as exciter field voltage (4) +- $`V_{F}`$ - stabilizing feedback signal (5) +### Parameters +- $`T_{R}`$ - filter time constant, sec (0) +- $`K_{A}`$ - voltage regulator gain (40) +- $`T_{A}`$ - time constant, sec (0.1) +- $`T_{B}`$ - lag time constant, sec (0) +- $`T_{C}`$ - lead time constant, sec (0) +- $`V_{RMAX}`$ - maximum control element output, pu (1) +- $`V_{RMIN}`$ - minimum control element output, pu (-1) +- $`K_{E}`$ - exciter field resistance line slope margine, pu (0.1) +- $`T_{E}`$ - exciter time constant, sec (0.5) +- $`K_{F}`$ - rate feedback gain, pu (0.05) +- $`T_{F1}`$ - rate feedback time constant, sec (0.7) +- $`E1`$ - field voltage value, 1 (2.8) +- $`SE1`$ - saturation factor at E1, (3.7) +- $`E2`$ - field voltage value, 2 (3.7) +- $`SE2`$ - saturation factor at E2, (0.33) + +## Equations +First block +```math +\dfrac{dV_{t}}{dt}=\dfrac{1}{T_{R}}(E_{C}-V_{t}) +``` +Second block +```math +\dfrac{dx_{1}}{dt}=\dfrac{1}{T_{B}}((V_{REF}-V_{t}-V_{F}+V_{S}+V_{UEL}+V_{OEL})-V_{B}) +``` +```math +V_{B}=x_{1}+\dfrac{T_{C}}{T_{B}}(V_{REF}-V_{t}-V_{F}+V_{S}+V_{UEL}+V_{OEL}) +``` +Third block +```math +\dfrac{dV_{R}}{dt} = \begin{cases} + \dfrac{1}{T_{A}}(K_{A}V_{B}-V_{R}) &\text{if } V_{RMIN}<=V_{R}<= V_{RMAX}\\ + 0 &\text{if } V_{B}>0 \text{ and } V_{R}>=V_{RMAX} &\text{ also then } V_{R}=V_{RMAX}\\ + 0 &\text{if } V_{B}<0 \text{ and } V_{R}<=V_{RMIN} &\text{ also then } V_{R}=V_{RMIN}\\ +\end{cases} +``` +Fourth block +```math +\dfrac{d\dfrac{E_{FD}}{\omega}}{dt}=\dfrac{1}{T_{E}}(V_{R}-\dfrac{(K_{E}+S_{E})E_{FD}}{\omega}) +``` +Feedback loop +```math +\dfrac{dx_{2}}{dt}=-\dfrac{V_{F}}{T_{F1}} +``` +```math +V_{F}=x_{2}+\dfrac{K_{F}}{T_{F1}}\dfrac{E_{FD}}{\omega} +``` +Saturation is modeled using an alternative quadratic function, with the value of Se specified at two points : +```math +Sat(x) = \begin{cases} + \dfrac{B(x-A)^2}{x} &\text{if } x>A \\ + 0 &\text{if } x<=A +\end{cases} +``` +same as with the synchronous machines. There are two solutions, and one where $`A<1`$ should be chosen. + +## Initialization +```math +V_{t}=V_{t_{0}} +``` +```math +E_{C}=V_{t_{0}} +``` +```math +(V_{REF}-V_{t}-V_{F}+V_{S}+V_{UEL}+V_{OEL})=V_{B} +``` +```math +V_{R}=V{R_{0}} +``` +```math +V_{B}=\dfrac{V{R_{0}}}{K_{A}} +``` +```math +\dfrac{E_{FD}}{\omega}=\dfrac{E_{FD_{0}}}{\omega} +``` +```math +V_{R}-\dfrac{(K_{E}+S_{E})E_{FD}}{\omega}=0 +``` +```math +V_{F}=0 +``` +```math +x_{2_{0}}=-\dfrac{K_{F}}{T_{F1}}\dfrac{E_{FD}}{\omega} + + diff --git a/ComponentLib/Generator2/CMakeLists.txt b/ComponentLib/Generator2/CMakeLists.txt index a842c2b..49b643a 100644 --- a/ComponentLib/Generator2/CMakeLists.txt +++ b/ComponentLib/Generator2/CMakeLists.txt @@ -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 @@ -55,5 +55,6 @@ # endorsement purposes. # -add_library(Generator2 Generator2.cpp) -set(component_models ${component_models} Generator2 PARENT_SCOPE) +add_library(Generator2 SHARED Generator2.cpp) +install(TARGETS Generator2 LIBRARY DESTINATION lib) +# set(component_models ${component_models} Generator2 PARENT_SCOPE) diff --git a/ComponentLib/Generator2/Generator2.cpp b/ComponentLib/Generator2/Generator2.cpp index d8df171..1324759 100644 --- a/ComponentLib/Generator2/Generator2.cpp +++ b/ComponentLib/Generator2/Generator2.cpp @@ -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 diff --git a/ComponentLib/Generator2/Generator2.hpp b/ComponentLib/Generator2/Generator2.hpp index 309d510..3604ce3 100644 --- a/ComponentLib/Generator2/Generator2.hpp +++ b/ComponentLib/Generator2/Generator2.hpp @@ -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 @@ -109,6 +109,12 @@ namespace ModelLib //int evaluateAdjointJacobian(); int evaluateAdjointIntegrand(); + void updateTime(real_type t, real_type a) + { + time_ = t; + alpha_ = a; + } + const ScalarT& V() const { return bus_->V(); diff --git a/ComponentLib/Generator4/CMakeLists.txt b/ComponentLib/Generator4/CMakeLists.txt index 3eec5c8..b56bd64 100644 --- a/ComponentLib/Generator4/CMakeLists.txt +++ b/ComponentLib/Generator4/CMakeLists.txt @@ -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 @@ -55,5 +55,6 @@ # endorsement purposes. # -add_library(Generator4 Generator4.cpp) -set(component_models ${component_models} Generator4 PARENT_SCOPE) +add_library(Generator4 SHARED Generator4.cpp) +install(TARGETS Generator4 LIBRARY DESTINATION lib) +# set(component_models ${component_models} Generator4 PARENT_SCOPE) diff --git a/ComponentLib/Generator4/Generator4.cpp b/ComponentLib/Generator4/Generator4.cpp index 0b791a8..f6a70e7 100644 --- a/ComponentLib/Generator4/Generator4.cpp +++ b/ComponentLib/Generator4/Generator4.cpp @@ -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 diff --git a/ComponentLib/Generator4/Generator4.hpp b/ComponentLib/Generator4/Generator4.hpp index 7ef9fb1..ff4333e 100644 --- a/ComponentLib/Generator4/Generator4.hpp +++ b/ComponentLib/Generator4/Generator4.hpp @@ -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 @@ -112,6 +112,12 @@ namespace ModelLib //int evaluateAdjointJacobian(); int evaluateAdjointIntegrand(); + void updateTime(real_type t, real_type a) + { + time_ = t; + alpha_ = a; + } + // Inline accesor functions ScalarT& V() { diff --git a/ComponentLib/Generator4Governor/CMakeLists.txt b/ComponentLib/Generator4Governor/CMakeLists.txt index 9d5567a..6fddb19 100644 --- a/ComponentLib/Generator4Governor/CMakeLists.txt +++ b/ComponentLib/Generator4Governor/CMakeLists.txt @@ -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 @@ -55,5 +55,6 @@ # endorsement purposes. # -add_library(Generator4Governor Generator4Governor.cpp) -set(component_models ${component_models} Generator4Governor PARENT_SCOPE) +add_library(Generator4Governor SHARED Generator4Governor.cpp) +install(TARGETS Generator4Governor LIBRARY DESTINATION lib) +# set(component_models ${component_models} Generator4Governor PARENT_SCOPE) diff --git a/ComponentLib/Generator4Governor/Generator4Governor.cpp b/ComponentLib/Generator4Governor/Generator4Governor.cpp index 6274fc6..0bd2fc1 100644 --- a/ComponentLib/Generator4Governor/Generator4Governor.cpp +++ b/ComponentLib/Generator4Governor/Generator4Governor.cpp @@ -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 diff --git a/ComponentLib/Generator4Governor/Generator4Governor.hpp b/ComponentLib/Generator4Governor/Generator4Governor.hpp index 2c2d820..c8fd2c4 100644 --- a/ComponentLib/Generator4Governor/Generator4Governor.hpp +++ b/ComponentLib/Generator4Governor/Generator4Governor.hpp @@ -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 @@ -113,6 +113,12 @@ namespace ModelLib //int evaluateAdjointJacobian(); int evaluateAdjointIntegrand(); + void updateTime(real_type t, real_type a) + { + time_ = t; + alpha_ = a; + } + private: // // Private model methods diff --git a/ComponentLib/Generator4Param/CMakeLists.txt b/ComponentLib/Generator4Param/CMakeLists.txt new file mode 100644 index 0000000..2544c7f --- /dev/null +++ b/ComponentLib/Generator4Param/CMakeLists.txt @@ -0,0 +1,60 @@ +# +# Copyright (c) 2017, Lawrence Livermore National Security, LLC. +# Produced at the Lawrence Livermore National Laboratory. +# Written by Slaven Peles . +# LLNL-CODE-718378. +# All rights reserved. +# +# 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 +# modification, are permitted provided that the following conditions are met: +# - Redistributions of source code must retain the above copyright notice, +# this list of conditions and the disclaimer below. +# - Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the disclaimer (as noted below) in the +# documentation and/or other materials provided with the distribution. +# - Neither the name of the LLNS/LLNL nor the names of its contributors may +# be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL +# SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, +# OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISINGIN ANY +# WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +# THE POSSIBILITY OF SUCH DAMAGE. +# +# Lawrence Livermore National Laboratory is operated by Lawrence Livermore +# National Security, LLC, for the U.S. Department of Energy, National +# Nuclear Security Administration under Contract DE-AC52-07NA27344. +# +# This document was prepared as an account of work sponsored by an agency +# of the United States government. Neither the United States government nor +# Lawrence Livermore National Security, LLC, nor any of their employees +# makes any warranty, expressed or implied, or assumes any legal liability +# or responsibility for the accuracy, completeness, or usefulness of any +# information, apparatus, product, or process disclosed, or represents that +# its use would not infringe privately owned rights. Reference herein to +# any specific commercial product, process, or service by trade name, +# trademark, manufacturer, or otherwise does not necessarily constitute or +# imply its endorsement, recommendation, or favoring by the United States +# government or Lawrence Livermore National Security, LLC. The views and +# opinions of authors expressed herein do not necessarily state or reflect +# those of the United States government or Lawrence Livermore National +# Security, LLC, and shall not be used for advertising or product +# endorsement purposes. +# + +add_library(Generator4Param Generator4Param.cpp) +install(TARGETS Generator4Param LIBRARY DESTINATION lib) +# set(component_models ${component_models} Generator4Param PARENT_SCOPE) diff --git a/ComponentLib/Generator4Param/Generator4Param.cpp b/ComponentLib/Generator4Param/Generator4Param.cpp new file mode 100644 index 0000000..36e3c19 --- /dev/null +++ b/ComponentLib/Generator4Param/Generator4Param.cpp @@ -0,0 +1,475 @@ +/* + * + * Copyright (c) 2017, Lawrence Livermore National Security, LLC. + * Produced at the Lawrence Livermore National Laboratory. + * Written by Slaven Peles . + * LLNL-CODE-718378. + * All rights reserved. + * + * 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 + * modification, are permitted provided that the following conditions are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the disclaimer (as noted below) in the + * documentation and/or other materials provided with the distribution. + * - Neither the name of the LLNS/LLNL nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL + * SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISINGIN ANY + * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + * Lawrence Livermore National Laboratory is operated by Lawrence Livermore + * National Security, LLC, for the U.S. Department of Energy, National + * Nuclear Security Administration under Contract DE-AC52-07NA27344. + * + * This document was prepared as an account of work sponsored by an agency + * of the United States government. Neither the United States government nor + * Lawrence Livermore National Security, LLC, nor any of their employees + * makes any warranty, expressed or implied, or assumes any legal liability + * or responsibility for the accuracy, completeness, or usefulness of any + * information, apparatus, product, or process disclosed, or represents that + * its use would not infringe privately owned rights. Reference herein to + * any specific commercial product, process, or service by trade name, + * trademark, manufacturer, or otherwise does not necessarily constitute or + * imply its endorsement, recommendation, or favoring by the United States + * government or Lawrence Livermore National Security, LLC. The views and + * opinions of authors expressed herein do not necessarily state or reflect + * those of the United States government or Lawrence Livermore National + * Security, LLC, and shall not be used for advertising or product + * endorsement purposes. + * + */ + + +#include +#include +#include +#include "Generator4Param.hpp" + +namespace ModelLib { + +/*! + * @brief Constructor for a simple generator model + * + * Arguments passed to ModelEvaluatorImpl: + * - Number of equations = 4 differential + 2 algebraic = 6 + * - Number of quadratures = 1 + * - Number of optimization parameters = 1 + */ +template +Generator4Param::Generator4Param(bus_type* bus, ScalarT P0, ScalarT Q0) + : ModelEvaluatorImpl(6, 1, 1), + H_(5.0), + D_(0.04), + Xq_(0.85), + Xd_(1.05), + Xqp_(0.35), + Xdp_(0.35), + Rs_(0.01), + Tq0p_(1.0), // [s] + Td0p_(8.0), // [s] + Ef_(1.45), + Pm_(1.0), + omega_s_(1.0), + omega_b_(2.0*60.0*M_PI), + P0_(P0), + Q0_(Q0), + bus_(bus) +{ +} + +template +Generator4Param::~Generator4Param() +{ +} + +/*! + * @brief This function will be used to allocate sparse Jacobian matrices. + * + */ +template +int Generator4Param::allocate() +{ + //std::cout << "Allocate Generator4Param..." << std::endl; + tag_.resize(size_); + + return 0; +} + +/** + * @brief Initialization of the generator model + * + * Initialization equations are derived from example 9.2 in Power System + * Modeling and Scripting, Federico Milano, Chapter 9, p. 225: + * \f{eqnarray*}{ + * &~& \omega_0 = 0, \\ + * &~& \delta_0 = \tan^{-1} \left(\frac{X_q P_0 - R_s Q_0}{V_0^2 + R_s P_0 + X_q Q_0} \right) + \theta_0, \\ + * &~& \phi_0 = \delta_0 - \theta_0 + \tan^{-1} \left( \frac{Q_0}{P_0} \right), \\ + * &~& I_{d0} = \frac{\sqrt{P_0^2 + Q_0^2}}{V_0} \sin(\phi_0), \\ + * &~& I_{q0} = \frac{\sqrt{P_0^2 + Q_0^2}}{V_0} \cos(\phi_0), \\ + * &~& E_{d0}' = V_0 \sin(\delta_0 - \theta_0) + R_s I_{d0} - X_q' I_{q0}, \\ + * &~& E_{q0}' = V_0 \cos(\delta_0 - \theta_0) + R_s I_{q0} + X_d' I_{d0} + * \f} + * + * The input from exciter and governor is set to the steady state value: + * \f{eqnarray*}{ + * &~& E_{f0} = E_{q0}' + (X_d - X_d') I_{d0}, \\ + * &~& P_{m0} = E_{d0}' I_{d0} + E_{q0}' I_{q0} + ( X_q' - X_d') I_{d0} I_{q0} + * \f} + * + */ +template +int Generator4Param::initialize() +{ + // std::cout << "Initialize Generator4Param..." << std::endl; + + // Compute initial guess for the generator voltage phase + const ScalarT delta = atan((Xq_*P0_ - Rs_*Q0_) / (V()*V() + Rs_*P0_ + Xq_*Q0_)) + theta(); + + // Compute initial guess for the generator current phase + const ScalarT phi = theta() - delta - atan(Q0_/P0_); + + // Compute initial gueses for generator currents and potentials in d-q frame + const ScalarT Id = std::sqrt(P0_*P0_ + Q0_*Q0_)/V() * sin(phi); + const ScalarT Iq = std::sqrt(P0_*P0_ + Q0_*Q0_)/V() * cos(phi); + const ScalarT Ed = V()*sin(theta() - delta) + Rs_*Id + Xqp_*Iq; + const ScalarT Eq = V()*cos(theta() - delta) + Rs_*Iq - Xdp_*Id; + + y_[0] = delta; + y_[1] = omega_s_; + y_[2] = Ed; + y_[3] = Eq; + y_[4] = Id; + y_[5] = Iq; + yp_[0] = 0.0; + yp_[1] = 0.0; + yp_[2] = 0.0; + yp_[3] = 0.0; + yp_[4] = 0.0; + yp_[5] = 0.0; + + // Set control parameter values here. + Ef_ = Eq - (Xd_ - Xdp_)*Id; // <~ set to steady state value + Pm_ = Ed*Id + Eq*Iq + (Xdp_ - Xqp_)*Id*Iq; // <~ set to steady state value + + // Initialize optimization parameters + param_[0] = H_; + param_up_[0] = 10.0; + param_lo_[0] = 2.0; + + // param_[0] = Pm_; + // param_up_[0] = 1.5; + // param_lo_[0] = 0.0; + + // param_[1] = Ef_; + // param_up_[1] = 1.7; + // param_lo_[1] = 0.0; + + return 0; +} + +/** + * \brief Identify differential variables. + */ +template +int Generator4Param::tagDifferentiable() +{ + tag_[0] = true; + tag_[1] = true; + tag_[2] = true; + tag_[3] = true; + + for (IdxT i=4; i < size_; ++i) + { + tag_[i] = false; + } + + return 0; +} + +/** + * @brief Computes residual vector for the generator model. + * + * Residual equations are given per model in Power System Modeling and + * Scripting, Federico Milano, Chapter 15, p. 334: + * \f{eqnarray*}{ + * f_0: &~& \dot{\delta} -\omega_b (\omega - \omega_s), \\ + * f_1: &~& 2H/\omega_s \dot{\omega} - L_m(P_m) + E_q' I_q + E_d' I_d + (X_q' - X_d')I_d I_q + D (\omega - \omega_s), \\ + * f_2: &~& T_{q0}' \dot{E}_d' + E_d' - (X_q - X_q')I_q, \\ + * f_3: &~& T_{d0}' \dot{E}_q' + E_q' + (X_d - X_d')I_d - E_f, \\ + * f_4: &~& R_s I_d - X_q' I_q + V \sin(\delta - \theta) - E_d', \\ + * f_5: &~& R_s I_q + X_d' I_d + V \cos(\delta - \theta) - E_q', + * \f} + * where \f$ \Omega_b \f$ is the synchronous frequency in [rad/s], and + * overdot denotes time derivative. + * + * Generator injection active and reactive power are + * \f{eqnarray*}{ + * P_g &=& E_d' I_d + E_q' I_q + (X_q' - X_d') I_d I_q - R_s (I_d^2 + I_q^2), \\ + * Q_q &=& E_q' I_d - E_d' I_q - X_q' I_q^2 - X_d' I_d^2, \\ + * \f} + * respectively. + * + * State variables are: + * \f$ y_0 = \omega \f$, \f$ y_1 = \delta \f$, \f$ y_2 = E_d' \f$, \f$ y_3 = E_q' \f$, + * \f$ y_4 = I_d \f$, \f$ y_5 = I_q \f$. + * + */ +template +int Generator4Param::evaluateResidual() +{ + // std::cout << "Evaluate residual for Generator4Param..." << std::endl; + f_[0] = dotDelta() - omega_b_* (omega() - omega_s_); + f_[1] = (2.0*H())/omega_s_*dotOmega() - Pm() + Eqp()*Iq() + Edp()*Id() + (- Xdp_ + Xqp_)*Id()*Iq() + D_*(omega() - omega_s_); + f_[2] = Tq0p_*dotEdp() + Edp() - (Xq_ - Xqp_)*Iq(); + f_[3] = Td0p_*dotEqp() + Eqp() + (Xd_ - Xdp_)*Id() - Ef(); + f_[4] = Rs_*Id() - Xqp_*Iq() + V()*sin(delta() - theta()) - Edp(); + f_[5] = Xdp_*Id() + Rs_*Iq() + V()*cos(delta() - theta()) - Eqp(); + + // Compute active and reactive load provided by the infinite bus. + P() += Pg(); + Q() += Qg(); + + //std::cout << "Residual: t = " << time_ << std::endl; + + return 0; +} + +template +int Generator4Param::evaluateJacobian() +{ + std::cerr << "Evaluate Jacobian for Generator4Param..." << std::endl; + std::cerr << "Jacobian evaluation not implemented!" << std::endl; + return 0; +} + +template +int Generator4Param::evaluateIntegrand() +{ + // std::cout << "Evaluate Integrand for Generator4Param..." << std::endl; + g_[0] = trajectoryPenalty(time_); + return 0; +} + +template +int Generator4Param::initializeAdjoint() +{ + //std::cout << "Initialize adjoint for Generator4Param..." << std::endl; + for (IdxT i=0; i +int Generator4Param::evaluateAdjointResidual() +{ + // std::cout << "Evaluate adjoint residual for Generator4Param..." << std::endl; + ScalarT sinPhi = sin(delta() - theta()); + ScalarT cosPhi = cos(delta() - theta()); + + // Generator adjoint + fB_[0] = ypB_[0] - yB_[4]*V()*cosPhi + yB_[5]*V()*sinPhi; + fB_[1] = 2.0*H()/omega_s_*ypB_[1] + yB_[0]*omega_b_ - yB_[1]*D_; //+ frequencyPenaltyDer(omega()); + fB_[2] = Tq0p_*ypB_[2] - yB_[1]*Id() - yB_[2] + yB_[4] + trajectoryPenaltyDerEdp(time_); + fB_[3] = Td0p_*ypB_[3] - yB_[1]*Iq() - yB_[3] + yB_[5] + trajectoryPenaltyDerEqp(time_); + fB_[4] = -yB_[1]*(Edp() + (Xqp_ - Xdp_)*Iq()) - yB_[3]*(Xd_ - Xdp_) - yB_[4]*Rs_ - yB_[5]*Xdp_; + fB_[5] = -yB_[1]*(Eqp() + (Xqp_ - Xdp_)*Id()) + yB_[2]*(Xq_ - Xqp_) + yB_[4]*Xqp_ - yB_[5]*Rs_; + + return 0; +} + +// template +// int Generator4Param::evaluateAdjointJacobian() +// { +// std::cout << "Evaluate adjoint Jacobian for Generator4Param..." << std::endl; +// std::cout << "Adjoint Jacobian evaluation not implemented!" << std::endl; +// return 0; +// } + +template +int Generator4Param::evaluateAdjointIntegrand() +{ + // std::cout << "Evaluate adjoint Integrand for Generator4Param..." << std::endl; + gB_[0] = -2.0*yB_[1]*dotOmega()/omega_s_; + + return 0; +} + + +// +// Private functions +// + +/** + * Generator active power Pg. + * + * \f[ P_g = E_q' I_q + E_d' I_d + (X_q' - X_d') I_q I_d - R_a (I_d^2 + I_q^2) \f] + * + */ +template +ScalarT Generator4Param::Pg() +{ + return y_[5]*V()*cos(theta() - y_[0]) + y_[4]*V()*sin(theta() - y_[0]); +} + +/** + * Generator reactive power Qg. + * + * \f[ Q_g = E_q' I_d - E_d' I_q - X_d' I_d^2 - X_q' I_q^2 \f] + */ +template +ScalarT Generator4Param::Qg() +{ + return y_[5]*V()*sin(theta() - y_[0]) - y_[4]*V()*cos(theta() - y_[0]); +} + +/** + * @brief Difference between computed system state and look-up table value. + * + * @todo Look-up table should probably live outside the generator model. + */ +template +ScalarT Generator4Param::trajectoryPenalty(ScalarT t) const +{ + size_t N = table_.size(); + double ti = table_[0][0]; + double tf = table_[N-1][0]; + double dt = (tf - ti)/(N-1); + int n = std::trunc(t/tf*(N-1.0)); + + double Edp_est = 0.0; + double Eqp_est = 0.0; + + if(t >= ti && t < tf) + { + // Interpolate from look-up table + Edp_est = (table_[n+1][3] - table_[n][3])/(table_[n+1][0] - table_[n][0]) * (t - table_[n][0]) + table_[n][3]; + Eqp_est = (table_[n+1][4] - table_[n][4])/(table_[n+1][0] - table_[n][0]) * (t - table_[n][0]) + table_[n][4]; + } + else + { + if(tf <= t && t < tf + dt) + { + // Extrapolate from look-up table + Edp_est = (table_[n][3] - table_[n-1][3])/(table_[n][0] - table_[n-1][0]) * (t - table_[n-1][0]) + table_[n-1][3]; + Eqp_est = (table_[n][4] - table_[n-1][4])/(table_[n][0] - table_[n-1][0]) * (t - table_[n-1][0]) + table_[n-1][4]; + } + else + { + // Too far away to extrapolate + std::cerr << "Trajectory penalty: Out of time bounds at time " << t << "\n"; + return -1.0; + } + } + double d = (Edp() - Edp_est); + double q = (Eqp() - Eqp_est); + return (d*d + q*q); +} + +template +ScalarT Generator4Param::trajectoryPenaltyDerEdp(ScalarT t) const +{ + size_t N = table_.size(); + double ti = table_[0][0]; + double tf = table_[N-1][0]; + double dt = (tf - ti)/(N-1); + int n = std::trunc(t/tf*(N-1.0)); + double Edp_est = 0.0; + + if(t >= ti && t < tf) + { + Edp_est = (table_[n+1][3] - table_[n][3])/(table_[n+1][0] - table_[n][0]) * (t - table_[n][0]) + table_[n][3]; + } + else + { + if(tf <= t && t < tf + dt) + { + Edp_est = (table_[n][3] - table_[n-1][3])/(table_[n][0] - table_[n-1][0]) * (t - table_[n-1][0]) + table_[n-1][3]; + } + else + { + std::cerr << "Trajectory penalty: Out of time bounds at time " << t << "\n"; + return -1.0; + } + } + double d = (Edp() - Edp_est); + + return 2.0*d; +} + +template +ScalarT Generator4Param::trajectoryPenaltyDerEqp(ScalarT t) const +{ + size_t N = table_.size(); + double ti = table_[0][0]; + double tf = table_[N-1][0]; + double dt = (tf - ti)/(N-1); + int n = std::trunc(t/tf*(N-1.0)); + double Eqp_est = 0.0; + + if(t >= ti && t < tf) + { + Eqp_est = (table_[n+1][4] - table_[n][4])/(table_[n+1][0] - table_[n][0]) * (t - table_[n][0]) + table_[n][4]; + } + else + { + if(tf <= t && t < tf + dt) + { + Eqp_est = (table_[n][4] - table_[n-1][4])/(table_[n][0] - table_[n-1][0]) * (t - table_[n-1][0]) + table_[n-1][4]; + } + else + { + std::cerr << "Trajectory penalty: Out of time bounds at time " << t << "\n"; + return -1.0; + } + } + double q = (Eqp() - Eqp_est); + + return 2.0*q; +} + +template class Generator4Param; +template class Generator4Param; + + +} // namespace ModelLib + diff --git a/ComponentLib/Generator4Param/Generator4Param.hpp b/ComponentLib/Generator4Param/Generator4Param.hpp new file mode 100644 index 0000000..ea8774b --- /dev/null +++ b/ComponentLib/Generator4Param/Generator4Param.hpp @@ -0,0 +1,279 @@ +/* + * + * Copyright (c) 2017, Lawrence Livermore National Security, LLC. + * Produced at the Lawrence Livermore National Laboratory. + * Written by Slaven Peles . + * LLNL-CODE-718378. + * All rights reserved. + * + * 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 + * modification, are permitted provided that the following conditions are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the disclaimer (as noted below) in the + * documentation and/or other materials provided with the distribution. + * - Neither the name of the LLNS/LLNL nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL + * SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISINGIN ANY + * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + * Lawrence Livermore National Laboratory is operated by Lawrence Livermore + * National Security, LLC, for the U.S. Department of Energy, National + * Nuclear Security Administration under Contract DE-AC52-07NA27344. + * + * This document was prepared as an account of work sponsored by an agency + * of the United States government. Neither the United States government nor + * Lawrence Livermore National Security, LLC, nor any of their employees + * makes any warranty, expressed or implied, or assumes any legal liability + * or responsibility for the accuracy, completeness, or usefulness of any + * information, apparatus, product, or process disclosed, or represents that + * its use would not infringe privately owned rights. Reference herein to + * any specific commercial product, process, or service by trade name, + * trademark, manufacturer, or otherwise does not necessarily constitute or + * imply its endorsement, recommendation, or favoring by the United States + * government or Lawrence Livermore National Security, LLC. The views and + * opinions of authors expressed herein do not necessarily state or reflect + * those of the United States government or Lawrence Livermore National + * Security, LLC, and shall not be used for advertising or product + * endorsement purposes. + * + */ + +#ifndef _GENERATOR_4_H_ +#define _GENERATOR_4_H_ + +#include + +namespace ModelLib +{ + template class BaseBus; +} + +namespace ModelLib +{ + /*! + * @brief Implementation of a fourth order generator model. + * + */ + template + class Generator4Param : public ModelEvaluatorImpl + { + using ModelEvaluatorImpl::size_; + using ModelEvaluatorImpl::nnz_; + using ModelEvaluatorImpl::time_; + using ModelEvaluatorImpl::alpha_; + using ModelEvaluatorImpl::y_; + using ModelEvaluatorImpl::yp_; + using ModelEvaluatorImpl::tag_; + using ModelEvaluatorImpl::f_; + using ModelEvaluatorImpl::g_; + using ModelEvaluatorImpl::yB_; + using ModelEvaluatorImpl::ypB_; + using ModelEvaluatorImpl::fB_; + using ModelEvaluatorImpl::gB_; + using ModelEvaluatorImpl::param_; + using ModelEvaluatorImpl::param_up_; + using ModelEvaluatorImpl::param_lo_; + + typedef typename ModelEvaluatorImpl::real_type real_type; + typedef BaseBus bus_type; + + public: + Generator4Param(BaseBus* bus, ScalarT P0 = 1.0, ScalarT Q0 = 0.0); + virtual ~Generator4Param(); + + int allocate(); + int initialize(); + int tagDifferentiable(); + int evaluateResidual(); + int evaluateJacobian(); + int evaluateIntegrand(); + + int initializeAdjoint(); + int evaluateAdjointResidual(); + //int evaluateAdjointJacobian(); + int evaluateAdjointIntegrand(); + + void updateTime(real_type t, real_type a) + { + time_ = t; + alpha_ = a; + } + + // Inline accesor functions + ScalarT& V() + { + return bus_->V(); + } + + const ScalarT& V() const + { + return bus_->V(); + } + + ScalarT& theta() + { + return bus_->theta(); + } + + const ScalarT& theta() const + { + return bus_->theta(); + } + + ScalarT& P() + { + return bus_->P(); + } + + const ScalarT& P() const + { + return bus_->P(); + } + + ScalarT& Q() + { + return bus_->Q(); + } + + const ScalarT& Q() const + { + return bus_->Q(); + } + + ScalarT trajectoryPenalty(ScalarT t) const; + ScalarT trajectoryPenaltyDerEqp(ScalarT t) const; + ScalarT trajectoryPenaltyDerEdp(ScalarT t) const; + + std::vector>& getLookupTable() + { + return table_; + } + + std::vector> const& getLookupTable() const + { + return table_; + } + + private: + const ScalarT& H() const + { + return param_[0]; + } + + const ScalarT& Pm() const + { + return Pm_; + // return param_[0]; + } + + const ScalarT& Ef() const + { + return Ef_; + // return param_[1]; + } + + ScalarT Pg(); + ScalarT Qg(); + + private: + // + // Private inlined accessor methods + // + + const ScalarT dotDelta() const + { + return yp_[0]; + } + + const ScalarT dotOmega() const + { + return yp_[1]; + } + + const ScalarT dotEdp() const + { + return yp_[2]; + } + + const ScalarT dotEqp() const + { + return yp_[3]; + } + + const ScalarT delta() const + { + return y_[0]; + } + + const ScalarT omega() const + { + return y_[1]; + } + + const ScalarT Edp() const + { + return y_[2]; + } + + const ScalarT Eqp() const + { + return y_[3]; + } + + const ScalarT Id() const + { + return y_[4]; + } + + const ScalarT Iq() const + { + return y_[5]; + } + + private: + real_type H_; ///< Inertia constant [s] + real_type D_; ///< Damping constant [pu] + real_type Xq_; ///< q-axis synchronous reactance [pu] + real_type Xd_; ///< d-axis synchronous reactance [pu] + real_type Xqp_; ///< q-axis transient reactance [pu] + real_type Xdp_; ///< d-axis transient reactance [pu] + real_type Rs_; ///< stator armature resistance [pu] + real_type Tq0p_; ///< q-axis open circuit transient time constant [s] + real_type Td0p_; ///< d-axis open circuit transient time constant [s] + real_type Ef_; + real_type Pm_; + real_type omega_s_; + real_type omega_b_; + + ScalarT P0_; + ScalarT Q0_; + + bus_type* bus_; + + /// Look-up table data. @todo This should be part of a separate model. + std::vector> table_; + }; + +} // namespace ModelLib + + +#endif // _GENERATOR_4_H_ diff --git a/ComponentLib/Generator4Param/static_data.hpp b/ComponentLib/Generator4Param/static_data.hpp new file mode 100644 index 0000000..88dbac5 --- /dev/null +++ b/ComponentLib/Generator4Param/static_data.hpp @@ -0,0 +1,101 @@ +{ 0, 0.092182, 0.99596, -0.17574, 0.98107, 2.7864, 0.58172}, +{ 0.05, 0.032044, 0.99785, -0.15175, 0.98425, -0.058476, 0.52344}, +{ 0.1, 0.016599, 1.0006, -0.1331, 0.98738, -0.047843, 0.42635}, +{ 0.15, 0.05483, 1.0034, -0.11578, 0.99044, -0.036909, 0.48633}, +{ 0.2, 0.14141, 1.0056, -0.096146, 0.99341, -0.0096526, 0.67712}, +{ 0.25, 0.25913, 1.0067, -0.071796, 0.99616, 0.057594, 0.93888}, +{ 0.3, 0.38426, 1.0064, -0.042151, 0.9985, 0.16989, 1.1964}, +{ 0.35, 0.49314, 1.005, -0.0084123, 1.0003, 0.30164, 1.3852}, +{ 0.4, 0.5676, 1.0028, 0.02705, 1.0015, 0.41029, 1.4705}, +{ 0.45, 0.59823, 1.0004, 0.061508, 1.0024, 0.46162, 1.4465}, +{ 0.5, 0.58551, 0.99831, 0.092489, 1.0031, 0.44697, 1.3275}, +{ 0.55, 0.53921, 0.99693, 0.11815, 1.0041, 0.3845, 1.1404}, +{ 0.6, 0.47618, 0.99657, 0.13756, 1.0054, 0.30672, 0.92541}, +{ 0.65, 0.41655, 0.99727, 0.15094, 1.0069, 0.24321, 0.7317}, +{ 0.7, 0.37865, 0.99881, 0.1597, 1.0087, 0.20996, 0.60591}, +{ 0.75, 0.37438, 1.0008, 0.16612, 1.0105, 0.21157, 0.57628}, +{ 0.8, 0.40628, 1.0026, 0.17271, 1.0123, 0.24931, 0.64279}, +{ 0.85, 0.46736, 1.0038, 0.18152, 1.0138, 0.32351, 0.77782}, +{ 0.9, 0.5435, 1.0041, 0.19359, 1.0148, 0.42737, 0.93662}, +{ 0.95, 0.61757, 1.0036, 0.20876, 1.0154, 0.54119, 1.0735}, +{ 1, 0.67388, 1.0023, 0.2259, 1.0156, 0.63599, 1.1557}, +{ 1.05, 0.70183, 1.0006, 0.24337, 1.0154, 0.68574, 1.1689}, +{ 1.1, 0.69804, 0.999, 0.25946, 1.0151, 0.67947, 1.1144}, +{ 1.15, 0.66677, 0.99778, 0.27273, 1.0149, 0.62579, 1.0057}, +{ 1.2, 0.61875, 0.99726, 0.28227, 1.015, 0.54794, 0.86636}, +{ 1.25, 0.56848, 0.99754, 0.28791, 1.0155, 0.4729, 0.72906}, +{ 1.3, 0.53046, 0.99852, 0.2903, 1.0163, 0.42123, 0.62812}, +{ 1.35, 0.51537, 0.99991, 0.29083, 1.0172, 0.40344, 0.58875}, +{ 1.4, 0.52734, 1.0013, 0.29123, 1.0181, 0.42221, 0.6178}, +{ 1.45, 0.5631, 1.0024, 0.29303, 1.0188, 0.47491, 0.70149}, +{ 1.5, 0.61328, 1.0028, 0.29718, 1.0193, 0.5526, 0.81115}, +{ 1.55, 0.66527, 1.0026, 0.30377, 1.0194, 0.63849, 0.91394}, +{ 1.6, 0.70664, 1.0017, 0.31219, 1.0191, 0.71058, 0.98342}, +{ 1.65, 0.72829, 1.0005, 0.32131, 1.0186, 0.74915, 1.0051}, +{ 1.7, 0.72648, 0.9993, 0.3299, 1.018, 0.74483, 0.97655}, +{ 1.75, 0.70346, 0.99833, 0.33682, 1.0175, 0.70235, 0.90588}, +{ 1.8, 0.66675, 0.99787, 0.34134, 1.0173, 0.63805, 0.80994}, +{ 1.85, 0.62709, 0.99802, 0.34322, 1.0173, 0.5727, 0.7123}, +{ 1.9, 0.59559, 0.99871, 0.34287, 1.0176, 0.52403, 0.6382}, +{ 1.95, 0.58072, 0.99974, 0.34122, 1.0181, 0.50266, 0.60693}, +{ 2, 0.58615, 1.0008, 0.33951, 1.0186, 0.51207, 0.62506}, +{ 2.05, 0.60997, 1.0016, 0.33885, 1.0189, 0.54977, 0.68425}, +{ 2.1, 0.64547, 1.002, 0.33998, 1.0191, 0.6075, 0.76477}, +{ 2.15, 0.68324, 1.0019, 0.34304, 1.019, 0.67146, 0.8428}, +{ 2.2, 0.71374, 1.0013, 0.3476, 1.0186, 0.72486, 0.89803}, +{ 2.25, 0.72981, 1.0004, 0.35287, 1.018, 0.75305, 0.91825}, +{ 2.3, 0.72833, 0.99946, 0.35791, 1.0174, 0.749, 0.90057}, +{ 2.35, 0.71076, 0.99873, 0.36186, 1.0169, 0.71588, 0.8506}, +{ 2.4, 0.68267, 0.99837, 0.36412, 1.0166, 0.66543, 0.78114}, +{ 2.45, 0.65212, 0.99847, 0.36452, 1.0165, 0.61318, 0.70996}, +{ 2.5, 0.62752, 0.99898, 0.36334, 1.0166, 0.57309, 0.65581}, +{ 2.55, 0.61534, 0.99975, 0.36125, 1.0169, 0.55418, 0.63292}, +{ 2.6, 0.61846, 1.0006, 0.35916, 1.0171, 0.55973, 0.64633}, +{ 2.65, 0.63555, 1.0012, 0.3579, 1.0173, 0.58767, 0.69028}, +{ 2.7, 0.66163, 1.0015, 0.358, 1.0174, 0.63107, 0.75061}, +{ 2.75, 0.68963, 1.0014, 0.35959, 1.0172, 0.67891, 0.80984}, +{ 2.8, 0.71231, 1.001, 0.36238, 1.0168, 0.71845, 0.85255}, +{ 2.85, 0.7242, 1.0003, 0.36575, 1.0163, 0.73892, 0.86907}, +{ 2.9, 0.72287, 0.99958, 0.36901, 1.0158, 0.73524, 0.85679}, +{ 2.95, 0.7094, 0.99903, 0.3715, 1.0154, 0.70971, 0.81993}, +{ 3, 0.68797, 0.99876, 0.37276, 1.015, 0.67092, 0.76835}, +{ 3.05, 0.66468, 0.99883, 0.37265, 1.0149, 0.6304, 0.71561}, +{ 3.1, 0.64588, 0.99922, 0.3714, 1.0149, 0.59888, 0.67568}, +{ 3.15, 0.63643, 0.9998, 0.3695, 1.0151, 0.58359, 0.65904}, +{ 3.2, 0.63853, 1.0004, 0.36763, 1.0152, 0.58731, 0.66933}, +{ 3.25, 0.65119, 1.0009, 0.36639, 1.0153, 0.6084, 0.70238}, +{ 3.3, 0.67068, 1.0011, 0.36619, 1.0153, 0.64122, 0.74782}, +{ 3.35, 0.69166, 1.0011, 0.36714, 1.0151, 0.67717, 0.79271}, +{ 3.4, 0.70866, 1.0007, 0.369, 1.0148, 0.70663, 0.82539}, +{ 3.45, 0.71753, 1.0002, 0.37133, 1.0144, 0.72165, 0.83832}, +{ 3.5, 0.71642, 0.99968, 0.3736, 1.014, 0.71856, 0.82936}, +{ 3.55, 0.70615, 0.99926, 0.37529, 1.0136, 0.69908, 0.80173}, +{ 3.6, 0.68988, 0.99906, 0.37608, 1.0133, 0.66953, 0.76303}, +{ 3.65, 0.67221, 0.99911, 0.37585, 1.0132, 0.63849, 0.72359}, +{ 3.7, 0.65794, 0.99941, 0.37477, 1.0131, 0.61413, 0.69389}, +{ 3.75, 0.65073, 0.99984, 0.37322, 1.0132, 0.60214, 0.68163}, +{ 3.8, 0.65224, 1.0003, 0.3717, 1.0133, 0.60478, 0.68948}, +{ 3.85, 0.66172, 1.0007, 0.37066, 1.0133, 0.62075, 0.71435}, +{ 3.9, 0.67638, 1.0008, 0.37041, 1.0133, 0.64561, 0.74862}, +{ 3.95, 0.69218, 1.0008, 0.37103, 1.0131, 0.67272, 0.78261}, +{ 4, 0.70501, 1.0005, 0.37235, 1.0129, 0.6948, 0.80753}, +{ 4.05, 0.7117, 1.0002, 0.37404, 1.0125, 0.70598, 0.81755}, +{ 4.1, 0.71085, 0.99976, 0.37569, 1.0122, 0.70356, 0.81094}, +{ 4.15, 0.70308, 0.99944, 0.37691, 1.0118, 0.68882, 0.79015}, +{ 4.2, 0.69077, 0.99929, 0.37744, 1.0116, 0.66641, 0.76101}, +{ 4.25, 0.67741, 0.99933, 0.37722, 1.0115, 0.64275, 0.73138}, +{ 4.3, 0.66659, 0.99955, 0.37636, 1.0114, 0.62405, 0.70911}, +{ 4.35, 0.6611, 0.99988, 0.37516, 1.0115, 0.61473, 0.69993}, +{ 4.4, 0.66219, 1.0002, 0.37397, 1.0115, 0.61659, 0.70582}, +{ 4.45, 0.66931, 1.0005, 0.37315, 1.0115, 0.62866, 0.7245}, +{ 4.5, 0.68036, 1.0006, 0.37293, 1.0115, 0.64748, 0.75033}, +{ 4.55, 0.6923, 1.0006, 0.37336, 1.0113, 0.66796, 0.77607}, +{ 4.6, 0.70202, 1.0004, 0.37433, 1.0111, 0.6846, 0.79507}, +{ 4.65, 0.70713, 1.0001, 0.37559, 1.0108, 0.69303, 0.80285}, +{ 4.7, 0.70653, 0.99982, 0.37681, 1.0105, 0.69123, 0.79801}, +{ 4.75, 0.7007, 0.99958, 0.37772, 1.0103, 0.68014, 0.78239}, +{ 4.8, 0.69142, 0.99946, 0.37811, 1.0101, 0.6632, 0.76043}, +{ 4.85, 0.68132, 0.99949, 0.37794, 1.0099, 0.64521, 0.73809}, +{ 4.9, 0.67312, 0.99966, 0.37728, 1.0099, 0.63087, 0.7213}, +{ 4.95, 0.66892, 0.99991, 0.37636, 1.0099, 0.62362, 0.71433}, +{ 5, 0.66968, 1.0002, 0.37545, 1.0099, 0.6249, 0.71867} \ No newline at end of file diff --git a/ComponentLib/Governor/README.md b/ComponentLib/Governor/README.md new file mode 100644 index 0000000..be6be49 --- /dev/null +++ b/ComponentLib/Governor/README.md @@ -0,0 +1,57 @@ +# **Governor** + +## TGOV1 Model + + +**Note: Governor model not yet implemented** + +Standard model of the stream turbine + +
+ + + + Figure 1: Governor TGOV1 model. Figure courtesy of [PowerWorld](https://www.powerworld.com/WebHelp/) +
+ +## Nomenclature + +### Inputs +- $`P_{REF}`$ - reference power (set point) +- $`\Delta\omega`$ +### States +- $`P`$ - turbine power (state 1 in the Figure) +- $`V`$ - valve position (state 2 in the Figure) +### Parameters +- $`R`$ - permanent droop, pu (0.05) +- $`T2`$ - steam bowl time constant, sec (0.5) +- $`V_{max}`$ - maximum valve position limit (1) +- $`V_{min}`$ - minimum valve position limit (0) +- $`T2`$ - numerator time constant of T2, T3 block, sec (2.5) +- $`T3`$ - reheater time constant, sec (7.5) +- $`D_{t}`$ - turbine damping coefficient, pu (0) +- $`T_{rate}`$ - turbine rating, MW (0) + +## Equations +```math +\Delta\omega=\dfrac{\omega-\omega_{s}}{\omega_{s}} +``` +First block +```math +\dfrac{dV}{dt} = \begin{cases} + \dfrac{1}{T1}(\dfrac{P_{REF}-\Delta\omega}{R}-V) &\text{if } V_{min}<=V<= V_{max}\\ + 0 &\text{if } \dfrac{P_{REF}-\Delta\omega}{R}>0 \text{ and } V>=V_{max} &\text{ also then } V=V_{max}\\ + 0 &\text{if } \dfrac{P_{REF}-\Delta\omega}{R}<0 \text{ and } V<=V_{min} &\text{ also then } V=V_{min}\\ +\end{cases} +``` +Second block +```math +\dfrac{dx}{dt}=\dfrac{1}{T3}(V-P) +``` +```math +P=x+\dfrac{T2}{T3}V +``` +Output +```math +P_{mech}=P-\Delta\omega D_{t} +``` \ No newline at end of file diff --git a/ComponentLib/Load/CMakeLists.txt b/ComponentLib/Load/CMakeLists.txt index f441ece..860d32a 100644 --- a/ComponentLib/Load/CMakeLists.txt +++ b/ComponentLib/Load/CMakeLists.txt @@ -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 @@ -55,5 +55,6 @@ # endorsement purposes. # -add_library(Load Load.cpp) -set(component_models ${component_models} Load PARENT_SCOPE) +add_library(Load SHARED Load.cpp) +install(TARGETS Load LIBRARY DESTINATION lib) +# set(component_models ${component_models} Load PARENT_SCOPE) diff --git a/ComponentLib/Load/Load.cpp b/ComponentLib/Load/Load.cpp index bdf3c26..1dc798d 100644 --- a/ComponentLib/Load/Load.cpp +++ b/ComponentLib/Load/Load.cpp @@ -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 @@ -79,6 +79,7 @@ Load::Load(bus_type* bus, ScalarT P, ScalarT Q) bus_(bus) { //std::cout << "Create a load model with " << size_ << " variables ...\n"; + size_ = 0; } template @@ -121,8 +122,9 @@ int Load::tagDifferentiable() template int Load::evaluateResidual() { - bus_->P() += P_; - bus_->Q() += Q_; + // std::cout << "Evaluating load residual ...\n"; + bus_->P() -= P_; + bus_->Q() -= Q_; return 0; } diff --git a/ComponentLib/Load/Load.hpp b/ComponentLib/Load/Load.hpp index b16a140..e555e70 100644 --- a/ComponentLib/Load/Load.hpp +++ b/ComponentLib/Load/Load.hpp @@ -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 @@ -112,6 +112,12 @@ namespace ModelLib //int evaluateAdjointJacobian(); int evaluateAdjointIntegrand(); + void updateTime(real_type t, real_type a) + { + time_ = t; + alpha_ = a; + } + private: ScalarT P_; ScalarT Q_; diff --git a/ComponentLib/Load/README.md b/ComponentLib/Load/README.md new file mode 100644 index 0000000..fa10a08 --- /dev/null +++ b/ComponentLib/Load/README.md @@ -0,0 +1,32 @@ +# Load Model + + +Load models represent the relationship between the power and the voltage on the load bus. Depending on the type of studies different models are used. Generally, models can be divided into two categories: static and dynamic load models. The two most common models used for the static analysis are constant power (1) and constant impedance (2). + +```math +S_{L}=P_{L}+jQ_{L} +``` + +```math +S_{L}=\frac{\vert V \vert ^2}{Z_{L}} +``` + +Constant power loads are included in PF as a negative bus injection. The constant impedance load can be modeled as shunt element connected to a bus. +The dispatchable load can be modeled as a negative generator. +For more advanced studies, frequency and voltage dependence should be considered too. + + +# Shunt Model + + +Besides the main network elements listed above, the power grid also includes other devices such as shunt capacitors, reactors, and power electronic reactive control devices. These devices are used to control reactive injection into a given bus (thus control the voltage). There are passive (capacitors and reactors) as well as active shunts (advance power electronic devices that can vary the reactive output of the devices independent on the bus voltage). +Passive elements are included in the network models as a fixed impedance to ground at a bus. + +## Passive +```math +Y_{SH}=G_{SH}+jB_{SH} +``` + +## Active + +to be added \ No newline at end of file diff --git a/ComponentLib/MiniGrid/CMakeLists.txt b/ComponentLib/MiniGrid/CMakeLists.txt new file mode 100644 index 0000000..8505899 --- /dev/null +++ b/ComponentLib/MiniGrid/CMakeLists.txt @@ -0,0 +1,60 @@ +# +# Copyright (c) 2017, Lawrence Livermore National Security, LLC. +# Produced at the Lawrence Livermore National Laboratory. +# Written by Slaven Peles . +# LLNL-CODE-718378. +# All rights reserved. +# +# 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 +# modification, are permitted provided that the following conditions are met: +# - Redistributions of source code must retain the above copyright notice, +# this list of conditions and the disclaimer below. +# - Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the disclaimer (as noted below) in the +# documentation and/or other materials provided with the distribution. +# - Neither the name of the LLNS/LLNL nor the names of its contributors may +# be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL +# SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, +# OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISINGIN ANY +# WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +# THE POSSIBILITY OF SUCH DAMAGE. +# +# Lawrence Livermore National Laboratory is operated by Lawrence Livermore +# National Security, LLC, for the U.S. Department of Energy, National +# Nuclear Security Administration under Contract DE-AC52-07NA27344. +# +# This document was prepared as an account of work sponsored by an agency +# of the United States government. Neither the United States government nor +# Lawrence Livermore National Security, LLC, nor any of their employees +# makes any warranty, expressed or implied, or assumes any legal liability +# or responsibility for the accuracy, completeness, or usefulness of any +# information, apparatus, product, or process disclosed, or represents that +# its use would not infringe privately owned rights. Reference herein to +# any specific commercial product, process, or service by trade name, +# trademark, manufacturer, or otherwise does not necessarily constitute or +# imply its endorsement, recommendation, or favoring by the United States +# government or Lawrence Livermore National Security, LLC. The views and +# opinions of authors expressed herein do not necessarily state or reflect +# those of the United States government or Lawrence Livermore National +# Security, LLC, and shall not be used for advertising or product +# endorsement purposes. +# + +add_library(MiniGrid SHARED MiniGrid.cpp) +install(TARGETS MiniGrid LIBRARY DESTINATION lib) +# set(component_models ${component_models} MiniGrid PARENT_SCOPE) diff --git a/ComponentLib/MiniGrid/MiniGrid.cpp b/ComponentLib/MiniGrid/MiniGrid.cpp new file mode 100644 index 0000000..fbcfe14 --- /dev/null +++ b/ComponentLib/MiniGrid/MiniGrid.cpp @@ -0,0 +1,148 @@ +/* + * + * Copyright (c) 2017, Lawrence Livermore National Security, LLC. + * Produced at the Lawrence Livermore National Laboratory. + * Written by Slaven Peles . + * LLNL-CODE-718378. + * All rights reserved. + * + * 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 + * modification, are permitted provided that the following conditions are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the disclaimer (as noted below) in the + * documentation and/or other materials provided with the distribution. + * - Neither the name of the LLNS/LLNL nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL + * SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISINGIN ANY + * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + * Lawrence Livermore National Laboratory is operated by Lawrence Livermore + * National Security, LLC, for the U.S. Department of Energy, National + * Nuclear Security Administration under Contract DE-AC52-07NA27344. + * + * This document was prepared as an account of work sponsored by an agency + * of the United States government. Neither the United States government nor + * Lawrence Livermore National Security, LLC, nor any of their employees + * makes any warranty, expressed or implied, or assumes any legal liability + * or responsibility for the accuracy, completeness, or usefulness of any + * information, apparatus, product, or process disclosed, or represents that + * its use would not infringe privately owned rights. Reference herein to + * any specific commercial product, process, or service by trade name, + * trademark, manufacturer, or otherwise does not necessarily constitute or + * imply its endorsement, recommendation, or favoring by the United States + * government or Lawrence Livermore National Security, LLC. The views and + * opinions of authors expressed herein do not necessarily state or reflect + * those of the United States government or Lawrence Livermore National + * Security, LLC, and shall not be used for advertising or product + * endorsement purposes. + * + */ + + +#include +#include +#include +#include "MiniGrid.hpp" +#include + +namespace ModelLib { + +/*! + * @brief Constructor for a constant load model + * + * Calls default ModelEvaluatorImpl constructor. + */ + +template +MiniGrid::MiniGrid() + : ModelEvaluatorImpl(3, 0, 0), + Pl2_( 2.5), + Ql2_( -0.8), + Pg3_( 2.0), + V1_ ( 1.0), + th1_( 0.0), + V3_ ( 1.1), + B12_( 10.0), + B13_( 15.0), + B22_(-22.0), + B23_( 12.0) +{ + //std::cout << "Create a load model with " << size_ << " variables ...\n"; + rtol_ = 1e-5; + atol_ = 1e-5; +} + +template +MiniGrid::~MiniGrid() +{ +} + +/*! + * @brief allocate method computes sparsity pattern of the Jacobian. + */ +template +int MiniGrid::allocate() +{ + return 0; +} + +/** + * Initialization of the grid model + */ +template +int MiniGrid::initialize() +{ + th2() = 0.0; // th2 + V2() = 1.0; // V2 + th3() = 0.0; // th3 + return 0; +} + + +/** + * @brief Contributes to the bus residual. + * + * Must be connected to a PQ bus. + */ +template +int MiniGrid::evaluateResidual() +{ + f_[0] = -Pl2_ - V2()*(V1_*B12_*sin(th2()-th1_) + V3_*B23_*sin(th2() - th3())); + f_[1] = -Ql2_ + V2()*(V1_*B12_*cos(th2()-th1_) + B22_*V2() + V3_*B23_*cos(th2() - th3())); + f_[2] = Pg3_ - V3_ *(V1_*B13_*sin(th3()-th1_) + V2()*B23_*sin(th3() - th2())); + + return 0; +} + +template +int MiniGrid::evaluateJacobian() +{ + return 0; +} + +// Available template instantiations +template class MiniGrid; +template class MiniGrid; + + +} //namespace ModelLib + diff --git a/ComponentLib/MiniGrid/MiniGrid.hpp b/ComponentLib/MiniGrid/MiniGrid.hpp new file mode 100644 index 0000000..1ec9e43 --- /dev/null +++ b/ComponentLib/MiniGrid/MiniGrid.hpp @@ -0,0 +1,144 @@ +/* + * + * Copyright (c) 2017, Lawrence Livermore National Security, LLC. + * Produced at the Lawrence Livermore National Laboratory. + * Written by Slaven Peles . + * LLNL-CODE-718378. + * All rights reserved. + * + * 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 + * modification, are permitted provided that the following conditions are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the disclaimer (as noted below) in the + * documentation and/or other materials provided with the distribution. + * - Neither the name of the LLNS/LLNL nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL + * SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISINGIN ANY + * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + * Lawrence Livermore National Laboratory is operated by Lawrence Livermore + * National Security, LLC, for the U.S. Department of Energy, National + * Nuclear Security Administration under Contract DE-AC52-07NA27344. + * + * This document was prepared as an account of work sponsored by an agency + * of the United States government. Neither the United States government nor + * Lawrence Livermore National Security, LLC, nor any of their employees + * makes any warranty, expressed or implied, or assumes any legal liability + * or responsibility for the accuracy, completeness, or usefulness of any + * information, apparatus, product, or process disclosed, or represents that + * its use would not infringe privately owned rights. Reference herein to + * any specific commercial product, process, or service by trade name, + * trademark, manufacturer, or otherwise does not necessarily constitute or + * imply its endorsement, recommendation, or favoring by the United States + * government or Lawrence Livermore National Security, LLC. The views and + * opinions of authors expressed herein do not necessarily state or reflect + * those of the United States government or Lawrence Livermore National + * Security, LLC, and shall not be used for advertising or product + * endorsement purposes. + * + */ +#pragma once + +#include +#include + +namespace ModelLib +{ + /*! + * @brief Implementation of a power grid. + * + */ + template + class MiniGrid : public ModelEvaluatorImpl + { + using ModelEvaluatorImpl::size_; + using ModelEvaluatorImpl::nnz_; + using ModelEvaluatorImpl::time_; + using ModelEvaluatorImpl::y_; + using ModelEvaluatorImpl::f_; + using ModelEvaluatorImpl::rtol_; + using ModelEvaluatorImpl::atol_; + + typedef typename ModelEvaluatorImpl::real_type real_type; + + public: + MiniGrid(); + virtual ~MiniGrid(); + + int allocate(); + int initialize(); + int tagDifferentiable() {return -1;} + int evaluateResidual(); + int evaluateJacobian(); + int evaluateIntegrand() {return -1;} + + int initializeAdjoint() {return -1;} + int evaluateAdjointResidual() {return -1;} + //int evaluateAdjointJacobian() {return -1;} + int evaluateAdjointIntegrand() {return -1;} + + void updateTime(real_type t, real_type a) {} + + // const accessors are public + ScalarT const& th2() const + { + return y_[0]; + } + + ScalarT const& V2() const + { + return y_[1]; + } + + ScalarT const& th3() const + { + return y_[2]; + } + + ScalarT& th2() + { + return y_[0]; + } + + ScalarT& V2() + { + return y_[1]; + } + + ScalarT& th3() + { + return y_[2]; + } + + private: + ScalarT Pl2_; + ScalarT Ql2_; + ScalarT Pg3_; + ScalarT V1_ ; + ScalarT th1_; + ScalarT V3_ ; + ScalarT B12_; + ScalarT B13_; + ScalarT B22_; + ScalarT B23_; + }; +} diff --git a/ComponentLib/README.md b/ComponentLib/README.md new file mode 100644 index 0000000..93c2bc3 --- /dev/null +++ b/ComponentLib/README.md @@ -0,0 +1,56 @@ +## Component Models + +GridKit™ provides component models for power flow and electromechanical transient simulations, as well as experimental component models for dynamic constrained optimal power flow analysis. GridKit™ assembles components into a grid model using power flow equations. +## Network Equations + +The relation between all the bus current injections and bus voltage is given by the following node equation: +```math +I_{i}=\sum_{j=1}^{n} Y_{ij}V_{j} ~~~ i=1,2,...,n +``` +where $`n`$ is the number of buses in the network. $`I_{i}`$ and $`V_{j}`$ are injected current at bus $`i`$ and voltage at bus $`j`$. $`Y_{ij}`$ are the elements of the admittance matrix **Y**. Diagonal elements $`Y_{ii}`$ are equal to the sum of all admittances of all devices incident to the bus $`i`$. Off-diagonal elements $`Y_{ij}`$ are equal to the **negative** of the sum of the admittances that are joining buses $`i`$ and $`j`$. In case that there is shift transformer at the bus, $`Y_{ij}`$ should be calculated as explained in the branch section. + +In the power system, complex voltage and current values are unknown, but rather real power injections at the generator buses and voltage magnitude setpoint as well as complex power (S) consumed by the load. +The relation between injected current and power at the node is given as: +```math +S_{i}=P_{i}+jQ_{i}=V_{i}I^*_{i} +``` +Mode information on the sign convention used can be found [here](./Bus/README.md). + +Now the complex power flow equations are given as: + +```math +P_{i}+jQ_{i}=V_{i}\sum_{j=1}^{n} Y_{ij}^*V_{j}^* \;\;\;\;\;\; i=1,2,...,n +``` + +Considering: +```math +V_{i}=\vert V_{i} \vert e^{j\theta_{i}} +``` + +```math +Y_{ij}=\vert Y_{ij} \vert e^{j\psi_{ij}}=G_{ij}+jB_{ij} +``` + +```math +\theta_{ij}=\theta_{i}-\theta_{j} +``` + +The complex set can be rewritten as two sets of real power balance equations: + +```math +P_{i}= \vert V_{i} \vert \sum_{j=1}^{n}\vert Y_{ij} \vert \vert V_{j} \vert \cos (\theta_{ij}-\psi_{ij}) +``` + +```math +Q_{i}= \vert V_{i} \vert \sum_{j=1}^{n} \vert Y_{ij} \vert \vert V_{j} \vert \sin (\theta_{ij}-\psi_{ij}) +``` + +or + +```math +P_{i}= \vert V_{i} \vert \sum_{j=1}^{n}\vert V_{j} \vert (G_{ij}\cos\theta_{ij}+B_{ij}\sin\theta_{ij}) +``` + +```math +Q_{i}= \vert V_{i} \vert \sum_{j=1}^{n} \vert V_{j} \vert (G_{ij}\sin\theta_{ij}-B_{ij}\cos\theta_{ij}) +``` diff --git a/ComponentLib/Stabilizer/README.md b/ComponentLib/Stabilizer/README.md new file mode 100644 index 0000000..722741d --- /dev/null +++ b/ComponentLib/Stabilizer/README.md @@ -0,0 +1,77 @@ +# **Power System Stabilizer** + +**Note: Stabilizer model not yet implemented** + + +
+ + + + Figure 1: Power system stabilizer PSS1A model. Figure courtesy of [PowerWorld](https://www.powerworld.com/WebHelp/) +
+ +## Nomenclature + +### Inputs ($`I_{cs}`$) + +1. rotor speed deviation (p.u.) +2. bus frequency deviation (p.u.) - default +3. generator electrical power in Gen MVA Base (p.u.) +4. generator accelerating power (p.u.) +5. bus voltage (p.u.) +6. derivative of p.u. bus voltage + +### Parameters +- $`I_{cs}`$ - stabilizer input code, (2) +- $`A_{1}`$ - notch filter parameters, (0) +- $`A_{2}`$ - notch filter parameters, (0) +- $`T_{1}`$ - lead/lag time constant, sec (0.25) +- $`T_{2}`$ - lead/lag time constant, sec (0.03) +- $`T_{3}`$ - lead/lag time constant, sec (0.25) +- $`T_{4}`$ - lead/lag time constant, sec (0.03) +- $`T_{5}`$ - washout numerator time constant, sec (20) +- $`T_{6}`$ - washout denomirator time constant/transducer time constant, sec (0.02) +- $`K_{S}`$ - stabilizer gains, (10) +- $`L_{smax}`$ - maximum stabilizer output, pu (0.1) +- $`L_{smin}`$ - minimum stabilizer output, pu (-0.1) +- $`V_{cu}`$ - stabilizer input cutoff threshold, pu (0) +- $`V_{cl}`$ - stabilizer input cutoff threshold, pu (0) + + +## Equations +First block +```math +\dfrac{dV_{1}}{dt}=\dfrac{1}{T_{6}}(V_{SI}-V_{1}) +``` +Second block +```math +\dfrac{dx_{1}}{dt}=-\dfrac{V_{2}}{T_{5}} +``` +```math +V_{2}=x_{1}+K_{S}V_{1} +``` +Third block +```math +\dfrac{d^{2}V_{3}}{dt^{2}}+\dfrac{A_{1}}{A_{2}}\dfrac{dV_{3}}{dt}=\dfrac{1}{A_{2}}(V_{2}-1) +``` +Fourth block +```math +\dfrac{dx_{2}}{dt}=\dfrac{1}{T_{2}}(V_{3}-V_{4}) +``` +```math +V_{4}=x_{2}+\dfrac{T_{1}}{T_{2}}V_{3} +``` +Fifth block +```math +\dfrac{dx_{3}}{dt}=\dfrac{1}{T_{4}}(V_{4}-V_{5}) +``` +```math +V_{5}=x_{3}+\dfrac{T_{3}}{T_{4}}V_{4} +``` +```math +V_{llout} = \begin{cases} + L_{SMAX} &\text{if } V_{5}>V_{SMAX} \\ + L_{SMIN} &\text{if } V_{5} + + + + Figure 2: GENROU. Figure courtesy of [PowerWorld](https://www.powerworld.com/WebHelp/) + + +## Equations +### Algebraic Equations + + +- Fluxes + +``` math +E''_{d}=-\psi''_{q}=+E'_{d}\dfrac{X''_{q}-X_{l}}{X'_{q}-X_{l}}+\psi'_{q}\dfrac{X'_{q}-X''_{q}}{X'_{q}-X_{l}} +``` +``` math +E''_{q}=\psi''_{d}=+E'_{q}\dfrac{X''_{d}-X_{l}}{X'_{d}-X_{l}}+\psi'_{d}\dfrac{X'_{d}-X''_{d}}{X'_{d}-X_{l}} +``` +```math +\psi_{d}=-I_{d}X''_{d}+E'_{q}\dfrac{X''_{d}-X_{l}}{X'_{d}-X_{l}}+\psi'_{d}\dfrac{X'_{d}-X''_{d}}{X'_{d}-X_{l}}=-I_{d}X''_{d}+E''_{q} +``` +```math +\psi_{q}=-I_{q}X''_{q}-E'_{d}\dfrac{X''_{q}-X_{l}}{X'_{q}-X_{l}}-\psi'_{q}\dfrac{X'_{q}-X''_{q}}{X'_{q}-X_{l}}=-I_{q}X''_{q}-E''_{d} +``` +- Stator +``` math +V_{dterm}=E''_{d}(1+\Delta\omega_{pu})-R_{s}I_{d}+X''_{q}I_{q} +``` +``` math +V_{qterm}=E''_{q}(1+\Delta\omega_{pu})-R_{s}I_{q}-X''_{d}I_{d} +``` + +### Differential Equations + + +- Mechanical Dynamic Equations +``` math +\dfrac{d\delta}{dt}=\Delta \omega_{pu}*\omega_{s} +``` +``` math +2H\dfrac{d\omega}{dt}=\dfrac{P_{mech}-D\omega}{1+\Delta\omega_{pu}}-(\psi_{d}I_{q}-\psi_{q}I_{d}) +``` +- Rotor Dynamic Equations +```math +T'_{d0}\dfrac{dE'_{q}}{dt}=E_{fd}-E'_{q}-(X_{d}-X'_{d})(I_{d}-\dfrac{X'_{d}-X''_{d}}{(X'_{d}-X_{l})^2}(+\psi'_{d}+(X'_{d}-X_{l})I_{d}-E'_{q}))-\psi''_{d}Sat(\psi'') +``` +```math +T''_{d0}\dfrac{d\psi'_{d}}{dt}=-\psi'_{d}-(X'_{d}-X_{l})I_{d}+E'_{q} +``` +```math +T''_{q0}\dfrac{d\psi'_{q}}{dt}=-\psi'_{q}+(X'_{q}-X_{l})I_{q}+E'_{d} +``` +```math +T'_{q0}\dfrac{dE'_{d}}{dt}= -E'_{d}+(X_{q}-X'_{q})(I_{q}-\dfrac{X'_{q}-X''_{q}}{(X'_{q}-X_{l})^2}(-\psi'_{q}+(X'_{q}-X_{l})I_{q}+E'_{d}))+\psi''_{q}(\dfrac{X_{q}-X_{l}}{X_{d}-X_{l}})Sat(\psi'') +``` +## Initialization + +From the block diagram it can be written: + +```math +-\psi'_{d}-(X'_{d}-X_{l})I_{d}+E'_{q}=0 +``` +``` math +-\psi''_{d}+E'_{q}\dfrac{X''_{d}-X_{l}}{X'_{d}-X_{l}}+\psi'_{d}\dfrac{X'_{d}-X''_{d}}{X'_{d}-X_{l}}=0 +``` +```math +-\psi'_{q}+(X'_{q}-X_{l})I_{q}+E'_{d}=0 +``` +``` math +\psi''_{q}+E'_{d}\dfrac{X''_{q}-X_{l}}{X'_{q}-X_{l}}+\psi'_{q}\dfrac{X'_{q}-X''_{q}}{X'_{q}-X_{l}}=0 +``` +```math +-E'_{d}+(X_{q}-X'_{q})I_{q}+\psi''_{q}(\dfrac{X_{q}-X_{l}}{X_{d}-X_{l}})Sat(\psi'')=0 +``` + +Internal voltage on the referece frame can be calculated directly: +```math +V_{r}=V_{rterm}+R_{a}I_{r}-X''_{d}I_{i} +``` +``` math +V_{i}=V_{iterm}+R_{a}I_{i}-X''_{d}I_{r} +``` +then +```math +Sat(\psi'')=Sat(\vert V_{r}+jV_{i} \vert) +``` + +It is important to point out that finding the initial value of $`\delta`$ for the model without saturation direct method can be used. In case when saturation is considered some "claver" math is needed. Key insight for determining initial $`\delta`$ is that the magnitude of the saturation depends upon the magnitude of $`\psi''`$, which is independent of $`\delta`$. +```math +\delta=tan^{-1}(\dfrac{K_{sat}V_{iterm}+K_{sat}R_{a}I_{i}+(K_{sat}X''_{d}+X_{q}-X''_{q})I_{r}}{K_{sat}V_{rterm}+K_{sat}R_{a}I_{r}-(K_{sat}X''_{d}+X_{q}-X''_{q})I_{i}}) +``` +where +```math +K_{sat}=(1+(\dfrac{X_{q}-X_{l}}{X_{d}-X_{l}})Sat(\psi'')) +``` +Following must be true (if not enforce the corrections): + +```math +X_{l}<=X''{q}<=X'{q}<=Xq +``` +```math +X_{l}<=X''{d}<=X'{d}<=Xd +``` diff --git a/ComponentLib/SynchronousMachine/GENSALwS/README.md b/ComponentLib/SynchronousMachine/GENSALwS/README.md new file mode 100644 index 0000000..9c5b897 --- /dev/null +++ b/ComponentLib/SynchronousMachine/GENSALwS/README.md @@ -0,0 +1,92 @@ +# GENSAL +## Simplifications + +- $`X''_{q}=X''_{d}`$ +- $`X''_{d}`$ does not saturate +- only $`d`$ axis affected by saturation +- $`X_{q}=X'_{q}`$ +- $`T'_{q0}`$ is neglected + +
+ + + + Figure 2: GENSAL. Figure courtesy of [PowerWorld](https://www.powerworld.com/WebHelp/) +
+ +## Equations +### Algebraic Equations + + +- Fluxes + +``` math +E''_{d}=\psi''_{q} +``` +``` math +E''_{q}=\psi''_{d}=+E'_{q}\dfrac{X''_{d}-X_{l}}{X'_{d}-X_{l}}+\psi'_{d}\dfrac{X'_{d}-X''_{d}}{X'_{d}-X_{l}} +``` +```math +\psi_{d}=-I_{d}X''_{d}+E'_{q}\dfrac{X''_{d}-X_{l}}{X'_{d}-X_{l}}+\psi'_{d}\dfrac{X'_{d}-X''_{d}}{X'_{d}-X_{l}}=-I_{d}X''_{d}+E''_{q} +``` +```math +\psi_{q}=-I_{q}X''_{d}+\psi''_{q} +``` +- Stator +``` math +V_{dterm}=E''_{d}(1+\Delta\omega_{pu})-R_{s}I_{d}+X''_{q}I_{q} +``` +``` math +V_{qterm}=E''_{q}(1+\Delta\omega_{pu})-R_{s}I_{q}-X''_{d}I_{d} +``` + +### Differential Equations + + +- Mechanical Dynamic Equations +``` math +\dfrac{d\delta}{dt}=\Delta \omega_{pu}*\omega_{s} +``` +``` math +2H\dfrac{d\omega}{dt}=\dfrac{P_{mech}-D\omega}{1+\Delta\omega_{pu}}-(\psi_{d}I_{q}-\psi_{q}I_{d}) +``` +- Rotor Dynamic Equations +```math +T'_{d0}\dfrac{dE'_{q}}{dt}=E_{fd}-E'_{q}-(X_{d}-X'_{d})(I_{d}-\dfrac{X'_{d}-X''_{d}}{(X'_{d}-X_{l})^2}(+\psi'_{d}+(X'_{d}-X_{l})I_{d}-E'_{q}))-\psi''_{d}Sat(\psi'') +``` +```math +T''_{d0}\dfrac{d\psi'_{d}}{dt}=-\psi'_{d}-(X'_{d}-X_{l})I_{d}+E'_{q} +``` +```math +T''_{q0}\dfrac{d\psi''_{q}}{dt}=-\psi''_{q}-(X_{q}-X''_{q})I_{q} +``` + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ComponentLib/SynchronousMachine/README.md b/ComponentLib/SynchronousMachine/README.md new file mode 100644 index 0000000..66c5ccb --- /dev/null +++ b/ComponentLib/SynchronousMachine/README.md @@ -0,0 +1,122 @@ +# **Synchronous Machine - GENERAL** + + +**Note: Synchronous machine models not yet implemented** + + + +## Convention + + +
+ + + + Figure 1: Synchronous Machine. Figure courtesy of [PowerWorld](https://www.powerworld.com/files/Synchronous-Machines.pdf) +
+ +q-axis leads the d-axis + +rotor angle w.r.t. to q-axis + +## Types + +Two main types: + +- Round Rotor (we will use GENROU model) +- Salient Rotor/ Salient Pole (we will use GENSAL model) + +## Nomenclature +### Variables +- $`\delta`$ - rotor angle +- $`\omega_{s}`$ - synchronous speed (2$`\pi`$60) +- $`\Delta \omega_{pu}`$ - deviation of rotor speed away from synchronous speed +- $`I_{d}, I{q},I_{0}`$ - stator currents +- $`V_{dterm}, V_{qterm}, V_{0term}`$ - stator voltages +- $`\psi_{d}, \psi_{q}, \psi_{0}`$ - stator flux +- $`E'_{d}, E'_{q}, \psi'_{q}, \psi'_{d}`$ - rotor fluxes +- $`E_{fd}`$ - field voltage input (from exciter) +- $`P_{mech}`$ - mechanical +### Parameters +- $`H`$ - intertia constant, sec (3) +- $`D`$ - damping factor, pu (0) +- $`R_{s}`$ - stator resistance, pu (0) +- $`X_{l}`$ - stator leakage reactance, pu (0.15) +- $`X_{d}`$ - direct axis synchronous reactance, (2.1) +- $`X'_{d}`$ - direct axis transient reactance, (0.2) +- $`X''_{d}`$ - direct axis sub-transient reactance, (0.18) +- $`X_{q}`$ - quadrature axis synchronous reactance, (0.5) +- $`X'_{q}`$ - quadrature axis transient reactance, (0.47619) +- $`X''_{q}`$ - quadrature axis sub-transient reactance, (0.18) +- $`T'_{d0}`$ - open circuit direct axis transient time const., (7) +- $`T''_{d0}`$ - open circuit direct axis sub-transient time const., (0.04) +- $`T'_{q0}`$ - open circuit quadrature axis transient time const., (0.75) +- $`T''_{q0}`$ - open circuit quadrature axis sub-transient time const., (0.05) +- $`S1`$ - saturation factor at 1.0 pu flux, (0) +- $`S12`$ - saturation factor at 1.2 pu flux, (0) + +## Equations + +### Algebraic Equations + + +- Fluxes + +``` math +E''_{d}=-\psi''_{q}=+E'_{d}\dfrac{X''_{q}-X_{l}}{X'_{q}-X_{l}}+\psi'_{q}\dfrac{X'_{q}-X''_{q}}{X'_{q}-X_{l}} +``` +``` math +E''_{q}=\psi''_{d}=+E'_{q}\dfrac{X''_{d}-X_{l}}{X'_{d}-X_{l}}+\psi'_{d}\dfrac{X'_{d}-X''_{d}}{X'_{d}-X_{l}} +``` +```math +\psi_{d}=-I_{d}X''_{d}+E'_{q}\dfrac{X''_{d}-X_{l}}{X'_{d}-X_{l}}+\psi'_{d}\dfrac{X'_{d}-X''_{d}}{X'_{d}-X_{l}}=-I_{d}X''_{d}+E''_{q} +``` +```math +\psi_{q}=-I_{q}X''_{q}-E'_{d}\dfrac{X''_{q}-X_{l}}{X'_{q}-X_{l}}-\psi'_{q}\dfrac{X'_{q}-X''_{q}}{X'_{q}-X_{l}}=-I_{q}X''_{q}-E''_{d} +``` +- Stator +``` math +V_{dterm}=E''_{d}(1+\Delta\omega_{pu})-R_{s}I_{d}+X''_{q}I_{q} +``` +``` math +V_{qterm}=E''_{q}(1+\Delta\omega_{pu})-R_{s}I_{q}-X''_{d}I_{d} +``` + +### Differential Equations + + +- Mechanical Dynamic Equations +``` math +\dfrac{d\delta}{dt}=\Delta \omega_{pu}*\omega_{s} +``` +``` math +2H\dfrac{d\omega}{dt}=\dfrac{P_{mech}-D\omega}{1+\Delta\omega_{pu}}-(\psi_{d}I_{q}-\psi_{q}I_{d}) +``` +- Rotor Dynamic Equations +```math +T'_{d0}\dfrac{dE'_{q}}{dt}=E_{fd}-E'_{q}-(X_{d}-X'_{d})(I_{d}-\dfrac{X'_{d}-X''_{d}}{(X'_{d}-X_{l})^2}(+\psi'_{d}+(X'_{d}-X_{l})I_{d}-E'_{q})) +``` +```math +T''_{d0}\dfrac{d\psi'_{d}}{dt}=-\psi'_{d}-(X'_{d}-X_{l})I_{d}+E'_{q} +``` +```math +T''_{q0}\dfrac{d\psi'_{q}}{dt}=-\psi'_{q}+(X'_{q}-X_{l})I_{q}+E'_{d} +``` +```math +T'_{q0}\dfrac{dE'_{d}}{dt}= -E'_{d}+(X_{q}-X'_{q})(I_{q}-\dfrac{X'_{q}-X''_{q}}{(X'_{q}-X_{l})^2}(-\psi'_{q}+(X'_{q}-X_{l})I_{q}+E'_{d})) +``` +Previos equations can be used to model any machine, however ***SATURATION*** is missing. + +Saturation means increasingly large amounts of current are needed to increase the flux density. There are various methods to include the saturation (it is not standardized yet). We are going to use the approach implemented in PTI PSSS/E and PowerWorld Simulator (scaled quadratic). + +```math +Sat(x) = \begin{cases} + \dfrac{B(x-A)^2}{x} &\text{if } x>A \\ + 0 &\text{if } x<=A +\end{cases} +``` +There are two solutions, and one where $`A<1`$ should be chosen. + +Hint! + +Negative values are not allowed. diff --git a/Documentation/Figures/EXDC1.JPG b/Documentation/Figures/EXDC1.JPG new file mode 100644 index 0000000..7e2e87d Binary files /dev/null and b/Documentation/Figures/EXDC1.JPG differ diff --git a/Documentation/Figures/GENROU.JPG b/Documentation/Figures/GENROU.JPG new file mode 100644 index 0000000..0a594b7 Binary files /dev/null and b/Documentation/Figures/GENROU.JPG differ diff --git a/Documentation/Figures/GENSAL.JPG b/Documentation/Figures/GENSAL.JPG new file mode 100644 index 0000000..4329630 Binary files /dev/null and b/Documentation/Figures/GENSAL.JPG differ diff --git a/Documentation/Figures/PSS1A.JPG b/Documentation/Figures/PSS1A.JPG new file mode 100644 index 0000000..69af298 Binary files /dev/null and b/Documentation/Figures/PSS1A.JPG differ diff --git a/Documentation/Figures/SM1.JPG b/Documentation/Figures/SM1.JPG new file mode 100644 index 0000000..821ec35 Binary files /dev/null and b/Documentation/Figures/SM1.JPG differ diff --git a/Documentation/Figures/TGOV1.JPG b/Documentation/Figures/TGOV1.JPG new file mode 100644 index 0000000..995f212 Binary files /dev/null and b/Documentation/Figures/TGOV1.JPG differ diff --git a/Documentation/Figures/TL.jpg b/Documentation/Figures/TL.jpg new file mode 100644 index 0000000..6f39589 Binary files /dev/null and b/Documentation/Figures/TL.jpg differ diff --git a/Documentation/Figures/branch.jpg b/Documentation/Figures/branch.jpg new file mode 100644 index 0000000..90aff9d Binary files /dev/null and b/Documentation/Figures/branch.jpg differ diff --git a/Documentation/Figures/bus_variables.jpg b/Documentation/Figures/bus_variables.jpg new file mode 100644 index 0000000..edeb794 Binary files /dev/null and b/Documentation/Figures/bus_variables.jpg differ diff --git a/Documentation/Figures/example1.jpg b/Documentation/Figures/example1.jpg new file mode 100644 index 0000000..a4a2aa1 Binary files /dev/null and b/Documentation/Figures/example1.jpg differ diff --git a/Documentation/Figures/gen1.png b/Documentation/Figures/gen1.png new file mode 100644 index 0000000..e922d4b Binary files /dev/null and b/Documentation/Figures/gen1.png differ diff --git a/Documentation/Figures/gen2.png b/Documentation/Figures/gen2.png new file mode 100644 index 0000000..0ea503c Binary files /dev/null and b/Documentation/Figures/gen2.png differ diff --git a/Doxyfile b/Doxyfile index 1cbe548..501e614 100644 --- a/Doxyfile +++ b/Doxyfile @@ -1,5 +1,4 @@ -# Doxyfile 1.8.5 - +# Doxyfile 1.8.18 # # Lawrence Livermore National Laboratory is operated by Lawrence Livermore # National Security, LLC, for the U.S. Department of Energy, National @@ -20,14 +19,14 @@ # those of the United States government or Lawrence Livermore National # Security, LLC, and shall not be used for advertising or product # endorsement purposes. -# +# # This file describes the settings to be used by the documentation system # doxygen (www.doxygen.org) for a project. -# +# # All text after a double hash (##) is considered a comment and is placed in # front of the TAG it is preceding. -# +# # All text after a single hash (#) is considered a comment and will be ignored. # The format is: # TAG = value [value, ...] @@ -39,11 +38,11 @@ # Project related configuration options #--------------------------------------------------------------------------- -# This tag specifies the encoding used for all characters in the config file -# that follow. The default is UTF-8 which is also the encoding used for all text -# before the first occurrence of this tag. Doxygen uses libiconv (or the iconv -# built into libc) for the transcoding. See http://www.gnu.org/software/libiconv -# for the list of possible encodings. +# This tag specifies the encoding used for all characters in the configuration +# file that follow. The default is UTF-8 which is also the encoding used for all +# text before the first occurrence of this tag. Doxygen uses libiconv (or the +# iconv built into libc) for the transcoding. See +# https://www.gnu.org/software/libiconv/ for the list of possible encodings. # The default value is: UTF-8. DOXYFILE_ENCODING = UTF-8 @@ -60,20 +59,20 @@ PROJECT_NAME = gridkit # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = +PROJECT_NUMBER = # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a # quick idea about the purpose of the project. Keep the description short. -PROJECT_BRIEF = +PROJECT_BRIEF = -# With the PROJECT_LOGO tag one can specify an logo or icon that is included in -# the documentation. The maximum height of the logo should not exceed 55 pixels -# and the maximum width should not exceed 200 pixels. Doxygen will copy the logo -# to the output directory. +# With the PROJECT_LOGO tag one can specify a logo or an icon that is included +# in the documentation. The maximum height of the logo should not exceed 55 +# pixels and the maximum width should not exceed 200 pixels. Doxygen will copy +# the logo to the output directory. -PROJECT_LOGO = +PROJECT_LOGO = # The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path # into which the generated documentation will be written. If a relative path is @@ -82,7 +81,7 @@ PROJECT_LOGO = OUTPUT_DIRECTORY = ../doc -# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create 4096 sub- +# If the CREATE_SUBDIRS tag is set to YES then doxygen will create 4096 sub- # directories (in 2 levels) under the output directory of each output format and # will distribute the generated files over these directories. Enabling this # option can be useful when feeding doxygen a huge amount of source files, where @@ -92,29 +91,47 @@ OUTPUT_DIRECTORY = ../doc CREATE_SUBDIRS = NO +# If the ALLOW_UNICODE_NAMES tag is set to YES, doxygen will allow non-ASCII +# characters to appear in the names of generated files. If set to NO, non-ASCII +# characters will be escaped, for example _xE3_x81_x84 will be used for Unicode +# U+3044. +# The default value is: NO. + +ALLOW_UNICODE_NAMES = NO + # The OUTPUT_LANGUAGE tag is used to specify the language in which all # documentation generated by doxygen is written. Doxygen will use this # information to generate all constant output in the proper language. -# Possible values are: Afrikaans, Arabic, Brazilian, Catalan, Chinese, Chinese- -# Traditional, Croatian, Czech, Danish, Dutch, English, Esperanto, Farsi, -# Finnish, French, German, Greek, Hungarian, Italian, Japanese, Japanese-en, -# Korean, Korean-en, Latvian, Norwegian, Macedonian, Persian, Polish, -# Portuguese, Romanian, Russian, Serbian, Slovak, Slovene, Spanish, Swedish, -# Turkish, Ukrainian and Vietnamese. +# Possible values are: Afrikaans, Arabic, Armenian, Brazilian, Catalan, Chinese, +# Chinese-Traditional, Croatian, Czech, Danish, Dutch, English (United States), +# Esperanto, Farsi (Persian), Finnish, French, German, Greek, Hungarian, +# Indonesian, Italian, Japanese, Japanese-en (Japanese with English messages), +# Korean, Korean-en (Korean with English messages), Latvian, Lithuanian, +# Macedonian, Norwegian, Persian (Farsi), Polish, Portuguese, Romanian, Russian, +# Serbian, Serbian-Cyrillic, Slovak, Slovene, Spanish, Swedish, Turkish, +# Ukrainian and Vietnamese. # The default value is: English. OUTPUT_LANGUAGE = English -# If the BRIEF_MEMBER_DESC tag is set to YES doxygen will include brief member +# The OUTPUT_TEXT_DIRECTION tag is used to specify the direction in which all +# documentation generated by doxygen is written. Doxygen will use this +# information to generate all generated output in the proper direction. +# Possible values are: None, LTR, RTL and Context. +# The default value is: None. + +OUTPUT_TEXT_DIRECTION = None + +# If the BRIEF_MEMBER_DESC tag is set to YES, doxygen will include brief member # descriptions after the members that are listed in the file and class # documentation (similar to Javadoc). Set to NO to disable this. # The default value is: YES. BRIEF_MEMBER_DESC = YES -# If the REPEAT_BRIEF tag is set to YES doxygen will prepend the brief +# If the REPEAT_BRIEF tag is set to YES, doxygen will prepend the brief # description of a member or function before the detailed description -# +# # Note: If both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the # brief descriptions will be completely suppressed. # The default value is: YES. @@ -157,7 +174,7 @@ ALWAYS_DETAILED_SEC = NO INLINE_INHERITED_MEMB = NO -# If the FULL_PATH_NAMES tag is set to YES doxygen will prepend the full path +# If the FULL_PATH_NAMES tag is set to YES, doxygen will prepend the full path # before files name in the file list and in the header files. If set to NO the # shortest path that makes the file name unique will be used # The default value is: YES. @@ -169,12 +186,12 @@ FULL_PATH_NAMES = YES # part of the path. The tag can be used to show relative paths in the file list. # If left blank the directory from which doxygen is run is used as the path to # strip. -# +# # Note that you can specify absolute paths here, but also relative paths, which # will be relative from the directory where doxygen is started. # This tag requires that the tag FULL_PATH_NAMES is set to YES. -STRIP_FROM_PATH = +STRIP_FROM_PATH = # The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the # path mentioned in the documentation of a class, which tells the reader which @@ -183,7 +200,7 @@ STRIP_FROM_PATH = # specify the list of include paths that are normally passed to the compiler # using the -I flag. -STRIP_FROM_INC_PATH = +STRIP_FROM_INC_PATH = # If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter (but # less readable) file names. This can be useful is your file systems doesn't @@ -201,6 +218,16 @@ SHORT_NAMES = NO JAVADOC_AUTOBRIEF = NO +# If the JAVADOC_BANNER tag is set to YES then doxygen will interpret a line +# such as +# /*************** +# as being the beginning of a Javadoc-style comment "banner". If set to NO, the +# Javadoc-style will behave just like regular comments and it will not be +# interpreted by doxygen. +# The default value is: NO. + +JAVADOC_BANNER = NO + # If the QT_AUTOBRIEF tag is set to YES then doxygen will interpret the first # line (until the first dot) of a Qt-style comment as the brief description. If # set to NO, the Qt-style will behave just like regular Qt-style comments (thus @@ -214,7 +241,7 @@ QT_AUTOBRIEF = NO # a brief description. This used to be the default behavior. The new default is # to treat a multi-line C++ comment block as a detailed description. Set this # tag to YES if you prefer the old behavior instead. -# +# # Note that setting this tag to YES also means that rational rose comments are # not recognized any more. # The default value is: NO. @@ -227,9 +254,9 @@ MULTILINE_CPP_IS_BRIEF = NO INHERIT_DOCS = YES -# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce a -# new page for each member. If set to NO, the documentation of a member will be -# part of the file/class/namespace that contains it. +# If the SEPARATE_MEMBER_PAGES tag is set to YES then doxygen will produce a new +# page for each member. If set to NO, the documentation of a member will be part +# of the file/class/namespace that contains it. # The default value is: NO. SEPARATE_MEMBER_PAGES = NO @@ -248,15 +275,14 @@ TAB_SIZE = 4 # will allow you to put the command \sideeffect (or @sideeffect) in the # documentation, which will result in a user-defined paragraph with heading # "Side Effects:". You can put \n's in the value part of an alias to insert -# newlines. - -ALIASES = - -# This tag can be used to specify a number of word-keyword mappings (TCL only). -# A mapping has the form "name=value". For example adding "class=itcl::class" -# will allow you to use the command class in the itcl::class meaning. +# newlines (in the resulting output). You can put ^^ in the value part of an +# alias to insert a newline as if a physical newline was in the original file. +# When you need a literal { or } or , in the value part of an alias you have to +# escape them by means of a backslash (\), this can lead to conflicts with the +# commands \{ and \} for these it is advised to use the version @{ and @} or use +# a double escape (\\{ and \\}) -TCL_SUBST = +ALIASES = # Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources # only. Doxygen will then generate output that is more tailored for C. For @@ -286,25 +312,37 @@ OPTIMIZE_FOR_FORTRAN = NO OPTIMIZE_OUTPUT_VHDL = NO +# Set the OPTIMIZE_OUTPUT_SLICE tag to YES if your project consists of Slice +# sources only. Doxygen will then generate output that is more tailored for that +# language. For instance, namespaces will be presented as modules, types will be +# separated into more groups, etc. +# The default value is: NO. + +OPTIMIZE_OUTPUT_SLICE = NO + # Doxygen selects the parser to use depending on the extension of the files it # parses. With this tag you can assign which parser to use for a given # extension. Doxygen has a built-in mapping, but you can override or extend it # using this tag. The format is ext=language, where ext is a file extension, and -# language is one of the parsers supported by doxygen: IDL, Java, Javascript, -# C#, C, C++, D, PHP, Objective-C, Python, Fortran, VHDL. For instance to make -# doxygen treat .inc files as Fortran files (default is PHP), and .f files as C -# (default is Fortran), use: inc=Fortran f=C. -# -# Note For files without extension you can use no_extension as a placeholder. -# +# language is one of the parsers supported by doxygen: IDL, Java, JavaScript, +# Csharp (C#), C, C++, D, PHP, md (Markdown), Objective-C, Python, Slice, VHDL, +# Fortran (fixed format Fortran: FortranFixed, free formatted Fortran: +# FortranFree, unknown formatted Fortran: Fortran. In the later case the parser +# tries to guess whether the code is fixed or free formatted code, this is the +# default for Fortran type files). For instance to make doxygen treat .inc files +# as Fortran files (default is PHP), and .f files as C (default is Fortran), +# use: inc=Fortran f=C. +# +# Note: For files without extension you can use no_extension as a placeholder. +# # Note that for custom extensions you also need to set FILE_PATTERNS otherwise # the files are not read by doxygen. -EXTENSION_MAPPING = +EXTENSION_MAPPING = # If the MARKDOWN_SUPPORT tag is enabled then doxygen pre-processes all comments # according to the Markdown format, which allows for more readable -# documentation. See http://daringfireball.net/projects/markdown/ for details. +# documentation. See https://daringfireball.net/projects/markdown/ for details. # The output of markdown processing is further processed by doxygen, so you can # mix doxygen, HTML, and XML commands with Markdown formatting. Disable only in # case of backward compatibilities issues. @@ -312,10 +350,19 @@ EXTENSION_MAPPING = MARKDOWN_SUPPORT = YES +# When the TOC_INCLUDE_HEADINGS tag is set to a non-zero value, all headings up +# to that level are automatically included in the table of contents, even if +# they do not have an id attribute. +# Note: This feature currently applies only to Markdown headings. +# Minimum value: 0, maximum value: 99, default value: 5. +# This tag requires that the tag MARKDOWN_SUPPORT is set to YES. + +TOC_INCLUDE_HEADINGS = 5 + # When enabled doxygen tries to link words that correspond to documented # classes, or namespaces to their corresponding documentation. Such a link can -# be prevented in individual cases by by putting a % sign in front of the word -# or globally by setting AUTOLINK_SUPPORT to NO. +# be prevented in individual cases by putting a % sign in front of the word or +# globally by setting AUTOLINK_SUPPORT to NO. # The default value is: YES. AUTOLINK_SUPPORT = YES @@ -337,7 +384,7 @@ BUILTIN_STL_SUPPORT = NO CPP_CLI_SUPPORT = NO # Set the SIP_SUPPORT tag to YES if your project consists of sip (see: -# http://www.riverbankcomputing.co.uk/software/sip/intro) sources only. Doxygen +# https://www.riverbankcomputing.com/software/sip/intro) sources only. Doxygen # will parse them like normal C++ but will assume all classes use public instead # of private inheritance when no explicit protection keyword is present. # The default value is: NO. @@ -355,13 +402,20 @@ SIP_SUPPORT = NO IDL_PROPERTY_SUPPORT = YES # If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC -# tag is set to YES, then doxygen will reuse the documentation of the first +# tag is set to YES then doxygen will reuse the documentation of the first # member in the group (if any) for the other members of the group. By default # all members of a group must be documented explicitly. # The default value is: NO. DISTRIBUTE_GROUP_DOC = NO +# If one adds a struct or class to a group and this option is enabled, then also +# any nested class or struct is added to the same group. By default this option +# is disabled and one has to add nested compounds explicitly via \ingroup. +# The default value is: NO. + +GROUP_NESTED_COMPOUNDS = NO + # Set the SUBGROUPING tag to YES to allow class member groups of the same type # (for instance a group of public functions) to be put as a subgroup of that # type (e.g. under the Public Functions section). Set it to NO to prevent @@ -375,7 +429,7 @@ SUBGROUPING = YES # are shown inside the group in which they are included (e.g. using \ingroup) # instead of on a separate page (for HTML and Man pages) or section (for LaTeX # and RTF). -# +# # Note that this feature does not work in combination with # SEPARATE_MEMBER_PAGES. # The default value is: NO. @@ -420,7 +474,7 @@ LOOKUP_CACHE_SIZE = 0 # Build related configuration options #--------------------------------------------------------------------------- -# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in +# If the EXTRACT_ALL tag is set to YES, doxygen will assume all entities in # documentation are documented, even if no documentation was available. Private # class members and static file members will be hidden unless the # EXTRACT_PRIVATE respectively EXTRACT_STATIC tags are set to YES. @@ -430,35 +484,41 @@ LOOKUP_CACHE_SIZE = 0 EXTRACT_ALL = YES -# If the EXTRACT_PRIVATE tag is set to YES all private members of a class will +# If the EXTRACT_PRIVATE tag is set to YES, all private members of a class will # be included in the documentation. # The default value is: NO. EXTRACT_PRIVATE = NO -# If the EXTRACT_PACKAGE tag is set to YES all members with package or internal +# If the EXTRACT_PRIV_VIRTUAL tag is set to YES, documented private virtual +# methods of a class will be included in the documentation. +# The default value is: NO. + +EXTRACT_PRIV_VIRTUAL = NO + +# If the EXTRACT_PACKAGE tag is set to YES, all members with package or internal # scope will be included in the documentation. # The default value is: NO. EXTRACT_PACKAGE = NO -# If the EXTRACT_STATIC tag is set to YES all static members of a file will be +# If the EXTRACT_STATIC tag is set to YES, all static members of a file will be # included in the documentation. # The default value is: NO. EXTRACT_STATIC = NO -# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) defined -# locally in source files will be included in the documentation. If set to NO +# If the EXTRACT_LOCAL_CLASSES tag is set to YES, classes (and structs) defined +# locally in source files will be included in the documentation. If set to NO, # only classes defined in header files are included. Does not have any effect # for Java sources. # The default value is: YES. EXTRACT_LOCAL_CLASSES = YES -# This flag is only useful for Objective-C code. When set to YES local methods, +# This flag is only useful for Objective-C code. If set to YES, local methods, # which are defined in the implementation section but not in the interface are -# included in the documentation. If set to NO only methods in the interface are +# included in the documentation. If set to NO, only methods in the interface are # included. # The default value is: NO. @@ -483,21 +543,21 @@ HIDE_UNDOC_MEMBERS = NO # If the HIDE_UNDOC_CLASSES tag is set to YES, doxygen will hide all # undocumented classes that are normally visible in the class hierarchy. If set -# to NO these classes will be included in the various overviews. This option has -# no effect if EXTRACT_ALL is enabled. +# to NO, these classes will be included in the various overviews. This option +# has no effect if EXTRACT_ALL is enabled. # The default value is: NO. HIDE_UNDOC_CLASSES = NO # If the HIDE_FRIEND_COMPOUNDS tag is set to YES, doxygen will hide all friend -# (class|struct|union) declarations. If set to NO these declarations will be -# included in the documentation. +# declarations. If set to NO, these declarations will be included in the +# documentation. # The default value is: NO. HIDE_FRIEND_COMPOUNDS = NO # If the HIDE_IN_BODY_DOCS tag is set to YES, doxygen will hide any -# documentation blocks found inside the body of a function. If set to NO these +# documentation blocks found inside the body of a function. If set to NO, these # blocks will be appended to the function's detailed documentation block. # The default value is: NO. @@ -511,27 +571,41 @@ HIDE_IN_BODY_DOCS = NO INTERNAL_DOCS = NO # If the CASE_SENSE_NAMES tag is set to NO then doxygen will only generate file -# names in lower-case letters. If set to YES upper-case letters are also +# names in lower-case letters. If set to YES, upper-case letters are also # allowed. This is useful if you have classes or files whose names only differ # in case and if your file system supports case sensitive file names. Windows -# and Mac users are advised to set this option to NO. +# (including Cygwin) ands Mac users are advised to set this option to NO. # The default value is: system dependent. CASE_SENSE_NAMES = NO # If the HIDE_SCOPE_NAMES tag is set to NO then doxygen will show members with -# their full class and namespace scopes in the documentation. If set to YES the +# their full class and namespace scopes in the documentation. If set to YES, the # scope will be hidden. # The default value is: NO. HIDE_SCOPE_NAMES = NO +# If the HIDE_COMPOUND_REFERENCE tag is set to NO (default) then doxygen will +# append additional text to a page's title, such as Class Reference. If set to +# YES the compound reference will be hidden. +# The default value is: NO. + +HIDE_COMPOUND_REFERENCE= NO + # If the SHOW_INCLUDE_FILES tag is set to YES then doxygen will put a list of # the files that are included by a file in the documentation of that file. # The default value is: YES. SHOW_INCLUDE_FILES = YES +# If the SHOW_GROUPED_MEMB_INC tag is set to YES then Doxygen will add for each +# grouped member an include statement to the documentation, telling the reader +# which file to include in order to use the member. +# The default value is: NO. + +SHOW_GROUPED_MEMB_INC = NO + # If the FORCE_LOCAL_INCLUDES tag is set to YES then doxygen will list include # files with double quotes in the documentation rather than with sharp brackets. # The default value is: NO. @@ -546,14 +620,15 @@ INLINE_INFO = YES # If the SORT_MEMBER_DOCS tag is set to YES then doxygen will sort the # (detailed) documentation of file and class members alphabetically by member -# name. If set to NO the members will appear in declaration order. +# name. If set to NO, the members will appear in declaration order. # The default value is: YES. SORT_MEMBER_DOCS = YES # If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the brief # descriptions of file, namespace and class members alphabetically by member -# name. If set to NO the members will appear in declaration order. +# name. If set to NO, the members will appear in declaration order. Note that +# this will also influence the order of the classes in the class list. # The default value is: NO. SORT_BRIEF_DOCS = NO @@ -597,27 +672,25 @@ SORT_BY_SCOPE_NAME = NO STRICT_PROTO_MATCHING = NO -# The GENERATE_TODOLIST tag can be used to enable ( YES) or disable ( NO) the -# todo list. This list is created by putting \todo commands in the -# documentation. +# The GENERATE_TODOLIST tag can be used to enable (YES) or disable (NO) the todo +# list. This list is created by putting \todo commands in the documentation. # The default value is: YES. GENERATE_TODOLIST = YES -# The GENERATE_TESTLIST tag can be used to enable ( YES) or disable ( NO) the -# test list. This list is created by putting \test commands in the -# documentation. +# The GENERATE_TESTLIST tag can be used to enable (YES) or disable (NO) the test +# list. This list is created by putting \test commands in the documentation. # The default value is: YES. GENERATE_TESTLIST = YES -# The GENERATE_BUGLIST tag can be used to enable ( YES) or disable ( NO) the bug +# The GENERATE_BUGLIST tag can be used to enable (YES) or disable (NO) the bug # list. This list is created by putting \bug commands in the documentation. # The default value is: YES. GENERATE_BUGLIST = YES -# The GENERATE_DEPRECATEDLIST tag can be used to enable ( YES) or disable ( NO) +# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or disable (NO) # the deprecated list. This list is created by putting \deprecated commands in # the documentation. # The default value is: YES. @@ -628,7 +701,7 @@ GENERATE_DEPRECATEDLIST= YES # sections, marked by \if ... \endif and \cond # ... \endcond blocks. -ENABLED_SECTIONS = +ENABLED_SECTIONS = # The MAX_INITIALIZER_LINES tag determines the maximum number of lines that the # initial value of a variable or macro / define can have for it to appear in the @@ -642,8 +715,8 @@ ENABLED_SECTIONS = MAX_INITIALIZER_LINES = 30 # Set the SHOW_USED_FILES tag to NO to disable the list of files generated at -# the bottom of the documentation of classes and structs. If set to YES the list -# will mention the files that were used to generate the documentation. +# the bottom of the documentation of classes and structs. If set to YES, the +# list will mention the files that were used to generate the documentation. # The default value is: YES. SHOW_USED_FILES = YES @@ -670,7 +743,7 @@ SHOW_NAMESPACES = YES # by doxygen. Whatever the program writes to standard output is used as the file # version. For an example see the documentation. -FILE_VERSION_FILTER = +FILE_VERSION_FILTER = # The LAYOUT_FILE tag can be used to specify a layout file which will be parsed # by doxygen. The layout file controls the global structure of the generated @@ -678,23 +751,22 @@ FILE_VERSION_FILTER = # that represents doxygen's defaults, run doxygen with the -l option. You can # optionally specify a file name after the option, if omitted DoxygenLayout.xml # will be used as the name of the layout file. -# +# # Note that if you run doxygen from a directory containing a file called # DoxygenLayout.xml, doxygen will parse it automatically even if the LAYOUT_FILE # tag is left empty. -LAYOUT_FILE = +LAYOUT_FILE = # The CITE_BIB_FILES tag can be used to specify one or more bib files containing # the reference definitions. This must be a list of .bib files. The .bib # extension is automatically appended if omitted. This requires the bibtex tool -# to be installed. See also http://en.wikipedia.org/wiki/BibTeX for more info. +# to be installed. See also https://en.wikipedia.org/wiki/BibTeX for more info. # For LaTeX the style of the bibliography can be controlled using # LATEX_BIB_STYLE. To use this feature you need bibtex and perl available in the -# search path. Do not use file names with spaces, bibtex cannot handle them. See -# also \cite for info how to create references. +# search path. See also \cite for info how to create references. -CITE_BIB_FILES = +CITE_BIB_FILES = #--------------------------------------------------------------------------- # Configuration options related to warning and progress messages @@ -708,15 +780,15 @@ CITE_BIB_FILES = QUIET = NO # The WARNINGS tag can be used to turn on/off the warning messages that are -# generated to standard error ( stderr) by doxygen. If WARNINGS is set to YES +# generated to standard error (stderr) by doxygen. If WARNINGS is set to YES # this implies that the warnings are on. -# +# # Tip: Turn warnings on while writing the documentation. # The default value is: YES. WARNINGS = YES -# If the WARN_IF_UNDOCUMENTED tag is set to YES, then doxygen will generate +# If the WARN_IF_UNDOCUMENTED tag is set to YES then doxygen will generate # warnings for undocumented members. If EXTRACT_ALL is set to YES then this flag # will automatically be disabled. # The default value is: YES. @@ -733,12 +805,19 @@ WARN_IF_DOC_ERROR = YES # This WARN_NO_PARAMDOC option can be enabled to get warnings for functions that # are documented, but have no documentation for their parameters or return -# value. If set to NO doxygen will only warn about wrong or incomplete parameter -# documentation, but not about the absence of documentation. +# value. If set to NO, doxygen will only warn about wrong or incomplete +# parameter documentation, but not about the absence of documentation. If +# EXTRACT_ALL is set to YES then this flag will automatically be disabled. # The default value is: NO. WARN_NO_PARAMDOC = NO +# If the WARN_AS_ERROR tag is set to YES then doxygen will immediately stop when +# a warning is encountered. +# The default value is: NO. + +WARN_AS_ERROR = NO + # The WARN_FORMAT tag determines the format of the warning messages that doxygen # can produce. The string should contain the $file, $line, and $text tags, which # will be replaced by the file and line number from which the warning originated @@ -753,7 +832,7 @@ WARN_FORMAT = "$file:$line: $text" # messages should be written. If left blank the output is written to standard # error (stderr). -WARN_LOGFILE = +WARN_LOGFILE = #--------------------------------------------------------------------------- # Configuration options related to the input files @@ -762,15 +841,15 @@ WARN_LOGFILE = # The INPUT tag is used to specify the files and/or directories that contain # documented source files. You may enter file names like myfile.cpp or # directories like /usr/src/myproject. Separate the files or directories with -# spaces. +# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING # Note: If this tag is empty the current directory is searched. -INPUT = +INPUT = # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses # libiconv (or the iconv built into libc) for the transcoding. See the libiconv -# documentation (see: http://www.gnu.org/software/libiconv) for the list of +# documentation (see: https://www.gnu.org/software/libiconv/) for the list of # possible encodings. # The default value is: UTF-8. @@ -778,12 +857,19 @@ INPUT_ENCODING = UTF-8 # If the value of the INPUT tag contains directories, you can use the # FILE_PATTERNS tag to specify one or more wildcard patterns (like *.cpp and -# *.h) to filter out the source-files in the directories. If left blank the -# following patterns are tested:*.c, *.cc, *.cxx, *.cpp, *.c++, *.java, *.ii, -# *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h, *.hh, *.hxx, *.hpp, -# *.h++, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, *.inc, *.m, *.markdown, -# *.md, *.mm, *.dox, *.py, *.f90, *.f, *.for, *.tcl, *.vhd, *.vhdl, *.ucf, -# *.qsf, *.as and *.js. +# *.h) to filter out the source-files in the directories. +# +# Note that for custom extensions or not directly supported extensions you also +# need to set EXTENSION_MAPPING for the extension otherwise the files are not +# read by doxygen. +# +# If left blank the following patterns are tested:*.c, *.cc, *.cxx, *.cpp, +# *.c++, *.java, *.ii, *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h, +# *.hh, *.hxx, *.hpp, *.h++, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, *.inc, +# *.m, *.markdown, *.md, *.mm, *.dox (to be provided as doxygen C comment), +# *.doc (to be provided as doxygen C comment), *.txt (to be provided as doxygen +# C comment), *.py, *.pyw, *.f90, *.f95, *.f03, *.f08, *.f18, *.f, *.for, *.vhd, +# *.vhdl, *.ucf, *.qsf and *.ice. FILE_PATTERNS = *.c \ *.cc \ @@ -837,11 +923,11 @@ RECURSIVE = YES # The EXCLUDE tag can be used to specify files and/or directories that should be # excluded from the INPUT source files. This way you can easily exclude a # subdirectory from a directory tree whose root is specified with the INPUT tag. -# +# # Note that relative paths are relative to the directory from which doxygen is # run. -EXCLUDE = +EXCLUDE = # The EXCLUDE_SYMLINKS tag can be used to select whether or not files or # directories that are symbolic links (a Unix file system feature) are excluded @@ -853,28 +939,28 @@ EXCLUDE_SYMLINKS = NO # If the value of the INPUT tag contains directories, you can use the # EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude # certain files from those directories. -# +# # Note that the wildcards are matched against the file with absolute path, so to # exclude all test directories for example use the pattern */test/* -EXCLUDE_PATTERNS = +EXCLUDE_PATTERNS = # The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names # (namespaces, classes, functions, etc.) that should be excluded from the # output. The symbol name can be a fully qualified name, a word, or if the # wildcard * is used, a substring. Examples: ANamespace, AClass, # AClass::ANamespace, ANamespace::*Test -# +# # Note that the wildcards are matched against the file with absolute path, so to # exclude all test directories use the pattern */test/* -EXCLUDE_SYMBOLS = +EXCLUDE_SYMBOLS = # The EXAMPLE_PATH tag can be used to specify one or more files or directories # that contain example code fragments that are included (see the \include # command). -EXAMPLE_PATH = +EXAMPLE_PATH = # If the value of the EXAMPLE_PATH tag contains directories, you can use the # EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and @@ -894,24 +980,28 @@ EXAMPLE_RECURSIVE = NO # that contain images that are to be included in the documentation (see the # \image command). -IMAGE_PATH = +IMAGE_PATH = # The INPUT_FILTER tag can be used to specify a program that doxygen should # invoke to filter for each input file. Doxygen will invoke the filter program # by executing (via popen()) the command: -# +# # -# +# # where is the value of the INPUT_FILTER tag, and is the # name of an input file. Doxygen will then use the output that the filter # program writes to standard output. If FILTER_PATTERNS is specified, this tag # will be ignored. -# +# # Note that the filter must not add or remove lines; it is applied before the # code is scanned, but not when the output code is generated. If lines are added # or removed, the anchors will not be placed correctly. +# +# Note that for custom extensions or not directly supported extensions you also +# need to set EXTENSION_MAPPING for the extension otherwise the files are not +# properly processed by doxygen. -INPUT_FILTER = +INPUT_FILTER = # The FILTER_PATTERNS tag can be used to specify filters on a per file pattern # basis. Doxygen will compare the file name with each pattern and apply the @@ -919,11 +1009,15 @@ INPUT_FILTER = # (like *.cpp=my_cpp_filter). See INPUT_FILTER for further information on how # filters are used. If the FILTER_PATTERNS tag is empty or if none of the # patterns match the file name, INPUT_FILTER is applied. +# +# Note that for custom extensions or not directly supported extensions you also +# need to set EXTENSION_MAPPING for the extension otherwise the files are not +# properly processed by doxygen. -FILTER_PATTERNS = +FILTER_PATTERNS = # If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using -# INPUT_FILTER ) will also be used to filter the input files that are used for +# INPUT_FILTER) will also be used to filter the input files that are used for # producing the source files to browse (i.e. when SOURCE_BROWSER is set to YES). # The default value is: NO. @@ -935,14 +1029,14 @@ FILTER_SOURCE_FILES = NO # *.ext= (so without naming a filter). # This tag requires that the tag FILTER_SOURCE_FILES is set to YES. -FILTER_SOURCE_PATTERNS = +FILTER_SOURCE_PATTERNS = # If the USE_MDFILE_AS_MAINPAGE tag refers to the name of a markdown file that # is part of the input, its contents will be placed on the main page # (index.html). This can be useful if you have a project on for instance GitHub # and want to reuse the introduction page also for the doxygen output. -USE_MDFILE_AS_MAINPAGE = +USE_MDFILE_AS_MAINPAGE = #--------------------------------------------------------------------------- # Configuration options related to source browsing @@ -950,7 +1044,7 @@ USE_MDFILE_AS_MAINPAGE = # If the SOURCE_BROWSER tag is set to YES then a list of source files will be # generated. Documented entities will be cross-referenced with these sources. -# +# # Note: To get rid of all source code in the generated output, make sure that # also VERBATIM_HEADERS is set to NO. # The default value is: NO. @@ -971,7 +1065,7 @@ INLINE_SOURCES = NO STRIP_CODE_COMMENTS = YES # If the REFERENCED_BY_RELATION tag is set to YES then for each documented -# function all documented functions referencing it will be listed. +# entity all documented functions referencing it will be listed. # The default value is: NO. REFERENCED_BY_RELATION = NO @@ -983,7 +1077,7 @@ REFERENCED_BY_RELATION = NO REFERENCES_RELATION = NO # If the REFERENCES_LINK_SOURCE tag is set to YES and SOURCE_BROWSER tag is set -# to YES, then the hyperlinks from functions in REFERENCES_RELATION and +# to YES then the hyperlinks from functions in REFERENCES_RELATION and # REFERENCED_BY_RELATION lists will link to the source code. Otherwise they will # link to the documentation. # The default value is: YES. @@ -1003,18 +1097,18 @@ SOURCE_TOOLTIPS = YES # If the USE_HTAGS tag is set to YES then the references to source code will # point to the HTML generated by the htags(1) tool instead of doxygen built-in # source browser. The htags tool is part of GNU's global source tagging system -# (see http://www.gnu.org/software/global/global.html). You will need version +# (see https://www.gnu.org/software/global/global.html). You will need version # 4.8.6 or higher. -# +# # To use it do the following: # - Install the latest version of global -# - Enable SOURCE_BROWSER and USE_HTAGS in the config file +# - Enable SOURCE_BROWSER and USE_HTAGS in the configuration file # - Make sure the INPUT points to the root of the source tree # - Run doxygen as normal -# +# # Doxygen will invoke htags (and that will in turn invoke gtags), so these # tools must be available from the command line (i.e. in the search path). -# +# # The result: instead of the source browser generated by doxygen, the links to # source code will now point to the output of htags. # The default value is: NO. @@ -1054,13 +1148,13 @@ COLS_IN_ALPHA_INDEX = 5 # while generating the index headers. # This tag requires that the tag ALPHABETICAL_INDEX is set to YES. -IGNORE_PREFIX = +IGNORE_PREFIX = #--------------------------------------------------------------------------- # Configuration options related to the HTML output #--------------------------------------------------------------------------- -# If the GENERATE_HTML tag is set to YES doxygen will generate HTML output +# If the GENERATE_HTML tag is set to YES, doxygen will generate HTML output # The default value is: YES. GENERATE_HTML = YES @@ -1083,7 +1177,7 @@ HTML_FILE_EXTENSION = .html # The HTML_HEADER tag can be used to specify a user-defined HTML header file for # each generated HTML page. If the tag is left blank doxygen will generate a # standard header. -# +# # To get valid HTML the header file that includes any scripts and style sheets # that doxygen needs, which is dependent on the configuration options used (e.g. # the setting GENERATE_TREEVIEW). It is highly recommended to start with a @@ -1098,7 +1192,7 @@ HTML_FILE_EXTENSION = .html # of the possible markers and block names see the documentation. # This tag requires that the tag GENERATE_HTML is set to YES. -HTML_HEADER = +HTML_HEADER = # The HTML_FOOTER tag can be used to specify a user-defined HTML footer for each # generated HTML page. If the tag is left blank doxygen will generate a standard @@ -1108,7 +1202,7 @@ HTML_HEADER = # that doxygen normally uses. # This tag requires that the tag GENERATE_HTML is set to YES. -HTML_FOOTER = +HTML_FOOTER = # The HTML_STYLESHEET tag can be used to specify a user-defined cascading style # sheet that is used by each HTML page. It can be used to fine-tune the look of @@ -1120,18 +1214,20 @@ HTML_FOOTER = # obsolete. # This tag requires that the tag GENERATE_HTML is set to YES. -HTML_STYLESHEET = +HTML_STYLESHEET = -# The HTML_EXTRA_STYLESHEET tag can be used to specify an additional user- -# defined cascading style sheet that is included after the standard style sheets +# The HTML_EXTRA_STYLESHEET tag can be used to specify additional user-defined +# cascading style sheets that are included after the standard style sheets # created by doxygen. Using this option one can overrule certain style aspects. # This is preferred over using HTML_STYLESHEET since it does not replace the -# standard style sheet and is therefor more robust against future updates. -# Doxygen will copy the style sheet file to the output directory. For an example -# see the documentation. +# standard style sheet and is therefore more robust against future updates. +# Doxygen will copy the style sheet files to the output directory. +# Note: The order of the extra style sheet files is of importance (e.g. the last +# style sheet in the list overrules the setting of the previous ones in the +# list). For an example see the documentation. # This tag requires that the tag GENERATE_HTML is set to YES. -HTML_EXTRA_STYLESHEET = +HTML_EXTRA_STYLESHEET = # The HTML_EXTRA_FILES tag can be used to specify one or more extra images or # other source files which should be copied to the HTML output directory. Note @@ -1141,12 +1237,12 @@ HTML_EXTRA_STYLESHEET = # files will be copied as-is; there are no commands or markers available. # This tag requires that the tag GENERATE_HTML is set to YES. -HTML_EXTRA_FILES = +HTML_EXTRA_FILES = # The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. Doxygen -# will adjust the colors in the stylesheet and background images according to +# will adjust the colors in the style sheet and background images according to # this color. Hue is specified as an angle on a colorwheel, see -# http://en.wikipedia.org/wiki/Hue for more information. For instance the value +# https://en.wikipedia.org/wiki/Hue for more information. For instance the value # 0 represents red, 60 is yellow, 120 is green, 180 is cyan, 240 is blue, 300 # purple, and 360 is red again. # Minimum value: 0, maximum value: 359, default value: 220. @@ -1175,12 +1271,24 @@ HTML_COLORSTYLE_GAMMA = 80 # If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML # page will contain the date and time when the page was generated. Setting this -# to NO can help when comparing the output of multiple runs. -# The default value is: YES. +# to YES can help to show when doxygen was last run and thus if the +# documentation is up to date. +# The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_TIMESTAMP = YES +# If the HTML_DYNAMIC_MENUS tag is set to YES then the generated HTML +# documentation will contain a main index with vertical navigation menus that +# are dynamically created via JavaScript. If disabled, the navigation index will +# consists of multiple levels of tabs that are statically embedded in every HTML +# page. Disable this option to support browsers that do not have JavaScript, +# like the Qt help browser. +# The default value is: YES. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_DYNAMIC_MENUS = YES + # If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML # documentation will contain sections that can be hidden and shown after the # page has loaded. @@ -1204,13 +1312,13 @@ HTML_INDEX_NUM_ENTRIES = 100 # If the GENERATE_DOCSET tag is set to YES, additional index files will be # generated that can be used as input for Apple's Xcode 3 integrated development -# environment (see: http://developer.apple.com/tools/xcode/), introduced with -# OSX 10.5 (Leopard). To create a documentation set, doxygen will generate a +# environment (see: https://developer.apple.com/xcode/), introduced with OSX +# 10.5 (Leopard). To create a documentation set, doxygen will generate a # Makefile in the HTML output directory. Running make will produce the docset in # that directory and running make install will install the docset in # ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at -# startup. See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html -# for more information. +# startup. See https://developer.apple.com/library/archive/featuredarticles/Doxy +# genXcode/_index.html for more information. # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. @@ -1249,9 +1357,9 @@ DOCSET_PUBLISHER_NAME = Publisher # If the GENERATE_HTMLHELP tag is set to YES then doxygen generates three # additional HTML index files: index.hhp, index.hhc, and index.hhk. The # index.hhp is a project file that can be read by Microsoft's HTML Help Workshop -# (see: http://www.microsoft.com/en-us/download/details.aspx?id=21138) on +# (see: https://www.microsoft.com/en-us/download/details.aspx?id=21138) on # Windows. -# +# # The HTML Help Workshop contains a compiler that can convert all HTML output # generated by doxygen into a single compiled HTML file (.chm). Compiled HTML # files are now used as the Windows 98 help format, and will replace the old @@ -1269,31 +1377,32 @@ GENERATE_HTMLHELP = NO # written to the html output directory. # This tag requires that the tag GENERATE_HTMLHELP is set to YES. -CHM_FILE = +CHM_FILE = # The HHC_LOCATION tag can be used to specify the location (absolute path -# including file name) of the HTML help compiler ( hhc.exe). If non-empty +# including file name) of the HTML help compiler (hhc.exe). If non-empty, # doxygen will try to run the HTML help compiler on the generated index.hhp. # The file has to be specified with full path. # This tag requires that the tag GENERATE_HTMLHELP is set to YES. -HHC_LOCATION = +HHC_LOCATION = -# The GENERATE_CHI flag controls if a separate .chi index file is generated ( -# YES) or that it should be included in the master .chm file ( NO). +# The GENERATE_CHI flag controls if a separate .chi index file is generated +# (YES) or that it should be included in the master .chm file (NO). # The default value is: NO. # This tag requires that the tag GENERATE_HTMLHELP is set to YES. GENERATE_CHI = NO -# The CHM_INDEX_ENCODING is used to encode HtmlHelp index ( hhk), content ( hhc) +# The CHM_INDEX_ENCODING is used to encode HtmlHelp index (hhk), content (hhc) # and project file content. # This tag requires that the tag GENERATE_HTMLHELP is set to YES. -CHM_INDEX_ENCODING = +CHM_INDEX_ENCODING = -# The BINARY_TOC flag controls whether a binary table of contents is generated ( -# YES) or a normal table of contents ( NO) in the .chm file. +# The BINARY_TOC flag controls whether a binary table of contents is generated +# (YES) or a normal table of contents (NO) in the .chm file. Furthermore it +# enables the Previous and Next buttons. # The default value is: NO. # This tag requires that the tag GENERATE_HTMLHELP is set to YES. @@ -1320,11 +1429,11 @@ GENERATE_QHP = NO # the HTML output folder. # This tag requires that the tag GENERATE_QHP is set to YES. -QCH_FILE = +QCH_FILE = # The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help # Project output. For more information please see Qt Help Project / Namespace -# (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#namespace). +# (see: https://doc.qt.io/archives/qt-4.8/qthelpproject.html#namespace). # The default value is: org.doxygen.Project. # This tag requires that the tag GENERATE_QHP is set to YES. @@ -1332,7 +1441,7 @@ QHP_NAMESPACE = org.doxygen.Project # The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt # Help Project output. For more information please see Qt Help Project / Virtual -# Folders (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#virtual- +# Folders (see: https://doc.qt.io/archives/qt-4.8/qthelpproject.html#virtual- # folders). # The default value is: doc. # This tag requires that the tag GENERATE_QHP is set to YES. @@ -1341,33 +1450,33 @@ QHP_VIRTUAL_FOLDER = doc # If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom # filter to add. For more information please see Qt Help Project / Custom -# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom- +# Filters (see: https://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom- # filters). # This tag requires that the tag GENERATE_QHP is set to YES. -QHP_CUST_FILTER_NAME = +QHP_CUST_FILTER_NAME = # The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the # custom filter to add. For more information please see Qt Help Project / Custom -# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom- +# Filters (see: https://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom- # filters). # This tag requires that the tag GENERATE_QHP is set to YES. -QHP_CUST_FILTER_ATTRS = +QHP_CUST_FILTER_ATTRS = # The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this # project's filter section matches. Qt Help Project / Filter Attributes (see: -# http://qt-project.org/doc/qt-4.8/qthelpproject.html#filter-attributes). +# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#filter-attributes). # This tag requires that the tag GENERATE_QHP is set to YES. -QHP_SECT_FILTER_ATTRS = +QHP_SECT_FILTER_ATTRS = # The QHG_LOCATION tag can be used to specify the location of Qt's # qhelpgenerator. If non-empty doxygen will try to run qhelpgenerator on the # generated .qhp file. # This tag requires that the tag GENERATE_QHP is set to YES. -QHG_LOCATION = +QHG_LOCATION = # If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files will be # generated, together with the HTML files, they form an Eclipse help plugin. To @@ -1406,7 +1515,7 @@ DISABLE_INDEX = NO # index structure (just like the one that is generated for HTML Help). For this # to work a browser that supports JavaScript, DHTML, CSS and frames is required # (i.e. any modern browser). Windows users are probably better off using the -# HTML help feature. Via custom stylesheets (see HTML_EXTRA_STYLESHEET) one can +# HTML help feature. Via custom style sheets (see HTML_EXTRA_STYLESHEET) one can # further fine-tune the look of the index. As an example, the default style # sheet generated by doxygen has an example that shows how to put an image at # the root of the tree instead of the PROJECT_NAME. Since the tree basically has @@ -1419,7 +1528,7 @@ GENERATE_TREEVIEW = NO # The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that # doxygen will group on one line in the generated HTML documentation. -# +# # Note that a value of 0 will completely suppress the enum values from appearing # in the overview section. # Minimum value: 0, maximum value: 20, default value: 4. @@ -1434,13 +1543,24 @@ ENUM_VALUES_PER_LINE = 4 TREEVIEW_WIDTH = 250 -# When the EXT_LINKS_IN_WINDOW option is set to YES doxygen will open links to +# If the EXT_LINKS_IN_WINDOW option is set to YES, doxygen will open links to # external symbols imported via tag files in a separate window. # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. EXT_LINKS_IN_WINDOW = NO +# If the HTML_FORMULA_FORMAT option is set to svg, doxygen will use the pdf2svg +# tool (see https://github.com/dawbarton/pdf2svg) or inkscape (see +# https://inkscape.org) to generate formulas as SVG images instead of PNGs for +# the HTML output. These images will generally look nicer at scaled resolutions. +# Possible values are: png The default and svg Looks nicer but requires the +# pdf2svg tool. +# The default value is: png. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_FORMULA_FORMAT = svg + # Use this tag to change the font size of LaTeX formulas included as images in # the HTML documentation. When you change the font size after a successful # doxygen run you need to manually remove any form_*.png images from the HTML @@ -1450,10 +1570,10 @@ EXT_LINKS_IN_WINDOW = NO FORMULA_FONTSIZE = 10 -# Use the FORMULA_TRANPARENT tag to determine whether or not the images +# Use the FORMULA_TRANSPARENT tag to determine whether or not the images # generated for formulas are transparent PNGs. Transparent PNGs are not # supported properly for IE 6.0, but are supported on all modern browsers. -# +# # Note that when changing this option you need to delete any form_*.png files in # the HTML output directory before the changes have effect. # The default value is: YES. @@ -1461,16 +1581,22 @@ FORMULA_FONTSIZE = 10 FORMULA_TRANSPARENT = YES +# The FORMULA_MACROFILE can contain LaTeX \newcommand and \renewcommand commands +# to create new LaTeX commands to be used in formulas as building blocks. See +# the section "Including formulas" for details. + +FORMULA_MACROFILE = + # Enable the USE_MATHJAX option to render LaTeX formulas using MathJax (see -# http://www.mathjax.org) which uses client side Javascript for the rendering -# instead of using prerendered bitmaps. Use this if you do not have LaTeX +# https://www.mathjax.org) which uses client side JavaScript for the rendering +# instead of using pre-rendered bitmaps. Use this if you do not have LaTeX # installed or if you want to formulas look prettier in the HTML output. When # enabled you may also need to install MathJax separately and configure the path # to it using the MATHJAX_RELPATH option. # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. -USE_MATHJAX = NO +USE_MATHJAX = YES # When MathJax is enabled you can set the default output format to be used for # the MathJax output. See the MathJax site (see: @@ -1489,8 +1615,8 @@ MATHJAX_FORMAT = HTML-CSS # MATHJAX_RELPATH should be ../mathjax. The default value points to the MathJax # Content Delivery Network so you can quickly see the result without installing # MathJax. However, it is strongly recommended to install a local copy of -# MathJax from http://www.mathjax.org before deployment. -# The default value is: http://cdn.mathjax.org/mathjax/latest. +# MathJax from https://www.mathjax.org before deployment. +# The default value is: https://cdn.jsdelivr.net/npm/mathjax@2. # This tag requires that the tag USE_MATHJAX is set to YES. MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest @@ -1500,7 +1626,7 @@ MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest # MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols # This tag requires that the tag USE_MATHJAX is set to YES. -MATHJAX_EXTENSIONS = +MATHJAX_EXTENSIONS = # The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces # of code that will be used on startup of the MathJax code. See the MathJax site @@ -1508,7 +1634,7 @@ MATHJAX_EXTENSIONS = # example see the documentation. # This tag requires that the tag USE_MATHJAX is set to YES. -MATHJAX_CODEFILE = +MATHJAX_CODEFILE = # When the SEARCHENGINE tag is enabled doxygen will generate a search box for # the HTML output. The underlying search engine uses javascript and DHTML and @@ -1532,12 +1658,12 @@ MATHJAX_CODEFILE = SEARCHENGINE = YES # When the SERVER_BASED_SEARCH tag is enabled the search engine will be -# implemented using a web server instead of a web client using Javascript. There -# are two flavours of web server based searching depending on the -# EXTERNAL_SEARCH setting. When disabled, doxygen will generate a PHP script for -# searching and an index file used by the script. When EXTERNAL_SEARCH is -# enabled the indexing and searching needs to be provided by external tools. See -# the section "External Indexing and Searching" for details. +# implemented using a web server instead of a web client using JavaScript. There +# are two flavors of web server based searching depending on the EXTERNAL_SEARCH +# setting. When disabled, doxygen will generate a PHP script for searching and +# an index file used by the script. When EXTERNAL_SEARCH is enabled the indexing +# and searching needs to be provided by external tools. See the section +# "External Indexing and Searching" for details. # The default value is: NO. # This tag requires that the tag SEARCHENGINE is set to YES. @@ -1548,11 +1674,11 @@ SERVER_BASED_SEARCH = NO # which needs to be processed by an external indexer. Doxygen will invoke an # external search engine pointed to by the SEARCHENGINE_URL option to obtain the # search results. -# -# Doxygen ships with an example indexer ( doxyindexer) and search engine +# +# Doxygen ships with an example indexer (doxyindexer) and search engine # (doxysearch.cgi) which are based on the open source search engine library -# Xapian (see: http://xapian.org/). -# +# Xapian (see: https://xapian.org/). +# # See the section "External Indexing and Searching" for details. # The default value is: NO. # This tag requires that the tag SEARCHENGINE is set to YES. @@ -1561,14 +1687,14 @@ EXTERNAL_SEARCH = NO # The SEARCHENGINE_URL should point to a search engine hosted by a web server # which will return the search results when EXTERNAL_SEARCH is enabled. -# -# Doxygen ships with an example indexer ( doxyindexer) and search engine +# +# Doxygen ships with an example indexer (doxyindexer) and search engine # (doxysearch.cgi) which are based on the open source search engine library -# Xapian (see: http://xapian.org/). See the section "External Indexing and +# Xapian (see: https://xapian.org/). See the section "External Indexing and # Searching" for details. # This tag requires that the tag SEARCHENGINE is set to YES. -SEARCHENGINE_URL = +SEARCHENGINE_URL = # When SERVER_BASED_SEARCH and EXTERNAL_SEARCH are both enabled the unindexed # search data is written to a file for indexing by an external tool. With the @@ -1584,7 +1710,7 @@ SEARCHDATA_FILE = searchdata.xml # projects and redirect the results back to the right project. # This tag requires that the tag SEARCHENGINE is set to YES. -EXTERNAL_SEARCH_ID = +EXTERNAL_SEARCH_ID = # The EXTRA_SEARCH_MAPPINGS tag can be used to enable searching through doxygen # projects other than the one defined by this configuration file, but that are @@ -1594,13 +1720,13 @@ EXTERNAL_SEARCH_ID = # EXTRA_SEARCH_MAPPINGS = tagname1=loc1 tagname2=loc2 ... # This tag requires that the tag SEARCHENGINE is set to YES. -EXTRA_SEARCH_MAPPINGS = +EXTRA_SEARCH_MAPPINGS = #--------------------------------------------------------------------------- # Configuration options related to the LaTeX output #--------------------------------------------------------------------------- -# If the GENERATE_LATEX tag is set to YES doxygen will generate LaTeX output. +# If the GENERATE_LATEX tag is set to YES, doxygen will generate LaTeX output. # The default value is: YES. GENERATE_LATEX = YES @@ -1615,23 +1741,37 @@ LATEX_OUTPUT = latex # The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be # invoked. -# -# Note that when enabling USE_PDFLATEX this option is only used for generating -# bitmaps for formulas in the HTML output, but not in the Makefile that is -# written to the output directory. -# The default file is: latex. +# +# Note that when not enabling USE_PDFLATEX the default is latex when enabling +# USE_PDFLATEX the default is pdflatex and when in the later case latex is +# chosen this is overwritten by pdflatex. For specific output languages the +# default can have been set differently, this depends on the implementation of +# the output language. # This tag requires that the tag GENERATE_LATEX is set to YES. -LATEX_CMD_NAME = latex +LATEX_CMD_NAME = pdflatex # The MAKEINDEX_CMD_NAME tag can be used to specify the command name to generate # index for LaTeX. +# Note: This tag is used in the Makefile / make.bat. +# See also: LATEX_MAKEINDEX_CMD for the part in the generated output file +# (.tex). # The default file is: makeindex. # This tag requires that the tag GENERATE_LATEX is set to YES. MAKEINDEX_CMD_NAME = makeindex -# If the COMPACT_LATEX tag is set to YES doxygen generates more compact LaTeX +# The LATEX_MAKEINDEX_CMD tag can be used to specify the command name to +# generate index for LaTeX. In case there is no backslash (\) as first character +# it will be automatically added in the LaTeX code. +# Note: This tag is used in the generated output file (.tex). +# See also: MAKEINDEX_CMD_NAME for the part in the Makefile / make.bat. +# The default value is: makeindex. +# This tag requires that the tag GENERATE_LATEX is set to YES. + +LATEX_MAKEINDEX_CMD = makeindex + +# If the COMPACT_LATEX tag is set to YES, doxygen generates more compact LaTeX # documents. This may be useful for small projects and may help to save some # trees in general. # The default value is: NO. @@ -1646,41 +1786,57 @@ COMPACT_LATEX = NO # The default value is: a4. # This tag requires that the tag GENERATE_LATEX is set to YES. -PAPER_TYPE = a4 +PAPER_TYPE = letter # The EXTRA_PACKAGES tag can be used to specify one or more LaTeX package names -# that should be included in the LaTeX output. To get the times font for -# instance you can specify -# EXTRA_PACKAGES=times +# that should be included in the LaTeX output. The package can be specified just +# by its name or with the correct syntax as to be used with the LaTeX +# \usepackage command. To get the times font for instance you can specify : +# EXTRA_PACKAGES=times or EXTRA_PACKAGES={times} +# To use the option intlimits with the amsmath package you can specify: +# EXTRA_PACKAGES=[intlimits]{amsmath} # If left blank no extra packages will be included. # This tag requires that the tag GENERATE_LATEX is set to YES. -EXTRA_PACKAGES = +EXTRA_PACKAGES = # The LATEX_HEADER tag can be used to specify a personal LaTeX header for the # generated LaTeX document. The header should contain everything until the first # chapter. If it is left blank doxygen will generate a standard header. See # section "Doxygen usage" for information on how to let doxygen write the # default header to a separate file. -# +# # Note: Only use a user-defined header if you know what you are doing! The # following commands have a special meaning inside the header: $title, -# $datetime, $date, $doxygenversion, $projectname, $projectnumber. Doxygen will -# replace them by respectively the title of the page, the current date and time, -# only the current date, the version number of doxygen, the project name (see -# PROJECT_NAME), or the project number (see PROJECT_NUMBER). +# $datetime, $date, $doxygenversion, $projectname, $projectnumber, +# $projectbrief, $projectlogo. Doxygen will replace $title with the empty +# string, for the replacement values of the other commands the user is referred +# to HTML_HEADER. # This tag requires that the tag GENERATE_LATEX is set to YES. -LATEX_HEADER = +LATEX_HEADER = # The LATEX_FOOTER tag can be used to specify a personal LaTeX footer for the # generated LaTeX document. The footer should contain everything after the last -# chapter. If it is left blank doxygen will generate a standard footer. -# +# chapter. If it is left blank doxygen will generate a standard footer. See +# LATEX_HEADER for more information on how to generate a default footer and what +# special commands can be used inside the footer. +# # Note: Only use a user-defined footer if you know what you are doing! # This tag requires that the tag GENERATE_LATEX is set to YES. -LATEX_FOOTER = +LATEX_FOOTER = + +# The LATEX_EXTRA_STYLESHEET tag can be used to specify additional user-defined +# LaTeX style sheets that are included after the standard style sheets created +# by doxygen. Using this option one can overrule certain style aspects. Doxygen +# will copy the style sheet files to the output directory. +# Note: The order of the extra style sheet files is of importance (e.g. the last +# style sheet in the list overrules the setting of the previous ones in the +# list). +# This tag requires that the tag GENERATE_LATEX is set to YES. + +LATEX_EXTRA_STYLESHEET = # The LATEX_EXTRA_FILES tag can be used to specify one or more extra images or # other source files which should be copied to the LATEX_OUTPUT output @@ -1688,7 +1844,7 @@ LATEX_FOOTER = # markers available. # This tag requires that the tag GENERATE_LATEX is set to YES. -LATEX_EXTRA_FILES = +LATEX_EXTRA_FILES = # If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated is # prepared for conversion to PDF (using ps2pdf or pdflatex). The PDF file will @@ -1699,8 +1855,8 @@ LATEX_EXTRA_FILES = PDF_HYPERLINKS = YES -# If the LATEX_PDFLATEX tag is set to YES, doxygen will use pdflatex to generate -# the PDF file directly from the LaTeX files. Set this option to YES to get a +# If the USE_PDFLATEX tag is set to YES, doxygen will use pdflatex to generate +# the PDF file directly from the LaTeX files. Set this option to YES, to get a # higher quality PDF documentation. # The default value is: YES. # This tag requires that the tag GENERATE_LATEX is set to YES. @@ -1714,7 +1870,7 @@ USE_PDFLATEX = YES # The default value is: NO. # This tag requires that the tag GENERATE_LATEX is set to YES. -LATEX_BATCHMODE = NO +LATEX_BATCHMODE = YES # If the LATEX_HIDE_INDICES tag is set to YES then doxygen will not include the # index chapters (such as File Index, Compound Index, etc.) in the output. @@ -1725,7 +1881,7 @@ LATEX_HIDE_INDICES = NO # If the LATEX_SOURCE_CODE tag is set to YES then doxygen will include source # code with syntax highlighting in the LaTeX output. -# +# # Note that which sources are shown also depends on other settings such as # SOURCE_BROWSER. # The default value is: NO. @@ -1735,17 +1891,33 @@ LATEX_SOURCE_CODE = NO # The LATEX_BIB_STYLE tag can be used to specify the style to use for the # bibliography, e.g. plainnat, or ieeetr. See -# http://en.wikipedia.org/wiki/BibTeX and \cite for more info. +# https://en.wikipedia.org/wiki/BibTeX and \cite for more info. # The default value is: plain. # This tag requires that the tag GENERATE_LATEX is set to YES. LATEX_BIB_STYLE = plain +# If the LATEX_TIMESTAMP tag is set to YES then the footer of each generated +# page will contain the date and time when the page was generated. Setting this +# to NO can help when comparing the output of multiple runs. +# The default value is: NO. +# This tag requires that the tag GENERATE_LATEX is set to YES. + +LATEX_TIMESTAMP = NO + +# The LATEX_EMOJI_DIRECTORY tag is used to specify the (relative or absolute) +# path from which the emoji images will be read. If a relative path is entered, +# it will be relative to the LATEX_OUTPUT directory. If left blank the +# LATEX_OUTPUT directory will be used. +# This tag requires that the tag GENERATE_LATEX is set to YES. + +LATEX_EMOJI_DIRECTORY = + #--------------------------------------------------------------------------- # Configuration options related to the RTF output #--------------------------------------------------------------------------- -# If the GENERATE_RTF tag is set to YES doxygen will generate RTF output. The +# If the GENERATE_RTF tag is set to YES, doxygen will generate RTF output. The # RTF output is optimized for Word 97 and may not look too pretty with other RTF # readers/editors. # The default value is: NO. @@ -1760,7 +1932,7 @@ GENERATE_RTF = NO RTF_OUTPUT = rtf -# If the COMPACT_RTF tag is set to YES doxygen generates more compact RTF +# If the COMPACT_RTF tag is set to YES, doxygen generates more compact RTF # documents. This may be useful for small projects and may help to save some # trees in general. # The default value is: NO. @@ -1773,35 +1945,45 @@ COMPACT_RTF = NO # output) instead of page references. This makes the output suitable for online # browsing using Word or some other Word compatible readers that support those # fields. -# +# # Note: WordPad (write) and others do not support links. # The default value is: NO. # This tag requires that the tag GENERATE_RTF is set to YES. RTF_HYPERLINKS = NO -# Load stylesheet definitions from file. Syntax is similar to doxygen's config -# file, i.e. a series of assignments. You only have to provide replacements, -# missing definitions are set to their default value. -# +# Load stylesheet definitions from file. Syntax is similar to doxygen's +# configuration file, i.e. a series of assignments. You only have to provide +# replacements, missing definitions are set to their default value. +# # See also section "Doxygen usage" for information on how to generate the # default style sheet that doxygen normally uses. # This tag requires that the tag GENERATE_RTF is set to YES. -RTF_STYLESHEET_FILE = +RTF_STYLESHEET_FILE = # Set optional variables used in the generation of an RTF document. Syntax is -# similar to doxygen's config file. A template extensions file can be generated -# using doxygen -e rtf extensionFile. +# similar to doxygen's configuration file. A template extensions file can be +# generated using doxygen -e rtf extensionFile. +# This tag requires that the tag GENERATE_RTF is set to YES. + +RTF_EXTENSIONS_FILE = + +# If the RTF_SOURCE_CODE tag is set to YES then doxygen will include source code +# with syntax highlighting in the RTF output. +# +# Note that which sources are shown also depends on other settings such as +# SOURCE_BROWSER. +# The default value is: NO. # This tag requires that the tag GENERATE_RTF is set to YES. -RTF_EXTENSIONS_FILE = +RTF_SOURCE_CODE = NO #--------------------------------------------------------------------------- # Configuration options related to the man page output #--------------------------------------------------------------------------- -# If the GENERATE_MAN tag is set to YES doxygen will generate man pages for +# If the GENERATE_MAN tag is set to YES, doxygen will generate man pages for # classes and files. # The default value is: NO. @@ -1825,6 +2007,13 @@ MAN_OUTPUT = man MAN_EXTENSION = .3 +# The MAN_SUBDIR tag determines the name of the directory created within +# MAN_OUTPUT in which the man pages are placed. If defaults to man followed by +# MAN_EXTENSION with the initial . removed. +# This tag requires that the tag GENERATE_MAN is set to YES. + +MAN_SUBDIR = + # If the MAN_LINKS tag is set to YES and doxygen generates man output, then it # will generate one additional man file for each entity documented in the real # man page(s). These additional files only source the real man page, but without @@ -1838,7 +2027,7 @@ MAN_LINKS = NO # Configuration options related to the XML output #--------------------------------------------------------------------------- -# If the GENERATE_XML tag is set to YES doxygen will generate an XML file that +# If the GENERATE_XML tag is set to YES, doxygen will generate an XML file that # captures the structure of the code including all documentation. # The default value is: NO. @@ -1852,19 +2041,7 @@ GENERATE_XML = NO XML_OUTPUT = xml -# The XML_SCHEMA tag can be used to specify a XML schema, which can be used by a -# validating XML parser to check the syntax of the XML files. -# This tag requires that the tag GENERATE_XML is set to YES. - -XML_SCHEMA = - -# The XML_DTD tag can be used to specify a XML DTD, which can be used by a -# validating XML parser to check the syntax of the XML files. -# This tag requires that the tag GENERATE_XML is set to YES. - -XML_DTD = - -# If the XML_PROGRAMLISTING tag is set to YES doxygen will dump the program +# If the XML_PROGRAMLISTING tag is set to YES, doxygen will dump the program # listings (including syntax highlighting and cross-referencing information) to # the XML output. Note that enabling this will significantly increase the size # of the XML output. @@ -1873,11 +2050,18 @@ XML_DTD = XML_PROGRAMLISTING = YES +# If the XML_NS_MEMB_FILE_SCOPE tag is set to YES, doxygen will include +# namespace members in file scope as well, matching the HTML output. +# The default value is: NO. +# This tag requires that the tag GENERATE_XML is set to YES. + +XML_NS_MEMB_FILE_SCOPE = NO + #--------------------------------------------------------------------------- # Configuration options related to the DOCBOOK output #--------------------------------------------------------------------------- -# If the GENERATE_DOCBOOK tag is set to YES doxygen will generate Docbook files +# If the GENERATE_DOCBOOK tag is set to YES, doxygen will generate Docbook files # that can be used to generate PDF. # The default value is: NO. @@ -1891,14 +2075,23 @@ GENERATE_DOCBOOK = NO DOCBOOK_OUTPUT = docbook +# If the DOCBOOK_PROGRAMLISTING tag is set to YES, doxygen will include the +# program listings (including syntax highlighting and cross-referencing +# information) to the DOCBOOK output. Note that enabling this will significantly +# increase the size of the DOCBOOK output. +# The default value is: NO. +# This tag requires that the tag GENERATE_DOCBOOK is set to YES. + +DOCBOOK_PROGRAMLISTING = NO + #--------------------------------------------------------------------------- # Configuration options for the AutoGen Definitions output #--------------------------------------------------------------------------- -# If the GENERATE_AUTOGEN_DEF tag is set to YES doxygen will generate an AutoGen -# Definitions (see http://autogen.sf.net) file that captures the structure of -# the code including all documentation. Note that this feature is still -# experimental and incomplete at the moment. +# If the GENERATE_AUTOGEN_DEF tag is set to YES, doxygen will generate an +# AutoGen Definitions (see http://autogen.sourceforge.net/) file that captures +# the structure of the code including all documentation. Note that this feature +# is still experimental and incomplete at the moment. # The default value is: NO. GENERATE_AUTOGEN_DEF = NO @@ -1907,15 +2100,15 @@ GENERATE_AUTOGEN_DEF = NO # Configuration options related to the Perl module output #--------------------------------------------------------------------------- -# If the GENERATE_PERLMOD tag is set to YES doxygen will generate a Perl module +# If the GENERATE_PERLMOD tag is set to YES, doxygen will generate a Perl module # file that captures the structure of the code including all documentation. -# +# # Note that this feature is still experimental and incomplete at the moment. # The default value is: NO. GENERATE_PERLMOD = NO -# If the PERLMOD_LATEX tag is set to YES doxygen will generate the necessary +# If the PERLMOD_LATEX tag is set to YES, doxygen will generate the necessary # Makefile rules, Perl scripts and LaTeX code to be able to generate PDF and DVI # output from the Perl module output. # The default value is: NO. @@ -1923,9 +2116,9 @@ GENERATE_PERLMOD = NO PERLMOD_LATEX = NO -# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be nicely +# If the PERLMOD_PRETTY tag is set to YES, the Perl module output will be nicely # formatted so it can be parsed by a human reader. This is useful if you want to -# understand what is going on. On the other hand, if this tag is set to NO the +# understand what is going on. On the other hand, if this tag is set to NO, the # size of the Perl module output will be much smaller and Perl will parse it # just the same. # The default value is: YES. @@ -1939,20 +2132,20 @@ PERLMOD_PRETTY = YES # overwrite each other's variables. # This tag requires that the tag GENERATE_PERLMOD is set to YES. -PERLMOD_MAKEVAR_PREFIX = +PERLMOD_MAKEVAR_PREFIX = #--------------------------------------------------------------------------- # Configuration options related to the preprocessor #--------------------------------------------------------------------------- -# If the ENABLE_PREPROCESSING tag is set to YES doxygen will evaluate all +# If the ENABLE_PREPROCESSING tag is set to YES, doxygen will evaluate all # C-preprocessor directives found in the sources and include files. # The default value is: YES. ENABLE_PREPROCESSING = YES -# If the MACRO_EXPANSION tag is set to YES doxygen will expand all macro names -# in the source code. If set to NO only conditional compilation will be +# If the MACRO_EXPANSION tag is set to YES, doxygen will expand all macro names +# in the source code. If set to NO, only conditional compilation will be # performed. Macro expansion can be done in a controlled way by setting # EXPAND_ONLY_PREDEF to YES. # The default value is: NO. @@ -1968,7 +2161,7 @@ MACRO_EXPANSION = NO EXPAND_ONLY_PREDEF = NO -# If the SEARCH_INCLUDES tag is set to YES the includes files in the +# If the SEARCH_INCLUDES tag is set to YES, the include files in the # INCLUDE_PATH will be searched if a #include is found. # The default value is: YES. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES. @@ -1980,7 +2173,7 @@ SEARCH_INCLUDES = YES # preprocessor. # This tag requires that the tag SEARCH_INCLUDES is set to YES. -INCLUDE_PATH = +INCLUDE_PATH = # You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard # patterns (like *.h and *.hpp) to filter out the header-files in the @@ -1988,7 +2181,7 @@ INCLUDE_PATH = # used. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES. -INCLUDE_FILE_PATTERNS = +INCLUDE_FILE_PATTERNS = # The PREDEFINED tag can be used to specify one or more macro names that are # defined before the preprocessor is started (similar to the -D option of e.g. @@ -1998,7 +2191,7 @@ INCLUDE_FILE_PATTERNS = # recursively expanded use the := operator instead of the = operator. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES. -PREDEFINED = +PREDEFINED = # If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this # tag can be used to specify a list of macro names that should be expanded. The @@ -2007,12 +2200,12 @@ PREDEFINED = # definition found in the source code. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES. -EXPAND_AS_DEFINED = +EXPAND_AS_DEFINED = # If the SKIP_FUNCTION_MACROS tag is set to YES then doxygen's preprocessor will -# remove all refrences to function-like macros that are alone on a line, have an -# all uppercase name, and do not end with a semicolon. Such function macros are -# typically used for boiler-plate code, and will confuse the parser if not +# remove all references to function-like macros that are alone on a line, have +# an all uppercase name, and do not end with a semicolon. Such function macros +# are typically used for boiler-plate code, and will confuse the parser if not # removed. # The default value is: YES. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES. @@ -2032,49 +2225,44 @@ SKIP_FUNCTION_MACROS = YES # where loc1 and loc2 can be relative or absolute paths or URLs. See the # section "Linking to external documentation" for more information about the use # of tag files. -# Note: Each tag file must have an unique name (where the name does NOT include +# Note: Each tag file must have a unique name (where the name does NOT include # the path). If a tag file is not located in the directory in which doxygen is # run, you must also specify the path to the tagfile here. -TAGFILES = +TAGFILES = # When a file name is specified after GENERATE_TAGFILE, doxygen will create a # tag file that is based on the input files it reads. See section "Linking to # external documentation" for more information about the usage of tag files. -GENERATE_TAGFILE = +GENERATE_TAGFILE = -# If the ALLEXTERNALS tag is set to YES all external class will be listed in the -# class index. If set to NO only the inherited external classes will be listed. +# If the ALLEXTERNALS tag is set to YES, all external class will be listed in +# the class index. If set to NO, only the inherited external classes will be +# listed. # The default value is: NO. ALLEXTERNALS = NO -# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed in -# the modules index. If set to NO, only the current project's groups will be +# If the EXTERNAL_GROUPS tag is set to YES, all external groups will be listed +# in the modules index. If set to NO, only the current project's groups will be # listed. # The default value is: YES. EXTERNAL_GROUPS = YES -# If the EXTERNAL_PAGES tag is set to YES all external pages will be listed in +# If the EXTERNAL_PAGES tag is set to YES, all external pages will be listed in # the related pages index. If set to NO, only the current project's pages will # be listed. # The default value is: YES. EXTERNAL_PAGES = YES -# The PERL_PATH should be the absolute path and name of the perl script -# interpreter (i.e. the result of 'which perl'). -# The default file (with absolute path) is: /usr/bin/perl. - -PERL_PATH = /usr/bin/perl - #--------------------------------------------------------------------------- # Configuration options related to the dot tool #--------------------------------------------------------------------------- -# If the CLASS_DIAGRAMS tag is set to YES doxygen will generate a class diagram +# If the CLASS_DIAGRAMS tag is set to YES, doxygen will generate a class diagram # (in HTML and LaTeX) for classes with base or super classes. Setting the tag to # NO turns the diagrams off. Note that this option also works with HAVE_DOT # disabled, but it is recommended to install and use dot, since it yields more @@ -2083,16 +2271,14 @@ PERL_PATH = /usr/bin/perl CLASS_DIAGRAMS = NO -# You can define message sequence charts within doxygen comments using the \msc -# command. Doxygen will then run the mscgen tool (see: -# http://www.mcternan.me.uk/mscgen/)) to produce the chart and insert it in the -# documentation. The MSCGEN_PATH tag allows you to specify the directory where -# the mscgen tool resides. If left empty the tool is assumed to be found in the -# default search path. +# You can include diagrams made with dia in doxygen documentation. Doxygen will +# then run dia to produce the diagram and insert it in the documentation. The +# DIA_PATH tag allows you to specify the directory where the dia binary resides. +# If left empty dia is assumed to be found in the default search path. -MSCGEN_PATH = +DIA_PATH = -# If set to YES, the inheritance and collaboration graphs will hide inheritance +# If set to YES the inheritance and collaboration graphs will hide inheritance # and usage relations if the target is undocumented or is not a class. # The default value is: YES. @@ -2117,7 +2303,7 @@ HAVE_DOT = YES DOT_NUM_THREADS = 0 -# When you want a differently looking font n the dot files that doxygen +# When you want a differently looking font in the dot files that doxygen # generates you can specify the font name using DOT_FONTNAME. You need to make # sure dot is able to find the font, which can be done by putting it in a # standard location or by setting the DOTFONTPATH environment variable or by @@ -2139,7 +2325,7 @@ DOT_FONTSIZE = 10 # the path where dot can find it using this tag. # This tag requires that the tag HAVE_DOT is set to YES. -DOT_FONTPATH = +DOT_FONTPATH = # If the CLASS_GRAPH tag is set to YES then doxygen will generate a graph for # each documented class showing the direct and indirect inheritance relations. @@ -2165,7 +2351,7 @@ COLLABORATION_GRAPH = YES GROUP_GRAPHS = YES -# If the UML_LOOK tag is set to YES doxygen will generate inheritance and +# If the UML_LOOK tag is set to YES, doxygen will generate inheritance and # collaboration diagrams in a style similar to the OMG's Unified Modeling # Language. # The default value is: NO. @@ -2214,10 +2400,11 @@ INCLUDED_BY_GRAPH = YES # If the CALL_GRAPH tag is set to YES then doxygen will generate a call # dependency graph for every global function or class method. -# +# # Note that enabling this option will significantly increase the time of a run. # So in most cases it will be better to enable call graphs for selected -# functions only using the \callgraph command. +# functions only using the \callgraph command. Disabling a call graph can be +# accomplished by means of the command \hidecallgraph. # The default value is: NO. # This tag requires that the tag HAVE_DOT is set to YES. @@ -2225,10 +2412,11 @@ CALL_GRAPH = NO # If the CALLER_GRAPH tag is set to YES then doxygen will generate a caller # dependency graph for every global function or class method. -# +# # Note that enabling this option will significantly increase the time of a run. # So in most cases it will be better to enable caller graphs for selected -# functions only using the \callergraph command. +# functions only using the \callergraph command. Disabling a caller graph can be +# accomplished by means of the command \hidecallergraph. # The default value is: NO. # This tag requires that the tag HAVE_DOT is set to YES. @@ -2251,11 +2439,15 @@ GRAPHICAL_HIERARCHY = YES DIRECTORY_GRAPH = YES # The DOT_IMAGE_FORMAT tag can be used to set the image format of the images -# generated by dot. +# generated by dot. For an explanation of the image formats see the section +# output formats in the documentation of the dot tool (Graphviz (see: +# http://www.graphviz.org/)). # Note: If you choose svg you need to set HTML_FILE_EXTENSION to xhtml in order # to make the SVG files visible in IE 9+ (other browsers do not have this # requirement). -# Possible values are: png, jpg, gif and svg. +# Possible values are: png, jpg, gif, svg, png:gd, png:gd:gd, png:cairo, +# png:cairo:gd, png:cairo:cairo, png:cairo:gdiplus, png:gdiplus and +# png:gdiplus:gdiplus. # The default value is: png. # This tag requires that the tag HAVE_DOT is set to YES. @@ -2263,7 +2455,7 @@ DOT_IMAGE_FORMAT = png # If DOT_IMAGE_FORMAT is set to svg, then this option can be set to YES to # enable generation of interactive SVG images that allow zooming and panning. -# +# # Note that this requires a modern browser other than Internet Explorer. Tested # and working are Firefox, Chrome, Safari, and Opera. # Note: For IE 9+ you need to set HTML_FILE_EXTENSION to xhtml in order to make @@ -2277,20 +2469,44 @@ INTERACTIVE_SVG = NO # found. If left blank, it is assumed the dot tool can be found in the path. # This tag requires that the tag HAVE_DOT is set to YES. -DOT_PATH = +DOT_PATH = # The DOTFILE_DIRS tag can be used to specify one or more directories that # contain dot files that are included in the documentation (see the \dotfile # command). # This tag requires that the tag HAVE_DOT is set to YES. -DOTFILE_DIRS = +DOTFILE_DIRS = # The MSCFILE_DIRS tag can be used to specify one or more directories that # contain msc files that are included in the documentation (see the \mscfile # command). -MSCFILE_DIRS = +MSCFILE_DIRS = + +# The DIAFILE_DIRS tag can be used to specify one or more directories that +# contain dia files that are included in the documentation (see the \diafile +# command). + +DIAFILE_DIRS = + +# When using plantuml, the PLANTUML_JAR_PATH tag should be used to specify the +# path where java can find the plantuml.jar file. If left blank, it is assumed +# PlantUML is not used or called during a preprocessing step. Doxygen will +# generate a warning when it encounters a \startuml command in this case and +# will not generate output for the diagram. + +PLANTUML_JAR_PATH = + +# When using plantuml, the PLANTUML_CFG_FILE tag can be used to specify a +# configuration file for plantuml. + +PLANTUML_CFG_FILE = + +# When using plantuml, the specified paths are searched for files specified by +# the !include statement in a plantuml block. + +PLANTUML_INCLUDE_PATH = # The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of nodes # that will be shown in the graph. If the number of nodes in a graph becomes @@ -2319,7 +2535,7 @@ MAX_DOT_GRAPH_DEPTH = 0 # Set the DOT_TRANSPARENT tag to YES to generate images with a transparent # background. This is disabled by default, because dot on Windows does not seem # to support this out of the box. -# +# # Warning: Depending on the platform used, enabling this option may lead to # badly anti-aliased labels on the edges of a graph (i.e. they become hard to # read). @@ -2328,7 +2544,7 @@ MAX_DOT_GRAPH_DEPTH = 0 DOT_TRANSPARENT = NO -# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output +# Set the DOT_MULTI_TARGETS tag to YES to allow dot to generate multiple output # files in one run (i.e. multiple -o and -T options on the command line). This # makes dot run faster, but since only newer versions of dot (>1.8.10) support # this, this feature is disabled by default. @@ -2345,7 +2561,7 @@ DOT_MULTI_TARGETS = NO GENERATE_LEGEND = YES -# If the DOT_CLEANUP tag is set to YES doxygen will remove the intermediate dot +# If the DOT_CLEANUP tag is set to YES, doxygen will remove the intermediate dot # files that are used to generate the various graphs. # The default value is: YES. # This tag requires that the tag HAVE_DOT is set to YES. diff --git a/Examples/AdjointSensitivity/AdjointSensitivity.cpp b/Examples/AdjointSensitivity/AdjointSensitivity.cpp index 5ebf6f0..df9420b 100644 --- a/Examples/AdjointSensitivity/AdjointSensitivity.cpp +++ b/Examples/AdjointSensitivity/AdjointSensitivity.cpp @@ -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 @@ -65,6 +65,7 @@ #include #include #include +#include /* * Compute gradient of an objective function expressed as an integral over @@ -81,6 +82,7 @@ int main() using namespace ModelLib; using namespace AnalysisManager::Sundials; using namespace AnalysisManager; + using namespace GridKit::Testing; // Create an infinite bus BaseBus* bus = new BusSlack(1.0, 0.0); @@ -137,7 +139,7 @@ int main() idas->printFinalStats(); const double g1 = Q[0]; - const double eps = 1e-4; + const double eps = 2e-3; // Compute gradient of the objective function numerically std::vector dGdp(model->size_opt()); @@ -180,13 +182,21 @@ int main() idas->printFinalStats(); // Compare results + int retval = 0; std::cout << "\n\nComparison of numerical and adjoint results:\n\n"; double* neg_dGdp = idas->getAdjointIntegral(); for (unsigned i=0; isize_opt(); ++i) { - std::cout << "dG/dp" << i << " (numerical) = " << dGdp[i] << "\n"; - std::cout << "dG/dp" << i << " (adjoint) = " << -neg_dGdp[i] << "\n\n"; + std::cout << "dG/dp" << i << " (numerical) = " << dGdp[i] << "\n"; + std::cout << "dG/dp" << i << " (adjoint) = " << -neg_dGdp[i] << "\n\n"; + if(!isEqual(dGdp[i], -neg_dGdp[i], 10*eps)) + --retval; } - return 0; + if(retval < 0) + { + std::cout << "The two results differ beyond solver tolerance!\n"; + } + + return retval; } diff --git a/Examples/AdjointSensitivity/CMakeLists.txt b/Examples/AdjointSensitivity/CMakeLists.txt index 055808e..90f0c23 100644 --- a/Examples/AdjointSensitivity/CMakeLists.txt +++ b/Examples/AdjointSensitivity/CMakeLists.txt @@ -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 diff --git a/Examples/CMakeLists.txt b/Examples/CMakeLists.txt index d3063a7..4487fb8 100644 --- a/Examples/CMakeLists.txt +++ b/Examples/CMakeLists.txt @@ -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 @@ -56,6 +56,10 @@ # add_subdirectory(AdjointSensitivity) -add_subdirectory(DynamicConstrainedOpt) -add_subdirectory(GenConstLoad) -add_subdirectory(GenInfiniteBus) +add_subdirectory(Grid3Bus) +if(GRIDKIT_ENABLE_IPOPT) + add_subdirectory(DynamicConstrainedOpt) + add_subdirectory(GenConstLoad) + add_subdirectory(GenInfiniteBus) + add_subdirectory(ParameterEstimation) +endif() diff --git a/Examples/DynamicConstrainedOpt/CMakeLists.txt b/Examples/DynamicConstrainedOpt/CMakeLists.txt index d5d61dc..7a214e1 100644 --- a/Examples/DynamicConstrainedOpt/CMakeLists.txt +++ b/Examples/DynamicConstrainedOpt/CMakeLists.txt @@ -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 diff --git a/Examples/DynamicConstrainedOpt/DynamicConstrainedOpt.cpp b/Examples/DynamicConstrainedOpt/DynamicConstrainedOpt.cpp index 72cedbf..80f36fc 100644 --- a/Examples/DynamicConstrainedOpt/DynamicConstrainedOpt.cpp +++ b/Examples/DynamicConstrainedOpt/DynamicConstrainedOpt.cpp @@ -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 @@ -70,14 +70,14 @@ #include #include #include - - +#include int main() { using namespace ModelLib; using namespace AnalysisManager::Sundials; using namespace AnalysisManager; + using namespace GridKit::Testing; // Create an infinite bus BaseBus* bus = new BusSlack(1.0, 0.0); @@ -122,6 +122,9 @@ int main() // Set integration time for dynamic constrained optimization idas->setIntegrationTime(t_init, t_final, 100); + // Guess optimization parameter value + double Pm = 0.7; + // Create an instance of the IpoptApplication Ipopt::SmartPtr ipoptApp = IpoptApplicationFactory(); @@ -133,18 +136,24 @@ int main() return (int) status; } + // Set solver tolerance + const double tol = 1e-4; + // Configure Ipopt application ipoptApp->Options()->SetStringValue("hessian_approximation", "limited-memory"); - ipoptApp->Options()->SetNumericValue("tol", 1e-4); + ipoptApp->Options()->SetNumericValue("tol", tol); ipoptApp->Options()->SetIntegerValue("print_level", 0); // Create dynamic objective interface to Ipopt solver Ipopt::SmartPtr ipoptDynamicObjectiveInterface = new IpoptInterface::DynamicObjective(idas); + // Initialize problem + model->param()[0] = Pm; + // Solve the problem status = ipoptApp->OptimizeTNLP(ipoptDynamicObjectiveInterface); - std::cout << "\n\nProblem formulated as dynamic objective optimiztion ...\n"; + std::cout << "\n\nProblem formulated as dynamic objective optimization ...\n"; if (status == Ipopt::Solve_Succeeded) { // Print result @@ -155,13 +164,23 @@ int main() << ipoptApp->Statistics()->FinalObjective() << "\n\n"; } + // Store dynamic objective optimization results + double* results = new double[model->size_opt()]; + for(unsigned i=0; i size_opt(); ++i) + { + results[i] = model->param()[i]; + } + // Create dynamic constraint interface to Ipopt solver Ipopt::SmartPtr ipoptDynamicConstraintInterface = new IpoptInterface::DynamicConstraint(idas); + // Initialize problem + model->param()[0] = Pm; + // Solve the problem status = ipoptApp->OptimizeTNLP(ipoptDynamicConstraintInterface); - std::cout << "\n\nProblem formulated as dynamic constraint optimiztion ...\n"; + std::cout << "\n\nProblem formulated as dynamic constraint optimization ...\n"; if (status == Ipopt::Solve_Succeeded) { // Print result @@ -172,7 +191,21 @@ int main() << ipoptApp->Statistics()->FinalObjective() << "\n\n"; } + // Compare results of the two optimization methods + int retval = 0; + for(unsigned i=0; i size_opt(); ++i) + { + if(!isEqual(results[i], model->param()[i], 10*tol)) + --retval; + } + + if(retval < 0) + { + std::cout << "The two results differ beyond solver tolerance!\n"; + } + + delete [] results; delete idas; delete model; - return 0; + return retval; } diff --git a/Examples/GenConstLoad/CMakeLists.txt b/Examples/GenConstLoad/CMakeLists.txt index 9200126..7ff607e 100644 --- a/Examples/GenConstLoad/CMakeLists.txt +++ b/Examples/GenConstLoad/CMakeLists.txt @@ -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 diff --git a/Examples/GenConstLoad/GenConstLoad.cpp b/Examples/GenConstLoad/GenConstLoad.cpp index be3a0fc..744f0a8 100644 --- a/Examples/GenConstLoad/GenConstLoad.cpp +++ b/Examples/GenConstLoad/GenConstLoad.cpp @@ -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 @@ -71,13 +71,14 @@ #include #include #include - +#include int main() { using namespace ModelLib; using namespace AnalysisManager::Sundials; using namespace AnalysisManager; + using namespace GridKit::Testing; // Create a bus BaseBus* bus = new BusPQ(1.0, 0.0); @@ -86,7 +87,7 @@ int main() ModelEvaluatorImpl* gen = new Generator4Governor(bus, 0.8, 0.3); // Attach load to the bus - ModelEvaluatorImpl* load = new Load(bus, -0.8, -0.3); + ModelEvaluatorImpl* load = new Load(bus, 0.8, 0.3); // Create system model SystemModel* model = new SystemModel(); @@ -114,7 +115,11 @@ int main() idas->saveInitialCondition(); // Set integration time for dynamic constrained optimization - idas->setIntegrationTime(t_init, t_final, 100); + idas->setIntegrationTime(t_init, t_final, 250); + + // Guess optimization parameter values + double T2 = 0.15; + double K = 16.0; // Create an instance of the IpoptApplication Ipopt::SmartPtr ipoptApp = IpoptApplicationFactory(); @@ -127,17 +132,24 @@ int main() return (int) status; } + // Set solver tolerance + const double tol = 1e-4; + // Configure Ipopt application ipoptApp->Options()->SetStringValue("hessian_approximation", "limited-memory"); - ipoptApp->Options()->SetNumericValue("tol", 1e-4); - ipoptApp->Options()->SetIntegerValue("print_level", 3); + ipoptApp->Options()->SetNumericValue("tol", tol); + ipoptApp->Options()->SetIntegerValue("print_level", 5); // Create interface to Ipopt solver - Ipopt::SmartPtr ipoptInterface = + Ipopt::SmartPtr ipoptDynamicObjectiveInterface = new IpoptInterface::DynamicObjective(idas); + // Initialize problem + model->param()[0] = T2; + model->param()[1] = K; + // Solve the problem - status = ipoptApp->OptimizeTNLP(ipoptInterface); + status = ipoptApp->OptimizeTNLP(ipoptDynamicObjectiveInterface); if (status == Ipopt::Solve_Succeeded) { // Print result @@ -152,6 +164,16 @@ int main() << ipoptApp->Statistics()->FinalObjective() << "\n\n"; } + // Compare results of the two optimization methods + int retval = + isEqual(ipoptApp->Statistics()->FinalObjective(), 1239.0, 10*tol) ? 0 : 1; + + if(retval != 0) + { + std::cout << "The two results differ beyond solver tolerance!\n"; + } + + delete idas; delete gen; delete load; diff --git a/Examples/GenInfiniteBus/CMakeLists.txt b/Examples/GenInfiniteBus/CMakeLists.txt index 2566e0f..12accac 100644 --- a/Examples/GenInfiniteBus/CMakeLists.txt +++ b/Examples/GenInfiniteBus/CMakeLists.txt @@ -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 diff --git a/Examples/GenInfiniteBus/GenInfiniteBus.cpp b/Examples/GenInfiniteBus/GenInfiniteBus.cpp index afc2790..d4305ae 100644 --- a/Examples/GenInfiniteBus/GenInfiniteBus.cpp +++ b/Examples/GenInfiniteBus/GenInfiniteBus.cpp @@ -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 @@ -70,7 +70,7 @@ #include #include #include - +#include int main() @@ -78,6 +78,7 @@ int main() using namespace ModelLib; using namespace AnalysisManager::Sundials; using namespace AnalysisManager; + using namespace GridKit::Testing; // Create an infinite bus BaseBus* bus = new BusSlack(1.0, 0.0); @@ -124,6 +125,10 @@ int main() // Set integration time for dynamic constrained optimization idas->setIntegrationTime(t_init, t_final, 100); + // Guess initial values of optimization parameters + double Pm = 1.0; + double Ef = 1.45; + // Create an instance of the IpoptApplication Ipopt::SmartPtr ipoptApp = IpoptApplicationFactory(); @@ -135,15 +140,22 @@ int main() return (int) status; } + // Set solver tolerance + const double tol = 1e-4; + // Configure Ipopt application ipoptApp->Options()->SetStringValue("hessian_approximation", "limited-memory"); - ipoptApp->Options()->SetNumericValue("tol", 1e-4); + ipoptApp->Options()->SetNumericValue("tol", tol); ipoptApp->Options()->SetIntegerValue("print_level", 0); // Create dynamic objective interface to Ipopt solver Ipopt::SmartPtr ipoptDynamicObjectiveInterface = new IpoptInterface::DynamicObjective(idas); + // Initialize the problem + model->param()[0] = Pm; + model->param()[1] = Ef; + // Solve the problem status = ipoptApp->OptimizeTNLP(ipoptDynamicObjectiveInterface); std::cout << "\n\nProblem formulated as dynamic objective optimiztion ...\n"; @@ -162,6 +174,17 @@ int main() Ipopt::SmartPtr ipoptDynamicConstraintInterface = new IpoptInterface::DynamicConstraint(idas); + // Store dynamic objective optimization results + double* results = new double[model->size_opt()]; + for(unsigned i=0; i size_opt(); ++i) + { + results[i] = model->param()[i]; + } + + // Initialize the problem + model->param()[0] = Pm; + model->param()[1] = Ef; + // Solve the problem status = ipoptApp->OptimizeTNLP(ipoptDynamicConstraintInterface); std::cout << "\n\nProblem formulated as dynamic constraint optimiztion ...\n"; @@ -176,6 +199,20 @@ int main() << ipoptApp->Statistics()->FinalObjective() << "\n\n"; } + // Compare results of the two optimization methods + int retval = 0; + for(unsigned i=0; i size_opt(); ++i) + { + if(!isEqual(results[i], model->param()[i], 100*tol)) + --retval; + } + + if(retval < 0) + { + std::cout << "The two results differ beyond solver tolerance!\n"; + } + + delete [] results; delete idas; delete model; return 0; diff --git a/Examples/Grid3Bus/CMakeLists.txt b/Examples/Grid3Bus/CMakeLists.txt new file mode 100644 index 0000000..46296e2 --- /dev/null +++ b/Examples/Grid3Bus/CMakeLists.txt @@ -0,0 +1,64 @@ +# +# Copyright (c) 2017, Lawrence Livermore National Security, LLC. +# Produced at the Lawrence Livermore National Laboratory. +# Written by Slaven Peles . +# LLNL-CODE-718378. +# All rights reserved. +# +# 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 +# modification, are permitted provided that the following conditions are met: +# - Redistributions of source code must retain the above copyright notice, +# this list of conditions and the disclaimer below. +# - Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the disclaimer (as noted below) in the +# documentation and/or other materials provided with the distribution. +# - Neither the name of the LLNS/LLNL nor the names of its contributors may +# be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL +# SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, +# OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISINGIN ANY +# WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +# THE POSSIBILITY OF SUCH DAMAGE. +# +# Lawrence Livermore National Laboratory is operated by Lawrence Livermore +# National Security, LLC, for the U.S. Department of Energy, National +# Nuclear Security Administration under Contract DE-AC52-07NA27344. +# +# This document was prepared as an account of work sponsored by an agency +# of the United States government. Neither the United States government nor +# Lawrence Livermore National Security, LLC, nor any of their employees +# makes any warranty, expressed or implied, or assumes any legal liability +# or responsibility for the accuracy, completeness, or usefulness of any +# information, apparatus, product, or process disclosed, or represents that +# its use would not infringe privately owned rights. Reference herein to +# any specific commercial product, process, or service by trade name, +# trademark, manufacturer, or otherwise does not necessarily constitute or +# imply its endorsement, recommendation, or favoring by the United States +# government or Lawrence Livermore National Security, LLC. The views and +# opinions of authors expressed herein do not necessarily state or reflect +# those of the United States government or Lawrence Livermore National +# Security, LLC, and shall not be used for advertising or product +# endorsement purposes. +# + +# add_executable(grid3bus Grid3Bus.cpp) +# target_link_libraries(grid3bus MiniGrid ${solver_libs}) +# install(TARGETS grid3bus RUNTIME DESTINATION bin) + +add_executable(grid3bus Grid3BusSys.cpp) +target_link_libraries(grid3bus MiniGrid Bus Branch Load ${solver_libs}) +install(TARGETS grid3bus RUNTIME DESTINATION bin) diff --git a/Examples/Grid3Bus/Grid3Bus.cpp b/Examples/Grid3Bus/Grid3Bus.cpp new file mode 100644 index 0000000..aae37d2 --- /dev/null +++ b/Examples/Grid3Bus/Grid3Bus.cpp @@ -0,0 +1,119 @@ +/* + * + * Copyright (c) 2017, Lawrence Livermore National Security, LLC. + * Produced at the Lawrence Livermore National Laboratory. + * Written by Slaven Peles . + * LLNL-CODE-718378. + * All rights reserved. + * + * 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 + * modification, are permitted provided that the following conditions are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the disclaimer (as noted below) in the + * documentation and/or other materials provided with the distribution. + * - Neither the name of the LLNS/LLNL nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL + * SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISINGIN ANY + * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + * Lawrence Livermore National Laboratory is operated by Lawrence Livermore + * National Security, LLC, for the U.S. Department of Energy, National + * Nuclear Security Administration under Contract DE-AC52-07NA27344. + * + * This document was prepared as an account of work sponsored by an agency + * of the United States government. Neither the United States government nor + * Lawrence Livermore National Security, LLC, nor any of their employees + * makes any warranty, expressed or implied, or assumes any legal liability + * or responsibility for the accuracy, completeness, or usefulness of any + * information, apparatus, product, or process disclosed, or represents that + * its use would not infringe privately owned rights. Reference herein to + * any specific commercial product, process, or service by trade name, + * trademark, manufacturer, or otherwise does not necessarily constitute or + * imply its endorsement, recommendation, or favoring by the United States + * government or Lawrence Livermore National Security, LLC. The views and + * opinions of authors expressed herein do not necessarily state or reflect + * those of the United States government or Lawrence Livermore National + * Security, LLC, and shall not be used for advertising or product + * endorsement purposes. + * + */ + + +#include +#include +#include + +#include +#include + +#include + + +int main() +{ + using namespace ModelLib; + using namespace AnalysisManager::Sundials; + using namespace AnalysisManager; + using namespace GridKit::Testing; + + // Create a system model + // (usually from netfile or GUI input, this one is hard-wired) + MiniGrid* model = new MiniGrid(); + + // allocate model + model->allocate(); + + // Create numerical solver and attach the model to it. + // Here we use Kinsol solver from SUNDIALS library + Kinsol* kinsol = new Kinsol(model); + + // setup simulation + kinsol->configureSimulation(); + // initialize simulation with default initial guess + kinsol->getDefaultInitialCondition(); + // kinsol->initializeSimulation(); + + // Compute solution + kinsol->runSimulation(); + + // Print solution + double const th2 = model->th2() * 180.0/M_PI; + double const V2 = model->V2(); + double const th3 = model->th3() * 180.0/M_PI; + std::cout << "Solution:\n"; + std::cout << " theta2 = " << th2 << " deg, expected = " << " -4.87979 deg\n"; + std::cout << " V2 = " << V2 << " p.u., expected = " << " 1.08281 p.u.\n"; + std::cout << " theta3 = " << th3 << " deg, expected = " << " 1.46241 deg\n\n"; + + // Print solver performance statistics + kinsol->printFinalStats(); + + int retval = 0; + retval += isEqual(th2, -4.878, 1e-4); + retval += isEqual(V2, 1.096, 1e-4); + retval += isEqual(th3, 1.491, 1e-4); + + // Delete solver and model + delete kinsol; + delete model; + return retval; +} diff --git a/Examples/Grid3Bus/Grid3BusSys.cpp b/Examples/Grid3Bus/Grid3BusSys.cpp new file mode 100644 index 0000000..17362fe --- /dev/null +++ b/Examples/Grid3Bus/Grid3BusSys.cpp @@ -0,0 +1,206 @@ +/* + * + * Copyright (c) 2017, Lawrence Livermore National Security, LLC. + * Produced at the Lawrence Livermore National Laboratory. + * Written by Slaven Peles . + * LLNL-CODE-718378. + * All rights reserved. + * + * 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 + * modification, are permitted provided that the following conditions are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the disclaimer (as noted below) in the + * documentation and/or other materials provided with the distribution. + * - Neither the name of the LLNS/LLNL nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL + * SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISINGIN ANY + * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + * Lawrence Livermore National Laboratory is operated by Lawrence Livermore + * National Security, LLC, for the U.S. Department of Energy, National + * Nuclear Security Administration under Contract DE-AC52-07NA27344. + * + * This document was prepared as an account of work sponsored by an agency + * of the United States government. Neither the United States government nor + * Lawrence Livermore National Security, LLC, nor any of their employees + * makes any warranty, expressed or implied, or assumes any legal liability + * or responsibility for the accuracy, completeness, or usefulness of any + * information, apparatus, product, or process disclosed, or represents that + * its use would not infringe privately owned rights. Reference herein to + * any specific commercial product, process, or service by trade name, + * trademark, manufacturer, or otherwise does not necessarily constitute or + * imply its endorsement, recommendation, or favoring by the United States + * government or Lawrence Livermore National Security, LLC. The views and + * opinions of authors expressed herein do not necessarily state or reflect + * those of the United States government or Lawrence Livermore National + * Security, LLC, and shall not be used for advertising or product + * endorsement purposes. + * + */ + +/** + * @file Grid3BusSys.cpp + * @author Slaven Peles + * + * Simple 3-bus grid example. Two models are tested here -- a hard-wired model + * and a model assembled using GridKit's system composer. + * + */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + + +int main() +{ + using namespace ModelLib; + using namespace AnalysisManager::Sundials; + using namespace AnalysisManager; + using namespace GridKit::Testing; + + std::cout << "\nSolving power flow for a 3-bus monolithic model ...\n\n"; + // Create a 3-bus model + MiniGrid* model = new MiniGrid(); + + // allocate model + model->allocate(); + std::cout << "Model size: " << model->size() << "\n\n"; + + // Create numerical solver and attach the model to it. + // Here we use Kinsol solver from SUNDIALS library + Kinsol* kinsol = new Kinsol(model); + + // setup simulation + kinsol->configureSimulation(); + // initialize simulation with default initial guess V=1, theta=0 + kinsol->getDefaultInitialCondition(); + // Compute solution + kinsol->runSimulation(); + // Print solution + double th2 = model->th2() * 180.0/M_PI; + double V2 = model->V2(); + double th3 = model->th3() * 180.0/M_PI; + std::cout << "Solution:\n"; + std::cout << " theta2 = " << th2 << " deg, expected = " << " -4.87979 deg\n"; + std::cout << " V2 = " << V2 << " p.u., expected = " << " 1.08281 p.u.\n"; + std::cout << " theta3 = " << th3 << " deg, expected = " << " 1.46241 deg\n\n"; + + // Print solver performance statistics + kinsol->printFinalStats(); + + int retval1 = 0; + retval1 += isEqual(th2, -4.878, 1e-4); + retval1 += isEqual(V2, 1.096, 1e-4); + retval1 += isEqual(th3, 1.491, 1e-4); + + if(retval1 == 0) + std::cout << "\nSucess!\n\n\n"; + + // Delete solver and model + delete kinsol; kinsol = nullptr; + delete model; model = nullptr; + + std::cout << "Solving same problem, but assembled from components ...\n\n"; + + // First, create an empty system model + SystemSteadyStateModel* sysmodel = new SystemSteadyStateModel(); + + // Next create and add buses ... + // Create a slack bus, fix V=1, theta=0 + BaseBus* bus1 = new BusSlack(1.0, 0.0); + sysmodel->addBus(bus1); + // Create a PQ bus, initialize V=1, theta=0 + BaseBus* bus2 = new BusPQ(1.0, 0.0); + sysmodel->addBus(bus2); + // Create a PV bus, fix V=1.1, initialize theta=0, and set power injection Pg=2 + BaseBus* bus3 = new BusPV(1.1, 0.0, 2.0); + sysmodel->addBus(bus3); + + // Create and add branches ... + Branch* branch12 = new Branch(bus1, bus2); + branch12->setX(1.0/10.0); + sysmodel->addComponent(branch12); + Branch* branch13 = new Branch(bus1, bus3); + branch13->setX(1.0/15.0); + sysmodel->addComponent(branch13); + Branch* branch23 = new Branch(bus2, bus3); + branch23->setX(1.0/12.0); + sysmodel->addComponent(branch23); + + // Create and add loads ... + Load* load1 = new Load(bus1, 2.0, 0.0); + sysmodel->addComponent(load1); + Load* load2 = new Load(bus2, 2.5, -0.8); + sysmodel->addComponent(load2); + + // allocate model + sysmodel->allocate(); + std::cout << "Model size: " << sysmodel->size() << "\n\n"; + + // Create numerical solver and attach the model to it. + // Here we use Kinsol solver from SUNDIALS library + kinsol = new Kinsol(sysmodel); + + // setup simulation + kinsol->configureSimulation(); + // initialize simulation with default initial guess + kinsol->getDefaultInitialCondition(); + // Compute solution + kinsol->runSimulation(); + // Print solution + th2 = bus2->theta() * 180.0/M_PI; + V2 = bus2->V(); + th3 = bus3->theta() * 180.0/M_PI; + std::cout << "Solution:\n"; + std::cout << " theta2 = " << th2 << " deg, expected = " << " -4.87979 deg\n"; + std::cout << " V2 = " << V2 << " p.u., expected = " << " 1.08281 p.u.\n"; + std::cout << " theta3 = " << th3 << " deg, expected = " << " 1.46241 deg\n\n"; + + // Print solver performance statistics + kinsol->printFinalStats(); + + int retval2 = 0; + retval2 += isEqual(th2, -4.878, 1e-4); + retval2 += isEqual(V2, 1.096, 1e-4); + retval2 += isEqual(th3, 1.491, 1e-4); + + if(retval2 == 0) + std::cout << "\nSucess!\n\n\n"; + + + // Delete solver and model + delete kinsol; + delete sysmodel; + return retval1 + retval2; +} diff --git a/Examples/Grid3Bus/README.md b/Examples/Grid3Bus/README.md new file mode 100644 index 0000000..39d2774 --- /dev/null +++ b/Examples/Grid3Bus/README.md @@ -0,0 +1,110 @@ +# Power Flow Example for 3-bus Grid + +This example provides power flow analysis for a simple 3-bus grid model. The example runs power flow for a monolithic 3-bus model and a model assembled from components. + +The power flow is the analysis of the flow of electric power, voltages, and currents in normal steady-state operation. It calculates the voltage magnitude and phase angle of each bus from which real and reactive flow on all lines as well as the associated equipment losses can be computed. +The mathematical model of the power flow problem is formulated as a set of nonlinear equations. Due to the nonlinear nature of the problem formulation, power flow typically requires numerical solution. The model needs to provide residual vector and (typically) Jacobian matrix to the numerical nonlinear solver. + +## Model Equations + +The model and its parameters are described in Figure 1: + +
+ + + + Figure 1: A simple 3-bus grid example. +
+ +Problem variables are voltage magnitudes and phases; they are stored in bus objects. Branch and load models do not have any internal variables. Contributions to residual vector for the model are computed in individual component model objects. Residual values are sumed up and stored in buses. + +### Residual + +**Bus 1**: Slack bus, does not store variables no residuals. Voltage and phase are set to $`V_1 \equiv 1`$p.u. and $`\theta_1 \equiv 0`$, respectively. + +**Bus 2**: PQ bus, stores variables $`V_2, \theta_2`$ and residuals $`P_2, Q_2`$. Load $`P_{L2} = 2.5`$p.u., $`Q_{L2} = -j0.8`$p.u. is attached to it. From the equations for [branch](../../ComponentLib/Branch/README.md) and [load](../../ComponentLib/Load/README.md) components, we assemble Bus 2 residuals as: +```math +\begin{array}{rcll} +P_2 & = &-P_{L2} &~~~\mathrm{(load ~2)} \\ + &&+ b_{12}|V_1||V_2|\sin(\theta_2-\theta_1) &~~~\mathrm{(branch ~12)} \\ + &&+ b_{23}|V_2||V_3|\sin(\theta_2-\theta_3) &~~~\mathrm{(branch ~23)} \\ +Q_2 & = & -Q_{L2} &~~~\mathrm{(load ~2)} \\ + &&+ b_{12}|V_2|^2 - b_{12}|V_1||V_2|\cos(\theta_2-\theta_1) &~~~\mathrm{(branch ~12)} \\ + &&+ b_{23}|V_2|^2 - b_{23}|V_2||V_3|\cos(\theta_2-\theta_3) &~~~\mathrm{(branch ~23)} +\end{array} +``` + +**Bus 3**: PV bus, stores variable $`\theta_3`$ and residual $`P_3`$. Voltage is set to $`|V_3| \equiv 1.1`$p.u.. Generator $`P_{G3} = 2`$p.u. is attached to it. From the equations for [branch](../../ComponentLib/Branch/README.md) and [generator](../../ComponentLib/Gen/README.md) components, we assemble Bus 3 residual as: +```math +\begin{array}{rcll} +P_3 & = &P_{G3} &~~~\mathrm{(generator ~3)} \\ + &&+ b_{13}|V_1||V_3|\sin(\theta_3-\theta_1) &~~~\mathrm{(branch ~13)} \\ + &&+ b_{23}|V_2||V_3|\sin(\theta_3-\theta_2) &~~~\mathrm{(branch ~23)} \\ +\end{array} +``` + +By substituting $`b_{12}=-10`$p.u., $`b_{13}=-15`$p.u., and $`b_{23}=12`$p.u., we obtain residuals +```math +\begin{aligned} +P_{2} &= -2.5 - 10|V_2|\sin(\theta_2) - 13.2|V_2|\sin(\theta_2 - \theta_3), \\ +Q_{2} &= 0.8 - 22|V_2|^2 + 10|V_2|\cos(\theta_2) + 13.2|V_2|\cos(\theta_2 - \theta_3), \\ +P_{3} &= -2 - 16.5\sin(\theta_3) + 13.2|V_2|\sin(\theta_2 - \theta_3), +\end{aligned} +``` +with variables $`\theta_2, |V_2|`$ and $`\theta_3`$. + +### Jacobian + +Nonlinear solver can approximate Jacobian numerically, however this is computationaly expensive and scales poorly with the size of the problem. Typically, one needs to provide Jacobian in addition to residual to the nonlinear solver. For nonlinear problem defined by (vector) function $`\mathbf{f}(\mathbf{x})=0`$, Jacobian matrix is defined as +```math +J_{i,j}=\frac{\partial f_i}{\partial x_j}, ~~~ i,j=1,\ldots,N +``` +where $`N`$ is the size of vectors $`\mathbf{f}`$ and $`\mathbf{x}`$. Jacobian for our model is evaluated as +```math +\mathbf{J} = +\begin{bmatrix} +\dfrac{\partial P_{2}}{\partial \theta_{2}} & +\dfrac{\partial P_{2}}{\partial | V_{2} |} & +\dfrac{\partial P_{2}}{\partial \theta_{3}} \\ +&&\\ +\dfrac{\partial Q_{2}}{\partial \theta_{2}} & +\dfrac{\partial Q_{2}}{\partial | V_{2} |} & +\dfrac{\partial Q_{2}}{\partial \theta_{3}} \\ +&&\\ +\dfrac{\partial P_{3}}{\partial \theta_{2}} & +\dfrac{\partial P_{3}}{\partial | V_{2} |} & +\dfrac{\partial P_{3}}{\partial \theta_{3}} +\end{bmatrix} +``` +where partial derivatives are: + +```math +\begin{aligned} +\dfrac{\partial P_{2}}{\partial \theta_{2}} &= -10|V_{2}| \cos(\theta_{2}) - 13.2|V_{2}| \cos(\theta_{2}-\theta_{3}) \\ +\dfrac{\partial P_{2}}{\partial |V_{2}|} &= -10 \sin(\theta_{2}) - 13.2 \sin(\theta_{2}-\theta_{3}) \\ +\dfrac{\partial P_{2}}{\partial \theta_{3}} &= 13.2|V_{2}| \cos(\theta_{2}-\theta_{3}) \\ +\end{aligned} +``` +```math +\begin{aligned} +\dfrac{\partial Q_{2}}{\partial \theta_{2}} &= -10|V_{2}| \sin(\theta_{2}) - 13.2 |V_{2}| \sin(\theta_{2} - \theta_{3}) \\ +\dfrac{\partial Q_{2}}{\partial |V_{2}|} &= -44|V_{2}| + 10 \cos(\theta_{2}) + 13.2 \cos(\theta_{2} - \theta_{3}) \\ +\dfrac{\partial Q_{2}}{\partial \theta_{3}} &= 13.2|V_{2}| \sin(\theta_{2} - \theta_{3}) \\ +\end{aligned} +``` +```math +\begin{aligned} +\dfrac{\partial P_{3}}{\partial \theta_{2}} &= 13.2|V_{2}| \cos(\theta_{2}-\theta_{3}) \\ +\dfrac{\partial P_{3}}{\partial |V_{2}|} &= 13.2 \sin(\theta_{2}-\theta_{3}) \\ +\dfrac{\partial P_{3}}{\partial \theta_{3}} &= -16.5 \cos(\theta_{3}) - 13.2|V_{2}| \cos(\theta_{2}-\theta_{3}) \\ +\end{aligned} +``` + +### Reference solution + +The reference solution to the nonlinear problem is: +```math +\theta_{2} = -4.88\degree \\ +|V_{2}| = 1.10 \mathrm{p.u.} \\ +\theta_{3} = 1.49\degree \\ +``` diff --git a/Examples/ParameterEstimation/CMakeLists.txt b/Examples/ParameterEstimation/CMakeLists.txt new file mode 100644 index 0000000..c40a5a2 --- /dev/null +++ b/Examples/ParameterEstimation/CMakeLists.txt @@ -0,0 +1,61 @@ +# +# Copyright (c) 2017, Lawrence Livermore National Security, LLC. +# Produced at the Lawrence Livermore National Laboratory. +# Written by Slaven Peles . +# LLNL-CODE-718378. +# All rights reserved. +# +# 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 +# modification, are permitted provided that the following conditions are met: +# - Redistributions of source code must retain the above copyright notice, +# this list of conditions and the disclaimer below. +# - Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the disclaimer (as noted below) in the +# documentation and/or other materials provided with the distribution. +# - Neither the name of the LLNS/LLNL nor the names of its contributors may +# be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL +# SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, +# OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISINGIN ANY +# WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +# THE POSSIBILITY OF SUCH DAMAGE. +# +# Lawrence Livermore National Laboratory is operated by Lawrence Livermore +# National Security, LLC, for the U.S. Department of Energy, National +# Nuclear Security Administration under Contract DE-AC52-07NA27344. +# +# This document was prepared as an account of work sponsored by an agency +# of the United States government. Neither the United States government nor +# Lawrence Livermore National Security, LLC, nor any of their employees +# makes any warranty, expressed or implied, or assumes any legal liability +# or responsibility for the accuracy, completeness, or usefulness of any +# information, apparatus, product, or process disclosed, or represents that +# its use would not infringe privately owned rights. Reference herein to +# any specific commercial product, process, or service by trade name, +# trademark, manufacturer, or otherwise does not necessarily constitute or +# imply its endorsement, recommendation, or favoring by the United States +# government or Lawrence Livermore National Security, LLC. The views and +# opinions of authors expressed herein do not necessarily state or reflect +# those of the United States government or Lawrence Livermore National +# Security, LLC, and shall not be used for advertising or product +# endorsement purposes. +# + +add_executable(paramest ParameterEstimation.cpp) +target_link_libraries(paramest Bus Generator4Param ${solver_libs}) +install(TARGETS paramest RUNTIME DESTINATION bin) +install(FILES lookup_table.dat DESTINATION bin) diff --git a/Examples/ParameterEstimation/ParameterEstimation.cpp b/Examples/ParameterEstimation/ParameterEstimation.cpp new file mode 100644 index 0000000..c91308a --- /dev/null +++ b/Examples/ParameterEstimation/ParameterEstimation.cpp @@ -0,0 +1,221 @@ +/* + * + * Copyright (c) 2017, Lawrence Livermore National Security, LLC. + * Produced at the Lawrence Livermore National Laboratory. + * Written by Slaven Peles . + * LLNL-CODE-718378. + * All rights reserved. + * + * 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 + * modification, are permitted provided that the following conditions are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the disclaimer (as noted below) in the + * documentation and/or other materials provided with the distribution. + * - Neither the name of the LLNS/LLNL nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL + * SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISINGIN ANY + * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + * Lawrence Livermore National Laboratory is operated by Lawrence Livermore + * National Security, LLC, for the U.S. Department of Energy, National + * Nuclear Security Administration under Contract DE-AC52-07NA27344. + * + * This document was prepared as an account of work sponsored by an agency + * of the United States government. Neither the United States government nor + * Lawrence Livermore National Security, LLC, nor any of their employees + * makes any warranty, expressed or implied, or assumes any legal liability + * or responsibility for the accuracy, completeness, or usefulness of any + * information, apparatus, product, or process disclosed, or represents that + * its use would not infringe privately owned rights. Reference herein to + * any specific commercial product, process, or service by trade name, + * trademark, manufacturer, or otherwise does not necessarily constitute or + * imply its endorsement, recommendation, or favoring by the United States + * government or Lawrence Livermore National Security, LLC. The views and + * opinions of authors expressed herein do not necessarily state or reflect + * those of the United States government or Lawrence Livermore National + * Security, LLC, and shall not be used for advertising or product + * endorsement purposes. + * + */ + + +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + + +int main(int argc, char** argv) +{ + using namespace ModelLib; + using namespace AnalysisManager::Sundials; + using namespace AnalysisManager; + using namespace GridKit::Testing; + + // Create an infinite bus + BaseBus* bus = new BusSlack(1.0, 0.0); + + // Attach a generator to that bus + Generator4Param* gen = new Generator4Param(bus); + + // Create a system model + SystemModel* model = new SystemModel(); + model->addBus(bus); + model->addComponent(gen); + + // allocate model components + model->allocate(); + + // Create numerical integrator and configure it for the generator model + Ida* idas = new Ida(model); + + const std::string input_data = (argc == 2) ? argv[1] : "lookup_table.dat"; + double t_init = -1.0; + double t_final = -1.0; + + GridKit::setLookupTable(gen->getLookupTable(), input_data, t_init, t_final); + + std::cout << "Performing parameter estimation with respect to data\nfrom " + << "t_init = " << t_init << " to t_final = " << t_final << "\n"; + + // setup simulation + idas->configureSimulation(); + idas->configureAdjoint(); + idas->getDefaultInitialCondition(); + idas->initializeSimulation(t_init); + idas->configureQuadrature(); + idas->initializeQuadrature(); + + double t_fault = 0.1; + double t_clear = 0.1; + idas->runSimulation(t_fault); + idas->saveInitialCondition(); + // create initial condition after a fault + { + idas->getSavedInitialCondition(); + idas->initializeSimulation(t_init); + gen->V() = 0.0; + idas->runSimulation(t_clear, 20); + gen->V() = 1.0; + idas->saveInitialCondition(); + } + + // Set integration time for dynamic constrained optimization + idas->setIntegrationTime(t_init, t_final, 100); + + // Guess value of inertia coefficient + model->param()[0] = 3.0; + + // Create an instance of the IpoptApplication + Ipopt::SmartPtr ipoptApp = IpoptApplicationFactory(); + + // Set solver tolerance + const double tol = 1e-5; + + // Initialize the IpoptApplication and process the options + Ipopt::ApplicationReturnStatus status; + status = ipoptApp->Initialize(); + if (status != Ipopt::Solve_Succeeded) + { + std::cout << "\n\n*** Initialization failed! ***\n\n"; + return (int) status; + } + + // Configure Ipopt application + ipoptApp->Options()->SetStringValue("hessian_approximation", "limited-memory"); + ipoptApp->Options()->SetNumericValue("tol", tol); + ipoptApp->Options()->SetIntegerValue("print_level", 0); + + // Create dynamic objective interface to Ipopt solver + Ipopt::SmartPtr ipoptDynamicObjectiveInterface = + new IpoptInterface::DynamicObjective(idas); + + // Solve the problem + status = ipoptApp->OptimizeTNLP(ipoptDynamicObjectiveInterface); + std::cout << "\n\nProblem formulated as dynamic objective optimiztion ...\n"; + + if (status == Ipopt::Solve_Succeeded) + { + // Print result + std::cout << "\nSucess:\n The problem solved in " + << ipoptApp->Statistics()->IterationCount() << " iterations!\n" + << " Optimal value of H = " << model->param()[0] << "\n" + << " The final value of the objective function G(H) = " + << ipoptApp->Statistics()->FinalObjective() << "\n\n"; + } + + // Store dynamic objective optimization results + double* results = new double[model->size_opt()]; + for(unsigned i=0; i size_opt(); ++i) + { + results[i] = model->param()[i]; + } + + // Guess value of inertia coefficient + model->param()[0] = 3.0; + + // Create dynamic constraint interface to Ipopt solver + Ipopt::SmartPtr ipoptDynamicConstraintInterface = + new IpoptInterface::DynamicConstraint(idas); + + // Solve the problem + status = ipoptApp->OptimizeTNLP(ipoptDynamicConstraintInterface); + std::cout << "\n\nProblem formulated as dynamic constraint optimiztion ...\n"; + + if (status == Ipopt::Solve_Succeeded) + { + // Print result + std::cout << "\nSucess:\n The problem solved in " + << ipoptApp->Statistics()->IterationCount() << " iterations!\n" + << " Optimal value of H = " << model->param()[0] << "\n" + << " The final value of the objective function G(H) = " + << ipoptApp->Statistics()->FinalObjective() << "\n\n"; + } + + // Compare results of the two optimization methods + int retval = 0; + for(unsigned i=0; i size_opt(); ++i) + { + if(!isEqual(results[i], model->param()[i], 10*tol)) + --retval; + } + + if(retval < 0) + { + std::cout << "The two results differ beyond solver tolerance!\n"; + } + + delete [] results; + delete idas; + delete model; + return retval; +} diff --git a/Examples/ParameterEstimation/lookup_table.dat b/Examples/ParameterEstimation/lookup_table.dat new file mode 100644 index 0000000..bd4785e --- /dev/null +++ b/Examples/ParameterEstimation/lookup_table.dat @@ -0,0 +1,101 @@ + 0 0.092182 0.99596 -0.17574 0.98107 2.7864 0.58172 -1.5217 0.092914 0.4666 -0.18534 -0.49105 -1.3472 + 0.05 0.032044 0.99785 -0.15175 0.98425 -0.058476 0.52344 -0.80946 0.048601 0.41347 0.063192 0.20608 -3.487 + 0.1 0.016599 1.0006 -0.1331 0.98738 -0.047843 0.42635 0.22214 0.058264 0.34627 0.061871 0.19728 -0.34913 + 0.15 0.05483 1.0034 -0.11578 0.99044 -0.036909 0.48633 1.2885 0.052391 0.35895 0.060531 0.29873 2.6589 + 0.2 0.14141 1.0056 -0.096146 0.99341 -0.0096526 0.67712 2.1155 0.033619 0.4347 0.057775 0.88075 4.767 + 0.25 0.25913 1.0067 -0.071796 0.99616 0.057594 0.93888 2.5118 0.0078597 0.54123 0.051547 1.8306 5.4428 + 0.3 0.38426 1.0064 -0.042151 0.9985 0.16989 1.1964 2.4129 -0.017766 0.64033 0.04143 2.5703 4.6352 + 0.35 0.49314 1.005 -0.0084123 1.0003 0.30164 1.3852 1.8807 -0.037326 0.70102 0.029679 2.5484 2.803 + 0.4 0.5676 1.0028 0.02705 1.0015 0.41029 1.4705 1.0659 -0.047388 0.70818 0.020018 1.6775 0.59248 + 0.45 0.59823 1.0004 0.061508 1.0024 0.46162 1.4465 0.16122 -0.046838 0.66177 0.01542 0.34633 -1.5002 + 0.5 0.58551 0.99831 0.092489 1.0031 0.44697 1.3275 -0.63666 -0.03629 0.57124 0.016604 -0.86716 -3.1729 + 0.55 0.53921 0.99693 0.11815 1.0041 0.3845 1.1404 -1.1581 -0.01804 0.45206 0.021952 -1.5169 -4.1743 + 0.6 0.47618 0.99657 0.13756 1.0054 0.30672 0.92541 -1.2942 0.0037576 0.32514 0.028599 -1.4916 -4.2579 + 0.65 0.41655 0.99727 0.15094 1.0069 0.24321 0.7317 -1.0284 0.023663 0.2149 0.03396 -0.99666 -3.3294 + 0.7 0.37865 0.99881 0.1597 1.0087 0.20996 0.60591 -0.44676 0.036533 0.14325 0.036646 -0.32132 -1.6045 + 0.75 0.37438 1.0008 0.16612 1.0105 0.21157 0.57628 0.28444 0.039247 0.12202 0.036276 0.38888 0.41887 + 0.8 0.40628 1.0026 0.17271 1.0123 0.24931 0.64279 0.96721 0.031616 0.14868 0.032757 1.1244 2.1458 + 0.85 0.46736 1.0038 0.18152 1.0138 0.32351 0.77782 1.4274 0.01626 0.20738 0.026079 1.8233 3.1005 + 0.9 0.5435 1.0041 0.19359 1.0148 0.42737 0.93662 1.5597 -0.0023426 0.27472 0.016856 2.2643 3.094 + 0.95 0.61757 1.0036 0.20876 1.0154 0.54119 1.0735 1.3495 -0.019315 0.32797 0.0068229 2.1874 2.269 + 1 0.67388 1.0023 0.2259 1.0156 0.63599 1.1557 0.86676 -0.030741 0.35194 -0.0014869 1.5133 0.97283 + 1.05 0.70183 1.0006 0.24337 1.0154 0.68574 1.1689 0.23996 -0.034374 0.34107 -0.0058147 0.43855 -0.43842 + 1.1 0.69804 0.999 0.25946 1.0151 0.67947 1.1144 -0.37686 -0.029749 0.29776 -0.0052298 -0.65858 -1.6945 + 1.15 0.66677 0.99778 0.27273 1.0149 0.62579 1.0057 -0.8372 -0.018123 0.23009 -0.00051302 -1.4072 -2.5773 + 1.2 0.61875 0.99726 0.28227 1.015 0.54794 0.86636 -1.034 -0.0023951 0.1509 0.0062815 -1.6133 -2.8839 + 1.25 0.56848 0.99754 0.28791 1.0155 0.4729 0.72906 -0.92731 0.013357 0.076625 0.012787 -1.3187 -2.4894 + 1.3 0.53046 0.99852 0.2903 1.0163 0.42123 0.62812 -0.55695 0.024943 0.023763 0.017213 -0.71415 -1.4609 + 1.35 0.51537 0.99991 0.29083 1.0172 0.40344 0.58875 -0.032383 0.02938 0.0035422 0.018657 0.010285 -0.090332 + 1.4 0.52734 1.0013 0.29123 1.0181 0.42221 0.6178 0.49978 0.0258 0.01767 0.016901 0.73252 1.2044 + 1.45 0.5631 1.0024 0.29303 1.0188 0.47491 0.70149 0.89832 0.015603 0.057713 0.012197 1.3465 2.0439 + 1.5 0.61328 1.0028 0.29718 1.0193 0.5526 0.81115 1.0657 0.0018875 0.1084 0.005344 1.7041 2.2291 + 1.55 0.66527 1.0026 0.30377 1.0194 0.63849 0.91394 0.97119 -0.01157 0.1532 -0.0021811 1.6554 1.7927 + 1.6 0.70664 1.0017 0.31219 1.0191 0.71058 0.98342 0.65256 -0.02141 0.17953 -0.0084547 1.1596 0.93821 + 1.65 0.72829 1.0005 0.32131 1.0186 0.74915 1.0051 0.20084 -0.025446 0.18122 -0.011764 0.3506 -0.079491 + 1.7 0.72648 0.9993 0.3299 1.018 0.74483 0.97655 -0.26555 -0.022979 0.15838 -0.011312 -0.50674 -1.0341 + 1.75 0.70346 0.99833 0.33682 1.0175 0.70235 0.90588 -0.6294 -0.014823 0.11612 -0.0075355 -1.1352 -1.7356 + 1.8 0.66675 0.99787 0.34134 1.0173 0.63805 0.80994 -0.80214 -0.0031621 0.063634 -0.001879 -1.365 -2.0218 + 1.85 0.62709 0.99802 0.34322 1.0173 0.5727 0.7123 -0.74613 0.0088896 0.012931 0.0038326 -1.1886 -1.7971 + 1.9 0.59559 0.99871 0.34287 1.0176 0.52403 0.6382 -0.48508 0.018094 -0.023766 0.0080534 -0.72308 -1.1001 + 1.95 0.58072 0.99974 0.34122 1.0181 0.50266 0.60693 -0.097249 0.022059 -0.037756 0.0098658 -0.12061 -0.12788 + 2 0.58615 1.0008 0.33951 1.0186 0.51207 0.62506 0.30796 0.019946 -0.026975 0.0089817 0.48883 0.82404 + 2.05 0.60997 1.0016 0.33885 1.0189 0.54977 0.68425 0.62179 0.012644 0.0032742 0.0056364 0.99163 1.4751 + 2.1 0.64547 1.002 0.33998 1.0191 0.6075 0.76477 0.76601 0.0024013 0.042402 0.00056515 1.2707 1.6634 + 2.15 0.68324 1.0019 0.34304 1.019 0.67146 0.8428 0.71186 -0.007921 0.078364 -0.0050178 1.23 1.3886 + 2.2 0.71374 1.0013 0.3476 1.0186 0.72486 0.89803 0.48372 -0.015674 0.10141 -0.009643 0.85497 0.77941 + 2.25 0.72981 1.0004 0.35287 1.018 0.75305 0.91825 0.14867 -0.019057 0.10625 -0.01204 0.24823 0.020097 + 2.3 0.72833 0.99946 0.35791 1.0174 0.749 0.90057 -0.20298 -0.017433 0.092372 -0.011611 -0.39897 -0.70813 + 2.35 0.71076 0.99873 0.36186 1.0169 0.71588 0.8506 -0.48061 -0.0114 0.063443 -0.0086484 -0.88495 -1.2472 + 2.4 0.68267 0.99837 0.36412 1.0166 0.66543 0.78114 -0.61543 -0.0026342 0.026448 -0.0041938 -1.0793 -1.4707 + 2.45 0.65212 0.99847 0.36452 1.0165 0.61318 0.70996 -0.57767 0.0064863 -0.0095402 0.00038963 -0.96304 -1.3121 + 2.5 0.62752 0.99898 0.36334 1.0166 0.57309 0.65581 -0.38421 0.013511 -0.035433 0.0038837 -0.61044 -0.80482 + 2.55 0.61534 0.99975 0.36125 1.0169 0.55418 0.63292 -0.093179 0.016621 -0.044793 0.0055079 -0.13527 -0.093278 + 2.6 0.61846 1.0006 0.35916 1.0171 0.55973 0.64633 0.21335 0.015154 -0.035999 0.0049884 0.35025 0.60951 + 2.65 0.63555 1.0012 0.3579 1.0173 0.58767 0.69028 0.45307 0.0097381 -0.012759 0.0025188 0.74421 1.0994 + 2.7 0.66163 1.0015 0.358 1.0174 0.63107 0.75061 0.56599 0.0020367 0.017305 -0.0012824 0.95409 1.2537 + 2.75 0.68963 1.0014 0.35959 1.0172 0.67891 0.80984 0.52905 -0.0057959 0.045327 -0.0054476 0.91581 1.0628 + 2.8 0.71231 1.001 0.36238 1.0168 0.71845 0.85255 0.35956 -0.011729 0.0639 -0.008862 0.62861 0.61292 + 2.85 0.7242 1.0003 0.36575 1.0163 0.73892 0.86907 0.10785 -0.014355 0.068781 -0.010592 0.17277 0.03923 + 2.9 0.72287 0.99958 0.36901 1.0158 0.73524 0.85679 -0.15741 -0.013164 0.059383 -0.010203 -0.31194 -0.51585 + 2.95 0.7094 0.99903 0.3715 1.0154 0.70971 0.81993 -0.36713 -0.0086135 0.038466 -0.0079121 -0.67943 -0.92521 + 3 0.68797 0.99876 0.37276 1.015 0.67092 0.76835 -0.46903 -0.0019947 0.011418 -0.0044785 -0.83252 -1.0917 + 3.05 0.66468 0.99883 0.37265 1.0149 0.6304 0.71561 -0.44068 0.0048852 -0.01485 -0.00091673 -0.75152 -0.97008 + 3.1 0.64588 0.99922 0.3714 1.0149 0.59888 0.67568 -0.2949 0.010183 -0.033558 0.0018382 -0.48502 -0.59083 + 3.15 0.63643 0.9998 0.3695 1.0151 0.58359 0.65904 -0.075441 0.01254 -0.039986 0.0031594 -0.11729 -0.062448 + 3.2 0.63853 1.0004 0.36763 1.0152 0.58731 0.66933 0.15602 0.011455 -0.032964 0.002814 0.2606 0.45958 + 3.25 0.65119 1.0009 0.36639 1.0153 0.6084 0.70238 0.33753 0.0073916 -0.015201 0.00095678 0.56366 0.82657 + 3.3 0.67068 1.0011 0.36619 1.0153 0.64122 0.74782 0.42367 0.0015878 0.0077184 -0.0019123 0.71982 0.9468 + 3.35 0.69166 1.0011 0.36714 1.0151 0.67717 0.79271 0.39666 -0.0043362 0.029221 -0.0050367 0.68533 0.80895 + 3.4 0.70866 1.0007 0.369 1.0148 0.70663 0.82539 0.26923 -0.0088381 0.043696 -0.007574 0.46549 0.47247 + 3.45 0.71753 1.0002 0.37133 1.0144 0.72165 0.83832 0.079346 -0.010836 0.047827 -0.0088364 0.12275 0.037659 + 3.5 0.71642 0.99968 0.3736 1.014 0.71856 0.82936 -0.12092 -0.0099376 0.041085 -0.0085113 -0.2402 -0.3848 + 3.55 0.70615 0.99926 0.37529 1.0136 0.69908 0.80173 -0.27916 -0.0064934 0.025571 -0.0067586 -0.51702 -0.6947 + 3.6 0.68988 0.99906 0.37608 1.0133 0.66953 0.76303 -0.35586 -0.0014927 0.0054381 -0.0041382 -0.63556 -0.81792 + 3.65 0.67221 0.99911 0.37585 1.0132 0.63849 0.72359 -0.33426 0.003695 -0.014051 -0.0014053 -0.57805 -0.72362 + 3.7 0.65794 0.99941 0.37477 1.0131 0.61413 0.69389 -0.22416 0.0076861 -0.027824 0.00072777 -0.37704 -0.43804 + 3.75 0.65073 0.99984 0.37322 1.0132 0.60214 0.68163 -0.058541 0.0094643 -0.032405 0.0017685 -0.09503 -0.043211 + 3.8 0.65224 1.0003 0.3717 1.0133 0.60478 0.68948 0.11622 0.0086548 -0.026956 0.0015269 0.19601 0.34652 + 3.85 0.66172 1.0007 0.37066 1.0133 0.62075 0.71435 0.25351 0.0056002 -0.013481 0.00012396 0.42763 0.62217 + 3.9 0.67638 1.0008 0.37041 1.0133 0.64561 0.74862 0.31899 0.0012253 0.0038955 -0.0020459 0.54423 0.71516 + 3.95 0.69218 1.0008 0.37103 1.0131 0.67272 0.78261 0.29906 -0.0032526 0.020276 -0.0043979 0.51521 0.6146 + 4 0.70501 1.0005 0.37235 1.0129 0.6948 0.80753 0.20314 -0.0066648 0.031412 -0.006296 0.34779 0.36221 + 4.05 0.7117 1.0002 0.37404 1.0125 0.70598 0.81755 0.059802 -0.0081852 0.034732 -0.007231 0.089999 0.032724 + 4.1 0.71085 0.99976 0.37569 1.0122 0.70356 0.81094 -0.09153 -0.0075112 0.029785 -0.0069744 -0.18232 -0.28849 + 4.15 0.70308 0.99944 0.37691 1.0118 0.68882 0.79015 -0.21115 -0.0049103 0.018167 -0.0056445 -0.39125 -0.52331 + 4.2 0.69077 0.99929 0.37744 1.0116 0.66641 0.76101 -0.2692 -0.0011349 0.0030609 -0.0036548 -0.48291 -0.61537 + 4.25 0.67741 0.99933 0.37722 1.0115 0.64275 0.73138 -0.25306 0.0027796 -0.011534 -0.0015685 -0.44215 -0.54306 + 4.3 0.66659 0.99955 0.37636 1.0114 0.62405 0.70911 -0.17014 0.0057928 -0.021811 7.2391e-05 -0.29099 -0.32805 + 4.35 0.6611 0.99988 0.37516 1.0115 0.61473 0.69993 -0.045234 0.0071426 -0.025191 0.00088477 -0.075904 -0.032204 + 4.4 0.66219 1.0002 0.37397 1.0115 0.61659 0.70582 0.086781 0.0065456 -0.021061 0.00071617 0.14707 0.25992 + 4.45 0.66931 1.0005 0.37315 1.0115 0.62866 0.7245 0.19078 0.004254 -0.010901 -0.00034126 0.32386 0.46789 + 4.5 0.68036 1.0006 0.37293 1.0115 0.64748 0.75033 0.24079 0.00095771 0.0022315 -0.0019814 0.41169 0.54018 + 4.55 0.6923 1.0006 0.37336 1.0113 0.66796 0.77607 0.22633 -0.0024282 0.014673 -0.0037554 0.3887 0.46697 + 4.6 0.70202 1.0004 0.37433 1.0111 0.6846 0.79507 0.1543 -0.0050186 0.023205 -0.0051834 0.26195 0.2778 + 4.65 0.70713 1.0001 0.37559 1.0108 0.69303 0.80285 0.046181 -0.0061829 0.025838 -0.0058853 0.06809 0.028431 + 4.7 0.70653 0.99982 0.37681 1.0105 0.69123 0.79801 -0.068258 -0.0056866 0.022194 -0.0056915 -0.13671 -0.21565 + 4.75 0.7007 0.99958 0.37772 1.0103 0.68014 0.78239 -0.15895 -0.0037302 0.013473 -0.0046885 -0.29493 -0.39407 + 4.8 0.69142 0.99946 0.37811 1.0101 0.6632 0.76043 -0.20324 -0.00088299 0.0021014 -0.0031816 -0.36611 -0.4638 + 4.85 0.68132 0.99949 0.37794 1.0099 0.64521 0.73809 -0.19155 0.0020735 -0.0088886 -0.0015923 -0.33754 -0.40934 + 4.9 0.67312 0.99966 0.37728 1.0099 0.63087 0.7213 -0.12935 0.0043559 -0.016631 -0.00033208 -0.22427 -0.24786 + 4.95 0.66892 0.99991 0.37636 1.0099 0.62362 0.71433 -0.035255 0.0053896 -0.019197 0.000302 -0.060867 -0.025908 + 5 0.66968 1.0002 0.37545 1.0099 0.6249 0.71867 0.064531 0.0049577 -0.016122 0.00018828 0.10945 0.19374 diff --git a/LICENSE b/LICENSE index a5ec7f3..7c44911 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ ******************************************************************************* -GridKit: ................................, version 0.0.1 +GridKit™: ................................, version 0.0.5 Copyright (c) 2017, Lawrence Livermore National Security, LLC. Produced at the Lawrence Livermore National Laboratory. @@ -60,4 +60,4 @@ by the United States Government or Lawrence Livermore National Security, LLC. The views and opinions of authors expressed herein do not necessarily state or reflect those of the United States Government or Lawrence Livermore National Security, LLC, and shall not be used for advertising or product -endorsement purposes. \ No newline at end of file +endorsement purposes. diff --git a/ModelEvaluator.hpp b/ModelEvaluator.hpp index 1356dca..5eda481 100644 --- a/ModelEvaluator.hpp +++ b/ModelEvaluator.hpp @@ -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 diff --git a/ModelEvaluatorImpl.hpp b/ModelEvaluatorImpl.hpp index 76a224e..95b7a84 100644 --- a/ModelEvaluatorImpl.hpp +++ b/ModelEvaluatorImpl.hpp @@ -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 @@ -114,12 +114,12 @@ namespace ModelLib return size_opt_; } - virtual void updateTime(real_type t, real_type a) - { - time_ = t; - alpha_ = a; - //std::cout << "t = " << t << "\n"; - } + // virtual void updateTime(real_type t, real_type a) + // { + // time_ = t; + // alpha_ = a; + // std::cout << "updateTime: t = " << time_ << "\n"; + // } virtual void setTolerances(real_type& rtol, real_type& atol) const { diff --git a/README.md b/README.md index b3d30ca..31dc1aa 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,48 @@ -# GridKit +# GridKit™ This is experimental code for prototyping interfaces for dynamic simulations, sensitivity analysis and optimization. Target applications are power grids, but the methodology and the framework could be used in other areas without major modifications. + +## Installation Guide + +GridKit™ has been built and tested on Linux and Mac platforms. It should +be possible to build it on Windows, as well, with Cygwin or native. +Before installing GridKit™ make sure you have all needed dependencies. + +### Dependencies +You should have all of the following installed before installing GridKit™ +- A version of + - [SUNDIALS](https://github.com/LLNL/sundials) >= 4.x + - [Suitesparse](https://github.com/DrTimothyAldenDavis/SuiteSparse) >= 5.x (optional) + - [Ipopt](https://github.com/coin-or/Ipopt) >= 3.x (optional) +- [CMake](https://cmake.org/) >= 3.12 +- C++ 11 compiler + +### Installing + +GridKit™ uses CMake for build configuration. Per CMake best practices it is recommended +to build GridKit™ outside the source directory. Building GridKit™ can be as simple as executing +```bash +cmake source_dir +make +make install +``` +in the build directory. Dependencies should be autodetected if they are installed in +standard locations, otherwise you need to specify the location of the dependency +manually. For example: +```bash +cmake -DSUNDIALS_DIR=/path/to/sundials/install source_dir +``` +You can also use `ccmake` or `cmake-gui` tools to adjust GridKit™ build configuration. + +### Testing + +Several examples are built together with GridKit™ libraries. These are also used +as functionality test and executed by running `ctest` in the build directory. + +## Contributors + +GridKit™ is written by Slaven Peles (slaven.peles@pnnl.gov) and has received contributions +from Tamara Becejac, R. Cameron Rutherford and Asher J. Mancinelli, all from Pacific Northwest National Laboratory. diff --git a/ScalarTraits.hpp b/ScalarTraits.hpp index af2e617..072e837 100644 --- a/ScalarTraits.hpp +++ b/ScalarTraits.hpp @@ -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 diff --git a/Solver/CMakeLists.txt b/Solver/CMakeLists.txt index 8a07415..c9e30cc 100644 --- a/Solver/CMakeLists.txt +++ b/Solver/CMakeLists.txt @@ -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 @@ -56,6 +56,9 @@ # add_subdirectory(Dynamic) -add_subdirectory(Optimization) +add_subdirectory(SteadyState) +if(GRIDKIT_ENABLE_IPOPT) + add_subdirectory(Optimization) +endif() set(solver_libs ${solver_libs} PARENT_SCOPE) diff --git a/Solver/Dynamic/CMakeLists.txt b/Solver/Dynamic/CMakeLists.txt index d289a64..c75e7ec 100644 --- a/Solver/Dynamic/CMakeLists.txt +++ b/Solver/Dynamic/CMakeLists.txt @@ -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 diff --git a/Solver/Dynamic/DynamicSolver.hpp b/Solver/Dynamic/DynamicSolver.hpp index d172fef..7094d8a 100644 --- a/Solver/Dynamic/DynamicSolver.hpp +++ b/Solver/Dynamic/DynamicSolver.hpp @@ -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 diff --git a/Solver/Dynamic/Ida.cpp b/Solver/Dynamic/Ida.cpp index 97d5c7b..9370b72 100644 --- a/Solver/Dynamic/Ida.cpp +++ b/Solver/Dynamic/Ida.cpp @@ -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 @@ -61,7 +61,7 @@ #include #include -#include +// #include #include /* access to IDADls interface */ #include @@ -125,7 +125,7 @@ namespace Sundials // Tag differential variables std::vector& tag = model_->tag(); - if (tag.size() == model_->size()) + if (static_cast(tag.size()) == model_->size()) { tag_ = N_VClone(yy_); checkAllocation((void*) tag_, "N_VClone"); @@ -224,10 +224,12 @@ namespace Sundials /* In loop, call IDASolve, print results, and test for error. * Break out of loop when NOUT preset output times have been reached. */ + //printOutput(0.0); while(nout > iout) { retval = IDASolve(solver_, tout, &tret, yy_, yp_, IDA_NORMAL); checkOutput(retval, "IDASolve"); + //printOutput(tout); if (retval == IDA_SUCCESS) { @@ -235,7 +237,7 @@ namespace Sundials tout += dt; } } - + //std::cout << "\n"; return retval; } @@ -305,10 +307,14 @@ namespace Sundials real_type dt = tf/nout; real_type tout = dt; + //printOutput(0.0); + //printSpecial(0.0, yy_); for(int i = 0; i < nout; ++i) { retval = IDASolve(solver_, tout, &tret, yy_, yp_, IDA_NORMAL); checkOutput(retval, "IDASolve"); + //printSpecial(tout, yy_); + //printOutput(tout); if (retval == IDA_SUCCESS) { @@ -607,16 +613,35 @@ namespace Sundials template void Ida::printOutput(realtype t) { - realtype *yval = N_VGetArrayPointer_Serial(yy_); + realtype *yval = N_VGetArrayPointer_Serial(yy_); + realtype *ypval = N_VGetArrayPointer_Serial(yp_); std::cout << std::setprecision(5) << std::setw(7) << t << " "; for (IdxT i = 0; i < model_->size(); ++i) { std::cout << yval[i] << " "; } + for (IdxT i = 0; i < model_->size(); ++i) + { + std::cout << ypval[i] << " "; + } std::cout << "\n"; } + template + void Ida::printSpecial(realtype t, N_Vector y) + { + realtype *yval = N_VGetArrayPointer_Serial(y); + IdxT N = static_cast(N_VGetLength_Serial(y)); + std::cout << "{"; + std::cout << std::setprecision(5) << std::setw(7) << t; + for (IdxT i = 0; i < N; ++i) + { + std::cout << ", " << yval[i]; + } + std::cout << "},\n"; + } + template void Ida::printFinalStats() { diff --git a/Solver/Dynamic/Ida.hpp b/Solver/Dynamic/Ida.hpp index b13ffe9..8c82d98 100644 --- a/Solver/Dynamic/Ida.hpp +++ b/Solver/Dynamic/Ida.hpp @@ -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 @@ -65,7 +65,7 @@ #include #include #include /* access to sparse SUNMatrix */ -#include /* access to KLU linear solver */ +// #include /* access to KLU linear solver */ #include /* access to dense linear solver */ #include "ModelEvaluator.hpp" @@ -158,6 +158,7 @@ namespace AnalysisManager } void printOutput(realtype t); + void printSpecial(realtype t, N_Vector x); void printFinalStats(); private: diff --git a/Solver/Optimization/CMakeLists.txt b/Solver/Optimization/CMakeLists.txt index aaadda1..9e6b3fe 100644 --- a/Solver/Optimization/CMakeLists.txt +++ b/Solver/Optimization/CMakeLists.txt @@ -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 diff --git a/Solver/Optimization/DynamicConstraint.cpp b/Solver/Optimization/DynamicConstraint.cpp index ed674e2..486570e 100644 --- a/Solver/Optimization/DynamicConstraint.cpp +++ b/Solver/Optimization/DynamicConstraint.cpp @@ -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 diff --git a/Solver/Optimization/DynamicConstraint.hpp b/Solver/Optimization/DynamicConstraint.hpp index 857ef5c..234ebcf 100644 --- a/Solver/Optimization/DynamicConstraint.hpp +++ b/Solver/Optimization/DynamicConstraint.hpp @@ -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 diff --git a/Solver/Optimization/DynamicObjective.cpp b/Solver/Optimization/DynamicObjective.cpp index 5cd4e6f..04396d0 100644 --- a/Solver/Optimization/DynamicObjective.cpp +++ b/Solver/Optimization/DynamicObjective.cpp @@ -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 @@ -139,7 +139,7 @@ bool DynamicObjective::get_starting_point(Index n, bool init_x, N assert(init_lambda == false); // Initialize optimization parameters x - for(unsigned int i = 0; i < model_->size_opt(); ++i) + for(IdxT i = 0; i < model_->size_opt(); ++i) x[i] = model_->param()[i]; return true; @@ -169,7 +169,7 @@ bool DynamicObjective::eval_f(Index n, const Number* x, bool new_ template bool DynamicObjective::eval_grad_f(Index n, const Number* x, bool new_x, Number* grad_f) { - assert(model_->size_opt() == n); + assert(model_->size_opt() == static_cast(n)); // Update optimization parameters for(IdxT i = 0; i < model_->size_opt(); ++i) model_->param()[i] = x[i]; diff --git a/Solver/Optimization/DynamicObjective.hpp b/Solver/Optimization/DynamicObjective.hpp index be4e9dc..d299973 100644 --- a/Solver/Optimization/DynamicObjective.hpp +++ b/Solver/Optimization/DynamicObjective.hpp @@ -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 diff --git a/Solver/Optimization/OptimizationSolver.hpp b/Solver/Optimization/OptimizationSolver.hpp index 9cca2d2..4da3981 100644 --- a/Solver/Optimization/OptimizationSolver.hpp +++ b/Solver/Optimization/OptimizationSolver.hpp @@ -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 diff --git a/Solver/SteadyState/CMakeLists.txt b/Solver/SteadyState/CMakeLists.txt new file mode 100644 index 0000000..d216262 --- /dev/null +++ b/Solver/SteadyState/CMakeLists.txt @@ -0,0 +1,62 @@ +# +# Copyright (c) 2017, Lawrence Livermore National Security, LLC. +# Produced at the Lawrence Livermore National Laboratory. +# Written by Slaven Peles . +# LLNL-CODE-718378. +# All rights reserved. +# +# 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 +# modification, are permitted provided that the following conditions are met: +# - Redistributions of source code must retain the above copyright notice, +# this list of conditions and the disclaimer below. +# - Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the disclaimer (as noted below) in the +# documentation and/or other materials provided with the distribution. +# - Neither the name of the LLNS/LLNL nor the names of its contributors may +# be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL +# SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, +# OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISINGIN ANY +# WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +# THE POSSIBILITY OF SUCH DAMAGE. +# +# Lawrence Livermore National Laboratory is operated by Lawrence Livermore +# National Security, LLC, for the U.S. Department of Energy, National +# Nuclear Security Administration under Contract DE-AC52-07NA27344. +# +# This document was prepared as an account of work sponsored by an agency +# of the United States government. Neither the United States government nor +# Lawrence Livermore National Security, LLC, nor any of their employees +# makes any warranty, expressed or implied, or assumes any legal liability +# or responsibility for the accuracy, completeness, or usefulness of any +# information, apparatus, product, or process disclosed, or represents that +# its use would not infringe privately owned rights. Reference herein to +# any specific commercial product, process, or service by trade name, +# trademark, manufacturer, or otherwise does not necessarily constitute or +# imply its endorsement, recommendation, or favoring by the United States +# government or Lawrence Livermore National Security, LLC. The views and +# opinions of authors expressed herein do not necessarily state or reflect +# those of the United States government or Lawrence Livermore National +# Security, LLC, and shall not be used for advertising or product +# endorsement purposes. +# + +include_directories(${SUITESPARSE_INCLUDE_DIR} ${SUNDIALS_INCLUDE_DIR}) +add_library(Kinsol SHARED Kinsol.cpp) +target_link_libraries(Kinsol ${SUITESPARSE_LIBRARY} ${SUNDIALS_LIBRARY}) +set(solver_libs ${solver_libs} Kinsol PARENT_SCOPE) +install(TARGETS Kinsol LIBRARY DESTINATION lib) diff --git a/Solver/SteadyState/Kinsol.cpp b/Solver/SteadyState/Kinsol.cpp new file mode 100644 index 0000000..8ffadd8 --- /dev/null +++ b/Solver/SteadyState/Kinsol.cpp @@ -0,0 +1,335 @@ +/* + * + * Copyright (c) 2017, Lawrence Livermore National Security, LLC. + * Produced at the Lawrence Livermore National Laboratory. + * Written by Slaven Peles . + * LLNL-CODE-718378. + * All rights reserved. + * + * 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 + * modification, are permitted provided that the following conditions are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the disclaimer (as noted below) in the + * documentation and/or other materials provided with the distribution. + * - Neither the name of the LLNS/LLNL nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL + * SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISINGIN ANY + * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + * Lawrence Livermore National Laboratory is operated by Lawrence Livermore + * National Security, LLC, for the U.S. Department of Energy, National + * Nuclear Security Administration under Contract DE-AC52-07NA27344. + * + * This document was prepared as an account of work sponsored by an agency + * of the United States government. Neither the United States government nor + * Lawrence Livermore National Security, LLC, nor any of their employees + * makes any warranty, expressed or implied, or assumes any legal liability + * or responsibility for the accuracy, completeness, or usefulness of any + * information, apparatus, product, or process disclosed, or represents that + * its use would not infringe privately owned rights. Reference herein to + * any specific commercial product, process, or service by trade name, + * trademark, manufacturer, or otherwise does not necessarily constitute or + * imply its endorsement, recommendation, or favoring by the United States + * government or Lawrence Livermore National Security, LLC. The views and + * opinions of authors expressed herein do not necessarily state or reflect + * those of the United States government or Lawrence Livermore National + * Security, LLC, and shall not be used for advertising or product + * endorsement purposes. + * + */ + +/** + * @file Kinsol.cpp + * @author Slaven Peles + * + * Contains definition of interface to KINSOL nonlinear solver from + * SUNDIALS library. + * + */ + +#include +#include + +#include // access to KINSOL func., consts. +#include // access to serial N_Vector +#include // access to dense SUNMatrix +#include // access to dense SUNLinearSolver + +#include "ModelEvaluator.hpp" +#include "Kinsol.hpp" + + +namespace AnalysisManager +{ + +namespace Sundials +{ + + template + Kinsol::Kinsol(ModelLib::ModelEvaluator* model) + : SteadyStateSolver(model) + { + solver_ = KINCreate(); + tag_ = NULL; + } + + template + Kinsol::~Kinsol() + { + } + + template + int Kinsol::configureSimulation() + { + int retval = 0; + + // Allocate solution vectors + yy_ = N_VNew_Serial(model_->size()); + checkAllocation((void*) yy_, "N_VNew_Serial"); + + // Allocate scaling vector + scale_ = N_VClone(yy_); + checkAllocation((void*) scale_, "N_VClone"); + + // Create vectors to store restart initial condition + yy0_ = N_VClone(yy_); + checkAllocation((void*) yy0_, "N_VClone"); + + // Allocate and initialize KIN workspace + retval = KINInit(solver_, this->Residual, yy_); + checkOutput(retval, "KINInit"); + + // Set pointer to model data + retval = KINSetUserData(solver_, model_); + checkOutput(retval, "KINSetUserData"); + + // Set output verbosity level + retval = KINSetPrintLevel(solver_, 0); + checkOutput(retval, "KINSetPrintLevel"); + + // Set tolerances + realtype fnormtol; ///< Residual tolerance + realtype scsteptol; ///< Scaled step tolerance + + model_->setTolerances(fnormtol, scsteptol); ///< \todo Function name should be "getTolerances"! + retval = KINSetFuncNormTol(solver_, fnormtol); + checkOutput(retval, "KINSetFuncNormTol"); + + retval = KINSetScaledStepTol(solver_, scsteptol); + checkOutput(retval, "KINSetScaledStepTol"); + + // Set up linear solver + JacobianMat_ = SUNDenseMatrix(model_->size(), model_->size()); + checkAllocation((void*) JacobianMat_, "SUNDenseMatrix"); + + linearSolver_ = SUNLinSol_Dense(yy_, JacobianMat_); + checkAllocation((void*) linearSolver_, "SUNLinSol_Dense"); + + retval = KINSetLinearSolver(solver_, linearSolver_, JacobianMat_); + checkOutput(retval, "KINSetLinearSolver"); + + return retval; + } + + template + int Kinsol::configureLinearSolver() + { + int retval = 0; + + // Set up linear solver + JacobianMat_ = SUNDenseMatrix(model_->size(), model_->size()); + checkAllocation((void*) JacobianMat_, "SUNDenseMatrix"); + + linearSolver_ = SUNLinSol_Dense(yy_, JacobianMat_); + checkAllocation((void*) linearSolver_, "SUNLinSol_Dense"); + + retval = KINSetLinearSolver(solver_, linearSolver_, JacobianMat_); + checkOutput(retval, "KINSetLinearSolver"); + + return retval; + } + + template + int Kinsol::getDefaultInitialCondition() + { + model_->initialize(); + + copyVec(model_->y(), yy_); + + return 0; + } + + template + int Kinsol::runSimulation() + { + int retval = 0; + N_VConst(1.0, scale_); + retval = KINSol(solver_, yy_, KIN_LINESEARCH, scale_, scale_); + checkOutput(retval, "KINSol"); + //printOutput(tout); + //std::cout << "\n"; + return retval; + } + + template + int Kinsol::deleteSimulation() + { + KINFree(&solver_); + SUNLinSolFree(linearSolver_); + N_VDestroy(yy_); + N_VDestroy(scale_); + return 0; + } + + template + int Kinsol::Residual(N_Vector yy, N_Vector rr, void *user_data) + { + ModelLib::ModelEvaluator* model = + static_cast*>(user_data); + + copyVec(yy, model->y()); + + model->evaluateResidual(); + const std::vector& f = model->getResidual(); + copyVec(f, rr); + + return 0; + } + + template + void Kinsol::copyVec(const N_Vector x, std::vector< ScalarT >& y) + { + const ScalarT* xdata = NV_DATA_S(x); + for(unsigned int i = 0; i < y.size(); ++i) + { + y[i] = xdata[i]; + } + } + + + template + void Kinsol::copyVec(const std::vector< ScalarT >& x, N_Vector y) + { + ScalarT* ydata = NV_DATA_S(y); + for(unsigned int i = 0; i < x.size(); ++i) + { + ydata[i] = x[i]; + } + } + + template + void Kinsol::copyVec(const std::vector< bool >& x, N_Vector y) + { + ScalarT* ydata = NV_DATA_S(y); + for(unsigned int i = 0; i < x.size(); ++i) + { + if (x[i]) + ydata[i] = 1.0; + else + ydata[i] = 0.0; + } + } + + + template + void Kinsol::printOutput() + { + realtype *yval = N_VGetArrayPointer_Serial(yy_); + + std::cout << std::setprecision(5) << std::setw(7); + for (IdxT i = 0; i < model_->size(); ++i) + { + std::cout << yval[i] << " "; + } + std::cout << "\n"; + } + + template + void Kinsol::printSpecial(realtype t, N_Vector y) + { + realtype *yval = N_VGetArrayPointer_Serial(y); + IdxT N = N_VGetLength_Serial(y); + std::cout << "{"; + std::cout << std::setprecision(5) << std::setw(7) << t; + for (IdxT i = 0; i < N; ++i) + { + std::cout << ", " << yval[i]; + } + std::cout << "},\n"; + } + + template + void Kinsol::printFinalStats() + { + int retval = 0; + void* mem = solver_; + long int nni; + long int nfe; + long int nje; + long int nlfe; + + // retval = KINGetNumSteps(mem, &nst); + // checkOutput(retval, "KINGetNumSteps"); + retval = KINGetNumNonlinSolvIters(mem, &nni); + checkOutput(retval, "KINGetNumNonlinSolvIters"); + retval = KINGetNumFuncEvals(mem, &nfe); + checkOutput(retval, "KINGetNumFuncEvals"); + retval = KINGetNumJacEvals(mem, &nje); + checkOutput(retval, "KINGetNumJacEvals"); + retval = KINGetNumLinFuncEvals(mem, &nlfe); + checkOutput(retval, "KINGetNumLinFuncEvals"); + + // std::cout << "\nFinal Run Statistics: \n\n"; + std::cout << "Number of nonlinear iterations = " << nni << "\n"; + std::cout << "Number of function evaluations = " << nfe << "\n"; + std::cout << "Number of Jacobian evaluations = " << nje << "\n"; + std::cout << "Number of linear function evals. = " << nlfe << "\n"; + } + + + template + void Kinsol::checkAllocation(void* v, const char* functionName) + { + if (v == NULL) + { + std::cerr << "\nERROR: Function " << functionName << " failed -- returned NULL pointer!\n\n"; + throw SundialsException(); + } + } + + template + void Kinsol::checkOutput(int retval, const char* functionName) + { + if (retval < 0) + { + std::cerr << "\nERROR: Function " << functionName << " failed with flag " << retval << "!\n\n"; + throw SundialsException(); + } + } + + // Compiler will prevent building modules with data type incompatible with realtype + template class Kinsol; + template class Kinsol; + template class Kinsol; + +} // namespace Sundials +} // namespace AnalysisManager diff --git a/Solver/SteadyState/Kinsol.hpp b/Solver/SteadyState/Kinsol.hpp new file mode 100644 index 0000000..a39e081 --- /dev/null +++ b/Solver/SteadyState/Kinsol.hpp @@ -0,0 +1,223 @@ +/* + * + * Copyright (c) 2017, Lawrence Livermore National Security, LLC. + * Produced at the Lawrence Livermore National Laboratory. + * Written by Slaven Peles . + * LLNL-CODE-718378. + * All rights reserved. + * + * 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 + * modification, are permitted provided that the following conditions are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the disclaimer (as noted below) in the + * documentation and/or other materials provided with the distribution. + * - Neither the name of the LLNS/LLNL nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL + * SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISINGIN ANY + * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + * Lawrence Livermore National Laboratory is operated by Lawrence Livermore + * National Security, LLC, for the U.S. Department of Energy, National + * Nuclear Security Administration under Contract DE-AC52-07NA27344. + * + * This document was prepared as an account of work sponsored by an agency + * of the United States government. Neither the United States government nor + * Lawrence Livermore National Security, LLC, nor any of their employees + * makes any warranty, expressed or implied, or assumes any legal liability + * or responsibility for the accuracy, completeness, or usefulness of any + * information, apparatus, product, or process disclosed, or represents that + * its use would not infringe privately owned rights. Reference herein to + * any specific commercial product, process, or service by trade name, + * trademark, manufacturer, or otherwise does not necessarily constitute or + * imply its endorsement, recommendation, or favoring by the United States + * government or Lawrence Livermore National Security, LLC. The views and + * opinions of authors expressed herein do not necessarily state or reflect + * those of the United States government or Lawrence Livermore National + * Security, LLC, and shall not be used for advertising or product + * endorsement purposes. + * + */ + + +/** + * @file Kinsol.hpp + * @author Slaven Peles + * + * Contains declaration of interface to KINSOL nonlinear solver from + * SUNDIALS library. + * + */ +#pragma once + +#include +#include +#include +#include /* access to sparse SUNMatrix */ +// #include /* access to KLU linear solver */ +#include /* access to dense linear solver */ + +#include "ModelEvaluator.hpp" +#include "SteadyStateSolver.hpp" + +namespace AnalysisManager +{ + namespace Sundials + { + template + class Kinsol : public SteadyStateSolver + { + using SteadyStateSolver::model_; + + typedef typename GridKit::ScalarTraits::real_type real_type; + + public: + Kinsol(ModelLib::ModelEvaluator* model); + ~Kinsol(); + + int configureSimulation(); + int configureLinearSolver(); + int getDefaultInitialCondition(); + // int setIntegrationTime(real_type t_init, real_type t_final, int nout); + // int initializeSimulation(); + int runSimulation(); + int deleteSimulation(); + + // int configureQuadrature(); + // int initializeQuadrature(); + // int runSimulationQuadrature(real_type tf, int nout=1); + // int deleteQuadrature(); + + // int configureAdjoint(); + // int configureLinearSolverBackward(); + // int initializeAdjoint(IdxT steps = 100); + // int initializeBackwardSimulation(real_type tf); + // int runForwardSimulation(real_type tf, int nout=1); + // int runBackwardSimulation(real_type t0); + // int deleteAdjoint(); + + + int saveInitialCondition() + { + N_VScale(1.0, yy_, yy0_); + return 0; + } + + int getSavedInitialCondition() + { + N_VScale(1.0, yy0_, yy_); + return 0; + } + + // real_type getInitialTime() + // { + // return t_init_; + // } + + // real_type getFinalTime() + // { + // return t_final_; + // } + + // int getNumberOutputTimes() + // { + // return nout_; + // } + + // const real_type* getIntegral() const + // { + // return NV_DATA_S(q_); + // } + + // real_type* getIntegral() + // { + // return NV_DATA_S(q_); + // } + + // const real_type* getAdjointIntegral() const + // { + // return NV_DATA_S(qB_); + // } + + // real_type* getAdjointIntegral() + // { + // return NV_DATA_S(qB_); + // } + + void printOutput(); + void printSpecial(realtype t, N_Vector x); + void printFinalStats(); + + private: + static int Residual(N_Vector yy, N_Vector rr, void *user_data); + + // static int Integrand(realtype t, + // N_Vector yy, N_Vector yp, + // N_Vector rhsQ, void *user_data); + + // static int adjointResidual(realtype t, + // N_Vector yy, N_Vector yp, + // N_Vector yyB, N_Vector ypB, + // N_Vector rrB, void *user_data); + + // static int adjointIntegrand(realtype t, + // N_Vector yy, N_Vector yp, + // N_Vector yyB, N_Vector ypB, + // N_Vector rhsQB, void *user_data); + + private: + void* solver_; + SUNMatrix JacobianMat_; + SUNLinearSolver linearSolver_; + + N_Vector yy_; ///< Solution vector + N_Vector scale_; ///< Scaling vector + N_Vector tag_; ///< Tags differential variables + N_Vector q_; ///< Integrand vector + + N_Vector yy0_; ///< Storage for initial values + + private: + //static void copyMat(ModelEvaluator::Mat& J, SlsMat Jida); + static void copyVec(const N_Vector x, std::vector& y); + static void copyVec(const std::vector& x, N_Vector y); + static void copyVec(const std::vector& x, N_Vector y); + + //int check_flag(void *flagvalue, const char *funcname, int opt); + inline void checkAllocation(void* v, const char* functionName); + inline void checkOutput(int retval, const char* functionName); + + }; + + /// Simple exception to use within Kinsol class. + class SundialsException : public std::exception + { + virtual const char* what() const throw() + { + return "Method in Kinsol class failed!\n"; + } + }; + + + } // namespace Sundials + + +} // namespace AnalysisManager diff --git a/Solver/SteadyState/SteadyStateSolver.hpp b/Solver/SteadyState/SteadyStateSolver.hpp new file mode 100644 index 0000000..eb9380c --- /dev/null +++ b/Solver/SteadyState/SteadyStateSolver.hpp @@ -0,0 +1,83 @@ +/* + * + * Copyright (c) 2017, Lawrence Livermore National Security, LLC. + * Produced at the Lawrence Livermore National Laboratory. + * Written by Slaven Peles . + * LLNL-CODE-718378. + * All rights reserved. + * + * 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 + * modification, are permitted provided that the following conditions are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the disclaimer (as noted below) in the + * documentation and/or other materials provided with the distribution. + * - Neither the name of the LLNS/LLNL nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL + * SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISINGIN ANY + * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + * Lawrence Livermore National Laboratory is operated by Lawrence Livermore + * National Security, LLC, for the U.S. Department of Energy, National + * Nuclear Security Administration under Contract DE-AC52-07NA27344. + * + * This document was prepared as an account of work sponsored by an agency + * of the United States government. Neither the United States government nor + * Lawrence Livermore National Security, LLC, nor any of their employees + * makes any warranty, expressed or implied, or assumes any legal liability + * or responsibility for the accuracy, completeness, or usefulness of any + * information, apparatus, product, or process disclosed, or represents that + * its use would not infringe privately owned rights. Reference herein to + * any specific commercial product, process, or service by trade name, + * trademark, manufacturer, or otherwise does not necessarily constitute or + * imply its endorsement, recommendation, or favoring by the United States + * government or Lawrence Livermore National Security, LLC. The views and + * opinions of authors expressed herein do not necessarily state or reflect + * those of the United States government or Lawrence Livermore National + * Security, LLC, and shall not be used for advertising or product + * endorsement purposes. + * + */ +#pragma once + +#include "ModelEvaluator.hpp" + +namespace AnalysisManager +{ + template + class SteadyStateSolver + { + public: + SteadyStateSolver(ModelLib::ModelEvaluator* model) : model_(model) + { + } + virtual ~SteadyStateSolver(){} + + ModelLib::ModelEvaluator* getModel() + { + return model_; + } + + protected: + ModelLib::ModelEvaluator* model_; + }; + +} diff --git a/SystemModel.hpp b/SystemModel.hpp index a36a568..34c7ff1 100644 --- a/SystemModel.hpp +++ b/SystemModel.hpp @@ -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 @@ -64,6 +64,7 @@ #include #include +#include #include namespace ModelLib @@ -84,6 +85,7 @@ class SystemModel : public ModelEvaluatorImpl { typedef BaseBus bus_type; typedef ModelEvaluatorImpl component_type; + using real_type = typename ModelEvaluatorImpl::real_type; using ModelEvaluatorImpl::size_; using ModelEvaluatorImpl::size_quad_; @@ -672,6 +674,14 @@ class SystemModel : public ModelEvaluatorImpl return 0; } + void updateTime(real_type t, real_type a) + { + for(const auto& component : components_) + { + component->updateTime(t, a); + } + } + void addBus(bus_type* bus) { buses_.push_back(bus); diff --git a/SystemSteadyStateModel.hpp b/SystemSteadyStateModel.hpp new file mode 100644 index 0000000..6eaa34c --- /dev/null +++ b/SystemSteadyStateModel.hpp @@ -0,0 +1,378 @@ +/* + * + * Copyright (c) 2017, Lawrence Livermore National Security, LLC. + * Produced at the Lawrence Livermore National Laboratory. + * Written by Slaven Peles . + * LLNL-CODE-718378. + * All rights reserved. + * + * 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 + * modification, are permitted provided that the following conditions are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the disclaimer (as noted below) in the + * documentation and/or other materials provided with the distribution. + * - Neither the name of the LLNS/LLNL nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL + * SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISINGIN ANY + * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + * Lawrence Livermore National Laboratory is operated by Lawrence Livermore + * National Security, LLC, for the U.S. Department of Energy, National + * Nuclear Security Administration under Contract DE-AC52-07NA27344. + * + * This document was prepared as an account of work sponsored by an agency + * of the United States government. Neither the United States government nor + * Lawrence Livermore National Security, LLC, nor any of their employees + * makes any warranty, expressed or implied, or assumes any legal liability + * or responsibility for the accuracy, completeness, or usefulness of any + * information, apparatus, product, or process disclosed, or represents that + * its use would not infringe privately owned rights. Reference herein to + * any specific commercial product, process, or service by trade name, + * trademark, manufacturer, or otherwise does not necessarily constitute or + * imply its endorsement, recommendation, or favoring by the United States + * government or Lawrence Livermore National Security, LLC. The views and + * opinions of authors expressed herein do not necessarily state or reflect + * those of the United States government or Lawrence Livermore National + * Security, LLC, and shall not be used for advertising or product + * endorsement purposes. + * + */ + +/** + * @file SystemSteadyStaeModel.hpp + * @author Slaven Peles + * + * Contains definition of power flow analysis class. + * + */ +#pragma once + +#include +#include +#include + +#include +#include + +namespace ModelLib +{ + +/** + * @brief Prototype for a system model class + * + * This class maps component data to system data and implements + * ModelEvaluator for the system model. This is still work in + * progress and code is not optimized. + * + * @todo Address thread safety for the system model methods. + * + * @todo Tolerance management needs to be reconsidered. + * + */ +template +class SystemSteadyStateModel : public ModelEvaluatorImpl +{ + typedef BaseBus bus_type; + typedef ModelEvaluatorImpl component_type; + using real_type = typename ModelEvaluatorImpl::real_type; + + using ModelEvaluatorImpl::size_; + // using ModelEvaluatorImpl::size_quad_; + // using ModelEvaluatorImpl::size_opt_; + using ModelEvaluatorImpl::nnz_; + // using ModelEvaluatorImpl::time_; + // using ModelEvaluatorImpl::alpha_; + using ModelEvaluatorImpl::y_; + // using ModelEvaluatorImpl::yp_; + // using ModelEvaluatorImpl::yB_; + // using ModelEvaluatorImpl::ypB_; + // using ModelEvaluatorImpl::tag_; + using ModelEvaluatorImpl::f_; + // using ModelEvaluatorImpl::fB_; + // using ModelEvaluatorImpl::g_; + // using ModelEvaluatorImpl::gB_; + using ModelEvaluatorImpl::rtol_; + using ModelEvaluatorImpl::atol_; + // using ModelEvaluatorImpl::param_; + // using ModelEvaluatorImpl::param_up_; + // using ModelEvaluatorImpl::param_lo_; + +public: + /** + * @brief Constructor for the system model + */ + SystemSteadyStateModel() : ModelEvaluatorImpl(0, 0, 0) + { + // Set system model tolerances + rtol_ = 1e-5; + atol_ = 1e-5; + } + + /** + * @brief Destructor for the system model + */ + virtual ~SystemSteadyStateModel() + { + } + + /** + * @brief Allocate buses, components, and system objects. + * + * This method first allocates bus objects, then component objects, + * and computes system size (number of unknowns). Once the size is + * computed, system global objects are allocated. + * + * @post size_quad_ == 0 or 1 + * @post size_ >= 1 + * @post size_opt_ >= 0 + * + */ + int allocate() + { + size_ = 0; + + // Allocate all buses + for(const auto& bus: buses_) + { + bus->allocate(); + size_ += bus->size(); + } + + // Allocate all components + for(const auto& component : components_) + { + component->allocate(); + size_ += component->size(); + } + + // Allocate global vectors + y_.resize(size_); + f_.resize(size_); + + return 0; + } + + /** + * @brief Initialize buses first, then all the other components. + * + * @pre All buses and components must be allocated at this point. + * @pre Bus variables are written before component variables in the + * system variable vector. + * + * Buses must be initialized before other components, because other + * components may write to buses during the initialization. + * + * Also, generators may write to control devices (e.g. governors, + * exciters, etc.) during the initialization. + * + * @todo Implement writting to system vectors in a thread-safe way. + */ + int initialize() + { + // Set initial values for global solution vectors + IdxT varOffset = 0; + + for(const auto& bus: buses_) + { + bus->initialize(); + } + + for(const auto& bus: buses_) + { + for(IdxT j=0; jsize(); ++j) + { + y_[varOffset + j] = bus->y()[j]; + } + varOffset += bus->size(); + } + + // Initialize components + for(const auto& component : components_) + { + component->initialize(); + } + + for(const auto& component : components_) + { + for(IdxT j=0; jsize(); ++j) + { + y_[varOffset + j] = component->y()[j]; + } + varOffset += component->size(); + } + return 0; + } + + /** + * @todo Tagging differential variables + * + * Identify what variables in the system of differential-algebraic + * equations are differential variables, i.e. their derivatives + * appear in the equations. + */ + int tagDifferentiable() + { + return 0; + } + + /** + * @brief Compute system residual vector + * + * First, update bus and component variables from the system solution + * vector. Next, evaluate residuals in buses and components, and + * then copy values to the global residual vector. + * + * @warning Residuals must be computed for buses, before component + * residuals are computed. Buses own residuals for active and + * power P and Q, but the contributions to these residuals come + * from components. Buses assign their residual values, while components + * add to those values by in-place adition. This is why bus residuals + * need to be computed first. + * + * @todo Here, components write to local values, which are then copied + * to global system vectors. Make components write to the system + * vectors directly. + */ + int evaluateResidual() + { + // Update variables + IdxT varOffset = 0; + for(const auto& bus: buses_) + { + for(IdxT j=0; jsize(); ++j) + { + bus->y()[j] = y_[varOffset + j]; + } + varOffset += bus->size(); + bus->evaluateResidual(); + } + + for(const auto& component : components_) + { + for(IdxT j=0; jsize(); ++j) + { + component->y()[j] = y_[varOffset + j]; + } + varOffset += component->size(); + component->evaluateResidual(); + } + + // Update system residual vector + IdxT resOffset = 0; + for(const auto& bus : buses_) + { + for(IdxT j=0; jsize(); ++j) + { + f_[resOffset + j] = bus->getResidual()[j]; + } + resOffset += bus->size(); + } + + for(const auto& component : components_) + { + for(IdxT j=0; jsize(); ++j) + { + f_[resOffset + j] = component->getResidual()[j]; + } + resOffset += component->size(); + } + + return 0; + } + + /** + * @brief Evaluate system Jacobian. + * + * @todo Need to implement Jacobian. For now, using finite difference + * approximation provided by IDA. This works for dense Jacobian matrix + * only. + * + */ + int evaluateJacobian(){return 0;} + + /** + * @brief Evaluate integrands for the system quadratures. + */ + int evaluateIntegrand() + { + + return 0; + } + + /** + * @brief Initialize system adjoint. + * + * Updates variables and optimization parameters, then initializes + * adjoints locally and copies them to the system adjoint vector. + */ + int initializeAdjoint() + { + return 0; + } + + /** + * @brief Compute adjoint residual for the system model. + * + * @warning Components write to bus residuals. Do not copy bus residuals + * to system vectors before components computed their residuals. + * + */ + int evaluateAdjointResidual() + { + return 0; + } + + //int evaluateAdjointJacobian(){return 0;} + + /** + * @brief Evaluate adjoint integrand for the system model. + * + * @pre Assumes there are no integrands in bus models. + * @pre Assumes integrand is implemented in only _one_ component. + * + */ + int evaluateAdjointIntegrand() + { + return 0; + } + + void updateTime(real_type t, real_type a) + { + } + + void addBus(bus_type* bus) + { + buses_.push_back(bus); + } + + void addComponent(component_type* component) + { + components_.push_back(component); + } + +private: + std::vector buses_; + std::vector components_; + +}; // class SystemSteadyStateModel + +} // namespace ModelLib diff --git a/Utilities/FileIO.hpp b/Utilities/FileIO.hpp new file mode 100644 index 0000000..2edee98 --- /dev/null +++ b/Utilities/FileIO.hpp @@ -0,0 +1,124 @@ +/* + * + * Copyright (c) 2017, Lawrence Livermore National Security, LLC. + * Produced at the Lawrence Livermore National Laboratory. + * Written by Slaven Peles . + * LLNL-CODE-718378. + * All rights reserved. + * + * 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 + * modification, are permitted provided that the following conditions are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the disclaimer (as noted below) in the + * documentation and/or other materials provided with the distribution. + * - Neither the name of the LLNS/LLNL nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL + * SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISINGIN ANY + * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + * Lawrence Livermore National Laboratory is operated by Lawrence Livermore + * National Security, LLC, for the U.S. Department of Energy, National + * Nuclear Security Administration under Contract DE-AC52-07NA27344. + * + * This document was prepared as an account of work sponsored by an agency + * of the United States government. Neither the United States government nor + * Lawrence Livermore National Security, LLC, nor any of their employees + * makes any warranty, expressed or implied, or assumes any legal liability + * or responsibility for the accuracy, completeness, or usefulness of any + * information, apparatus, product, or process disclosed, or represents that + * its use would not infringe privately owned rights. Reference herein to + * any specific commercial product, process, or service by trade name, + * trademark, manufacturer, or otherwise does not necessarily constitute or + * imply its endorsement, recommendation, or favoring by the United States + * government or Lawrence Livermore National Security, LLC. The views and + * opinions of authors expressed herein do not necessarily state or reflect + * those of the United States government or Lawrence Livermore National + * Security, LLC, and shall not be used for advertising or product + * endorsement purposes. + * + */ + +/** + * @file FileIO.hpp + * @author Slaven Peles + * + * Contains definition of a utility for reading lookup tables. + * + */ +#pragma once + +#include +#include +#include + +namespace GridKit +{ + template + void setLookupTable(std::vector>& table, std::string filename, ScalarT& ti, ScalarT& tf) + { + std::ifstream idata(filename); + std::string line; + int oldwordcount = -1; + while (std::getline(idata, line)) + { + std::istringstream iss(line); + double word; + int wordcount = 0; + std::vector row; + while (iss >> word) + { + row.push_back(word); + ++wordcount; + } + table.push_back(std::move(row)); + if(oldwordcount != -1) + { + if(oldwordcount != wordcount) + { + std::cerr << "Corrupted input data!\n"; + return; + } + } + else + { + oldwordcount = wordcount; + } + } + size_t N = table.size(); + ti = table[0][0]; + tf = table[N-1][0]; + } + + template + void printLookupTable(std::vector> const& table) + { + for(size_t i=0; i. + * LLNL-CODE-718378. + * All rights reserved. + * + * 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 + * modification, are permitted provided that the following conditions are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the disclaimer (as noted below) in the + * documentation and/or other materials provided with the distribution. + * - Neither the name of the LLNS/LLNL nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL + * SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISINGIN ANY + * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + * Lawrence Livermore National Laboratory is operated by Lawrence Livermore + * National Security, LLC, for the U.S. Department of Energy, National + * Nuclear Security Administration under Contract DE-AC52-07NA27344. + * + * This document was prepared as an account of work sponsored by an agency + * of the United States government. Neither the United States government nor + * Lawrence Livermore National Security, LLC, nor any of their employees + * makes any warranty, expressed or implied, or assumes any legal liability + * or responsibility for the accuracy, completeness, or usefulness of any + * information, apparatus, product, or process disclosed, or represents that + * its use would not infringe privately owned rights. Reference herein to + * any specific commercial product, process, or service by trade name, + * trademark, manufacturer, or otherwise does not necessarily constitute or + * imply its endorsement, recommendation, or favoring by the United States + * government or Lawrence Livermore National Security, LLC. The views and + * opinions of authors expressed herein do not necessarily state or reflect + * those of the United States government or Lawrence Livermore National + * Security, LLC, and shall not be used for advertising or product + * endorsement purposes. + * + */ + +/** + * @file Testing.hpp + * @author Slaven Peles + * + * Contains utilies for testing. + * + */ +#pragma once + +#include + +namespace GridKit +{ +namespace Testing +{ + +template +bool isEqual(const T value, const T ref, const T tol) +{ + return (std::abs(value - ref)/(1.0 + std::abs(ref)) < tol); +} + +} // namespace Testing + +} // namespace GridKit \ No newline at end of file diff --git a/config/FindIpopt.cmake b/config/FindIpopt.cmake index e9b211f..3ba2f00 100644 --- a/config/FindIpopt.cmake +++ b/config/FindIpopt.cmake @@ -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 @@ -55,39 +55,62 @@ # endorsement purposes. # -# Find Ipopt installation path -find_path (IPOPT_DIR NAMES share/coin/doc/Ipopt/ipopt_addlibs_cpp.txt HINTS ~/local/ipopt) -message (STATUS "Found Ipopt in ${IPOPT_DIR}") +#[[ -# Find Ipopt header path and ensure all needed files are there -find_path(IPOPT_INCLUDE_DIR - IpTNLP.hpp - HINTS ${IPOPT_DIR}/include/coin -) -message (STATUS "Found Ipopt headers in ${IPOPT_INCLUDE_DIR}") +Finds Ipopt include directory and libraries and exports target `Ipopt` + +User may set: +- IPOPT_ROOT_DIR + +]] + +find_library(IPOPT_LIBRARY + NAMES + ipopt + PATHS + ${IPOPT_DIR} $ENV{IPOPT_DIR} ${IPOPT_ROOT_DIR} + ENV LD_LIBRARY_PATH ENV DYLD_LIBRARY_PATH + PATH_SUFFIXES + lib64 lib) -# Assume Ipopt lib directory is in the same place as the include directory -set(IPOPT_LIBRARY_DIR ${IPOPT_DIR}/lib) +if(IPOPT_LIBRARY) + set(IPOPT_LIBRARY CACHE FILEPATH "Path to Ipopt library") + message(STATUS "Found Ipopt library: " ${IPOPT_LIBRARY}) + get_filename_component(IPOPT_LIBRARY_DIR ${IPOPT_LIBRARY} DIRECTORY CACHE) + set(IPOPT_LIBRARY_DIR CACHE PATH "Path to Ipopt library") + if(NOT IPOPT_DIR) + get_filename_component(IPOPT_DIR ${IPOPT_LIBRARY_DIR} DIRECTORY CACHE) + endif() +endif() -# Ipopt modules needed for the build -# The order matters in case of static build! -set(IPOPT_MODULES - ipopt - coinmetis - coinmumps -) +find_path(IPOPT_INCLUDE_DIR + NAMES + IpTNLP.hpp + PATHS + ${IPOPT_DIR} ${IPOPT_ROOT_DIR} $ENV{IPOPT_DIR} ${IPOPT_LIBRARY_DIR}/.. + PATH_SUFFIXES + include + include/coin + include/coin-or + include/coinor) -# Find each Ipopt module and add it to the list of libraries to link -set(IPOPT_LIBRARY) -foreach(mod ${IPOPT_MODULES}) - find_library(IPOPT_${mod} - NAMES ${mod} - HINTS ${IPOPT_LIBRARY_DIR} - ) - if(IPOPT_${mod}) - set(IPOPT_LIBRARY ${IPOPT_LIBRARY} ${IPOPT_${mod}}) - else() - # unset ${IPOPT_LIBRARY_DIR} and ask user to supply it +if(IPOPT_LIBRARY AND IPOPT_INCLUDE_DIR) + set(IPOPT_INCLUDE_DIR CACHE PATH "Path to Ipopt header files") + message(STATUS "Found Ipopt include directory: " ${IPOPT_INCLUDE_DIR}) + add_library(Ipopt INTERFACE) + target_link_libraries(Ipopt INTERFACE ${IPOPT_LIBRARY}) + target_include_directories(Ipopt INTERFACE ${IPOPT_INCLUDE_DIR}) +else() + if(NOT IPOPT_ROOT_DIR) + message(STATUS "Ipopt dir not found! Please provide correct filepath.") + set(IPOPT_DIR CACHE PATH "Path to Ipopt installation root.") + unset(IPOPT_INCLUDE_DIR CACHE) + unset(IPOPT_LIBRARY CACHE) + elseif(NOT IPOPT_LIB) + message(STATUS "Ipopt library not found! Please provide correct filepath.") endif() -endforeach() -message (STATUS "Found Ipopt libraries ${IPOPT_LIBRARY}") + if(IPOPT_ROOT_DIR AND NOT IPOPT_INCLUDE_DIR) + message(STATUS "Ipopt include directory not found! Please provide correct path.") + endif() +endif() + diff --git a/config/FindSUNDIALS.cmake b/config/FindSUNDIALS.cmake index c1c7f02..95f26f6 100644 --- a/config/FindSUNDIALS.cmake +++ b/config/FindSUNDIALS.cmake @@ -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 @@ -55,46 +55,80 @@ # endorsement purposes. # -# Find SUNDIALS installation path -find_path (SUNDIALS_DIR NAMES include/sundials/sundials_config.h HINTS ~/local/sundials) -message (STATUS "Found SUNDIALS in ${SUNDIALS_DIR}") +#[[ + +Finds Sundials include directory and libraries and exports target `SUNDIALS` + +User may set: +- SUNDIALS_ROOT_DIR + +]] + +# SUNDIALS modules needed for the build +# The order matters in case of static build! +set(SUNDIALS_MODULES + sundials_idas + sundials_kinsol + sundials_nvecserial +) + +find_library(SUNDIALS_LIBRARY + NAMES + ${SUNDIALS_MODULES} + PATHS + ${SUNDIALS_ROOT_DIR} ${SUNDIALS_DIR} $ENV{SUNDIALS_DIR} + ENV LD_LIBRARY_PATH ENV DYLD_LIBRARY_PATH + PATH_SUFFIXES + lib) + +if(SUNDIALS_LIBRARY) + get_filename_component(SUNDIALS_LIBRARY_DIR ${SUNDIALS_LIBRARY} DIRECTORY CACHE) + set(SUNDIALS_LIBRARY_DIR CACHE PATH "Path to Sundials library") + if(NOT SUNDIALS_DIR) + get_filename_component(SUNDIALS_DIR ${SUNDIALS_LIBRARY_DIR} DIRECTORY CACHE) + endif() +endif() # Find SUNDIALS header path and ensure all needed files are there find_path(SUNDIALS_INCLUDE_DIR + NAMES nvector/nvector_serial.h sundials/sundials_dense.h sundials/sundials_sparse.h sundials/sundials_types.h idas/idas.h - idas/idas_dense.h - idas/idas_band.h - idas/idas_klu.h - idas/idas_impl.h - HINTS ${SUNDIALS_DIR}/include -) -message (STATUS "Found SUNDIALS headers in ${SUNDIALS_INCLUDE_DIR}") - -# Assume SUNDIALS lib directory is in the same place as the include directory -set(SUNDIALS_LIBRARY_DIR ${SUNDIALS_DIR}/lib) - -# SUNDIALS modules needed for the build -# The order matters in case of static build! -set(SUNDIALS_MODULES - sundials_idas - sundials_nvecserial + idas/idas_ls.h + PATHS + ${SUNDIALS_ROOT_DIR} ${SUNDIALS_DIR} + PATH_SUFFIXES + include ) -# Find each SUNDIALS module and add it to the list of libraries to link -set(SUNDIALS_LIBRARY) -foreach(mod ${SUNDIALS_MODULES}) - find_library(SUNDIALS_${mod} - NAMES ${mod} - HINTS ${SUNDIALS_LIBRARY_DIR} - ) - if(SUNDIALS_${mod}) - set(SUNDIALS_LIBRARY ${SUNDIALS_LIBRARY} ${SUNDIALS_${mod}}) - else() - # unset ${SUNDIALS_LIBRARY_DIR} and ask user to supply it +if(SUNDIALS_LIBRARY AND SUNDIALS_INCLUDE_DIR) +set(SUNDIALS_INCLUDE_DIR CACHE PATH "Path to Sundials Include dir") + # Find each SUNDIALS module and add it to the list of libraries to link + unset(SUNDIALS_LIBRARY CACHE) + foreach(mod ${SUNDIALS_MODULES}) + find_library(SUNDIALS_${mod} + NAMES ${mod} + HINTS ${SUNDIALS_LIBRARY_DIR} + ) + if(SUNDIALS_${mod}) + set(SUNDIALS_LIBRARY ${SUNDIALS_LIBRARY} ${SUNDIALS_${mod}}) + else() + # unset ${SUNDIALS_LIBRARY_DIR} and ask user to supply it + endif() + endforeach() + message (STATUS "Found Sundials libraries ${SUNDIALS_LIBRARY}") +else() + if(NOT SUNDIALS_ROOT_DIR) + message(STATUS "Sundials dir not found! Please provide correct filepath.") + set(SUNDIALS_DIR CACHE PATH "Path to SUNDIALS installation root.") + unset(SUNDIALS_LIBRARY CACHE) + unset(SUNDIALS_INCLUDE_DIR CACHE) + elseif(NOT SUNDIALS_LIBRARY) + message(STATUS "Sundials library not found! Please provide correct filepath.") + elseif(NOT SUNDIALS_INCLUDE_DIR) + message(STATUS "Sundials include dir not found! Please provide correct filepath.") endif() -endforeach() -message (STATUS "Found SUNDIALS libraries ${SUNDIALS_LIBRARY}") +endif() diff --git a/config/FindSuiteSparse.cmake b/config/FindSuiteSparse.cmake index 95ebf4b..8f67b55 100644 --- a/config/FindSuiteSparse.cmake +++ b/config/FindSuiteSparse.cmake @@ -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 @@ -55,51 +55,73 @@ # endorsement purposes. # -set(SUITESPARSE_DIR_HINTS - /usr - /usr/local - /opt -) +#[[ -# Find SUITESPARSE installation path -find_path (SUITESPARSE_DIR NAMES include/suitesparse/klu.h HINTS ${SUITESPARSE_DIR_HINTS}) -message (STATUS "Found SUITESPARSE in ${SUITESPARSE_DIR}") +Finds Sutiesparse include directory and libraries and exports target `Suitesparse` + +User may set: +- SUITESPARSE_ROOT_DIR + +]] + +find_library(SUITESPARSE_LIBRARY + NAMES + suitesparseconfig + PATHS + ${SUITESPARSE_DIR} $ENV{SUITESPARSE_DIR} ${SUITESPARSE_ROOT_DIR} + ENV LD_LIBRARY_PATH ENV DYLD_LIBRARY_PATH + PATH_SUFFIXES + lib64 lib) +if(SUITESPARSE_LIBRARY) + get_filename_component(SUITESPARSE_LIBRARY_DIR ${SUITESPARSE_LIBRARY} DIRECTORY CACHE) + set(SUITESPARSE_LIBRARY_DIR CACHE PATH "Path to Suitesparse library") + if(NOT SUITESPARSE_DIR) + get_filename_component(SUITESPARSE_DIR ${SUITESPARSE_LIBRARY_DIR} DIRECTORY CACHE) + endif() +endif() # Find SUITESPARSE header path and ensure all needed files are there find_path(SUITESPARSE_INCLUDE_DIR + NAMES amd.h colamd.h klu.h - HINTS ${SUITESPARSE_DIR}/include/suitesparse -) -message (STATUS "Found SUITESPARSE headers in ${SUITESPARSE_INCLUDE_DIR}") + PATHS + ${SUITESPARSE_DIR} ${SUITESPARSE_ROOT_DIR} $ENV{SUITESPARSE_DIR} ${SUITESPARSE_LIBRARY_DIR}/.. + PATH_SUFFIXES + include) -# Assume SUITESPARSE lib directory is in the same place as the include directory -set(SUITESPARSE_LIBRARY_DIR - ${SUITESPARSE_DIR}/lib64 - ${SUITESPARSE_DIR}/lib -) - -# SUITESPARSE modules needed for the build -# The order matters in case of static build! -set(SUITESPARSE_MODULES - amd - colamd - klu -) - -# Find each SUITESPARSE module and add it to the list of libraries to link -set(SUITESPARSE_LIBRARY) -foreach(mod ${SUITESPARSE_MODULES}) - find_library(SUITESPARSE_${mod} - NAMES ${mod} - HINTS ${SUITESPARSE_LIBRARY_DIR} - ) - if(SUITESPARSE_${mod}) - set(SUITESPARSE_LIBRARY ${SUITESPARSE_LIBRARY} ${SUITESPARSE_${mod}}) - else() - # unset ${SUITESPARSE_LIBRARY_DIR} and ask user to supply it +if(SUITESPARSE_LIBRARY AND SUITESPARSE_INCLUDE_DIR) + set(SUITESPARSE_INCLUDE_DIR CACHE PATH "Path to Suitesparse header files") + # SUITESPARSE modules needed for the build + # The order matters in case of static build! + set(SUITESPARSE_MODULES + amd + colamd + klu) + unset(SUITESPARSE_LIBRARY CACHE) + foreach(mod ${SUITESPARSE_MODULES}) + find_library(SUITESPARSE_${mod} + NAMES ${mod} + HINTS ${SUITESPARSE_LIBRARY_DIR}) + if(SUITESPARSE_${mod}) + set(SUITESPARSE_LIBRARY ${SUITESPARSE_LIBRARY} ${SUITESPARSE_${mod}}) + else() + # unset ${SUITESPARSE_LIBRARY_DIR} and ask user to supply it + endif() + endforeach() + message (STATUS "Found SUITESPARSE libraries in ${SUITESPARSE_LIBRARY_DIR}") +else() + if(NOT SUITESPARSE_ROOT_DIR) + message(STATUS "Suitesparse dir not found! Please provide correct filepath.") + set(SUITESPARSE_DIR CACHE PATH "Path to Suitesparse installation root.") + unset(SUITESPARSE_LIBRARY CACHE) + unset(SUITESPARSE_INCLUDE_DIR CACHE) + elseif(NOT SUITESPARSE_LIBRARY) + message(STATUS "Suitesparse library not found! Please provide correct filepath.") + endif() + if(SUITESPARSE_ROOT_DIR AND NOT SUITESPARSE_INCLUDE_DIR) + message(STATUS "Suitesparse include dir not found! Please provide correct filepath.") endif() -endforeach() -message (STATUS "Found SUITESPARSE libraries ${SUITESPARSE_LIBRARY}") +endif() diff --git a/mainpage.dox b/mainpage.dox index 09e0001..572d450 100644 --- a/mainpage.dox +++ b/mainpage.dox @@ -8,7 +8,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