Feature/links part 2#1344
Feature/links part 2#1344marcvanraalte wants to merge 15 commits intoPowerGridModel:feature/add_reduced_echelon_form_functionfrom
Conversation
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>
Signed-off-by: marc van raalte <marc.van.raalte@alliander.com>
| 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; |
There was a problem hiding this comment.
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]; |
There was a problem hiding this comment.
Let's do static casting instead here.
| 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); |
There was a problem hiding this comment.
Same suggestion as in #1344 (comment):
| 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; |
There was a problem hiding this comment.
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?
| 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); | ||
| } | ||
| } |
There was a problem hiding this comment.
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);
}| 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; |
There was a problem hiding this comment.
Given #1344 (comment), maybe (you would need to check) this changes a bit, but integer multiplication is cheap.
| dot_product_rhs = 0.; | ||
| dot_product_matrix = 0.; |
There was a problem hiding this comment.
Let's make declaration and initialization on the same place here
| 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) { |
There was a problem hiding this comment.
| [[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, |
There was a problem hiding this comment.
| [[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, |
Implementation of the functions:
to project the minimalization solution out of the set of solutions.