Eclipse SUMO - Simulation of Urban MObility
Element.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2020 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 /****************************************************************************/
19 // Representation of electric circuit elements: resistors, voltage and current sources
21 /****************************************************************************/
22 #include <cfloat>
23 #include <cmath>
24 #include "Element.h"
25 #include "Node.h"
26 
27 Element::Element(string name, ElementType type, double value) {
28  this->id = -2;
29  this->name = name;
30  this->type = type;
31  this->isenabled = true;
32  this->resistance = 0;
33  this->current = 0;
34  this->voltage = 0;
35  this->powerWanted = NAN;
36  switch (type) {
38  this->current = value;
39  break;
41  this->voltage = value;
42  break;
44  this->resistance = value;
45  break;
46  default:
47  cout << "ERROR: TYPE UNDEFINED.\n";
48  break;
49  }
50  this->pNode = nullptr;
51  this->nNode = nullptr;
52 }
53 
54 void Element::setVoltage(double voltageIn) {
55  this->voltage = voltageIn;
56 }
57 void Element::setCurrent(double currentIn) {
58  this->current = currentIn;
59 }
60 void Element::setResistance(double resistanceIn) {
61  if (resistanceIn <= 1e-6) {
62  this->resistance = 1e-6;
63  } else {
64  this->resistance = resistanceIn;
65  }
66 }
67 void Element::setPowerWanted(double powerWantedIn) {
68  this->powerWanted = powerWantedIn;
69 }
71  if (this->isenabled == false) {
72  return DBL_MAX;
73  }
74  if (getType() == Element::ElementType::VOLTAGE_SOURCE_traction_wire) {
75  return voltage;
76  }
77  return this->pNode->getVoltage() - this->nNode->getVoltage();
78 }
80  if (this->isenabled == false) {
81  return DBL_MAX;
82  }
83  switch (this->type) {
84  case Element::ElementType::RESISTOR_traction_wire:
85  return -1 * getVoltage() / resistance;
86  case Element::ElementType::CURRENT_SOURCE_traction_wire:
87  case Element::ElementType::VOLTAGE_SOURCE_traction_wire:
88  return current;
89  default:
90  return 0;
91  }
92 }
94  return this->resistance;
95 }
97  return this->powerWanted;
98 }
100  return -1 * getCurrent() * getVoltage();
101 }
103 
104  return this->id;
105 }
107  return this->pNode;
108 }
110  return this->nNode;
111 }
112 
114  return this->type;
115 }
117  return this->name;
118 }
119 
121  this->pNode = node;
122 
123 }
125  this->nNode = node;
126 }
127 void Element::setId(int newId) {
128  this->id = newId;
129 }
130 
131 // if node == pNode, return nNode, else if node == nNode return pNode, else return nullptr
133  if (node == pNode) {
134  return nNode;
135  } else if (node == nNode) {
136  return pNode;
137  } else {
138  return nullptr;
139  }
140 }
141 
143  return isenabled;
144 }
145 
146 void Element::setEnabled(bool newIsEnabled) {
147  this->isenabled = newIsEnabled;
148 }
149 
151  this->type = ET;
152 }
void setId(int id)
Definition: Element.cpp:127
ElementType getType()
Definition: Element.cpp:113
double getResistance()
Definition: Element.cpp:93
void setNegNode(Node *node)
Definition: Element.cpp:124
void setVoltage(double voltage)
Definition: Element.cpp:54
void setCurrent(double current)
Definition: Element.cpp:57
double getPowerWanted()
Definition: Element.cpp:96
Element(string name, ElementType type, double value)
Definition: Element.cpp:27
ElementType type
Definition: Element.h:59
string getName()
Definition: Element.cpp:116
Node * getNegNode()
Definition: Element.cpp:109
double powerWanted
Definition: Element.h:58
int id
Definition: Element.h:61
double getCurrent()
Definition: Element.cpp:79
void setType(ElementType ET)
Definition: Element.cpp:150
void setPosNode(Node *node)
Definition: Element.cpp:120
int getId()
Definition: Element.cpp:102
Node * getPosNode()
Definition: Element.cpp:106
double getVoltage()
Definition: Element.cpp:70
string name
Definition: Element.h:60
bool isEnabled()
Definition: Element.cpp:142
double getPower()
Definition: Element.cpp:99
void setResistance(double resistance)
Definition: Element.cpp:60
void setPowerWanted(double powerWanted)
Definition: Element.cpp:67
Node * getTheOtherNode(Node *node)
Definition: Element.cpp:132
void setEnabled(bool isenabled)
Definition: Element.cpp:146
Node * pNode
Definition: Element.h:53
bool isenabled
Definition: Element.h:62
Node * nNode
Definition: Element.h:54
double resistance
Definition: Element.h:57
double current
Definition: Element.h:56
double voltage
Definition: Element.h:55
ElementType
Definition: Element.h:45
@ RESISTOR_traction_wire
Definition: Element.h:46
@ CURRENT_SOURCE_traction_wire
Definition: Element.h:47
@ VOLTAGE_SOURCE_traction_wire
Definition: Element.h:48
Definition: Node.h:31
double getVoltage()
Definition: Node.cpp:51