Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
Element.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 elements: resistors, voltage and current sources
22/****************************************************************************/
23#include <cfloat>
24#include <cmath>
26#include "Element.h"
27#include "Node.h"
28
29
30// ===========================================================================
31// method definitions
32// ===========================================================================
33Element::Element(std::string name, ElementType type, double value) {
34 this->id = -2;
35 this->name = name;
36 this->type = type;
37 this->isenabled = true;
38 this->resistance = 0;
39 this->current = 0;
40 this->voltage = 0;
41 this->powerWanted = NAN;
42 switch (type) {
44 this->current = value;
45 break;
47 this->voltage = value;
48 break;
50 this->resistance = value;
51 break;
52 default:
53 WRITE_ERRORF(TL("Undefined element type for '%'."), name);
54 break;
55 }
56 this->pNode = nullptr;
57 this->nNode = nullptr;
58}
59
60void Element::setVoltage(double voltageIn) {
61 this->voltage = voltageIn;
62}
63void Element::setCurrent(double currentIn) {
64 this->current = currentIn;
65}
66void Element::setResistance(double resistanceIn) {
67 if (resistanceIn <= 1e-6) {
68 this->resistance = 1e-6;
69 } else {
70 this->resistance = resistanceIn;
71 }
72}
73void Element::setPowerWanted(double powerWantedIn) {
74 this->powerWanted = powerWantedIn;
75}
77 if (!this->isenabled) {
78 return DBL_MAX;
79 }
81 return voltage;
82 }
83 return this->pNode->getVoltage() - this->nNode->getVoltage();
84}
86 if (!this->isenabled) {
87 return DBL_MAX;
88 }
89 switch (this->type) {
91 return -1 * getVoltage() / resistance;
94 return current;
95 default:
96 return 0;
97 }
98}
100 return this->resistance;
101}
103 return this->powerWanted;
104}
106 return -1 * getCurrent() * getVoltage();
107}
109
110 return this->id;
111}
113 return this->pNode;
114}
116 return this->nNode;
117}
118
120 return this->type;
121}
122std::string Element::getName() {
123 return this->name;
124}
125
127 this->pNode = node;
128
129}
131 this->nNode = node;
132}
133void Element::setId(int newId) {
134 this->id = newId;
135}
136
137// if node == pNode, return nNode, else if node == nNode return pNode, else return nullptr
139 if (node == pNode) {
140 return nNode;
141 } else if (node == nNode) {
142 return pNode;
143 } else {
144 return nullptr;
145 }
146}
147
149 return isenabled;
150}
151
152void Element::setEnabled(bool newIsEnabled) {
153 this->isenabled = newIsEnabled;
154}
155
157 this->type = ET;
158}
#define WRITE_ERRORF(...)
Definition MsgHandler.h:305
#define TL(string)
Definition MsgHandler.h:315
void setId(int id)
Definition Element.cpp:133
ElementType getType()
Definition Element.cpp:119
double getResistance()
Definition Element.cpp:99
void setNegNode(Node *node)
Definition Element.cpp:130
void setVoltage(double voltage)
Definition Element.cpp:60
void setCurrent(double current)
Definition Element.cpp:63
std::string name
Definition Element.h:68
double getPowerWanted()
Definition Element.cpp:102
ElementType type
Definition Element.h:67
Node * getNegNode()
Definition Element.cpp:115
std::string getName()
Definition Element.cpp:122
double powerWanted
Definition Element.h:66
int id
Definition Element.h:69
double getCurrent()
Definition Element.cpp:85
void setType(ElementType ET)
Definition Element.cpp:156
void setPosNode(Node *node)
Definition Element.cpp:126
int getId()
Definition Element.cpp:108
Element(std::string name, ElementType type, double value)
Definition Element.cpp:33
Node * getPosNode()
Definition Element.cpp:112
double getVoltage()
Definition Element.cpp:76
bool isEnabled()
Definition Element.cpp:148
double getPower()
Definition Element.cpp:105
void setResistance(double resistance)
Definition Element.cpp:66
void setPowerWanted(double powerWanted)
Definition Element.cpp:73
Node * getTheOtherNode(Node *node)
Definition Element.cpp:138
void setEnabled(bool isenabled)
Definition Element.cpp:152
Node * pNode
Definition Element.h:61
bool isenabled
Definition Element.h:70
Node * nNode
Definition Element.h:62
double resistance
Definition Element.h:65
double current
Definition Element.h:64
double voltage
Definition Element.h:63
ElementType
Definition Element.h:53
@ RESISTOR_traction_wire
Definition Element.h:54
@ CURRENT_SOURCE_traction_wire
Definition Element.h:55
@ VOLTAGE_SOURCE_traction_wire
Definition Element.h:56
Definition Node.h:39
double getVoltage()
Definition Node.cpp:53