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

Newton Raphson State Esimation Implementation #438

Merged
merged 144 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from 67 commits
Commits
Show all changes
144 commits
Select commit Hold shift + click to select a range
299943c
Revert "remove result"
nitbharambe Dec 20, 2023
a7439c8
Revert "remove space"
nitbharambe Dec 20, 2023
7c42656
Revert "remove unused variable function"
nitbharambe Dec 20, 2023
4c2b741
Revert "remove unused variable"
nitbharambe Dec 20, 2023
e1e9c23
Revert "remove extra line"
nitbharambe Dec 20, 2023
7758fbf
Revert "remove all content"
nitbharambe Dec 20, 2023
0622faf
Revert "nest namespace"
nitbharambe Dec 20, 2023
2d1d937
Merge branch 'feature/NRSE-low-level-design-2' into feature/NRSE-gene…
nitbharambe Dec 20, 2023
ed88dcf
Merge branch 'main' into feature/NRSE-general-structure
nitbharambe Dec 22, 2023
bdd7ccb
address peters comments
nitbharambe Dec 22, 2023
c6601f6
[skip ci] rename attribute
nitbharambe Dec 27, 2023
a927b66
[skip ci] new branch shunt wip
nitbharambe Dec 27, 2023
08cdbad
[skip ci] injection wip
nitbharambe Dec 28, 2023
d993d8e
[skip ci] uncommenting left
nitbharambe Dec 28, 2023
cc31b21
clean up new workout
nitbharambe Dec 28, 2023
a8c30bb
minor fix
nitbharambe Dec 28, 2023
e0868a2
comment unused
nitbharambe Dec 28, 2023
5324fa9
cleanup more
nitbharambe Dec 29, 2023
6a43519
remove uneeded code
nitbharambe Jan 2, 2024
9abc084
fix for sparse matrix
nitbharambe Jan 3, 2024
bf74e56
fix voltage usage
nitbharambe Jan 3, 2024
a4e59ad
extract methods
nitbharambe Jan 3, 2024
216ffab
add clear method to block
nitbharambe Jan 3, 2024
b37623b
change comment of unknown
nitbharambe Jan 3, 2024
b334238
Merge branch 'main' into feature/NRSE-general-structure
nitbharambe Jan 3, 2024
b36946f
change to complex
nitbharambe Jan 9, 2024
bf13dbc
recitfy commented 3ph tensor issues
nitbharambe Jan 9, 2024
5f1535a
add nrse as experimental validation checks
mgovers Jan 16, 2024
5197735
Merge branch 'main' into feature/NRSE-general-structure
mgovers Jan 16, 2024
a8e88b3
Merge remote-tracking branch 'origin/feature/NRSE-general-structure' …
mgovers Jan 16, 2024
16f0caa
fix injection sum
nitbharambe Jan 16, 2024
89d2085
improve failure implementation
mgovers Jan 17, 2024
f8a71c7
Merge branch 'feature/experimental-validation-tests' into feature/nrs…
mgovers Jan 17, 2024
9b71d74
make up to date
mgovers Jan 17, 2024
6a9f97d
Merge branch 'feature/experimental-validation-tests' into feature/nrs…
mgovers Jan 17, 2024
38ea6db
Merge remote-tracking branch 'origin/feature/NRSE-general-structure' …
mgovers Jan 17, 2024
262a7c0
Merge branch 'feature/experimental-validation-tests' into feature/nrs…
mgovers Jan 17, 2024
92ea3d7
capture segfaults from python as os errors
mgovers Jan 17, 2024
eb81354
Merge branch 'feature/nrse-validation-off-main' into feature/nrse-val…
mgovers Jan 17, 2024
1bfda30
handle w_angle
nitbharambe Jan 17, 2024
a0776ec
Merge remote-tracking branch 'origin/feature/experimental-validation-…
mgovers Jan 17, 2024
a585084
Merge branch 'feature/NRSE-general-structure' into feature/nrse-valid…
mgovers Jan 17, 2024
2b706ad
Merge branch 'main' into feature/NRSE-general-structure
mgovers Jan 17, 2024
19dce48
Merge remote-tracking branch 'origin/main' into feature/nrse-validation
mgovers Jan 17, 2024
6b4eede
Merge remote-tracking branch 'origin/feature/NRSE-general-structure' …
mgovers Jan 17, 2024
87268a8
Merge branch 'feature/nrse-validation' of github.com:PowerGridModel/p…
mgovers Jan 17, 2024
e935162
Update measured_values.hpp
nitbharambe Jan 17, 2024
f2cfc36
Merge pull request #473 from PowerGridModel/feature/nrse-validation
mgovers Jan 18, 2024
f43b041
segfaults were fixed. replace by appropriate
mgovers Jan 18, 2024
a995f2c
Update measured_values.hpp
nitbharambe Jan 18, 2024
b5c8c2a
refactor voltage linearization
mgovers Jan 22, 2024
a493538
nrse with angle measurement
mgovers Jan 22, 2024
da4a8e1
first unit tests
petersalemink95 Jan 2, 2024
d0009bb
asym voltage sensor unit test
petersalemink95 Jan 2, 2024
b230b05
node injection
petersalemink95 Jan 2, 2024
f85f66e
change to nr
petersalemink95 Jan 2, 2024
e93480a
add angle test to it linear
petersalemink95 Jan 3, 2024
685d50e
no angle test it linear
petersalemink95 Jan 3, 2024
16cef90
angle checks for asym voltage sensor - iterative linear
petersalemink95 Jan 3, 2024
b41b5ca
angle test for NRSE
petersalemink95 Jan 4, 2024
30e16c8
comment failing angle tests to check sparse matrix error
petersalemink95 Jan 8, 2024
743e852
clean-up code -> no duplicate code for various calculation methods
petersalemink95 Jan 8, 2024
8b3e97a
fix overcompensating angle offset
mgovers Jan 22, 2024
5125054
voltage angle injection fixes
nitbharambe Jan 23, 2024
5cfa4f2
Merge branch 'main' into feature/NRSE-general-structure
mgovers Jan 23, 2024
a1c15fe
fix msvc compilation + fix pytest
mgovers Jan 23, 2024
f2717cb
initialize phi
nitbharambe Jan 23, 2024
ecf5d54
address comments, line wip
nitbharambe Jan 24, 2024
90153de
Apply suggestions from code review
nitbharambe Jan 24, 2024
50193e8
comments formatting
nitbharambe Jan 24, 2024
d17306f
move cabs
nitbharambe Jan 24, 2024
4520586
Merge branch 'main' into feature/NRSE-general-structure
nitbharambe Jan 24, 2024
5b973b1
move calculate result
nitbharambe Jan 24, 2024
f8c2bd1
address comment
nitbharambe Jan 24, 2024
c285a26
Update power_grid_model_c/power_grid_model/include/power_grid_model/m…
nitbharambe Jan 24, 2024
9c72530
xfail sensor update
nitbharambe Jan 24, 2024
232eeaa
add exception hpp
nitbharambe Jan 24, 2024
8d5e631
fix multiplication
nitbharambe Jan 24, 2024
6a2802f
rearrange branch injection
nitbharambe Jan 25, 2024
762a9e5
add phi condition
nitbharambe Jan 25, 2024
761bd6d
rename variable
nitbharambe Jan 25, 2024
44d3f15
Merge branch 'feature/NRSE-general-structure' into fix/nrse-line-meas…
nitbharambe Jan 25, 2024
c018a17
refactor big blocks
nitbharambe Jan 25, 2024
ac02947
solve comments
mgovers Jan 26, 2024
1fbec29
fix adding to both
nitbharambe Jan 26, 2024
03d5101
remove commentted code
nitbharambe Jan 26, 2024
4562c35
change condition
nitbharambe Jan 26, 2024
ac2d703
fix CI
mgovers Jan 26, 2024
3c62f60
rename to workout
nitbharambe Jan 26, 2024
6ad0718
rename del to delta
nitbharambe Jan 26, 2024
2f49229
pre-merge to comments
nitbharambe Jan 26, 2024
38c1b0f
add docstring
nitbharambe Jan 26, 2024
7b5bb6b
Merge branch 'main' into feature/NRSE-general-structure
mgovers Jan 29, 2024
f19996c
Merge branch 'main' into feature/NRSE-general-structure
mgovers Jan 29, 2024
98760e2
angle logic, initialization, antishift
nitbharambe Jan 29, 2024
56a81f8
Merge branch 'feature/NRSE-general-structure' of https://github.com/P…
nitbharambe Jan 29, 2024
abc5b2a
format changes
nitbharambe Jan 29, 2024
0d6e780
merge fixes to angle
nitbharambe Jan 29, 2024
cb21b9f
add newton raphson state estimation unit tests to math solver
mgovers Jan 29, 2024
632412a
add shunt tests
nitbharambe Jan 29, 2024
811bd43
Update newton_raphson_se_solver.hpp
nitbharambe Jan 29, 2024
098c961
Merge branch 'feature/NRSE-general-structure' into fix/nrse-line-meas…
nitbharambe Jan 29, 2024
cbcba36
fix injection variance
nitbharambe Jan 29, 2024
e448712
1os2msr also contains sensor on branch
mgovers Jan 30, 2024
5f0549d
Merge branch 'main' into feature/NRSE-general-structure
mgovers Jan 30, 2024
6aea7f5
Merge branch 'feature/NRSE-general-structure' into fix/nrse-line-meas…
mgovers Jan 30, 2024
de343e4
minor
mgovers Jan 30, 2024
00d4325
format
mgovers Jan 30, 2024
ebab04f
Merge branch 'main' into feature/NRSE-general-structure
mgovers Jan 30, 2024
c6cec66
Merge branch 'feature/NRSE-general-structure' into fix/nrse-line-meas…
mgovers Jan 30, 2024
b54487c
fix branch logic
nitbharambe Jan 30, 2024
5ddaa96
remove rough branch logic
nitbharambe Jan 30, 2024
12cfb32
improve readability
nitbharambe Jan 31, 2024
6d397e1
Merge branch 'fix/nrse-line-measurements' of https://github.com/Power…
nitbharambe Jan 31, 2024
e54b85a
refactor zero voltage angle
nitbharambe Jan 31, 2024
307bf50
fix spell
nitbharambe Jan 31, 2024
fab7277
change injection uj to ui
nitbharambe Jan 31, 2024
a706503
fix zero injection fx addition
nitbharambe Feb 1, 2024
4c471ca
revert line order change
nitbharambe Feb 2, 2024
0027661
correct lagrange multiplier
nitbharambe Feb 4, 2024
061d592
fix tau
nitbharambe Feb 5, 2024
1cac73b
remove unused variable
nitbharambe Feb 5, 2024
5e273ac
fix shunt
nitbharambe Feb 5, 2024
ec04c22
xfail distribution and sensor update
nitbharambe Feb 5, 2024
7b37e15
refactor, fix any zero to all zero
nitbharambe Feb 5, 2024
5247ea4
fix NRSE validation jsons
mgovers Feb 6, 2024
b46998b
fix compiler warning
mgovers Feb 6, 2024
22feb91
Merge branch 'main' into feature/NRSE-general-structure
mgovers Feb 6, 2024
1dcccea
Merge branch 'feature/NRSE-general-structure' into fix/nrse-line-meas…
mgovers Feb 6, 2024
84b3e65
Merge branch 'fix/nrse-line-measurements' of https://github.com/Power…
mgovers Feb 6, 2024
9940af1
minor resolve comments
mgovers Feb 6, 2024
bada724
refactor iteration logic
mgovers Feb 6, 2024
451a420
refactor
mgovers Feb 6, 2024
be53049
replace inline comments by multiline docstrings
mgovers Feb 6, 2024
f7e2cf0
fix bug in measured values
mgovers Feb 6, 2024
cdcd535
fix clang tidy
mgovers Feb 6, 2024
5eddc40
Merge pull request #478 from PowerGridModel/fix/nrse-line-measurements
mgovers Feb 6, 2024
b150f1c
back to any zero for measured values
mgovers Feb 6, 2024
f9d43c2
remove todo
mgovers Feb 6, 2024
34de38e
resolve comments
mgovers Feb 8, 2024
284e6d4
resolve comments
mgovers Feb 8, 2024
a6ac10d
fix code smells
mgovers Feb 8, 2024
05c8b68
fix code smells
mgovers Feb 8, 2024
9d4751c
fix typo
mgovers Feb 8, 2024
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 @@ -112,7 +112,7 @@ using BranchIdx = std::array<Idx, 2>;
using Branch3Idx = std::array<Idx, 3>;

struct MathModelTopology {
Idx slack_bus_{};
Idx slack_bus{};
std::vector<double> phase_shift;
std::vector<BranchIdx> branch_bus_idx;
std::vector<BranchIdx> fill_in;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class Block : public block_trait<T, sym, is_tensor, n_sub_block>::ArrayType {
return (*this)(get_asym_row_idx<r>(), get_asym_col_idx<c>());
}
}

void clear() { *this = Block<T, sym, is_tensor, n_sub_block>{}; }
mgovers marked this conversation as resolved.
Show resolved Hide resolved
};

} // namespace power_grid_model::math_solver
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ template <bool sym> class IterativeLinearSESolver {
sub_timer = Timer(calculation_info, 2225, "Solve sparse linear equation (pre-factorized)");
sparse_solver_.solve_with_prefactorized_matrix(data_gain_, perm_, x_rhs_, x_rhs_);
sub_timer = Timer(calculation_info, 2226, "Iterate unknown");
max_dev = iterate_unknown(output.u, measured_values.has_angle_measurement());
max_dev = iterate_unknown(output.u, measured_values.has_angle());
mgovers marked this conversation as resolved.
Show resolved Hide resolved
};

// calculate math result
Expand Down Expand Up @@ -167,7 +167,7 @@ template <bool sym> class IterativeLinearSESolver {
Idx const col = col_indices[data_idx_lu];
// get a reference and reset block to zero
ILSEGainBlock<sym>& block = data_gain_[data_idx_lu];
block = ILSEGainBlock<sym>{};
block.clear();
// get data idx of y bus,
// skip for a fill-in
Idx const data_idx = y_bus.map_lu_y_bus()[data_idx_lu];
Expand Down Expand Up @@ -259,14 +259,14 @@ template <bool sym> class IterativeLinearSESolver {
std::vector<BranchIdx> const branch_bus_idx = y_bus.math_topology().branch_bus_idx;
// get generated (measured/estimated) voltage phasor
// with current result voltage angle
ComplexValueVector<sym> u = measured_value.voltage(current_u);
ComplexValueVector<sym> u = linearize_voltage(current_u, measured_value);

// loop all bus to fill rhs
for (Idx bus = 0; bus != n_bus_; ++bus) {
Idx const data_idx = y_bus.bus_entry()[bus];
// reset rhs block to fill values
ILSERhs<sym>& rhs_block = x_rhs_[bus];
rhs_block = ILSERhs<sym>{};
rhs_block.clear();
// fill block with voltage measurement
if (measured_value.has_voltage(bus)) {
// eta += u / variance
Expand Down Expand Up @@ -315,18 +315,18 @@ template <bool sym> class IterativeLinearSESolver {
}
}

double iterate_unknown(ComplexValueVector<sym>& u, bool has_angle_measurement) {
double iterate_unknown(ComplexValueVector<sym>& u, bool has_angle) {
double max_dev = 0.0;
// phase shift anti offset of slack bus, phase a
// if no angle measurement is present
DoubleComplex const angle_offset = [&]() -> DoubleComplex {
if (has_angle_measurement) {
if (has_angle) {
return 1.0;
}
if constexpr (sym) {
return cabs(x_rhs_[math_topo_->slack_bus_].u()) / x_rhs_[math_topo_->slack_bus_].u();
return cabs(x_rhs_[math_topo_->slack_bus].u()) / x_rhs_[math_topo_->slack_bus].u();
} else {
return cabs(x_rhs_[math_topo_->slack_bus_].u()(0)) / x_rhs_[math_topo_->slack_bus_].u()(0);
return cabs(x_rhs_[math_topo_->slack_bus].u()(0)) / x_rhs_[math_topo_->slack_bus].u()(0);
}
nitbharambe marked this conversation as resolved.
Show resolved Hide resolved
}();

Expand All @@ -350,6 +350,32 @@ template <bool sym> class IterativeLinearSESolver {
std::tie(output.load_gen, output.source) =
measured_value.calculate_load_gen_source(output.u, output.bus_injection);
}

// getter of voltage value for all buses
nitbharambe marked this conversation as resolved.
Show resolved Hide resolved
// for no measurement, the voltage phasor is used from the current iteration
// for magnitude only measurement, angle is added from the current iteration
// for magnitude and angle measurement, the measured phasor is returned
nitbharambe marked this conversation as resolved.
Show resolved Hide resolved
ComplexValueVector<sym> linearize_voltage(ComplexValueVector<sym> const& current_u,
MeasuredValues<sym> const& measured_values) const {
ComplexValueVector<sym> u(current_u.size());

for (Idx bus = 0; bus != static_cast<Idx>(current_u.size()); ++bus) {
// no measurement
if (!measured_values.has_voltage(bus)) {
nitbharambe marked this conversation as resolved.
Show resolved Hide resolved
u[bus] = current_u[bus];
}
// no angle measurement
else if (!measured_values.has_angle_measurement(bus)) {
nitbharambe marked this conversation as resolved.
Show resolved Hide resolved
u[bus] = real(measured_values.voltage(bus)) * current_u[bus] /
cabs(current_u[bus]); // U / |U| to get angle shift
}
// full measurement
else {
nitbharambe marked this conversation as resolved.
Show resolved Hide resolved
u[bus] = measured_values.voltage(bus);
}
}
return u;
}
};

template class IterativeLinearSESolver<true>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ template <bool sym> class MathSolver {

switch (calculation_method) {
case default_method:
[[fallthrough]]; // use Newton-Raphson by default
[[fallthrough]]; // use iterative linear by default
TonyXiang8787 marked this conversation as resolved.
Show resolved Hide resolved
case iterative_linear:
return run_state_estimation_iterative_linear(input, err_tol, max_iter, calculation_info, y_bus);
case newton_raphson:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,47 +57,24 @@ template <bool sym> class MeasuredValues {
normalize_variance();
}

// checker of measured data, return true if measurement is available
bool has_voltage(Idx bus) const { return idx_voltage_[bus] >= 0; }
bool has_bus_injection(Idx bus) const { return bus_injection_[bus].idx_bus_injection >= 0; }
bool has_branch_from(Idx branch) const { return idx_branch_from_power_[branch] >= 0; }
bool has_branch_to(Idx branch) const { return idx_branch_to_power_[branch] >= 0; }
bool has_shunt(Idx shunt) const { return idx_shunt_power_[shunt] >= 0; }
bool has_load_gen(Idx load_gen) const { return idx_load_gen_power_[load_gen] >= 0; }
bool has_source(Idx source) const { return idx_source_power_[source] >= 0; }
bool has_angle() const { return n_angle_ > 0; }
constexpr bool has_angle() const { return n_voltage_angle_measurements_ > 0; }
constexpr bool has_voltage_measurements() const { return n_voltage_measurements_ > 0; }

constexpr bool has_voltage(Idx bus) const { return idx_voltage_[bus] >= 0; }
constexpr bool has_angle_measurement(Idx bus) const { return !is_nan(imag(voltage(bus))); }
constexpr bool has_bus_injection(Idx bus) const { return bus_injection_[bus].idx_bus_injection >= 0; }
constexpr bool has_branch_from(Idx branch) const { return idx_branch_from_power_[branch] >= 0; }
constexpr bool has_branch_to(Idx branch) const { return idx_branch_to_power_[branch] >= 0; }
constexpr bool has_shunt(Idx shunt) const { return idx_shunt_power_[shunt] >= 0; }
constexpr bool has_load_gen(Idx load_gen) const { return idx_load_gen_power_[load_gen] >= 0; }
constexpr bool has_source(Idx source) const { return idx_source_power_[source] >= 0; }

// getter of measurement and variance
// if the obj is not measured, it is undefined behaviour to call this function
// use checker first

// getter of voltage variance
double voltage_var(Idx bus) const { return voltage_main_value_[idx_voltage_[bus]].variance; }
// getter of voltage value for all buses
// for no measurement, the voltage phasor is used from the current iteration
// for magnitude only measurement, angle is added from the current iteration
// for magnitude and angle measurement, the measured phasor is returned
ComplexValueVector<sym> voltage(ComplexValueVector<sym> const& current_u) const {
ComplexValueVector<sym> u(current_u.size());
for (Idx bus = 0; bus != static_cast<Idx>(current_u.size()); ++bus) {
// no measurement
if (idx_voltage_[bus] == unmeasured) {
u[bus] = current_u[bus];
}
// no angle measurement
else if (is_nan(imag(voltage_main_value_[idx_voltage_[bus]].value))) {
u[bus] = real(voltage_main_value_[idx_voltage_[bus]].value) * current_u[bus] /
cabs(current_u[bus]); // U / |U| to get angle shift
}
// full measurement
else {
u[bus] = voltage_main_value_[idx_voltage_[bus]].value;
}
}
return u;
}

// power measurement
constexpr double voltage_var(Idx bus) const { return voltage_main_value_[idx_voltage_[bus]].variance; }
constexpr auto const& voltage(Idx bus) const { return voltage_main_value_[idx_voltage_[bus]].value; }
constexpr auto const& bus_injection(Idx bus) const {
return power_main_value_[bus_injection_[bus].idx_bus_injection];
}
Expand All @@ -109,9 +86,13 @@ template <bool sym> class MeasuredValues {
constexpr auto const& load_gen_power(Idx load_gen) const { return extra_value_[idx_load_gen_power_[load_gen]]; }
constexpr auto const& source_power(Idx source) const { return extra_value_[idx_source_power_[source]]; }

constexpr auto first_voltage_measurement() const {
assert(has_voltage_measurements());
return first_voltage_measurement_;
}

// getter mean angle shift
RealValue<sym> mean_angle_shift() const { return mean_angle_shift_; }
constexpr bool has_angle_measurement() const { return n_angle_ > 0; }

// calculate load_gen and source flow
// with given bus voltage and bus current injection
Expand Down Expand Up @@ -177,11 +158,14 @@ template <bool sym> class MeasuredValues {
// relevant for extra value
IdxVector idx_load_gen_power_;
IdxVector idx_source_power_;
// number of angle measurement
Idx n_angle_{};

Idx n_voltage_measurements_{};
Idx n_voltage_angle_measurements_{}; // number of angle measurement
nitbharambe marked this conversation as resolved.
Show resolved Hide resolved
mgovers marked this conversation as resolved.
Show resolved Hide resolved

// average angle shift of voltages with angle measurement
// default is zero is no voltage has angle measurement
RealValue<sym> mean_angle_shift_;
Idx first_voltage_measurement_{};
nitbharambe marked this conversation as resolved.
Show resolved Hide resolved

constexpr MathModelTopology const& math_topology() const { return *math_topology_; }

Expand Down Expand Up @@ -227,9 +211,14 @@ template <bool sym> class MeasuredValues {
}

// assign a meaningful mean angle shift, if at least one voltage has angle measurement
if (n_angle_ > 0) {
mean_angle_shift_ = angle_cum / n_angle_;
if (has_angle()) {
mean_angle_shift_ = angle_cum / n_voltage_angle_measurements_;
}

auto const is_measured = [](auto const& value) { return value >= 0; };
nitbharambe marked this conversation as resolved.
Show resolved Hide resolved
n_voltage_measurements_ = std::ranges::count_if(idx_voltage_, is_measured);
first_voltage_measurement_ =
std::distance(idx_voltage_.begin(), std::ranges::find_if(idx_voltage_, is_measured));
}

RealValue<sym> process_bus_voltage_measurements(Idx bus, IdxRange const& sensors,
Expand All @@ -256,7 +245,7 @@ template <bool sym> class MeasuredValues {
idx_voltage_[bus] = static_cast<Idx>(voltage_main_value_.size());
voltage_main_value_.push_back(aggregated);
if (angle_measured) {
++n_angle_;
++n_voltage_angle_measurements_;
// accumulate angle, offset by intrinsic phase shift
angle_cum = arg(aggregated.value * std::exp(-1.0i * math_topology().phase_shift[bus]));
}
Expand Down Expand Up @@ -401,11 +390,7 @@ template <bool sym> class MeasuredValues {
accumulated_inverse_variance += inv_variance;
if constexpr (only_magnitude) {
ComplexValue<sym> abs_value = piecewise_complex_value<sym>(DoubleComplex{0.0, nan});
if (is_nan(imag(measurement.value))) {
abs_value += real(measurement.value); // only keep real part
} else {
abs_value += cabs(measurement.value); // get abs of the value
}
abs_value += cabs_or_real<sym>(measurement.value);
accumulated_value += abs_value * inv_variance;
} else {
// accumulate value
Expand Down Expand Up @@ -520,10 +505,11 @@ template <bool sym> class MeasuredValues {
}

// scale
std::ranges::for_each(voltage_main_value_, [min_var](auto& x) { x.variance /= min_var; });
std::ranges::for_each(power_main_value_, [min_var](auto& x) {
x.p_variance /= min_var;
x.q_variance /= min_var;
auto inv_norm_var = 1.0 / min_var;
mgovers marked this conversation as resolved.
Show resolved Hide resolved
std::ranges::for_each(voltage_main_value_, [inv_norm_var](auto& x) { x.variance *= inv_norm_var; });
std::ranges::for_each(power_main_value_, [inv_norm_var](auto& x) {
x.p_variance *= inv_norm_var;
x.q_variance *= inv_norm_var;
});
}

Expand Down