DPsim
Loading...
Searching...
No Matches
Definitions.h
Go to the documentation of this file.
1/* Copyright 2017-2021 Institute for Automation of Complex Power Systems,
2 * EONERC, RWTH Aachen University
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
7 *********************************************************************************/
8
9#pragma once
10
11#include <cerrno>
12#include <cmath>
13#include <complex>
14#include <exception>
15#include <memory>
16#include <string>
17#include <system_error>
18
19#ifdef __clang__
20#elif defined(__GNUC__)
21#pragma GCC diagnostic push
22#if __GNUC__ >= 7
23#pragma GCC diagnostic ignored \
24 "-Wint-in-bool-context" // https://eigen.tuxfamily.org/bz/show_bug.cgi?id=1402
25#endif
26#endif
27
28#include <Eigen/Dense>
29#include <Eigen/Sparse>
30
31#ifdef __clang__
32#elif defined(__GNUC__)
33#pragma GCC diagnostic pop
34#endif
35
36// VS2017 doesn't define M_PI unless _USE_MATH_DEFINES is included before cmath
37// which is hard to guarantee, so we make sure it is defined here
38#define DPS_PI PI
39#ifndef PI
40#ifndef M_PI
41#define M_PI 3.14159265358979323846
42#endif
43#define PI M_PI
44#endif
45
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.)
52
53#define P_SNUB_TRANSFORMER 1e-3 // 0.1% of rated power
54#define Q_SNUB_TRANSFORMER 5e-4 // 0.05% of rated power
55#define DOUBLE_EPSILON 1E-12
56
57namespace CPS {
58
59// ### Types ###
60typedef unsigned int UInt;
61typedef int Int;
62typedef double Real;
63typedef std::complex<Real> Complex;
64typedef bool Bool;
65typedef std::string String;
66
68typedef Eigen::Matrix<Complex, Eigen::Dynamic, 1> VectorComp;
70typedef Eigen::Matrix<Real, Eigen::Dynamic, 1> Vector;
72typedef Eigen::SparseMatrix<Real, Eigen::ColMajor> SparseMatrix;
74typedef Eigen::SparseMatrix<Real, Eigen::RowMajor> SparseMatrixRow;
76typedef Eigen::SparseMatrix<Complex, Eigen::ColMajor> SparseMatrixComp;
78typedef Eigen::SparseMatrix<Complex, Eigen::RowMajor> SparseMatrixCompRow;
80typedef Eigen::Matrix<Real, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor>
83typedef Eigen::Matrix<Complex, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor>
86typedef Eigen::Matrix<Int, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor>
89typedef Eigen::Matrix<Real, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>
92typedef Eigen::PartialPivLU<Matrix> LUFactorized;
94typedef Eigen::SparseLU<SparseMatrix> LUFactorizedSparse;
96template <typename VarType>
97using MatrixVar =
98 Eigen::Matrix<VarType, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor>;
100template <int rows, int cols>
101using MatrixFixedSize = Eigen::Matrix<Real, rows, cols, Eigen::ColMajor>;
103template <int rows, int cols>
104using MatrixFixedSizeComp = Eigen::Matrix<Complex, rows, cols, Eigen::ColMajor>;
105
106// ### Constants ###
108static const Complex jComp(0.0, 1.0);
110
111// ### Enumerations ###
113enum class PhaseType { A, B, C, ABC, Single };
114enum class Domain { SP, DP, EMT };
115enum class PowerflowBusType { PV, PQ, VD, None };
134
136
137// ### Exceptions ###
138class Exception : public std::exception {};
139class AccessException : public Exception {};
140class TypeException : public Exception {};
143
145protected:
146 std::error_code mErrorCode;
148
149public:
150 SystemError(const String &desc, int e)
151 : mErrorCode(e, std::system_category()), mDescription(desc){};
152
153 SystemError(const String &desc)
154 : mErrorCode(errno, std::system_category()), mDescription(desc){};
155
156 SystemError() : mErrorCode(errno, std::system_category()){};
157
158 String descr() const {
159 std::ostringstream os;
160
161 os << "System Error: " << mDescription << ": " << mErrorCode.message()
162 << "(" << mErrorCode.value() << ")";
163
164 return os.str();
165 };
166};
167} // namespace CPS
String descr() const
std::error_code mErrorCode
SystemError(const String &desc, int e)
SystemError(const String &desc)
PowerflowBusType
Eigen::SparseMatrix< Real, Eigen::ColMajor > SparseMatrix
Sparse matrix for real numbers.
Definition Definitions.h:72
Eigen::Matrix< Real, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > Matrix
Dense matrix for real numbers.
Definition Definitions.h:81
std::string String
Definition Definitions.h:65
Eigen::SparseMatrix< Complex, Eigen::ColMajor > SparseMatrixComp
Sparse matrix for complex numbers.
Definition Definitions.h:76
Eigen::Matrix< Int, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > MatrixInt
Dense matrix for integers.
Definition Definitions.h:87
Eigen::PartialPivLU< Matrix > LUFactorized
Definition Definitions.h:92
Eigen::SparseMatrix< Complex, Eigen::RowMajor > SparseMatrixCompRow
Sparse matrix for complex numbers (row major).
Definition Definitions.h:78
Eigen::Matrix< Real, rows, cols, Eigen::ColMajor > MatrixFixedSize
Dense matrix for real numbers with fixed dimension.
double Real
Definition Definitions.h:62
Eigen::Matrix< Complex, Eigen::Dynamic, 1 > VectorComp
Dense vector for complex numbers.
Definition Definitions.h:68
CouplingMethod
Eigen::Matrix< Real, Eigen::Dynamic, 1 > Vector
Dense vector for real numbers.
Definition Definitions.h:70
Eigen::Matrix< Real, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > MatrixRow
Definition Definitions.h:90
int Int
Definition Definitions.h:61
Eigen::Matrix< VarType, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > MatrixVar
Definition Definitions.h:97
std::complex< Real > Complex
Definition Definitions.h:63
Eigen::Matrix< Complex, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > MatrixComp
Dense matrix for complex numbers.
Definition Definitions.h:84
bool Bool
Definition Definitions.h:64
GeneratorType
unsigned int UInt
Definition Definitions.h:60
Eigen::Matrix< Complex, rows, cols, Eigen::ColMajor > MatrixFixedSizeComp
Dense matrix for complex numbers with fixed dimension.
Eigen::SparseLU< SparseMatrix > LUFactorizedSparse
Definition Definitions.h:94
NumericalMethod
Eigen::SparseMatrix< Real, Eigen::RowMajor > SparseMatrixRow
Sparse matrix for real numbers (row major).
Definition Definitions.h:74