Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
4 : // This program and the accompanying materials are made available under the
5 : // terms of the Eclipse Public License 2.0 which is available at
6 : // https://www.eclipse.org/legal/epl-2.0/
7 : // This Source Code may also be made available under the following Secondary
8 : // Licenses when the conditions for such availability set forth in the Eclipse
9 : // Public License 2.0 are satisfied: GNU General Public License, version 2
10 : // or later which is available at
11 : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 : /****************************************************************************/
14 : /// @file Node.cpp
15 : /// @author Jakub Sevcik (RICE)
16 : /// @author Jan Prikryl (RICE)
17 : /// @date 2019-12-15
18 : ///
19 : /// @note based on work 2017 Ahmad Khaled, Ahmad Essam, Omnia Zakaria, Mary Nader
20 : ///
21 : // Representation of electric circuit nodes, i.e. wire junctions and connection points.
22 : /****************************************************************************/
23 : #include <config.h>
24 :
25 : #include <string>
26 : #include <algorithm>
27 : #include "Node.h"
28 : #include "Element.h"
29 :
30 :
31 : // A constructor, same functionality as "init" functions
32 264 : Node::Node(std::string name, int id) {
33 264 : isground = false;
34 264 : this->name = name; // unique property, each object has distinctive and unique name
35 264 : this->id = id; // a sequential ID number, might be useful when making the equation
36 264 : this->num_matrixRow = -1;
37 264 : this->num_matrixCol = -1;
38 264 : this->voltage = 0;
39 264 : this->elements = new std::vector<Element*>(0);
40 264 : isremovable = false;
41 264 : }
42 :
43 : // connects an element to the node
44 1223 : void Node::addElement(Element* element) {
45 1223 : elements->push_back(element);
46 1223 : }
47 :
48 1719 : void Node::eraseElement(Element* element) {
49 1719 : elements->erase(std::remove(elements->begin(), elements->end(), element), elements->end());
50 1719 : }
51 :
52 : // getters and setters
53 7808 : double Node::getVoltage() {
54 7808 : return this->voltage;
55 : }
56 :
57 2433 : void Node::setVoltage(double volt) {
58 2433 : this->voltage = volt;
59 2433 : }
60 :
61 93 : int Node::getNumOfElements() {
62 93 : return (int) elements->size();
63 : }
64 :
65 3050 : std::string& Node::getName() {
66 3050 : return this->name;
67 : }
68 :
69 15068 : bool Node::isGround() {
70 15068 : return this->isground;
71 : }
72 :
73 8 : void Node::setGround(bool newIsGround) {
74 8 : this->isground = newIsGround;
75 8 : }
76 :
77 51642 : int Node::getId() {
78 51642 : return this->id;
79 : }
80 :
81 15 : void Node::setId(int newId) {
82 15 : this->id = newId;
83 15 : }
84 :
85 2613 : void Node::setNumMatrixRow(int num) {
86 2613 : this->num_matrixRow = num;
87 2613 : }
88 :
89 4572 : int Node::getNumMatrixRow() {
90 4572 : return this->num_matrixRow;
91 : }
92 :
93 2433 : void Node::setNumMatrixCol(int num) {
94 2433 : this->num_matrixCol = num;
95 2433 : }
96 :
97 1242 : int Node::getNumMatrixCol() {
98 1242 : return this->num_matrixCol;
99 : }
100 :
101 31311 : std::vector<Element*>* Node::getElements() {
102 31311 : return elements;
103 : }
104 :
105 4304 : void Node::setRemovability(bool newIsRemovable) {
106 4304 : this->isremovable = newIsRemovable;
107 4304 : }
108 :
109 5648 : Element* Node::getAnOtherElement(Element* element) {
110 9286 : for (Element* it : *this->getElements()) {
111 9286 : if (it != element) {
112 : return it;
113 : }
114 : }
115 : return nullptr;
116 : }
|