Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/utils/traction_wire/Node.cpp
169678 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2025 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
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
61
int Node::getNumOfElements() {
62
return (int) elements->size();
63
}
64
65
std::string& Node::getName() {
66
return this->name;
67
}
68
69
bool Node::isGround() {
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
89
int Node::getNumMatrixRow() {
90
return this->num_matrixRow;
91
}
92
93
void Node::setNumMatrixCol(int num) {
94
this->num_matrixCol = num;
95
}
96
97
int Node::getNumMatrixCol() {
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
109
Element* Node::getAnOtherElement(Element* element) {
110
for (Element* it : *this->getElements()) {
111
if (it != element) {
112
return it;
113
}
114
}
115
return nullptr;
116
}
117
118