Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NRSE low level design #455

Merged
merged 40 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
5582b8a
Revert "reduce nrse to interface only"
mgovers Nov 29, 2023
996f8a4
fix header guard
mgovers Nov 29, 2023
cebbbae
Merge remote-tracking branch 'origin/feature/NRSE-interface' into fea…
mgovers Nov 29, 2023
7ee09ab
Merge remote-tracking branch 'origin/feature/NRSE-interface' into fea…
mgovers Nov 29, 2023
f526496
Merge branch 'main' into feature/NRSE-general-structure
mgovers Nov 29, 2023
a7702c8
[skip ci] make fills to separate files
nitbharambe Nov 30, 2023
cfde7da
[skip ci] change adding of values
nitbharambe Dec 1, 2023
a001bde
[skip ci] checkpoint split block things
nitbharambe Dec 1, 2023
88d6e49
[skip ci] add most structure
nitbharambe Dec 4, 2023
0b62f65
[skip ci] equations fix
nitbharambe Dec 4, 2023
3d64948
wip correct types
nitbharambe Dec 5, 2023
54a8bcb
[skip ci] type fix
nitbharambe Dec 11, 2023
821e0df
Merge branch 'main' into feature/NRSE-general-structure
nitbharambe Dec 11, 2023
f2f5203
[skip ci] wip split jacobian
nitbharambe Dec 13, 2023
2f0e94f
[skip ci] weird merge
nitbharambe Dec 13, 2023
4a844b0
[skip ci] wip branch restructure
nitbharambe Dec 16, 2023
466566d
[skip ci] making types work
nitbharambe Dec 18, 2023
a60f0cd
[skip ci] clean comment
nitbharambe Dec 18, 2023
52321cc
Merge branch 'main' into feature/NRSE-general-structure
mgovers Dec 18, 2023
8c78ade
Merge branch 'main' into feature/NRSE-general-structure
nitbharambe Dec 19, 2023
905c221
remove all content
nitbharambe Dec 19, 2023
855c3bb
remove extra line
nitbharambe Dec 19, 2023
20ccead
remove unused variable
nitbharambe Dec 19, 2023
7e17112
remove unused variable function
nitbharambe Dec 19, 2023
39581d1
nest namespace
nitbharambe Dec 19, 2023
8d7bdea
remove space
nitbharambe Dec 19, 2023
1b3e65b
remove result
nitbharambe Dec 19, 2023
82d5cf4
remove diagonal inverse
nitbharambe Dec 19, 2023
ee09eb6
Apply suggestions from code review
nitbharambe Dec 19, 2023
75821b1
add namespace solvers
nitbharambe Dec 19, 2023
67a35ce
add namespace solvers fix
nitbharambe Dec 19, 2023
b223787
namespace concat
nitbharambe Dec 19, 2023
ed9002c
namespace rename
nitbharambe Dec 19, 2023
7e009dc
make namespace changes
nitbharambe Dec 20, 2023
55febd6
make namespace changes 2
nitbharambe Dec 20, 2023
5c22621
format sparse_solver
nitbharambe Dec 20, 2023
eec38e0
address namespace comments
nitbharambe Dec 20, 2023
00fe7bb
move to math solver namespace
nitbharambe Dec 22, 2023
ffd0304
Merge branch 'main' into feature/NRSE-low-level-design-2
nitbharambe Dec 22, 2023
09f954b
nitpick
mgovers Dec 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "../power_grid_model.hpp"
#include "../three_phase_tensor.hpp"

namespace power_grid_model::math_model_impl {
namespace power_grid_model::math_solver {

template <scalar_value T, bool sym, bool is_tensor, int n_sub_block> struct block_trait {
static constexpr int n_row = sym ? n_sub_block : n_sub_block * 3;
Expand Down Expand Up @@ -64,6 +64,6 @@ class Block : public block_trait<T, sym, is_tensor, n_sub_block>::ArrayType {
}
};

} // namespace power_grid_model::math_model_impl
} // namespace power_grid_model::math_solver

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include "../calculation_parameters.hpp"

namespace power_grid_model::common_solver_functions {
namespace power_grid_model::math_solver::detail {

template <bool sym>
inline void add_sources(IdxRange const& sources, Idx /* bus_number */, YBus<sym> const& y_bus,
Expand Down Expand Up @@ -91,12 +91,12 @@ inline void calculate_result(YBus<sym> const& y_bus, PowerFlowInput<sym> const&
output.bus_injection.resize(sources_per_bus.size());

for (auto const& [bus_number, sources, load_gens] : enumerated_zip_sequence(sources_per_bus, load_gens_per_bus)) {
common_solver_functions::calculate_source_result<sym>(sources, bus_number, y_bus, input, output);
common_solver_functions::calculate_load_gen_result<sym>(load_gens, bus_number, input, output, load_gen_func);
calculate_source_result<sym>(sources, bus_number, y_bus, input, output);
calculate_load_gen_result<sym>(load_gens, bus_number, input, output, load_gen_func);
}
output.bus_injection = y_bus.calculate_injection(output.u);
}

} // namespace power_grid_model::common_solver_functions
} // namespace power_grid_model::math_solver::detail

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Iterative Power Flow
namespace power_grid_model {

// hide implementation in inside namespace
namespace math_model_impl {
namespace math_solver {

// solver
template <bool sym> class IterativeCurrentPFSolver : public IterativePFSolver<sym, IterativeCurrentPFSolver<sym>> {
Expand All @@ -91,7 +91,7 @@ template <bool sym> class IterativeCurrentPFSolver : public IterativePFSolver<sy
// re-build matrix and prefactorize Build y bus data with source admittance
if (y_data_ptr_ != &y_bus.admittance()) {
ComplexTensorVector<sym> mat_data(y_bus.nnz_lu());
common_solver_functions::copy_y_bus<sym>(y_bus, mat_data);
detail::copy_y_bus<sym>(y_bus, mat_data);

for (auto const& [bus_number, sources] : enumerated_zip_sequence(sources_per_bus)) {
Idx const data_sequence = bus_entry[bus_number];
Expand Down Expand Up @@ -193,9 +193,9 @@ template <bool sym> class IterativeCurrentPFSolver : public IterativePFSolver<sy
template class IterativeCurrentPFSolver<true>;
template class IterativeCurrentPFSolver<false>;

} // namespace math_model_impl
} // namespace math_solver

template <bool sym> using IterativeCurrentPFSolver = math_model_impl::IterativeCurrentPFSolver<sym>;
template <bool sym> using IterativeCurrentPFSolver = math_solver::IterativeCurrentPFSolver<sym>;

} // namespace power_grid_model

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "../three_phase_tensor.hpp"
#include "../timer.hpp"

namespace power_grid_model::math_model_impl {
namespace power_grid_model::math_solver {
mgovers marked this conversation as resolved.
Show resolved Hide resolved

// solver
template <bool sym, typename DerivedSolver> class IterativePFSolver {
Expand Down Expand Up @@ -102,8 +102,8 @@ template <bool sym, typename DerivedSolver> class IterativePFSolver {
}

void calculate_result(YBus<sym> const& y_bus, PowerFlowInput<sym> const& input, MathOutput<sym>& output) {
common_solver_functions::calculate_result(y_bus, input, *sources_per_bus_, *load_gens_per_bus_, output,
[this](Idx i) { return (*load_gen_type_)[i]; });
detail::calculate_result(y_bus, input, *sources_per_bus_, *load_gens_per_bus_, output,
[this](Idx i) { return (*load_gen_type_)[i]; });
}

private:
Expand All @@ -120,6 +120,6 @@ template <bool sym, typename DerivedSolver> class IterativePFSolver {
load_gen_type_{topo_ptr, &topo_ptr->load_gen_type} {}
};

} // namespace power_grid_model::math_model_impl
} // namespace power_grid_model::math_solver

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ if there are sources

namespace power_grid_model {

namespace math_solver {
nitbharambe marked this conversation as resolved.
Show resolved Hide resolved

template <bool sym> class LinearPFSolver {

public:
Expand All @@ -63,7 +65,7 @@ template <bool sym> class LinearPFSolver {

// prepare matrix
Timer sub_timer(calculation_info, 2221, "Prepare matrix");
common_solver_functions::copy_y_bus<sym>(y_bus, mat_data_);
detail::copy_y_bus<sym>(y_bus, mat_data_);
prepare_matrix_and_rhs(y_bus, input, output);

// solve
Expand Down Expand Up @@ -91,7 +93,7 @@ template <bool sym> class LinearPFSolver {
typename SparseLUSolver<ComplexTensor<sym>, ComplexValue<sym>, ComplexValue<sym>>::BlockPermArray perm_;

void prepare_matrix_and_rhs(YBus<sym> const& y_bus, PowerFlowInput<sym> const& input, MathOutput<sym>& output) {
using common_solver_functions::add_sources;
using detail::add_sources;

IdxVector const& bus_entry = y_bus.lu_diag();
for (auto const& [bus_number, load_gens, sources] :
Expand All @@ -113,13 +115,16 @@ template <bool sym> class LinearPFSolver {
}

void calculate_result(YBus<sym> const& y_bus, PowerFlowInput<sym> const& input, MathOutput<sym>& output) {
common_solver_functions::calculate_result(y_bus, input, *sources_per_bus_, *load_gens_per_bus_, output,
[](Idx /*i*/) { return LoadGenType::const_y; });
detail::calculate_result(y_bus, input, *sources_per_bus_, *load_gens_per_bus_, output,
[](Idx /*i*/) { return LoadGenType::const_y; });
}
};

template class LinearPFSolver<true>;
template class LinearPFSolver<false>;
} // namespace math_solver

template <bool sym> using LinearPFSolver = math_solver::LinearPFSolver<sym>;
mgovers marked this conversation as resolved.
Show resolved Hide resolved

} // namespace power_grid_model

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

namespace power_grid_model {

namespace math_solver {

template <bool sym> class MathSolver {
public:
explicit MathSolver(std::shared_ptr<MathModelTopology const> const& topo_ptr)
Expand Down Expand Up @@ -171,6 +173,9 @@ template <bool sym> class MathSolver {

template class MathSolver<true>;
template class MathSolver<false>;
} // namespace math_solver

template <bool sym> using MathSolver = math_solver::MathSolver<sym>;
nitbharambe marked this conversation as resolved.
Show resolved Hide resolved

} // namespace power_grid_model

Expand Down