Skip to content

Aligning the code with contributing guidelines #42

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 18 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
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
8 changes: 4 additions & 4 deletions examples/Grid3Bus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ Problem variables are voltage magnitudes and phases; they are stored in bus obje

**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](../../src/Model/PowerFlow/Branch/README.md) and [load](../../src/Model/PowerFlow/Load/README.md) components, we assemble Bus 2 residuals as:
**Bus 2**: PQ bus, stores variables $`V_2, \theta_2`$ and residuals $`P_2, Q_2`$. Load $`P_{L1} = 2.5`$p.u., $`Q_{L1} = -j0.8`$p.u. is attached to it. From the equations for [branch](../../src/Model/PowerFlow/Branch/README.md) and [load](../../src/Model/PowerFlow/Load/README.md) components, we assemble Bus 2 residuals as:
```math
\begin{array}{rcll}
P_2 & = &-P_{L2} &~~~\mathrm{(load ~2)} \\
P_2 & = &-P_{L1} &~~~\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)} \\
Q_2 & = & -Q_{L1} &~~~\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}
Expand Down Expand Up @@ -57,7 +57,7 @@ with variables $`\theta_2, |V_2|`$ and $`\theta_3`$.

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
jac_{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
Expand Down
10 changes: 4 additions & 6 deletions examples/Microgrid/Microgrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
int main(int argc, char const *argv[])
{
///@todo Needs to be modified. Some components are small relative to others thus there error is high (or could be matlab vector issue)
double abstol = 1.0e-8;
double reltol = 1.0e-8;
double abs_tol = 1.0e-8;
double rel_tol = 1.0e-8;
size_t max_step_amount = 3000;
bool usejac = true;
bool use_jac = true;

//Create model
GridKit::PowerElectronicsModel<double, size_t>* sysmodel = new GridKit::PowerElectronicsModel<double, size_t>(reltol, abstol, usejac, max_step_amount);
GridKit::PowerElectronicsModel<double, size_t>* sysmodel = new GridKit::PowerElectronicsModel<double, size_t>(rel_tol, abs_tol, use_jac, max_step_amount);

//Modeled after the problem in the paper
double RN = 1.0e4;
Expand Down Expand Up @@ -336,8 +336,6 @@ int main(int argc, char const *argv[])
sysmodel->updateTime(0.0, 1.0e-8);
sysmodel->evaluateJacobian();
std::cout << "Intial Jacobian with alpha:\n";
// std::cout << sysmodel->getJacobian().frobnorm() << "\n";


//Create numerical integrator and configure it for the generator model
AnalysisManager::Sundials::Ida<double, size_t>* idas = new AnalysisManager::Sundials::Ida<double, size_t>(sysmodel);
Expand Down
8 changes: 4 additions & 4 deletions examples/RLCircuit/RLCircuit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@

int main(int argc, char const *argv[])
{
double abstol = 1.0e-8;
double reltol = 1.0e-8;
bool usejac = true;
double abs_tol = 1.0e-8;
double rel_tol = 1.0e-8;
bool use_jac = true;

//TODO:setup as named parameters
//Create circuit model
GridKit::PowerElectronicsModel<double, size_t>* sysmodel = new GridKit::PowerElectronicsModel<double, size_t>(reltol, abstol, usejac);
auto* sysmodel = new GridKit::PowerElectronicsModel<double, size_t>(rel_tol, abs_tol, use_jac);

size_t idoff = 0;

Expand Down
12 changes: 6 additions & 6 deletions examples/ScaleMicrogrid/ScaleMicrogrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,18 @@ int test(index_type Nsize, real_type error_tol, bool debug_output)
{
using namespace GridKit;

bool usejac = true;
bool use_jac = true;

real_type t_init = 0.0;
real_type t_final = 1.0;

real_type reltol = SCALE_MICROGRID_REL_TOL;
real_type abstol = SCALE_MICROGRID_ABS_TOL;
real_type rel_tol = SCALE_MICROGRID_REL_TOL;
real_type abs_tol = SCALE_MICROGRID_ABS_TOL;

// Create circuit model
auto* sysmodel = new PowerElectronicsModel<real_type, index_type>(reltol,
abstol,
usejac,
auto* sysmodel = new PowerElectronicsModel<real_type, index_type>(rel_tol,
abs_tol,
use_jac,
SCALE_MICROGRID_MAX_STEPS);

const std::vector<real_type>* true_vec = &answer_key_N8;
Expand Down
2 changes: 1 addition & 1 deletion examples/ScaleMicrogrid/SolutionKeys.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @brief Answer keys for Scaled Microgrid test with Nsize = 2, 4, 8
*
* Data generated with Matlab ode23tb solver with tolerances set to
* abstol = 1e-12 and reltol = 1e-12 for the ODE derivation of the model.
* abs_tol = 1e-12 and rel_tol = 1e-12 for the ODE derivation of the model.
* No index reduction was preformed to get to the ODE model.
*
* @note This file is only to be included in ScaleMicrogrid.cpp. It has no
Expand Down
2 changes: 1 addition & 1 deletion examples/SparseTest/SparseTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ int main(int argc, char const *argv[])
std::vector<size_t> r;
std::vector<size_t> c;
std::vector<double> v;
std::tie(r,c,v) = A.getDataToCSR();
std::tie(r,c,v) = A.setDataToCSR();

for (size_t i = 0; i < r.size() - 1; i++)
{
Expand Down
5 changes: 3 additions & 2 deletions src/CircuitGraph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,13 @@ size_t CircuitGraph<N, E>::amountHyperEdges()
}

/**
* @brief Printing
* @brief Print the bipartite graph
*
* @todo need to add verbose printing for connections display
*
* @tparam IdxT
* @param verbose
* @param[in] verbose if true will print connections,
* otherwise just the number of nodes and edges
*/

template <typename N, typename E>
Expand Down
Loading