Skip to content

Commit

Permalink
Add phasor dynamics bus and branch models (#38)
Browse files Browse the repository at this point in the history
* First stab at phasor dynamics models:

* Add bus component model.

* Add branch model.

* Updated docs and notation for the two models.
  • Loading branch information
pelesh authored Jan 21, 2025
1 parent 942654b commit 46ddca6
Show file tree
Hide file tree
Showing 21 changed files with 1,230 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
.vscode/

build/
*.DS_Store
1 change: 1 addition & 0 deletions ComponentLib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
# - Cameron Rutherford <cameron.rutherford@pnnl.gov>
#]]

add_subdirectory(PhasorDynamics)
add_subdirectory(PowerFlow)
add_subdirectory(PowerElectronics)

224 changes: 224 additions & 0 deletions ComponentLib/PhasorDynamics/Branch/Branch.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
/*
*
* Copyright (c) 2017, Lawrence Livermore National Security, LLC.
* Produced at the Lawrence Livermore National Laboratory.
* Written by Slaven Peles <peles2@llnl.gov> and Duan Nan <duan4@llnl.gov>.
* 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 <iostream>
#include <cmath>
#include <ComponentLib/PhasorDynamics/Bus/Bus.hpp>
#include <PowerSystemData.hpp>

#include "Branch.hpp"

namespace ModelLib { // change to GridKit
namespace PhasorDynamics {

/*!
* @brief Constructor for a pi-model branch
*
* Arguments passed to ModelEvaluatorImpl:
* - Number of equations = 0
* - Number of independent variables = 0
* - Number of quadratures = 0
* - Number of optimization parameters = 0
*/

template <class ScalarT, typename IdxT>
Branch<ScalarT, IdxT>::Branch(bus_type* bus1, bus_type* bus2)
: R_(0.0),
X_(0.01),
G_(0.0),
B_(0.0),
bus1ID_(0),
bus2ID_(0),
bus1_(bus1),
bus2_(bus2)
{
size_ = 0;
}

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

template <class ScalarT, typename IdxT>
Branch<ScalarT, IdxT>::Branch(bus_type* bus1, bus_type* bus2, BranchData& data)
: R_(data.r),
X_(data.x),
G_(0.0),
B_(data.b),
bus1ID_(data.fbus),
bus2ID_(data.tbus),
bus1_(bus1),
bus2_(bus2)
{
size_ = 0;
}


template <class ScalarT, typename IdxT>
Branch<ScalarT, IdxT>::~Branch()
{
//std::cout << "Destroy Branch..." << std::endl;
}

/*!
* @brief allocate method computes sparsity pattern of the Jacobian.
*/
template <class ScalarT, typename IdxT>
int Branch<ScalarT, IdxT>::allocate()
{
//std::cout << "Allocate Branch..." << std::endl;
return 0;
}

/**
* Initialization of the branch model
*
*/
template <class ScalarT, typename IdxT>
int Branch<ScalarT, IdxT>::initialize()
{
return 0;
}

/**
* \brief Identify differential variables.
*/
template <class ScalarT, typename IdxT>
int Branch<ScalarT, IdxT>::tagDifferentiable()
{
return 0;
}

/**
* \brief Residual contribution of the branch is pushed to the
* two terminal buses.
*
* @todo Add and verify conductance to ground (B and G)
*/
template <class ScalarT, typename IdxT>
int Branch<ScalarT, IdxT>::evaluateResidual()
{
// std::cout << "Evaluating branch residual ...\n";
real_type b = -X_/(R_*R_ + X_*X_);
real_type g = R_/(R_*R_ + X_*X_);

Ir1() += -(g + 0.5*G_)*Vr1() + (b + 0.5*B_)*Vi1() + g*Vr2() - b*Vi2();
Ii1() += -(b + 0.5*B_)*Vr1() - (g + 0.5*G_)*Vi1() + b*Vr2() + g*Vi2();
Ir2() += g*Vr1() - b*Vi1() - (g + 0.5*G_)*Vr2() + (b + 0.5*B_)*Vi2();
Ii2() += b*Vr1() + g*Vi1() - (b + 0.5*B_)*Vr2() - (g + 0.5*G_)*Vi2();

return 0;
}

template <class ScalarT, typename IdxT>
int Branch<ScalarT, IdxT>::evaluateJacobian()
{
std::cout << "Evaluate Jacobian for Branch..." << std::endl;
std::cout << "Jacobian evaluation not implemented!" << std::endl;
return 0;
}

template <class ScalarT, typename IdxT>
int Branch<ScalarT, IdxT>::evaluateIntegrand()
{
// std::cout << "Evaluate Integrand for Branch..." << std::endl;
return 0;
}

template <class ScalarT, typename IdxT>
int Branch<ScalarT, IdxT>::initializeAdjoint()
{
//std::cout << "Initialize adjoint for Branch..." << std::endl;
return 0;
}

template <class ScalarT, typename IdxT>
int Branch<ScalarT, IdxT>::evaluateAdjointResidual()
{
// std::cout << "Evaluate adjoint residual for Branch..." << std::endl;
return 0;
}

template <class ScalarT, typename IdxT>
int Branch<ScalarT, IdxT>::evaluateAdjointIntegrand()
{
// std::cout << "Evaluate adjoint Integrand for Branch..." << std::endl;
return 0;
}

// Available template instantiations
template class Branch<double, long int>;
template class Branch<double, size_t>;

} //namespace PhasorDynamics
} //namespace GridKit
Loading

0 comments on commit 46ddca6

Please sign in to comment.