Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
90f8ae5
Remove short-circuit from COO::axpy
alexander-novo Nov 6, 2025
b4c18d4
Add sparsity pattern computation
alexander-novo Nov 6, 2025
6edf7d0
Update CHANGELOG.md
alexander-novo Nov 11, 2025
75bc32e
Remove unneeded dependency
alexander-novo Nov 11, 2025
669d989
Remove unnecessary this->
alexander-novo Nov 11, 2025
759f22f
Remove std::vector for component_sparsities
alexander-novo Nov 11, 2025
c0c6c37
Update member names for guidelines
alexander-novo Nov 13, 2025
963c127
Change reverse_map buckets to linked list
alexander-novo Nov 13, 2025
2cd9248
Change sparsity test to use scalable microgrid
alexander-novo Nov 13, 2025
7c79359
Calculate sparsity directly into CsrMatrix
alexander-novo Nov 13, 2025
56d2f6b
Add levvel of indirection to csr_jac_
alexander-novo Nov 13, 2025
0266df9
Add resize() to CsrMatrix
alexander-novo Nov 13, 2025
6a999c0
Add CsrMatrix dependency to power electronics examples
alexander-novo Nov 13, 2025
f6fcd97
Allocate csr matrix properly
alexander-novo Nov 13, 2025
2522abc
[skip ci] Update documentation
alexander-novo Nov 13, 2025
22edecb
Ensure system vector is mapped correctly
alexander-novo Nov 19, 2025
756d9a9
Ensure local variable grouping in system vector
alexander-novo Nov 19, 2025
a68ec9d
Ensure components are sorted in system vector
alexander-novo Nov 19, 2025
c031309
Comment
alexander-novo Nov 19, 2025
1dbdc34
Construct internal and external row sparsities separately
alexander-novo Nov 20, 2025
ba0794e
Removed some magic numbers
alexander-novo Nov 20, 2025
a371239
Fix RLCircuit example's system vector ordering
alexander-novo Nov 20, 2025
e2b8ba2
[skip ci] Remove extra comment
alexander-novo Nov 20, 2025
e87b59b
PowerElectronics test 13-->dg_ref.NUM_INTERNALS.
nkoukpaizan Dec 12, 2025
7975429
Workaround warnings.
nkoukpaizan Dec 12, 2025
295b572
Remove std::next
alexander-novo Dec 22, 2025
00360c0
Remove component CSR sparsities from alloc sparsity calculations
alexander-novo Dec 22, 2025
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
- Added support for DependencyTracking::Variable in PowerElectronics models.
- Updated Jacobian value storage from `ScalarT` to `RealT`.
- Added a header file defining constants to be used throughout the code.
- Added Jacobian sparsity pattern computation into `PowerElectronics`.

## v0.1

Expand Down
8 changes: 0 additions & 8 deletions GridKit/LinearAlgebra/SparseMatrix/COO_Matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,6 @@ namespace GridKit
template <typename RealT, typename IdxT>
inline void COO_Matrix<RealT, IdxT>::axpy(RealT alpha, COO_Matrix<RealT, IdxT>& a)
{
if (alpha == 0)
{
return;
}

if (!this->sorted_)
{
this->sortSparse();
Expand Down Expand Up @@ -372,9 +367,6 @@ namespace GridKit
template <typename RealT, typename IdxT>
inline void COO_Matrix<RealT, IdxT>::axpy(RealT alpha, std::vector<IdxT> r, std::vector<IdxT> c, std::vector<RealT> v)
{
if (alpha == 0)
return;

if (!this->sorted_)
{
this->sortSparse();
Expand Down
20 changes: 20 additions & 0 deletions GridKit/LinearAlgebra/SparseMatrix/CsrMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,26 @@ namespace GridKit
}
}

/**
* @brief Changes the size of the matrix. De-allocates the matrix, if needed, since the
* old indices corresponded to a differently-size matrix and no longer make sense.
* Does not re-allocate any memory.
* @param n The new number of rows
* @param m The new number of columns
* @return 0 if succesful
*/
template <typename RealT, typename IdxT>
int CsrMatrix<RealT, IdxT>::resize(IdxT n, IdxT m)
{
destroyMatrixData(memory::HOST);
destroyMatrixData(memory::DEVICE);

n_ = n;
m_ = m;

return 0;
}

template class CsrMatrix<double, long int>;
template class CsrMatrix<double, size_t>;
} // namespace LinearAlgebra
Expand Down
2 changes: 2 additions & 0 deletions GridKit/LinearAlgebra/SparseMatrix/CsrMatrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ namespace GridKit
virtual int setValuesPointer(RealT* new_vals,
memory::MemorySpace memspace);

int resize(IdxT n, IdxT m);

private:
IdxT n_{0}; ///< number of rows
IdxT m_{0}; ///< number of columns
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ namespace GridKit
{
// internals [\delta_i, Pi, Qi, phi_di, phi_qi, gamma_di, gamma_qi, il_di, il_qi, vo_di, vo_qi, io_di, io_qi]
// externals [\omega_ref, vba_out, vbb_out]
size_ = 16;
n_intern_ = 13;
n_extern_ = 3;
size_ = NUM_INTERNALS + NUM_EXTERNALS;
n_intern_ = NUM_INTERNALS;
n_extern_ = NUM_EXTERNALS;
extern_indices_ = {0, 1, 2};
idc_ = id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ namespace GridKit
using CircuitComponent<ScalarT, IdxT>::n_intern_;

public:
static constexpr size_t NUM_INTERNALS = 13;
static constexpr size_t NUM_EXTERNALS = 3;

DistributedGenerator(IdxT id,
DistributedGeneratorParameters<RealT, IdxT> parm,
bool reference_frame);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ namespace GridKit
: RN_(RN)
{
// externals [vbus_d, vbus_q]
size_ = 2;
n_intern_ = 0;
n_extern_ = 2;
size_ = NUM_INTERNALS + NUM_EXTERNALS;
n_intern_ = NUM_INTERNALS;
n_extern_ = NUM_EXTERNALS;
extern_indices_ = {0, 1};
idc_ = id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ namespace GridKit
using CircuitComponent<ScalarT, IdxT>::n_intern_;

public:
static constexpr size_t NUM_INTERNALS = 0;
static constexpr size_t NUM_EXTERNALS = 2;

MicrogridBusDQ(IdxT id, RealT RN);
virtual ~MicrogridBusDQ();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ namespace GridKit
{
// internals [id, iq]
// externals [\omegaref, vbd_in, vbq_in, vbd_out, vbq_out]
size_ = 7;
n_intern_ = 2;
n_extern_ = 5;
size_ = NUM_INTERNALS + NUM_EXTERNALS;
n_intern_ = NUM_INTERNALS;
n_extern_ = NUM_EXTERNALS;
extern_indices_ = {0, 1, 2, 3, 4};
idc_ = id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ namespace GridKit
using CircuitComponent<ScalarT, IdxT>::n_intern_;

public:
static constexpr size_t NUM_INTERNALS = 2;
static constexpr size_t NUM_EXTERNALS = 5;

MicrogridLine(IdxT id, RealT R, RealT L);
virtual ~MicrogridLine();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ namespace GridKit
{
// internals [id, iq]
// externals [\omegaref, vbd_out, vbq_out]
size_ = 5;
n_intern_ = 2;
n_extern_ = 3;
size_ = NUM_INTERNALS + NUM_EXTERNALS;
n_intern_ = NUM_INTERNALS;
n_extern_ = NUM_EXTERNALS;
extern_indices_ = {0, 1, 2};
idc_ = id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ namespace GridKit
using CircuitComponent<ScalarT, IdxT>::n_intern_;

public:
static constexpr size_t NUM_INTERNALS = 2;
static constexpr size_t NUM_EXTERNALS = 3;

MicrogridLoad(IdxT id, RealT R, RealT L);
virtual ~MicrogridLoad();

Expand Down
Loading