SystemModel.h 3.12 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
#ifndef SYSTEMMODEL_H
#define SYSTEMMODEL_H

#include <iostream>
#include <vector>
#include "MathLibrary.h"
#include "Logger.h"

namespace DPsim {

	enum class SimulationType { DynPhasor, EMT };
12
	enum class NumericalMethod { Euler, AdamBashforth, Trapezoidal_flux, Trapezoidal_current };
13
14
15
16
17
18

	class SystemModel {

	private:
		/// Simulation type
		SimulationType mSimType;
19
20
		///Numerical method
		NumericalMethod mNumMethod;
21
22
23
24
25
26
27
28
		/// Number of nodes
		int mNumNodes;
		/// Index offset for imaginary part
		int mCompOffset;
		/// Angular frequency of the phasor
		Real mSystemOmega;
		/// Simulation time step
		Real mTimeStep;
29
30
		/// Number of ideal Voltage Sources
		Int mNumIdealVS;
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

		
		/// LU decomposition of system matrix A
		Eigen::PartialPivLU<DPSMatrix> mLuFactored;
		/// LU decomposition of system matrix A
		std::vector<Eigen::PartialPivLU<DPSMatrix> > mLuFactoredVector;
		/// System matrix A that is modified by matrix stamps 
		DPSMatrix mSystemMatrix;
		/// System matrices list for swtiching events
		std::vector<DPSMatrix> mSystemMatrixVector;
		/// Vector of known quantities
		DPSMatrix mRightSideVector;
		/// Vector of unknown quantities
		DPSMatrix mLeftSideVector;

46
47
48
		/** Matrix of all edge currents; diagonal is used for currents to ground. */
		SparseMatrixComp mCurrentMatrix;

49
	public:
50
		SystemModel() { }
51
		void initialize(Int numNodes, Int numIdealVS);
52
		void addSystemMatrix(Matrix& systemMatrix);
53

54
55
56
57
		Matrix & getCurrentSystemMatrix() { return mSystemMatrix; }
		const Matrix & getLUdecomp() { return mLuFactored.matrixLU(); }
		Matrix & getRightSideVector() { return mRightSideVector; }
		Matrix & getLeftSideVector() { return mLeftSideVector; }
58
59
60
61
62
		Real getTimeStep() { return mTimeStep; }
		Real getOmega() { return mSystemOmega; }
		Int getCompOffset() { return mCompOffset; }
		Real getRealFromLeftSideVector(Int row) { return mLeftSideVector(row, 0); }
		Real getImagFromLeftSideVector(Int row) { return mLeftSideVector(row + mCompOffset, 0); }
63
64
		SimulationType getSimType() { return mSimType; }
		Int getNumNodes() { return mNumNodes; }		
65
		Int getNumIdealVS() { return mNumIdealVS; }
66
67
		NumericalMethod getNumMethod() { return mNumMethod; }
		
68
69
70
71
		
		void setSimType(SimulationType simType) { mSimType = simType; }
		void setTimeStep(Real timeStep) { mTimeStep = timeStep; }
		void setOmega(Real omega) { mSystemOmega = omega; }
72
		void setSystemMatrixElement(Int row, Int column, Real value) { mSystemMatrix(row, column) = value; }
73
		void setNumMethod(NumericalMethod numMethod) { mNumMethod = numMethod; }
74

75
		void InitializeRightSideVector(DPsim::Matrix& rightSideVector) { mRightSideVector = rightSideVector; }
76
77
78
79
		void InitializeLeftSideVector(DPsim::Matrix& leftSideVector) { mLeftSideVector = leftSideVector; }		
		void switchSystemMatrix(Int systemMatrixIndex);
		void addRealToSystemMatrix(Int row, Int column, Real value);
		void addCompToSystemMatrix(Int row, Int column, Real reValue, Real imValue);
80
		void addCompToSystemMatrix(Int row, Int column, Complex value);
81
82
		void addCompToRightSideVector(Int row, Real reValue, Real imValue);
		void addRealToRightSideVector(Int row, Real value);
83
		void setRightSideVectorToZero();
84

85
		void solve();
86
87
88
	};
}
#endif