17#include <system_error>
20#elif defined(__GNUC__)
21#pragma GCC diagnostic push
23#pragma GCC diagnostic ignored \
24 "-Wint-in-bool-context"
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
59typedef unsigned int UInt;
62typedef std::complex<Real> Complex;
64typedef std::string String;
67typedef Eigen::Matrix<Complex, Eigen::Dynamic, 1> VectorComp;
69typedef Eigen::Matrix<Real, Eigen::Dynamic, 1> Vector;
71typedef Eigen::SparseMatrix<Real, Eigen::ColMajor> SparseMatrix;
73typedef Eigen::SparseMatrix<Real, Eigen::RowMajor> SparseMatrixRow;
75typedef Eigen::SparseMatrix<Complex, Eigen::ColMajor> SparseMatrixComp;
77typedef Eigen::SparseMatrix<Complex, Eigen::RowMajor> SparseMatrixCompRow;
79typedef Eigen::Matrix<Real, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor>
82typedef Eigen::Matrix<Complex, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor>
85typedef Eigen::Matrix<Int, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor>
88typedef Eigen::Matrix<Real, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>
91typedef Eigen::PartialPivLU<Matrix> LUFactorized;
93typedef Eigen::SparseLU<SparseMatrix> LUFactorizedSparse;
95template <
typename VarType>
97 Eigen::Matrix<VarType, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor>;
99template <
int rows,
int cols>
100using MatrixFixedSize = Eigen::Matrix<Real, rows, cols, Eigen::ColMajor>;
102template <
int rows,
int cols>
103using MatrixFixedSizeComp = Eigen::Matrix<Complex, rows, cols, Eigen::ColMajor>;
107static const Complex jComp(0.0, 1.0);
111enum class NumericalMethod { Euler, Trapezoidal };
112enum class PhaseType { A, B, C, ABC, Single };
113enum class Domain { SP, DP, EMT };
114enum class PowerflowBusType { PV, PQ, VD, None };
115enum class GeneratorType {
132enum class SGOrder { SG3Order, SG4Order, SG5Order, SG6aOrder, SG6bOrder };
143 std::error_code mErrorCode;
147 SystemError(
const String &desc,
int e)
148 : mErrorCode(e, std::system_category()), mDescription(desc){};
150 SystemError(
const String &desc)
151 : mErrorCode(errno, std::system_category()), mDescription(desc){};
153 SystemError() : mErrorCode(errno, std::system_category()){};
155 String descr()
const {
156 std::ostringstream os;
158 os <<
"System Error: " << mDescription <<
": " << mErrorCode.message()
159 <<
"(" << mErrorCode.value() <<
")";