17 #include <system_error>
20 #elif defined(__GNUC__)
21 #pragma GCC diagnostic push
23 #pragma GCC diagnostic ignored \
24 "-Wint-in-bool-context"
28 #include <Eigen/Dense>
29 #include <Eigen/Sparse>
32 #elif defined(__GNUC__)
33 #pragma GCC diagnostic pop
41 #define M_PI 3.14159265358979323846
46 #define SHIFT_TO_PHASE_B Complex(cos(-2 * M_PI / 3), sin(-2 * M_PI / 3))
47 #define SHIFT_TO_PHASE_C Complex(cos(2 * M_PI / 3), sin(2 * M_PI / 3))
48 #define RMS_TO_PEAK sqrt(2.)
49 #define PEAK_TO_RMS sqrt(1 / 2.)
50 #define RMS3PH_TO_PEAK1PH sqrt(2. / 3.)
51 #define PEAK1PH_TO_RMS3PH sqrt(3. / 2.)
53 #define P_SNUB_TRANSFORMER 1e-3
54 #define Q_SNUB_TRANSFORMER 5e-4
59 typedef unsigned int UInt;
62 typedef std::complex<Real> Complex;
64 typedef std::string String;
67 typedef Eigen::Matrix<Complex, Eigen::Dynamic, 1> VectorComp;
69 typedef Eigen::Matrix<Real, Eigen::Dynamic, 1> Vector;
71 typedef Eigen::SparseMatrix<Real, Eigen::ColMajor> SparseMatrix;
73 typedef Eigen::SparseMatrix<Real, Eigen::RowMajor> SparseMatrixRow;
75 typedef Eigen::SparseMatrix<Complex, Eigen::ColMajor> SparseMatrixComp;
77 typedef Eigen::SparseMatrix<Complex, Eigen::RowMajor> SparseMatrixCompRow;
79 typedef Eigen::Matrix<Real, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor>
82 typedef Eigen::Matrix<Complex, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor>
85 typedef Eigen::Matrix<Int, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor>
88 typedef Eigen::Matrix<Real, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>
91 typedef Eigen::PartialPivLU<Matrix> LUFactorized;
93 typedef Eigen::SparseLU<SparseMatrix> LUFactorizedSparse;
95 typedef Eigen::Matrix<Real, Eigen::Dynamic, 1> Vector;
97 template <
typename VarType>
99 Eigen::Matrix<VarType, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor>;
101 template <
int rows,
int cols>
102 using MatrixFixedSize = Eigen::Matrix<Real, rows, cols, Eigen::ColMajor>;
104 template <
int rows,
int cols>
105 using MatrixFixedSizeComp = Eigen::Matrix<Complex, rows, cols, Eigen::ColMajor>;
109 static const Complex jComp(0.0, 1.0);
113 enum class NumericalMethod { Euler, Trapezoidal };
114 enum class PhaseType { A, B, C, ABC, Single };
115 enum class Domain { SP, DP, EMT };
116 enum class PowerflowBusType { PV, PQ, VD, None };
117 enum class GeneratorType {
134 enum class SGOrder { SG3Order, SG4Order, SG5Order, SG6aOrder, SG6bOrder };
145 std::error_code mErrorCode;
150 : mErrorCode(e, std::system_category()), mDescription(desc){};
153 : mErrorCode(errno, std::system_category()), mDescription(desc){};
155 SystemError() : mErrorCode(errno, std::system_category()){};
157 String descr()
const {
158 std::ostringstream os;
160 os <<
"System Error: " << mDescription <<
": " << mErrorCode.message()
161 <<
"(" << mErrorCode.value() <<
")";