DP_Ph1_ControlledVoltageSource.h 4.76 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
 *********************************************************************************/
#pragma once

10
#include <cps/SimPowerComp.h>
Markus Mirz's avatar
Markus Mirz committed
11
12
13
14
15
16
17
#include <cps/Solver/MNAInterface.h>

namespace CPS {
	namespace DP {
		namespace Ph1 {
			class ControlledVoltageSource :
				public MNAInterface,
Markus Mirz's avatar
Markus Mirz committed
18
				public SimPowerComp<Complex>,
Markus Mirz's avatar
Markus Mirz committed
19
20
21
22
23
24
25
26
27
28
29
30
31
				public SharedFactory<ControlledVoltageSource> {
			protected:
				void updateVoltage(Real time);

			public:
				/// Defines UID, name and logging level
				ControlledVoltageSource(String uid, String name, Logger::Level logLevel = Logger::Level::off);
				///
				ControlledVoltageSource(String name, Logger::Level logLevel = Logger::Level::off)
					: ControlledVoltageSource(name, name, logLevel) { }

				void setParameters(MatrixComp voltageRefABC);

Markus Mirz's avatar
Markus Mirz committed
32
				SimPowerComp<Complex>::Ptr clone(String name);
Markus Mirz's avatar
Markus Mirz committed
33
34
				// #### General ####
				/// Initializes component from power flow data
Markus Mirz's avatar
Markus Mirz committed
35
				void initializeFromNodesAndTerminals(Real frequency) { }
Markus Mirz's avatar
Markus Mirz committed
36
37
38
39
40
41
42
43
44
45

				// #### 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);
46
47
48
49
50
51
				/// MNA pre and post step operations
				void mnaPreStep(Real time, Int timeStepCount);
				void mnaPostStep(Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector);
				/// add MNA pre and post step dependencies
				void mnaAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes);
				void mnaAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute<Matrix>::Ptr &leftVector);
Markus Mirz's avatar
Markus Mirz committed
52
53
54
55
56

				class MnaPreStep : public CPS::Task {
				public:
					MnaPreStep(ControlledVoltageSource& ControlledVoltageSource) :
						Task(ControlledVoltageSource.mName + ".MnaPreStep"), mControlledVoltageSource(ControlledVoltageSource) {
57
58
59
							mControlledVoltageSource.mnaAddPreStepDependencies(mPrevStepDependencies, mAttributeDependencies, mModifiedAttributes);
				}
				void execute(Real time, Int timeStepCount) { mControlledVoltageSource.mnaPreStep(time, timeStepCount); };
Markus Mirz's avatar
Markus Mirz committed
60
61
62
63
64
65
66
				private:
					ControlledVoltageSource& mControlledVoltageSource;
				};

				class MnaPostStep : public CPS::Task {
				public:
					MnaPostStep(ControlledVoltageSource& ControlledVoltageSource, Attribute<Matrix>::Ptr leftVector) :
67
68
69
70
						Task(ControlledVoltageSource.mName + ".MnaPostStep"), mControlledVoltageSource(ControlledVoltageSource), mLeftVector(leftVector) {
							mControlledVoltageSource.mnaAddPostStepDependencies(mPrevStepDependencies, mAttributeDependencies, mModifiedAttributes, mLeftVector);
				}
				void execute(Real time, Int timeStepCount) { mControlledVoltageSource.mnaPostStep(time, timeStepCount, mLeftVector); };
Markus Mirz's avatar
Markus Mirz committed
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
				private:
					ControlledVoltageSource& mControlledVoltageSource;
					Attribute<Matrix>::Ptr mLeftVector;
				};
				class MnaPreStepHarm : public CPS::Task {
				public:
					MnaPreStepHarm(ControlledVoltageSource& voltageSource) :
						Task(voltageSource.mName + ".MnaPreStepHarm"),
						mControlledVoltageSource(voltageSource) {
						mAttributeDependencies.push_back(voltageSource.attribute("V_ref"));
						mModifiedAttributes.push_back(mControlledVoltageSource.attribute("right_vector"));
						mModifiedAttributes.push_back(mControlledVoltageSource.attribute("v_intf"));
					}
					void execute(Real time, Int timeStepCount);
				private:
					ControlledVoltageSource& mControlledVoltageSource;
				};

				class MnaPostStepHarm : public CPS::Task {
				public:
					MnaPostStepHarm(ControlledVoltageSource& voltageSource, std::vector<Attribute<Matrix>::Ptr> leftVectors) :
						Task(voltageSource.mName + ".MnaPostStepHarm"),
						mControlledVoltageSource(voltageSource), mLeftVectors(leftVectors) {
						for (UInt i = 0; i < mLeftVectors.size(); i++)
							mAttributeDependencies.push_back(mLeftVectors[i]);
						mModifiedAttributes.push_back(mControlledVoltageSource.attribute("i_intf"));
					}
					void execute(Real time, Int timeStepCount);
				private:
					ControlledVoltageSource& mControlledVoltageSource;
					std::vector< Attribute<Matrix>::Ptr > mLeftVectors;
				};
			};
		}
	}
}