DPsim
TopologicalNode.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/TopologicalNode.h>
10 
11 using namespace CPS;
12 
13 Bool TopologicalNode::isGround() const { return mIsGround; }
14 
15 MatrixComp TopologicalNode::initialVoltage() const { return **mInitialVoltage; }
16 
17 void TopologicalNode::setInitialVoltage(MatrixComp voltage) const {
18  **mInitialVoltage = voltage;
19 }
20 
21 void TopologicalNode::setInitialVoltage(Complex voltage) const {
22  if (mPhaseType == PhaseType::Single) {
23  (**mInitialVoltage)(0, 0) = voltage;
24  } else {
25  (**mInitialVoltage)(0, 0) = voltage;
26  (**mInitialVoltage)(1, 0) = SHIFT_TO_PHASE_B * voltage;
27  (**mInitialVoltage)(2, 0) = SHIFT_TO_PHASE_C * voltage;
28  }
29 }
30 
31 void TopologicalNode::setInitialVoltage(Complex voltage, Int phaseIndex) const {
32  (**mInitialVoltage)(phaseIndex, 0) = voltage;
33 }
34 
35 PhaseType TopologicalNode::phaseType() const { return mPhaseType; }
36 
37 TopologicalNode::TopologicalNode(String uid, String name, PhaseType phaseType,
38  const std::vector<Complex> &initialVoltage)
39  : IdentifiedObject(uid, name),
40  mInitialVoltage(mAttributes->create<MatrixComp>("voltage_init")) {
41 
42  mPhaseType = phaseType;
43  if (phaseType == PhaseType::ABC) {
44  //mMatrixNodeIndex = matrixNodeIndex;
45  **mInitialVoltage = MatrixComp::Zero(3, 1);
46  **mInitialVoltage << initialVoltage[0], initialVoltage[1],
47  initialVoltage[2];
48  } else {
49  //mMatrixNodeIndex = { matrixNodeIndex[0] };
50  **mInitialVoltage = MatrixComp::Zero(1, 1);
51  **mInitialVoltage << initialVoltage[0];
52  }
53 }
54 
55 Complex TopologicalNode::initialSingleVoltage(PhaseType phaseType) {
56  if (phaseType == PhaseType::B)
57  return (**mInitialVoltage)(1, 0);
58  else if (phaseType == PhaseType::C)
59  return (**mInitialVoltage)(2, 0);
60  else // phaseType == PhaseType::Single || mPhaseType == PhaseType::A
61  return (**mInitialVoltage)(0, 0);
62 }