DPsim
TopologicalTerminal.cpp
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 #include <dpsim-models/TopologicalTerminal.h>
10 
11 using namespace CPS;
12 
13 TopologicalTerminal::TopologicalTerminal(String uid, String name,
14  PhaseType phase)
15  : IdentifiedObject(uid, name) {
16  setPhaseType(phase);
17 }
18 
19 MatrixComp TopologicalTerminal::power() const { return mPower; }
20 
21 void TopologicalTerminal::setPower(Complex power) { mPower(0, 0) = power; }
22 
23 void TopologicalTerminal::setPower(MatrixComp power) { mPower = power; }
24 
25 void TopologicalTerminal::setPhaseType(PhaseType type) {
26  mPhaseType = type;
27  if (mPhaseType == PhaseType::ABC)
28  mPower = MatrixComp::Zero(3, 1);
29  else
30  mPower = MatrixComp::Zero(1, 1);
31 }
32 
33 Real TopologicalTerminal::singleActivePower() { return singlePower().real(); }
34 
35 Real TopologicalTerminal::singleReactivePower() { return singlePower().imag(); }
36 
37 Complex TopologicalTerminal::initialSingleVoltage() {
38  return topologicalNodes()->initialSingleVoltage(mPhaseType);
39 }
40 
41 UInt TopologicalTerminal::matrixNodeIndex() {
42  return topologicalNodes()->matrixNodeIndex(mPhaseType);
43 }
44 
45 std::vector<UInt> TopologicalTerminal::matrixNodeIndices() {
46  return topologicalNodes()->matrixNodeIndices();
47 }
48 
50  if (mPhaseType == PhaseType::B)
51  return mPower(1, 0);
52  else if (mPhaseType == PhaseType::C)
53  return mPower(2, 0);
54  else // mPhaseType == PhaseType::Single || mPhaseType == PhaseType::A
55  return mPower(0, 0);
56 }
57 
58 MatrixComp TopologicalTerminal::initialVoltage() {
59  if (mPhaseType == PhaseType::Single || mPhaseType == PhaseType::A)
60  return topologicalNodes()->initialVoltage().block(0, 0, 1, 1);
61  else if (mPhaseType == PhaseType::B)
62  return topologicalNodes()->initialVoltage().block(1, 0, 1, 1);
63  else if (mPhaseType == PhaseType::C)
64  return topologicalNodes()->initialVoltage().block(2, 0, 1, 1);
65  else
66  return topologicalNodes()->initialVoltage();
67 }
String type()
Get component type (cross-platform)
virtual TopologicalNode::Ptr topologicalNodes()=0
Returns reference to TopologicalNode.
MatrixComp power() const
Returns Power as complex matrix, where the size depends on the number of phases.
PhaseType mPhaseType
Determines the connection between Component and Node.
MatrixComp mPower
Power through the Terminal.
Complex singlePower()
Returns single complex number for power.