Skip to content

Feature/links part 2#1344

Open
marcvanraalte wants to merge 15 commits intoPowerGridModel:feature/add_reduced_echelon_form_functionfrom
marcvanraalte:feature/links-part-2
Open

Feature/links part 2#1344
marcvanraalte wants to merge 15 commits intoPowerGridModel:feature/add_reduced_echelon_form_functionfrom
marcvanraalte:feature/links-part-2

Conversation

@marcvanraalte
Copy link
Copy Markdown

@marcvanraalte marcvanraalte commented Mar 26, 2026

Implementation of the functions:

  • set_solution_system
  • set_projection_system

to project the minimalization solution out of the set of solutions.

marcvanraalte and others added 13 commits March 17, 2026 15:37
Signed-off-by: marc van raalte <marc.van.raalte@alliander.com>
Signed-off-by: Santiago Figueroa Manrique <figueroa1395@gmail.com>
Signed-off-by: Santiago Figueroa Manrique <figueroa1395@gmail.com>
Signed-off-by: Santiago Figueroa Manrique <figueroa1395@gmail.com>
Signed-off-by: Santiago Figueroa Manrique <figueroa1395@gmail.com>
Signed-off-by: marc van raalte <marc.van.raalte@alliander.com>
Signed-off-by: marc van raalte <marc.van.raalte@alliander.com>
…/links-part-1

Signed-off-by: Santiago Figueroa Manrique <figueroa1395@gmail.com>
Signed-off-by: marc van raalte <marc.van.raalte@alliander.com>
Signed-off-by: marc van raalte <marc.van.raalte@alliander.com>
Signed-off-by: marc van raalte <marc.van.raalte@alliander.com>
Signed-off-by: marc van raalte <marc.van.raalte@alliander.com>
Signed-off-by: marc van raalte <marc.van.raalte@alliander.com>
@figueroa1395 figueroa1395 added the feature New feature or request label Mar 26, 2026
marcvanraalte and others added 2 commits March 27, 2026 09:45
Signed-off-by: marc van raalte <marc.van.raalte@alliander.com>
Comment on lines +274 to +278
auto& [matrix, rhs, free_edge_indices, pivot_edge_indices, edges_history] = result;

auto const pivot_indices_size = pivot_edge_indices.size();
auto const free_indices_size = free_edge_indices.size();
auto const total_indices_size = pivot_indices_size + free_indices_size;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe these are only being used within this function to get total_indices_size and free_indices_size. If that's the case, perhaps it is a good idea to remove EliminationResult from this function and just pass in what we need.

dot_product_matrix = 0.;
for (uint64_t dfs_matrix_row = 0; dfs_matrix_row < total_indices_size; dfs_matrix_row++) {
if (dfs_matrix.get_value(first_value, dfs_matrix_row, dfs_matrix_col)) {
dot_product_rhs += (DoubleComplex)first_value * extended_rhs[dfs_matrix_row];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do static casting instead here.

Suggested change
dot_product_rhs += (DoubleComplex)first_value * extended_rhs[dfs_matrix_row];
dot_product_rhs += static_cast<DoubleComplex>(first_value) * extended_rhs[dfs_matrix_row];

if (dfs_matrix.get_value(first_value, dfs_matrix_row, dfs_matrix_col)) {
dot_product_rhs += (DoubleComplex)first_value * extended_rhs[dfs_matrix_row];
if (dfs_matrix.get_value(second_value, dfs_matrix_row, second_dfs_matrix_col)) {
dot_product_matrix += (DoubleComplex)(first_value * second_value);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same suggestion as in #1344 (comment):

Suggested change
dot_product_matrix += (DoubleComplex)(first_value * second_value);
dot_product_matrix += static_cast<DoubleComplex>(first_value * second_value);

auto const free_indices_size = free_edge_indices.size();
auto const total_indices_size = pivot_indices_size + free_indices_size;

auto& [dfs_matrix, extended_rhs] = solution_set;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been thinking about the dfs_matrix data structure. I think it will be mostly a dense matrix, so there is no point on using a sparse representation. With that said, do you think it would be better to change only the dfs_matrix to dense representation? It probably has better performance in this case. What I propose is to consider using an std::vector<std::vector<IntS>> instead. And then initialize to 0 and access/set as one normally would. If an entry is zero, just proceed normally.

What do you think? Would this be a good idea?

Comment on lines +295 to +301
for (uint64_t dfs_matrix_row = 0; dfs_matrix_row < total_indices_size; dfs_matrix_row++) {
if (dfs_matrix.get_value(first_value, dfs_matrix_row, dfs_matrix_col)) {
dot_product_rhs += (DoubleComplex)first_value * extended_rhs[dfs_matrix_row];
if (dfs_matrix.get_value(second_value, dfs_matrix_row, second_dfs_matrix_col)) {
dot_product_matrix += (DoubleComplex)(first_value * second_value);
}
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the dense representation, this would then change to something along the lines of:

for (uint64_t dfs_matrix_row = 0; dfs_matrix_row < total_indices_size; dfs_matrix_row++) {
    IntS const first_value = dfs_matrix[dfs_matrix_row][dfs_matrix_col];
    IntS const second_value = dfs_matrix[dfs_matrix_row][second_dfs_matrix_col];
    dot_product_rhs += static_cast<DoubleComplex>(first_value) * extended_rhs[dfs_matrix_row];
    dot_product_matrix += static_cast<DoubleComplex>(first_value * second_value);
}

Comment on lines +303 to +305
projection_system[dfs_matrix_col][free_indices_size] = dot_product_rhs;
projection_system[dfs_matrix_col][second_dfs_matrix_col] = dot_product_matrix;
projection_system[second_dfs_matrix_col][dfs_matrix_col] = dot_product_matrix;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given #1344 (comment), maybe (you would need to check) this changes a bit, but integer multiplication is cheap.

Comment on lines +293 to +294
dot_product_rhs = 0.;
dot_product_matrix = 0.;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make declaration and initialization on the same place here

Suggested change
dot_product_rhs = 0.;
dot_product_matrix = 0.;
DoubleComplex dot_product_rhs = 0.;
DoubleComplex dot_product_matrix = 0.;

Maybe with the dense representation and what I suggested you only need one of these, but I'm not sure.

std::vector<DoubleComplex> extended_rhs{};
};

[[nodiscard]] inline SolutionSet set_solution_system(EliminationResult& result) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[[nodiscard]] inline SolutionSet set_solution_system(EliminationResult& result) {
[[nodiscard]] inline SolutionSet set_solution_system(EliminationResult const& result) {

return solution_set;
};

[[nodiscard]] inline std::vector<std::vector<DoubleComplex>> set_projection_system(EliminationResult& result,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[[nodiscard]] inline std::vector<std::vector<DoubleComplex>> set_projection_system(EliminationResult& result,
[[nodiscard]] inline std::vector<std::vector<DoubleComplex>> set_projection_system(EliminationResult const& result,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants