-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDevice.hpp
executable file
·169 lines (130 loc) · 5.16 KB
/
Device.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*
MIT License
Copyright (c) 2017 Joe Hood
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef DEVICE_H
#define DEVICE_H
enum sourceType { DCSOURCE, SINESOURCE, SQUARESOURCE, TRISOURCE };
class Simulator;
/**
Generic device type that defines the interface that needs to be implemented by derived
device classes, like Resistor, Inductor, Capacitor, Voltage, etc
**/
class Device
{
public:
/////////////// Device Interface ///////////////
/*
NOTE: The derived device must implement it's own contructor that takes in the node
indices and device parameters, and stores them in member variables
*/
/**
This function is where you should do any pre-simulation set up. Also, you should
get and store integer values for internal nodes here with the GetNextNode() function
(example: nodep = GetNextNode())
*/
virtual void Init();
/**
Stamps the DC model of the device for DC operating point calculation (optional,
default behavior is to call Step(0, 0)).
*/
virtual void DC();
/**
Steps the device for transient analysis.
Its function is to implement the behavior needed for transient analysis (.trans).
It takes in the current time (s) and time step (s), and applies the stamps to the J
and B matrices accordingly
@param t is the current simulation time in seconds
@param dt is the current simulation time step in seconds
*/
virtual void Step(double t, double dt);
/**
Steps the device to update the simulator signals.
It takes in the current time (s) and time step (s), and you should get and/or set
signals her with the GetSignal() and SetSignal() function
@param t is the current simulation time in seconds
@param dt is the current simulation time step in seconds
*/
virtual void SignalStep(double t, double dt);
///////////// End Device Interface /////////////
// This function exists to set the parent simulator instance:
void SetSim(Simulator& sim);
protected:
// reference to the parent simulator object:
Simulator* sim;
// utility functions for accessing sim matrices
// (wrappers around simulator accessors):
/*
Wrapper for Simulator::GetTime() const
*/
double GetTime() const;
/*
Wrapper for Simulator::GetTimeStep() const
*/
double GetTimeStep() const;
/*
Wrapper for Simulator::GetState(const int i) const
*/
double GetState(const int i) const;
/*
Wrapper for Simulator::GetIterationState(const int i) const
*/
double GetIterationState(const int i) const;
/*
Wrapper for Simulator::GetStateDifference(const int i, const int j) const
*/
double GetStateDifference(const int i, const int j) const;
/*
Wrapper for Simulator::GetIterationStateDifference(const int i, const int j) const
*/
double GetIterationStateDifference(const int i, const int j) const;
/*
Wrapper for Simulator::GetJacobian(const int i, const int j) const
*/
double GetJacobian(const int i, const int j) const;
/*
Wrapper for Simulator::GetBEquivalent(const int i) const
*/
double GetBEquivalent(const int i) const;
/*
Allows the addition of internal nodes
*/
int GetNextNode();
/*
Wrapper for Simulator::SetInitialState(const int i, const double value)
*/
void SetInitialState(const int i, const double value);
/*
Wrapper for Simulator::AddJacobian(const int i, const int j, const double value)
*/
void AddJacobian(const int i, const int j, const double value);
/*
Wrapper for Simulator::AddBEquivalent(const int i, const double value)
*/
void AddBEquivalent(const int i, const double value);
///////////////// Signal Solver interface //////////////////////
/*
Wrapper for const double Simulator::GetSignal(const int signal) const
*/
double GetSignal(const int signal) const;
/*
Wrapper for Simulator::SetSignal(const int signal, const double value)
*/
void SetSignal(const int signal, const double value);
};
#endif