Bug fix. Reformat code.

This commit is contained in:
CismonX 2018-12-13 22:33:28 +08:00
parent b64418b584
commit 66c5b8184e
2 changed files with 19 additions and 10 deletions

View File

@ -165,11 +165,13 @@ namespace flow
verbose_ = verbose;
epsilon_ = epsilon;
ignore_load_ = ignore_load;
if (short_circuit_node < 1 || short_circuit_node > num_nodes_) {
writer::error("Bad node ID for short circuit calculation.");
if (short_circuit_) {
if (short_circuit_node < 1 || short_circuit_node > num_nodes_) {
writer::error("Bad node ID for short circuit calculation.");
}
short_circuit_node_ = node_offset(short_circuit_node - 1);
z_f_ = z_f;
}
short_circuit_node_ = node_offset(short_circuit_node - 1);
z_f_ = z_f;
}
std::pair<arma::mat, arma::mat> calc::node_admittance()
@ -249,7 +251,7 @@ namespace flow
auto i_p = 0;
auto i_q = 0;
auto i_v = 0;
e_.resize(num_nodes_);
e_.set_size(num_nodes_);
for (auto&& node : nodes_) {
if (node.type == node_data::pq) {
init_p_[i_p] = -node.p;
@ -342,11 +344,15 @@ namespace flow
const auto x_vec = spsolve(j_, f_x_, "superlu");
vec_elem_foreach(f_, [&x_vec](auto& elem, auto row)
{
elem += x_vec.at(2 * row, 0);
if (2 * row < x_vec.n_elem) {
elem += x_vec.at(2 * row, 0);
}
});
vec_elem_foreach(e_, [&x_vec](auto& elem, auto row)
{
elem += x_vec.at(2 * row + 1, 0);
if (2 * row + 1 < x_vec.n_elem) {
elem += x_vec.at(2 * row + 1, 0);
}
});
if (verbose_) {
writer::println("Correction vector of voltage (real):");

View File

@ -213,9 +213,11 @@ namespace flow
template <typename M, typename F>
static void mat_elem_foreach(M& mat, F func)
{
for (auto row = 0U; row < mat.n_rows; ++row)
for (auto col = 0U; col < mat.n_cols; ++col)
for (auto row = 0U; row < mat.n_rows; ++row) {
for (auto col = 0U; col < mat.n_cols; ++col) {
func(mat.at(row, col), row, col);
}
}
}
/**
@ -227,8 +229,9 @@ namespace flow
template <typename V, typename F>
static void vec_elem_foreach(V& vec, F func)
{
for (auto i = 0U; i < vec.n_elem; ++i)
for (auto i = 0U; i < vec.n_elem; ++i) {
func(vec[i], i);
}
}
/**