Skip to content

Commit d809098

Browse files
committed
resolve comments
Signed-off-by: Santiago Figueroa Manrique <figueroa1395@gmail.com>
1 parent 9b733d8 commit d809098

1 file changed

Lines changed: 15 additions & 16 deletions

File tree

  • power_grid_model_c/power_grid_model/include/power_grid_model

power_grid_model_c/power_grid_model/include/power_grid_model/link_solver.hpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -320,24 +320,28 @@ inline std::vector<std::vector<DoubleComplex>> set_projection_system(Idx free_in
320320
};
321321

322322
inline void gauss_elimination(std::vector<std::vector<DoubleComplex>>& system) {
323+
auto const system_size = narrow_cast<Idx>(std::ssize(system));
323324

324-
auto const system_size = std::ssize(system);
325-
326-
for (Idx column = 0; column < system_size; column++) {
327-
for (Idx row = column + 1; row < system_size; row++) {
325+
// we skip pivoting since the matrix system is mostly diagonally dominant
326+
// and given the real power systems topology of super nodes, this should not introduce
327+
// any numerical instabilities in practice
328328

329+
// forward elimination
330+
for (Idx column : IdxRange{system_size}) {
331+
for (Idx row : IdxRange{column + Idx{1}, system_size}) {
329332
system[row][column] = -system[row][column] / system[column][column];
330333

331-
for (Idx column_part = column + 1; column_part < system_size + 1; column_part++) {
334+
for (Idx column_part : IdxRange{column + Idx{1}, system_size + Idx{1}}) {
332335
system[row][column_part] += system[row][column] * system[column][column_part];
333336
}
334337
}
335338
}
336339

340+
// backward substitution
337341
system[system_size - 1][system_size] /= system[system_size - 1][system_size - 1];
338342
for (Idx row = system_size - 1; row-- > 0;) {
339343
auto element_sum = DoubleComplex{};
340-
for (Idx column = row + 1; column < system_size; column++) {
344+
for (Idx column : IdxRange{row + Idx{1}, system_size}) {
341345
element_sum -= system[row][column] * system[column][system_size];
342346
}
343347
system[row][system_size] = (system[row][system_size] + element_sum) / system[row][row];
@@ -346,23 +350,18 @@ inline void gauss_elimination(std::vector<std::vector<DoubleComplex>>& system) {
346350

347351
inline std::vector<DoubleComplex> compute_internal_loads(SolutionSet& solution_set,
348352
std::vector<std::vector<DoubleComplex>>& system) {
349-
350-
std::vector<DoubleComplex> internal_loads{};
351-
352353
auto const number_of_rows = narrow_cast<Idx>(solution_set.extended_rhs.size());
353354
auto const number_of_columns = narrow_cast<Idx>(system.size());
354-
355-
internal_loads.resize(number_of_rows);
355+
std::vector<DoubleComplex> internal_loads(number_of_rows);
356356

357357
for (auto row : IdxRange{number_of_rows}) {
358-
359358
internal_loads[row] = solution_set.extended_rhs[row];
360359
auto sum_value = DoubleComplex{};
361360
for (auto column : IdxRange{number_of_columns}) {
362-
auto const value = solution_set.dfs_matrix.get_value(row, column);
363-
if (value.has_value()) {
364-
sum_value += static_cast<DoubleComplex>(value.value()) * system[column].back();
365-
}
361+
solution_set.dfs_matrix.get_value(row, column).transform([&sum_value, &system, &column](IntS value) {
362+
sum_value += static_cast<DoubleComplex>(value) * system[column].back();
363+
return value;
364+
});
366365
}
367366
internal_loads[row] -= sum_value;
368367
}

0 commit comments

Comments
 (0)