EMT_Ph3_VoltageSource.h 4.04 KB
Newer Older
1
2
/* Copyright 2017-2020 Institute for Automation of Complex Power Systems,
 *                     EONERC, RWTH Aachen University
Markus Mirz's avatar
Markus Mirz committed
3
 *
4
5
6
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
Markus Mirz's avatar
Markus Mirz committed
7
8
9
10
 *********************************************************************************/
#pragma once


11
#include <cps/SimPowerComp.h>
Markus Mirz's avatar
Markus Mirz committed
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <cps/Solver/MNAInterface.h>

namespace CPS {
	namespace EMT {
		namespace Ph3 {
			/// \brief Ideal Voltage source model
			///
			/// This model uses modified nodal analysis to represent an ideal voltage source.
			/// For a voltage source between nodes j and k, a new variable (current across the voltage source)
			/// is added to the left side vector
			/// as unkown and it is taken into account for the equation of node j as positve and for the equation
			/// of node k as negative. Moreover
			/// a new equation ej - ek = V is added to the problem.
			class VoltageSource :
				public MNAInterface,
Markus Mirz's avatar
Markus Mirz committed
27
				public SimPowerComp<Real>,
Markus Mirz's avatar
Markus Mirz committed
28
29
30
31
32
				public SharedFactory<VoltageSource> {
			protected:
				void updateVoltage(Real time);
				void updateVoltage(Matrix vabc);

33
				/// Magnitude of the sinusoidal voltage (peak-value, phase-to-ground)
Markus Mirz's avatar
Markus Mirz committed
34
				Attribute<Complex>::Ptr mVoltageRef;
35
				/// Frequency of the sinusoidal voltage
Markus Mirz's avatar
Markus Mirz committed
36
37
38
39
40
41
42
43
44
45
				Attribute<Real>::Ptr mSrcFreq;
			public:
				/// Defines UID, name and logging level
				VoltageSource(String uid, String name, Logger::Level logLevel = Logger::Level::off);
				///
				VoltageSource(String name, Logger::Level logLevel = Logger::Level::off)
					: VoltageSource(name, name, logLevel) { }

				void setParameters(Complex voltageRef, Real srcFreq = -1);

Markus Mirz's avatar
Markus Mirz committed
46
				SimPowerComp<Real>::Ptr clone(String name);
Markus Mirz's avatar
Markus Mirz committed
47
48
				// #### General ####
				/// Initializes component from power flow data
Jan Dinkelbach's avatar
Jan Dinkelbach committed
49
				void initializeFromNodesAndTerminals(Real frequency);
Markus Mirz's avatar
Markus Mirz committed
50
51
52
53
54
55
56
57
58
59

				// #### MNA section ####
				/// Initializes internal variables of the component
				void mnaInitialize(Real omega, Real timeStep, Attribute<Matrix>::Ptr leftVector);
				/// Stamps system matrix
				void mnaApplySystemMatrixStamp(Matrix& systemMatrix);
				/// Stamps right side (source) vector
				void mnaApplyRightSideVectorStamp(Matrix& rightVector);
				/// Returns current through the component
				void mnaUpdateCurrent(const Matrix& leftVector);
60
61
62
63
64
65
66
67
				/// MNA pre step operations
				void mnaPreStep(Real time, Int timeStepCount);
				/// MNA post step operations
				void mnaPostStep(Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector);
				/// Add MNA pre step dependencies
				void mnaAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes);
				/// Add MNA post step dependencies
				void mnaAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute<Matrix>::Ptr &leftVector);
Markus Mirz's avatar
Markus Mirz committed
68

69
				class MnaPreStep : public Task {
Markus Mirz's avatar
Markus Mirz committed
70
71
72
				public:
					MnaPreStep(VoltageSource& voltageSource) :
						Task(voltageSource.mName + ".MnaPreStep"), mVoltageSource(voltageSource) {
73
74
75
							mVoltageSource.mnaAddPreStepDependencies(mPrevStepDependencies, mAttributeDependencies, mModifiedAttributes);
						}
						void execute(Real time, Int timeStepCount) { mVoltageSource.mnaPreStep(time, timeStepCount); };
Markus Mirz's avatar
Markus Mirz committed
76
77
78
79
				private:
					VoltageSource& mVoltageSource;
				};

80
				class MnaPostStep : public Task {
Markus Mirz's avatar
Markus Mirz committed
81
82
				public:
					MnaPostStep(VoltageSource& voltageSource, Attribute<Matrix>::Ptr leftVector) :
83
84
85
						Task(voltageSource.mName + ".MnaPostStep"),			
						mVoltageSource(voltageSource), mLeftVector(leftVector) {
							mVoltageSource.mnaAddPostStepDependencies(mPrevStepDependencies, mAttributeDependencies, mModifiedAttributes, mLeftVector);
Markus Mirz's avatar
Markus Mirz committed
86
					}
87
					void execute(Real time, Int timeStepCount)  { mVoltageSource.mnaPostStep(time, timeStepCount, mLeftVector); };
Markus Mirz's avatar
Markus Mirz committed
88
89
90
91
92
93
94
95
				private:
					VoltageSource& mVoltageSource;
					Attribute<Matrix>::Ptr mLeftVector;
				};
			};
		}
	}
}