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 Element.h
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 elements: resistors, voltage and current sources
22 : /****************************************************************************/
23 : #pragma once
24 : #include <config.h>
25 :
26 : #include <string>
27 : #include <iostream>
28 :
29 :
30 : // ===========================================================================
31 : // class declarations
32 : // ===========================================================================
33 : class Node;
34 :
35 :
36 : // ===========================================================================
37 : // class definitions
38 : // ===========================================================================
39 : /**
40 : * An element is any component in the circuit (resistor, current source, voltage source)
41 : * Every element has two terminals pNode (positive terminal) and nNode (negative terminal)
42 : * value is the resistance in case of a resistor, current in case of a current source
43 : * and voltage in case of voltage source.
44 : *
45 : * Conventions used:
46 : *
47 : * 1 - in case of a current source, "value" represents the current going from nNode to pNode,
48 : * 2 - in case of a voltage source, "value" represents the voltage difference of pNode - nNode.
49 : */
50 402 : class Element {
51 :
52 : public:
53 : enum ElementType {
54 : RESISTOR_traction_wire,
55 : CURRENT_SOURCE_traction_wire,
56 : VOLTAGE_SOURCE_traction_wire,
57 : ERROR_traction_wire
58 : };
59 :
60 : private:
61 : Node* pNode;
62 : Node* nNode;
63 : double voltage;
64 : double current;
65 : double resistance;
66 : double powerWanted;
67 : ElementType type;
68 : std::string name; // unique property, each object has distinctive and unique name
69 : int id; // a sequential ID number, might be useful when making the equation
70 : bool isenabled;
71 :
72 : public:
73 : // a constructor. same functionality as init functions in the last project
74 : Element(std::string name, ElementType type, double value);
75 :
76 : //getters and setters
77 : double getVoltage(); // get the voltage across the element
78 : double getCurrent(); // get the current running through the element
79 : double getResistance();
80 : double getPowerWanted();
81 : double getPower();
82 : int getId();
83 : Node* getPosNode();
84 : Node* getNegNode();
85 : ElementType getType();
86 : std::string getName();
87 : bool isEnabled();
88 :
89 : void setPosNode(Node* node);
90 : void setNegNode(Node* node);
91 : void setId(int id);
92 : void setVoltage(double voltage);
93 : void setCurrent(double current);
94 : void setResistance(double resistance);
95 : void setPowerWanted(double powerWanted);
96 : void setEnabled(bool isenabled);
97 :
98 : // if node == pNode, return nNode, else if node == nNode return pNode, else return NULL
99 : Node* getTheOtherNode(Node* node);
100 : // sets the type of elements
101 : void setType(ElementType ET);
102 :
103 : };
|