@@ -319,4 +319,54 @@ inline std::vector<std::vector<DoubleComplex>> set_projection_system(Idx free_in
319319 return projection_system;
320320};
321321
322+ inline void naive_gauss_elimination (std::vector<std::vector<DoubleComplex>>& system) {
323+ auto const system_size = narrow_cast<Idx>(std::ssize (system));
324+
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
328+
329+ // forward elimination
330+ for (Idx const column : IdxRange{system_size}) {
331+ auto const pivot = system[column][column];
332+ for (Idx const row : IdxRange{column + Idx{1 }, system_size}) {
333+ auto & row_col_value = system[row][column];
334+ row_col_value /= -pivot;
335+ for (Idx const column_part : IdxRange{column + Idx{1 }, system_size + Idx{1 }}) {
336+ system[row][column_part] += row_col_value * system[column][column_part];
337+ }
338+ }
339+ }
340+
341+ // backward substitution
342+ system[system_size - 1 ][system_size] /= system[system_size - 1 ][system_size - 1 ];
343+ for (Idx const row : IdxRange{system_size - 1 } | std::views::reverse) {
344+ auto element_sum = DoubleComplex{};
345+ for (Idx const column : IdxRange{row + Idx{1 }, system_size}) {
346+ element_sum -= system[row][column] * system[column][system_size];
347+ }
348+ system[row][system_size] = (system[row][system_size] + element_sum) / system[row][row];
349+ }
350+ };
351+
352+ inline std::vector<DoubleComplex> compute_internal_loads (SolutionSet const & solution_set,
353+ std::vector<std::vector<DoubleComplex>> const & system) {
354+ auto const number_of_rows = narrow_cast<Idx>(solution_set.extended_rhs .size ());
355+ auto const number_of_columns = narrow_cast<Idx>(system.size ());
356+ std::vector<DoubleComplex> internal_loads (number_of_rows);
357+
358+ for (auto const row : IdxRange{number_of_rows}) {
359+ internal_loads[row] = solution_set.extended_rhs [row];
360+ auto sum_value = DoubleComplex{};
361+ for (auto const column : IdxRange{number_of_columns}) {
362+ solution_set.dfs_matrix .get_value (row, column).transform ([&sum_value, &system, column](IntS value) {
363+ sum_value += static_cast <DoubleComplex>(value) * system[column].back ();
364+ return value;
365+ });
366+ }
367+ internal_loads[row] -= sum_value;
368+ }
369+
370+ return internal_loads;
371+ };
322372} // namespace power_grid_model::link_solver::detail
0 commit comments