Skip to content

Working Example of Solving RLCircuit and Microgrid with Jacobians #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 46 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
cbabd88
Add bus factory.
pelesh Oct 20, 2022
1603057
Add New Components and Changes to Composition
reid-g Jul 27, 2023
b9ce19f
Added COO Sparse Matrices, Component Jacobians, and Discrete Generator
reid-g Nov 16, 2023
be22b55
Added Jacobian Assembly. Fixed and Added New Functionality to COO Mat…
reid-g Nov 20, 2023
3f74458
Jacobian Assembly, IDA + KLU Cmake, RL Circuit
reid-g Dec 11, 2023
a42761c
Added the Transmission Line Component
reid-g Jan 30, 2024
fcf1cb9
Added Microgrid Example
reid-g Feb 19, 2024
1aa8865
Working Microgrid (Finite Difference)
reid-g Feb 19, 2024
723c785
Fixed the Jacobian in Microgrid Example
reid-g Feb 22, 2024
a3e5af8
Added a max step size control for model objects
reid-g Feb 22, 2024
c3f071e
Update Solver/Dynamic/CMakeLists.txt
reid-g Mar 12, 2024
7be79c7
Updated name DiscreteGenerator -> DistributedGenerator
reid-g Mar 12, 2024
d715372
Fixed Some Bugs
reid-g Mar 12, 2024
001d3c2
Fixed Memory Error with Grid3BusSys
reid-g Mar 15, 2024
d258ad5
Fixed Unitalized Variable Stepsize
reid-g Mar 22, 2024
c8de307
Fix max number of backward steps in IDA solver.
pelesh Apr 9, 2024
36df264
Merge pull request #4 from ORNL/composer-ida-fix
reid-g Apr 9, 2024
31e6f68
Fixing indentation from tabs to spaces
reid-g Apr 9, 2024
f8d6943
Formatting Fix Composer-Dev (#6)
reid-g Apr 10, 2024
8f55e94
Remove parts of generator model from BusPV (#7)
pelesh Apr 10, 2024
7bb9374
Formatting updates + Fixed Warnings
reid-g Apr 10, 2024
425b7d0
Add bus factory.
pelesh Oct 20, 2022
e0c778e
Add New Components and Changes to Composition
reid-g Jul 27, 2023
b57ec42
Added COO Sparse Matrices, Component Jacobians, and Discrete Generator
reid-g Nov 16, 2023
de2307c
Added Jacobian Assembly. Fixed and Added New Functionality to COO Mat…
reid-g Nov 20, 2023
1dc614c
Jacobian Assembly, IDA + KLU Cmake, RL Circuit
reid-g Dec 11, 2023
e005183
Added the Transmission Line Component
reid-g Jan 30, 2024
eb6fde4
Added Microgrid Example
reid-g Feb 19, 2024
1952b25
Working Microgrid (Finite Difference)
reid-g Feb 19, 2024
efc71f8
Fixed the Jacobian in Microgrid Example
reid-g Feb 22, 2024
9f99077
Added a max step size control for model objects
reid-g Feb 22, 2024
60b328c
Update Solver/Dynamic/CMakeLists.txt
reid-g Mar 12, 2024
6c223b3
Updated name DiscreteGenerator -> DistributedGenerator
reid-g Mar 12, 2024
226afca
Fixed Some Bugs
reid-g Mar 12, 2024
861b33c
Fixed Memory Error with Grid3BusSys
reid-g Mar 15, 2024
efddb28
Fixed Unitalized Variable Stepsize
reid-g Mar 22, 2024
3cb53a8
Fix max number of backward steps in IDA solver.
pelesh Apr 9, 2024
a2e71ab
Fixing indentation from tabs to spaces
reid-g Apr 9, 2024
17a0cb7
Formatting Fix Composer-Dev (#6)
reid-g Apr 10, 2024
d2ac21a
Formatting updates + Fixed Warnings
reid-g Apr 10, 2024
a192d47
Rebasing with BusPV Fixes
reid-g Apr 10, 2024
b0c02a1
Merge branch 'composer-dev' of https://github.com/ORNL/GridKit into c…
reid-g Apr 10, 2024
ad7f4af
Minor comments and style corrections.
pelesh Apr 13, 2024
7e685c5
Multiple Format & Comment Updates + Valgrind Error Fixes
reid-g Apr 16, 2024
a43404f
Formatting Updates with "this" and using + Minor Fixes
reid-g Apr 17, 2024
9250411
Added Better Description to the MicrogridBus
reid-g May 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CMake/FindSuiteSparse.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ Author(s):
set(SUITESPARSE_MODULES
amd
colamd
klu)
klu
suitesparseconfig)

find_library(SUITESPARSE_LIBRARY
NAMES
suitesparseconfig
${SUITESPARSE_MODULES}
PATHS
${SUITESPARSE_DIR} $ENV{SUITESPARSE_DIR} ${SUITESPARSE_ROOT_DIR}
Expand All @@ -97,6 +97,7 @@ find_path(SUITESPARSE_INCLUDE_DIR
amd.h
colamd.h
klu.h
SuiteSparse_config.h
PATHS
${SUITESPARSE_DIR} $ENV{SUITESPARSE_DIR} ${SUITESPARSE_ROOT_DIR} ${SUITESPARSE_LIBRARY_DIR}/..
PATH_SUFFIXES
Expand Down
7 changes: 5 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ option(GRIDKIT_ENABLE_IPOPT "Enable Ipopt support" ON)
option(GRIDKIT_ENABLE_SUNDIALS "Enable SUNDIALS support" ON)

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


set(CMAKE_MACOSX_RPATH 1)
Expand Down Expand Up @@ -110,7 +110,7 @@ endif("${isSystemDir}" STREQUAL "-1")


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

set(CMAKE_CXX_STANDARD 17)

Expand Down Expand Up @@ -143,6 +143,9 @@ add_subdirectory(ComponentLib)
# General Utilities and File IO
add_subdirectory(Utilities)

#Local Sparse matrix operations
add_subdirectory(SparseMatrix)

# Create solvers
add_subdirectory(Solver)

Expand Down
119 changes: 119 additions & 0 deletions CircuitGraph.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@


#include <iostream>
#include <cmath>
#include <vector>
#include <unordered_set>
#include <map>

/**
* @brief A very basic hypergraph setup for circuit representation. This forms the hypergraph as a bipartite graph. Doesn't allow removing. Can only grab sets of connections to nodes
*
* @todo should replace with something better and more efficent. Should replace with a libraries setup instead. This would allow fast and easy partitioning of circuits
*
* @todo should replace N and E with Node and Component classes respectively
*
* @tparam IdxT
* @tparam Label
*/
template <typename N, typename E>
class CircuitGraph
{
private:
std::set<N> hypernodes;
std::set<E> hyperedges;
std::map<E, std::set<N>> edgestonodes;
public:
CircuitGraph();
~CircuitGraph();
bool addHyperEdge(E he);
bool addHyperNode(N hn);
bool addConnection(N hn, E he);
std::set<N> getHyperEdgeConnections(E he);
size_t amountHyperNodes();
size_t amountHyperEdges();
void printBiPartiteGraph(bool verbose = false);
};

template <typename N, typename E>
CircuitGraph<N, E>::CircuitGraph()
{
}

template <typename N, typename E>
CircuitGraph<N, E>::~CircuitGraph()
{
}

template <typename N, typename E>
bool CircuitGraph<N, E>::addHyperNode(N hn)
{
return this->hypernodes.insert(hn).second;
}

template <typename N, typename E>
bool CircuitGraph<N, E>::addHyperEdge(E he)
{
return this->hyperedges.insert(he).second;
}


template <typename N, typename E>
bool CircuitGraph<N, E>::addConnection(N hn, E he)
{
if(this->hyperedges.count(he) == 0 || this->hypernodes.count(hn) == 0)
{
return false;
}
return this->edgestonodes[he].insert(hn).second;
}


template <typename N, typename E>
std::set<N> CircuitGraph<N, E>::getHyperEdgeConnections(E he)
{
return this->edgestonodes[he];
}


template <typename N, typename E>
size_t CircuitGraph<N, E>::amountHyperNodes()
{
return this->hypernodes.size();
}


template <typename N, typename E>
size_t CircuitGraph<N, E>::amountHyperEdges()
{
return this->hyperedges.size();
}

/**
* @brief Printing
*
* @todo need to add verbose printing for connections display
*
* @tparam IdxT
* @param verbose
*/

template <typename N, typename E>
void CircuitGraph<N, E>::printBiPartiteGraph(bool verbose)
{

std::cout << "Amount of HyperNodes: " << this->amountHyperNodes() << std::endl;
std::cout << "Amount of HyperEdges: " << this->amountHyperEdges() << std::endl;
std::cout << "Connections per Edge:" << std::endl;
for (auto i : this->edgestonodes)
{
std::cout << i.first << " : {";
for (auto j : i.second){
std::cout << j << ", ";
}
std::cout << "}\n";

}


}
16 changes: 7 additions & 9 deletions ComponentLib/Bus/BusPV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ namespace ModelLib {
*/
template <class ScalarT, typename IdxT>
BusPV<ScalarT, IdxT>::BusPV()
: BaseBus<ScalarT, IdxT>(0), V_(0.0), theta0_(0.0), Pg_(0.0)
: BaseBus<ScalarT, IdxT>(0), V_(0.0), theta0_(0.0)
{
//std::cout << "Create BusPV..." << std::endl;
//std::cout << "Number of equations is " << size_ << std::endl;
Expand All @@ -83,9 +83,7 @@ BusPV<ScalarT, IdxT>::BusPV()
}

/*!
* @brief BusPV constructor.
*
* This constructor sets initial values for voltage and phase angle.
* @brief Constructor for a PV bus
*
* @todo Arguments that should be passed to ModelEvaluatorImpl constructor:
* - Number of equations = 1 (size_)
Expand All @@ -94,10 +92,10 @@ BusPV<ScalarT, IdxT>::BusPV()
* - Number of optimization parameters = 0
*/
template <class ScalarT, typename IdxT>
BusPV<ScalarT, IdxT>::BusPV(ScalarT V, ScalarT theta0, ScalarT Pg)
: BaseBus<ScalarT, IdxT>(0), V_(V), theta0_(theta0), Pg_(Pg)
BusPV<ScalarT, IdxT>::BusPV(ScalarT V, ScalarT theta0)
: BaseBus<ScalarT, IdxT>(0), V_(V), theta0_(theta0)
{
//std::cout << "Create BusPV ..." << std::endl;
//std::cout << "Create BusPV..." << std::endl;
//std::cout << "Number of equations is " << size_ << std::endl;

size_ = 1;
Expand Down Expand Up @@ -171,8 +169,8 @@ template <class ScalarT, typename IdxT>
int BusPV<ScalarT, IdxT>::evaluateResidual()
{
// std::cout << "Evaluating residual of a PV bus ...\n";
P() = Pg_;
Q() = 0.0;
P() = 0.0; // <-- Residual P
Q() = 0.0; // <-- Output Qg, the reactive power generator needs to supply

return 0;
}
Expand Down
9 changes: 4 additions & 5 deletions ComponentLib/Bus/BusPV.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ namespace ModelLib
using BusData = GridKit::PowerSystemData::BusData<real_type, IdxT>;

BusPV();
BusPV(ScalarT V, ScalarT theta0, ScalarT P);
BusPV(ScalarT V, ScalarT theta0);
BusPV(BusData& data);
virtual ~BusPV();

Expand Down Expand Up @@ -197,10 +197,9 @@ namespace ModelLib
}

private:
ScalarT V_;
ScalarT theta0_; ///< Default initial value for phase
ScalarT Pg_; ///< Generator injection
ScalarT Q_;
ScalarT V_; ///< Bus voltage magnitude
ScalarT theta0_; ///< Default initial value for phase
ScalarT Q_; ///< Reactive power that generator needs to provide

ScalarT VB_;
ScalarT thetaB_;
Expand Down
4 changes: 4 additions & 0 deletions ComponentLib/Bus/BusSlack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ BusSlack<ScalarT, IdxT>::BusSlack(ScalarT V, ScalarT theta)
{
//std::cout << "Create BusSlack..." << std::endl;
//std::cout << "Number of equations is " << size_ << std::endl;
P() = 0.0;
Q() = 0.0;
size_ = 0;
}

Expand All @@ -106,6 +108,8 @@ BusSlack<ScalarT, IdxT>::BusSlack(BusData& data)
{
//std::cout << "Create BusSlack..." << std::endl;
//std::cout << "Number of equations is " << size_ << std::endl;
P() = 0.0;
Q() = 0.0;
size_ = 0;
}

Expand Down
2 changes: 2 additions & 0 deletions ComponentLib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,5 @@ add_subdirectory(Generator4Governor)
add_subdirectory(Generator4Param)
add_subdirectory(Load)
add_subdirectory(MiniGrid)
add_subdirectory(PowerElectronicsComponents)

8 changes: 6 additions & 2 deletions ComponentLib/Generator/GeneratorPV.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,18 @@ namespace ModelLib
return P_;
}

/// @brief Reactive power excess on PV bus
/// @return reference to negative PV generator reactive power
virtual ScalarT& Q()
{
return bus_->Q();
return (bus_->Q());
}

/// @brief Reactive power excess on PV bus
/// @return const reference to negative PV generator reactive power
virtual const ScalarT& Q() const
{
return bus_->Q();
return (bus_->Q());
}

private:
Expand Down
14 changes: 14 additions & 0 deletions ComponentLib/PowerElectronicsComponents/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@


add_subdirectory(Capacitor)
add_subdirectory(Resistor)
add_subdirectory(VoltageSource)
add_subdirectory(Inductor)
add_subdirectory(LinearTransformer)
add_subdirectory(InductionMotor)
add_subdirectory(SynchronousMachine)
add_subdirectory(DistributedGenerator)
add_subdirectory(TransmissionLine)
add_subdirectory(MicrogridLoad)
add_subdirectory(MicrogridLine)
add_subdirectory(MicrogridBusDQ)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@



gridkit_add_library(powerelec_capacitor
SOURCES
Capacitor.cpp
OUTPUT_NAME
gridkit_powerelec_capacitor)
Loading