Eclipse SUMO - Simulation of Urban MObility
Node.cpp
Go to the documentation of this file.
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 /****************************************************************************/
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 Node::Node(std::string name, int id) {
33  isground = false;
34  this->name = name; // unique property, each object has distinctive and unique name
35  this->id = id; // a sequential ID number, might be useful when making the equation
36  this->num_matrixRow = -1;
37  this->num_matrixCol = -1;
38  this->voltage = 0;
39  this->elements = new std::vector<Element*>(0);
40  isremovable = false;
41 }
42 
43 // connects an element to the node
44 void Node::addElement(Element* element) {
45  elements->push_back(element);
46 }
47 
48 void Node::eraseElement(Element* element) {
49  elements->erase(std::remove(elements->begin(), elements->end(), element), elements->end());
50 }
51 
52 // getters and setters
53 double Node::getVoltage() {
54  return this->voltage;
55 }
56 
57 void Node::setVoltage(double volt) {
58  this->voltage = volt;
59 }
60 
62  return (int) elements->size();
63 }
64 
65 std::string& Node::getName() {
66  return this->name;
67 }
68 
70  return this->isground;
71 }
72 
73 void Node::setGround(bool newIsGround) {
74  this->isground = newIsGround;
75 }
76 
77 int Node::getId() {
78  return this->id;
79 }
80 
81 void Node::setId(int newId) {
82  this->id = newId;
83 }
84 
85 void Node::setNumMatrixRow(int num) {
86  this->num_matrixRow = num;
87 }
88 
90  return this->num_matrixRow;
91 }
92 
93 void Node::setNumMatrixCol(int num) {
94  this->num_matrixCol = num;
95 }
96 
98  return this->num_matrixCol;
99 }
100 
101 std::vector<Element*>* Node::getElements() {
102  return elements;
103 }
104 
105 void Node::setRemovability(bool newIsRemovable) {
106  this->isremovable = newIsRemovable;
107 }
108 
110  for (Element* it : *this->getElements()) {
111  if (it != element) {
112  return it;
113  }
114  }
115  return nullptr;
116 }
void setVoltage(double volt)
Definition: Node.cpp:57
void setGround(bool isground)
Definition: Node.cpp:73
void setNumMatrixCol(int num)
Definition: Node.cpp:93
int getId()
Definition: Node.cpp:77
int getNumMatrixCol()
Definition: Node.cpp:97
int id
Definition: Node.h:45
Node(std::string name, int id)
Definition: Node.cpp:32
Element * getAnOtherElement(Element *element)
Definition: Node.cpp:109
bool isGround()
Definition: Node.cpp:69
bool isground
Definition: Node.h:42
void addElement(Element *element)
Definition: Node.cpp:44
void eraseElement(Element *element)
Definition: Node.cpp:48
bool isremovable
Definition: Node.h:43
int getNumOfElements()
Definition: Node.cpp:61
std::string & getName()
Definition: Node.cpp:65
double getVoltage()
Definition: Node.cpp:53
int num_matrixCol
Definition: Node.h:47
void setNumMatrixRow(int num)
Definition: Node.cpp:85
std::string name
Definition: Node.h:44
int num_matrixRow
Definition: Node.h:46
void setId(int id)
Definition: Node.cpp:81
void setRemovability(bool isremovable)
Definition: Node.cpp:105
std::vector< Element * > * getElements()
Definition: Node.cpp:101
std::vector< Element * > * elements
Definition: Node.h:49
double voltage
Definition: Node.h:48
int getNumMatrixRow()
Definition: Node.cpp:89