Update examples, fix bug, use `mat` instead of `dmat`.
This commit is contained in:
parent
efd2d79af7
commit
b922b3da13
|
@ -1,4 +1,4 @@
|
|||
n1,n2,R,X,B,k
|
||||
n1,n2,R,X,B/2,k
|
||||
1,4,0,0.0576,0,1
|
||||
2,7,0,0.0625,0,1
|
||||
3,9,0,0.0586,0,1
|
||||
|
|
|
|
@ -1,38 +1,38 @@
|
|||
n1,n2,R,X,B,k
|
||||
1,2,0.0035,0.0411,0.6987,0
|
||||
1,39,0.0010,0.0250,0.7500,0
|
||||
2,3,0.0013,0.0151,0.2572,0
|
||||
2,25,0.0070,0.0086,0.1460,0
|
||||
3,4,0.0013,0.0213,0.2214,0
|
||||
3,18,0.0011,0.0133,0.2138,0
|
||||
4,5,0.0008,0.0128,0.1342,0
|
||||
4,14,0.0008,0.0129,0.1382,0
|
||||
5,6,0.0002,0.0026,0.0434,0
|
||||
5,8,0.0008,0.0112,0.1476,0
|
||||
6,7,0.0006,0.0092,0.1130,0
|
||||
6,11,0.0007,0.0082,0.1389,0
|
||||
7,8,0.0004,0.0046,0.0780,0
|
||||
8,9,0.0023,0.0363,0.3804,0
|
||||
9,39,0.0010,0.0250,1.2000,0
|
||||
10,11,0.0004,0.0043,0.0729,0
|
||||
10,13,0.0004,0.0043,0.0729,0
|
||||
13,14,0.0009,0.0101,0.1723,0
|
||||
14,15,0.0018,0.0217,0.3660,0
|
||||
15,16,0.0009,0.0094,0.1710,0
|
||||
16,17,0.0007,0.0089,0.1342,0
|
||||
16,19,0.0016,0.0195,0.3040,0
|
||||
16,21,0.0008,0.0135,0.2548,0
|
||||
16,24,0.0003,0.0059,0.0680,0
|
||||
17,18,0.0007,0.0082,0.1319,0
|
||||
17,27,0.0013,0.0713,0.3216,0
|
||||
21,22,0.0008,0.0140,0.2565,0
|
||||
22,23,0.0006,0.0096,0.1846,0
|
||||
23,24,0.0022,0.0350,0.3610,0
|
||||
25,26,0.0032,0.0323,0.5130,0
|
||||
26,27,0.0014,0.0147,0.2396,0
|
||||
26,28,0.0043,0.0474,0.7802,0
|
||||
26,29,0.0057,0.0625,1.0290,0
|
||||
28,29,0.0014,0.0151,0.2490,0
|
||||
n1,n2,R,X,B/2,k
|
||||
1,2,0.0035,0.0411,0.3494,0
|
||||
1,39,0.0010,0.0250,0.3750,0
|
||||
2,3,0.0013,0.0151,0.1286,0
|
||||
2,25,0.0070,0.0086,0.0730,0
|
||||
3,4,0.0013,0.0213,0.1107,0
|
||||
3,18,0.0011,0.0133,0.1069,0
|
||||
4,5,0.0008,0.0128,0.0671,0
|
||||
4,14,0.0008,0.0129,0.0691,0
|
||||
5,6,0.0002,0.0026,0.0217,0
|
||||
5,8,0.0008,0.0112,0.0738,0
|
||||
6,7,0.0006,0.0092,0.0565,0
|
||||
6,11,0.0007,0.0082,0.0695,0
|
||||
7,8,0.0004,0.0046,0.0390,0
|
||||
8,9,0.0023,0.0363,0.1902,0
|
||||
9,39,0.0010,0.0250,0.6000,0
|
||||
10,11,0.0004,0.0043,0.0365,0
|
||||
10,13,0.0004,0.0043,0.0365,0
|
||||
13,14,0.0009,0.0101,0.0862,0
|
||||
14,15,0.0018,0.0217,0.1830,0
|
||||
15,16,0.0009,0.0094,0.0855,0
|
||||
16,17,0.0007,0.0089,0.0671,0
|
||||
16,19,0.0016,0.0195,0.1520,0
|
||||
16,21,0.0008,0.0135,0.1274,0
|
||||
16,24,0.0003,0.0059,0.0340,0
|
||||
17,18,0.0007,0.0082,0.0660,0
|
||||
17,27,0.0013,0.0713,0.1608,0
|
||||
21,22,0.0008,0.0140,0.1283,0
|
||||
22,23,0.0006,0.0096,0.0923,0
|
||||
23,24,0.0022,0.0350,0.1805,0
|
||||
25,26,0.0032,0.0323,0.2565,0
|
||||
26,27,0.0014,0.0147,0.1198,0
|
||||
26,28,0.0043,0.0474,0.3901,0
|
||||
26,29,0.0057,0.0625,0.5145,0
|
||||
28,29,0.0014,0.0151,0.1245,0
|
||||
12,11,0.0016,0.0435,0,1.006
|
||||
12,13,0.0016,0.0435,0,1.006
|
||||
6,31,0,0.0250,0,1.070
|
||||
|
|
|
20
src/calc.cpp
20
src/calc.cpp
|
@ -92,7 +92,7 @@ namespace flow
|
|||
});
|
||||
}
|
||||
|
||||
void calc::init(const arma::dmat& nodes, const arma::dmat& edges,
|
||||
void calc::init(const arma::mat& nodes, const arma::mat& edges,
|
||||
bool verbose, double epsilon)
|
||||
{
|
||||
if (nodes.n_cols != 5 || edges.n_cols != 6)
|
||||
|
@ -136,7 +136,7 @@ namespace flow
|
|||
epsilon_ = epsilon;
|
||||
}
|
||||
|
||||
std::pair<arma::dmat, arma::dmat> calc::node_admittance()
|
||||
std::pair<arma::mat, arma::mat> calc::node_admittance()
|
||||
{
|
||||
arma::cx_mat node_adm_cplx(num_nodes_, num_nodes_, arma::fill::zeros);
|
||||
arma::cx_mat adm_orig(num_nodes_, num_nodes_, arma::fill::zeros);
|
||||
|
@ -216,7 +216,7 @@ namespace flow
|
|||
f_x_[2 * row + 1] = row < num_pq_ ? delta_q_[row] : delta_v_[row - num_pq_];
|
||||
}
|
||||
// Cross-construct jacobian matrix.
|
||||
arma::dmat jacobian(2 * num_nodes_ - 2, 2 * num_nodes_ - 2);
|
||||
arma::mat jacobian(2 * num_nodes_ - 2, 2 * num_nodes_ - 2);
|
||||
for (auto row = 0U; row < num_nodes_ - 1; ++row)
|
||||
for (auto col = 0U; col < num_nodes_ - 1; ++col) {
|
||||
jacobian.at(2 * row, 2 * col) = j_h_.at(row, col);
|
||||
|
@ -270,14 +270,14 @@ namespace flow
|
|||
writer::println("Number of iterations: ", n_iter_, " (begin)");
|
||||
jacobian();
|
||||
prepare_solve();
|
||||
const auto x_vec = spsolve(j_, f_x_, "superlu").col(0);
|
||||
const auto x_vec = spsolve(j_, f_x_, "superlu");
|
||||
vec_elem_foreach(f_, [&x_vec](auto& elem, auto row)
|
||||
{
|
||||
elem += x_vec[2 * row];
|
||||
elem += x_vec.at(2 * row, 0);
|
||||
});
|
||||
vec_elem_foreach(e_, [&x_vec](auto& elem, auto row)
|
||||
{
|
||||
elem += x_vec[2 * row + 1];
|
||||
elem += x_vec.at(2 * row + 1, 0);
|
||||
});
|
||||
if (verbose_) {
|
||||
writer::println("Correction vector of voltage (real):");
|
||||
|
@ -293,7 +293,7 @@ namespace flow
|
|||
|
||||
double calc::get_max() const
|
||||
{
|
||||
arma::dmat mat = join_cols(join_cols(delta_p_, delta_q_), delta_v_);
|
||||
arma::mat mat = join_cols(join_cols(delta_p_, delta_q_), delta_v_);
|
||||
auto max = 0.0;
|
||||
for (auto&& elem : mat)
|
||||
if (std::abs(elem) > max)
|
||||
|
@ -301,7 +301,7 @@ namespace flow
|
|||
return max;
|
||||
}
|
||||
|
||||
arma::dmat calc::result()
|
||||
arma::mat calc::result()
|
||||
{
|
||||
p_[num_nodes_ - 1] = calc_p(num_nodes_ - 1);
|
||||
for (auto&& elem : p_)
|
||||
|
@ -335,8 +335,8 @@ namespace flow
|
|||
{
|
||||
elem = nodes_[row].id;
|
||||
});
|
||||
arma::dmat retval = join_rows(node_id, join_rows(join_rows(v, theta), join_rows(p_, q_)));
|
||||
arma::dmat sorted_retval(num_nodes_, 4);
|
||||
arma::mat retval = join_rows(node_id, join_rows(join_rows(v, theta), join_rows(p_, q_)));
|
||||
arma::mat sorted_retval(num_nodes_, 4);
|
||||
retval.each_row([&sorted_retval](const arma::rowvec& row)
|
||||
{
|
||||
sorted_retval.row(row[0]) = row.subvec(1, row.n_elem - 1);
|
||||
|
|
12
src/calc.hpp
12
src/calc.hpp
|
@ -94,7 +94,7 @@ namespace flow
|
|||
arma::uchar_mat adj_;
|
||||
|
||||
/// Node admittance matrix.
|
||||
arma::dmat n_adm_g_, n_adm_b_;
|
||||
arma::mat n_adm_g_, n_adm_b_;
|
||||
|
||||
/// Given values of power and voltage.
|
||||
arma::colvec init_p_, init_q_, init_v_;
|
||||
|
@ -106,13 +106,13 @@ namespace flow
|
|||
arma::colvec delta_p_, delta_q_, delta_v_;
|
||||
|
||||
/// Submatrix of Jacobian matrix.
|
||||
arma::dmat j_h_, j_n_, j_m_, j_l_, j_r_, j_s_;
|
||||
arma::mat j_h_, j_n_, j_m_, j_l_, j_r_, j_s_;
|
||||
|
||||
/// F(x) of jacobian matrix.
|
||||
arma::colvec f_x_;
|
||||
|
||||
/// Jacobian matrix (sparse).
|
||||
arma::sp_dmat j_;
|
||||
arma::sp_mat j_;
|
||||
|
||||
/// Power vector of nodes.
|
||||
arma::colvec p_, q_;
|
||||
|
@ -227,13 +227,13 @@ namespace flow
|
|||
/**
|
||||
* Initialize.
|
||||
*/
|
||||
void init(const arma::dmat& nodes, const arma::dmat& edges,
|
||||
void init(const arma::mat& nodes, const arma::mat& edges,
|
||||
bool verbose, double epsilon);
|
||||
|
||||
/**
|
||||
* Calculate node admittance.
|
||||
*/
|
||||
std::pair<arma::dmat, arma::dmat> node_admittance();
|
||||
std::pair<arma::mat, arma::mat> node_admittance();
|
||||
|
||||
/**
|
||||
* Initialize iteration.
|
||||
|
@ -256,6 +256,6 @@ namespace flow
|
|||
* Get result of calculation.
|
||||
*
|
||||
*/
|
||||
arma::dmat result();
|
||||
arma::mat result();
|
||||
};
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ namespace flow
|
|||
}
|
||||
}
|
||||
|
||||
const arma::dmat& reader::get_mat() const
|
||||
const arma::mat& reader::get_mat() const
|
||||
{
|
||||
return mat_;
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace flow
|
|||
class reader
|
||||
{
|
||||
/// The loaded matrix.
|
||||
arma::dmat mat_;
|
||||
arma::mat mat_;
|
||||
|
||||
/**
|
||||
* Read matrix from an istream.
|
||||
|
@ -41,6 +41,6 @@ namespace flow
|
|||
/**
|
||||
* Get loaded matrix.
|
||||
*/
|
||||
const arma::dmat& get_mat() const;
|
||||
const arma::mat& get_mat() const;
|
||||
};
|
||||
}
|
|
@ -40,7 +40,7 @@ namespace flow
|
|||
return str.substr(0, pos + 1);
|
||||
}
|
||||
|
||||
void writer::print_mat(const arma::dmat& mat)
|
||||
void writer::print_mat(const arma::mat& mat)
|
||||
{
|
||||
mat.each_row([](const arma::rowvec& row)
|
||||
{
|
||||
|
@ -58,7 +58,7 @@ namespace flow
|
|||
});
|
||||
}
|
||||
|
||||
bool writer::to_csv_file(const std::string& path, const arma::dmat& mat, const std::string& header)
|
||||
bool writer::to_csv_file(const std::string& path, const arma::mat& mat, const std::string& header)
|
||||
{
|
||||
std::ofstream ofstream;
|
||||
ofstream.exceptions(std::ifstream::failbit);
|
||||
|
|
|
@ -81,7 +81,7 @@ namespace flow
|
|||
*
|
||||
* @param mat Matrix to be printed.
|
||||
*/
|
||||
static void print_mat(const arma::dmat& mat);
|
||||
static void print_mat(const arma::mat& mat);
|
||||
|
||||
/**
|
||||
* Write a matrix to a file in CSV format.
|
||||
|
@ -90,6 +90,6 @@ namespace flow
|
|||
* @param mat Matrix to be printed.
|
||||
* @param header Header of CSV file
|
||||
*/
|
||||
bool to_csv_file(const std::string& path, const arma::dmat& mat, const std::string& header = "");
|
||||
bool to_csv_file(const std::string& path, const arma::mat& mat, const std::string& header = "");
|
||||
};
|
||||
}
|
Reference in New Issue