Skip to content
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

Working Example of Solving RLCircuit and Microgrid with Jacobians #1

Merged
merged 46 commits into from
May 3, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fixed Some Bugs
 - Fixed SpMatTest
 - Updates on rebase
reid-g committed Apr 10, 2024
commit 226afcae0f0599edfd2aff84938d815288261f1f
43 changes: 28 additions & 15 deletions Examples/Grid3Bus/Grid3BusSys.cpp
Original file line number Diff line number Diff line change
@@ -101,8 +101,8 @@ mpc.baseMVA = 100;
%% bus data
% bus_i type Pd Qd Gs Bs area Vm Va baseKV zone Vmax Vmin
mpc.bus = [
1 3 2.0 0.0 0 0 0 1 0.0 0 0 0 0.0;
2 1 2.5 -0.8 0 0 0 1 0.0 0 0 0 0.0;
1 3 2.0 0.0 0 0 0 1.0 0.0 0 0 0 0.0;
2 1 2.5 -0.8 0 0 0 1.0 0.0 0 0 0 0.0;
3 2 0 0 0 0 0 1.1 0.0 0 0 0 0.0;
];

@@ -216,6 +216,7 @@ int parser_case()

// allocate model
sysmodel->allocate();
sysmodel->initialize();
std::cout << "Model size: " << sysmodel->size() << "\n\n";

// Create numerical solver and attach the model to it.
@@ -274,71 +275,72 @@ int hardwired_case()

// Next create and add buses ...
// Create a slack bus, fix V=1, theta=0, bus ID = 1
BusData<double, size_t> bd1;
BusData<double, size_t> bd1 = {};
bd1.bus_i = 1; bd1.type = 3; bd1.Vm = 1.0; bd1.Va = 0.0;
auto* bus1 = BusFactory<double, size_t>::create(bd1);
sysmodel->addBus(bus1);

//Create a PQ bus, initialize V=1, theta=0, bus ID = 2
BusData<double, size_t> bd2;
BusData<double, size_t> bd2 = {};
bd2.bus_i = 2; bd2.type = 1; bd2.Vm = 1.0; bd2.Va = 0.0;
auto* bus2 = BusFactory<double, size_t>::create(bd2);
sysmodel->addBus(bus2);

// Create a PV bus, fix V=1.1, initialize theta=0, and set power injection Pg=2
BusData<double, size_t> bd3;
BusData<double, size_t> bd3 = {};
bd3.bus_i = 3; bd3.type = 2; bd3.Vm = 1.1; bd3.Va = 0.0;
auto* bus3 = BusFactory<double, size_t>::create(bd3);
sysmodel->addBus(bus3);

// Create and add generators ...
// Create and add slack generator connected to bus1
GenData<double, size_t> gd1;
GenData<double, size_t> gd1 = {};
gd1.bus = 1;
auto* gen1 = GeneratorFactory<double, size_t>::create(sysmodel->getBus(gd1.bus), gd1);
sysmodel->addComponent(gen1);

// Create and add PV generator connected to bus3
GenData<double, size_t> gd3;
GenData<double, size_t> gd3 = {};
gd3.Pg = 2.0; gd3.bus = 3;
auto* gen3 = GeneratorFactory<double, size_t>::create(sysmodel->getBus(gd3.bus), gd3);
sysmodel->addComponent(gen3);

// Create and add branches ...
// Branch 1-2
BranchData<double, size_t> brd12;
BranchData<double, size_t> brd12 = {};
brd12.fbus = 1; brd12.tbus = 2; brd12.x = 1.0/10.0; brd12.r = 0.0; brd12.b = 0.0;
Branch<double, size_t>* branch12 = new Branch<double, size_t>(sysmodel->getBus(brd12.fbus), sysmodel->getBus(brd12.tbus), brd12);
sysmodel->addComponent(branch12);

// Branch 1-3
BranchData<double, size_t> brd13;
BranchData<double, size_t> brd13 = {};
brd13.fbus = 1; brd13.tbus = 3; brd13.x = 1.0/15.0; brd13.r = 0.0; brd13.b = 0.0;
Branch<double, size_t>* branch13 = new Branch<double, size_t>(sysmodel->getBus(brd13.fbus), sysmodel->getBus(brd13.tbus), brd13);
sysmodel->addComponent(branch13);

// Branch 2-3
BranchData<double, size_t> brd23;
BranchData<double, size_t> brd23 = {};
brd23.fbus = 2; brd23.tbus = 3; brd23.x = 1.0/12.0; brd23.r = 0.0; brd23.b = 0.0;
Branch<double, size_t>* branch23 = new Branch<double, size_t>(sysmodel->getBus(brd23.fbus), sysmodel->getBus(brd23.tbus), brd23);
sysmodel->addComponent(branch23);


// Create and add loads ...
// Load on bus1
LoadData<double, size_t> ld1;
LoadData<double, size_t> ld1 = {};
ld1.bus_i = 1; ld1.Pd = 2.0; ld1.Qd = 0.0;
Load<double, size_t>* load1 = new Load<double, size_t>(sysmodel->getBus(ld1.bus_i), ld1);
sysmodel->addComponent(load1);

// Load on bus2
LoadData<double, size_t> ld2;
LoadData<double, size_t> ld2 = {};
ld2.bus_i = 2; ld2.Pd = 2.5; ld2.Qd = -0.8;
Load<double, size_t>* load2 = new Load<double, size_t>(sysmodel->getBus(ld2.bus_i), ld2);
sysmodel->addComponent(load2);

// allocate model
sysmodel->allocate();
sysmodel->initialize();
std::cout << "Model size: " << sysmodel->size() << "\n\n";

// Create numerical solver and attach the model to it.
@@ -354,7 +356,7 @@ int hardwired_case()
// Print solution
double th2 = bus2->theta() * 180.0/M_PI;
double V2 = bus2->V();
double th3 = bus3->theta() * 180.0/M_PI;
double th3 = bus3->theta() * 180.0/M_PI;


std::cout << "Solution:\n";
@@ -390,8 +392,19 @@ int main()
std::cout << std::string(32,'-') << std::endl;
resolve += monolithic_case();
std::cout << std::string(32,'-') << std::endl;
resolve += hardwired_case();
std::cout << std::string(32,'-') << std::endl;
resolve += parser_case();
std::cout << std::string(32,'-') << std::endl;
resolve += hardwired_case();

if (resolve)
{
std::cout << "Failure!\n";
}
else
{
std::cout << "Success!\n";
}


return resolve;
}
2 changes: 1 addition & 1 deletion SparseMatrix/COO_Matrix.hpp
Original file line number Diff line number Diff line change
@@ -294,9 +294,9 @@ inline void COO_Matrix<ScalarT, Intdx>::AXPY(ScalarT alpha, COO_Matrix<ScalarT,
this->row_indexes.push_back(r[aiter]);
this->column_indexes.push_back(c[aiter]);
this->values.push_back(alpha * val[aiter]);
aiter++;

this->checkIncreaseSize(r[aiter], c[aiter]);
aiter++;
}
if (aiter >= static_cast<Intdx>(r.size())) break;

39 changes: 1 addition & 38 deletions SystemSteadyStateModel.hpp
Original file line number Diff line number Diff line change
@@ -127,43 +127,6 @@ class SystemSteadyStateModel : public ModelEvaluatorImpl<ScalarT, IdxT>
atol_ = 1e-5;
}

SystemSteadyStateModel(GridKit::PowerSystemData::SystemModelData<ScalarT, IdxT> mp) : ModelEvaluatorImpl<ScalarT, IdxT>(0,0,0)
{
rtol_ = 1e-5;
atol_ = 1e-5;

//buses
for(auto busdata : mp.bus)
{
auto* bus = BusFactory<double, size_t>::create(busdata);
this->addBus(bus);
}

//generators
for (auto gendata : mp.gen)
{
auto* gen = GeneratorFactory<double,size_t>::create(this->getBus(gendata.bus),gendata);
this->addComponent(gen);
}

//branches
for (auto branchdata : mp.branch)
{
auto* branch = new Branch<double, size_t>(this->getBus(branchdata.fbus),this->getBus(branchdata.tbus),branchdata);
this->addComponent(branch);
}

//loads
for (auto loaddata : mp.load)
{
auto* loadm = new Load<double,size_t>(this->getBus(loaddata.bus_i),loaddata);
this->addComponent(loadm);
}

//There appears to not be a Generator Cost Object
//TODO: Implment for GenCost
}

/**
* @brief Construct a new System Steady State Model object. Allows for simple allocation.
*
@@ -463,4 +426,4 @@ class SystemSteadyStateModel : public ModelEvaluatorImpl<ScalarT, IdxT>

}; // class SystemSteadyStateModel

} // namespace ModelLib
} // namespace ModelLib