Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .clangd
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ Diagnostics:
UnusedIncludes: Strict
MissingIncludes: Strict
Includes:
IgnoreHeader: Eigen/Dense
IgnoreHeader:
- Eigen/.*
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,14 @@ class ColumnarAttributeRange : public std::ranges::view_interface<ColumnarAttrib
auto const& meta_attribute = *attribute_buffer.meta_attribute;
ctype_func_selector(
meta_attribute.ctype, [&value, &attribute_buffer, &meta_attribute, this]<typename AttributeType> {
AttributeType* buffer_ptr = reinterpret_cast<AttributeType*>(attribute_buffer.data) + idx_;
auto const& attribute_ref = meta_attribute.template get_attribute<AttributeType const>(
reinterpret_cast<RawDataConstPtr>(&value));
*buffer_ptr = attribute_ref;
if constexpr (sizeof(AttributeType) <= sizeof(value_type)) {
AttributeType* buffer_ptr = reinterpret_cast<AttributeType*>(attribute_buffer.data) + idx_;
auto const& attribute_ref = meta_attribute.template get_attribute<AttributeType const>(
reinterpret_cast<RawDataConstPtr>(&value));
*buffer_ptr = attribute_ref;
} else {
assert(false && "ColumnarAttributeRange::operator= AttributeType not equal to value_type!");
}
});
}
return *this;
Expand All @@ -104,14 +108,18 @@ class ColumnarAttributeRange : public std::ranges::view_interface<ColumnarAttrib
for (auto const& attribute_buffer : attribute_buffers_) {
assert(attribute_buffer.meta_attribute != nullptr);
auto const& meta_attribute = *attribute_buffer.meta_attribute;
ctype_func_selector(
meta_attribute.ctype, [&result, &attribute_buffer, &meta_attribute, this]<typename AttributeType> {
ctype_func_selector(meta_attribute.ctype, [&result, &attribute_buffer, &meta_attribute,
idx = idx_]<typename AttributeType> {
if constexpr (sizeof(AttributeType) <= sizeof(value_type)) {
AttributeType const* buffer_ptr =
reinterpret_cast<AttributeType const*>(attribute_buffer.data) + idx_;
reinterpret_cast<AttributeType const*>(attribute_buffer.data) + idx;
auto& attribute_ref =
meta_attribute.template get_attribute<AttributeType>(reinterpret_cast<RawDataPtr>(&result));
attribute_ref = *buffer_ptr;
});
} else {
assert(false && "ColumnarAttributeRange::get AttributeType not equal to value_type!");
}
});
Comment thread
TonyXiang8787 marked this conversation as resolved.
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ template <class T> using EigenDiagonalTensor3 = Eigen::DiagonalMatrix<T, 3>;

template <scalar_value T> class Vector : public EigenVector3<T> {
public:
Vector() { (*this) = EigenVector3<T>::Zero(); };
Vector() { this->setConstant(T{}); };
Comment thread
TonyXiang8787 marked this conversation as resolved.
// eigen expression
template <typename OtherDerived> Vector(Eigen::ArrayBase<OtherDerived> const& other) : EigenVector3<T>{other} {}
template <typename OtherDerived> Vector& operator=(Eigen::ArrayBase<OtherDerived> const& other) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,9 @@ template <symmetry_tag sym> class YBus {
std::shared_ptr<MathModelParam<sym> const> const& param,
std::shared_ptr<YBusStructure const> const& y_bus_struct = {})
: math_topology_{topo_ptr} {
assert(math_topology_ != nullptr);
assert(param != nullptr);
Comment thread
TonyXiang8787 marked this conversation as resolved.

// use existing struct or make new struct
if (y_bus_struct) {
y_bus_struct_ = y_bus_struct;
Expand Down Expand Up @@ -455,36 +458,40 @@ template <symmetry_tag sym> class YBus {
template <typename T>
requires std::same_as<T, BranchSolverOutput<sym>> || std::same_as<T, BranchShortCircuitSolverOutput<sym>>
std::vector<T> calculate_branch_flow(ComplexValueVector<sym> const& u) const {
std::vector<T> branch_flow(math_topology_->branch_bus_idx.size());
std::transform(math_topology_->branch_bus_idx.cbegin(), math_topology_->branch_bus_idx.cend(),
math_model_param_->branch_param.cbegin(), branch_flow.begin(),
[&u](BranchIdx branch_idx, BranchCalcParam<sym> const& param) {
auto const [f, t] = branch_idx;
// if one side is disconnected, use zero voltage at that side
ComplexValue<sym> const uf = f != -1 ? u[f] : ComplexValue<sym>{0.0};
ComplexValue<sym> const ut = t != -1 ? u[t] : ComplexValue<sym>{0.0};
T output;

// See "Branch Flow Calculation" in "State Estimation Alliander"
output.i_f = dot(param.yff(), uf) + dot(param.yft(), ut);
output.i_t = dot(param.ytf(), uf) + dot(param.ytt(), ut);

if constexpr (std::same_as<T, BranchSolverOutput<sym>>) {
// See "Shunt Injection Flow Calculation" in "State Estimation Alliander"
output.s_f = uf * conj(output.i_f);
output.s_t = ut * conj(output.i_t);
}

return output;
});
return branch_flow;
assert(math_topology_ != nullptr);

return std::views::zip(math_topology_->branch_bus_idx, math_model_param_->branch_param) |
std::views::transform([&u](auto const& branch_idx_params) -> T {
auto const& [branch_idx, param] = branch_idx_params;

auto const [f, t] = branch_idx;
// if one side is disconnected, use zero voltage at that side
ComplexValue<sym> const uf = f != -1 ? u[f] : ComplexValue<sym>{0.0};
ComplexValue<sym> const ut = t != -1 ? u[t] : ComplexValue<sym>{0.0};
T output;

// See "Branch Flow Calculation" in "State Estimation Alliander"
output.i_f = dot(param.yff(), uf) + dot(param.yft(), ut);
output.i_t = dot(param.ytf(), uf) + dot(param.ytt(), ut);

if constexpr (std::same_as<T, BranchSolverOutput<sym>>) {
// See "Shunt Injection Flow Calculation" in "State Estimation Alliander"
output.s_f = uf * conj(output.i_f);
output.s_t = ut * conj(output.i_t);
}

return output;
}) |
std::ranges::to<std::vector<T>>();
Comment thread
TonyXiang8787 marked this conversation as resolved.
}

// calculate shunt flow based on voltage, injection direction
template <typename SolverOutputType>
requires std::same_as<SolverOutputType, ApplianceSolverOutput<sym>> ||
std::same_as<SolverOutputType, ApplianceShortCircuitSolverOutput<sym>>
std::vector<SolverOutputType> calculate_shunt_flow(ComplexValueVector<sym> const& u) const {
assert(math_topology_ != nullptr);

std::vector<SolverOutputType> shunt_flow(math_topology_->n_shunt());
for (auto const [bus, shunts] : enumerated_zip_sequence(math_topology_->shunts_per_bus)) {
for (Idx const shunt : shunts) {
Expand Down
Loading