JUK1
BJT.hpp
Go to the documentation of this file.
1 #ifndef _BJT_HPP_INC_
2 #define _BJT_HPP_INC_
5 
9 template<typename T>
10 struct BJTN : public Component<T> {
11  public:
12  size_t c = 0;
13  size_t b = 0;
14  size_t e = 0;
15 
16  T alpha_f = 0.99;
17  T alpha_r = 0.02;
18 
19  const T I_es = 2e-14;
20  const T V_Te = 26e-3;
21  const T I_cs = 99e-14;
22  const T V_Tc = 26e-3;
23 
24  T V_bc_crit = V_Tc * std::log(V_Tc / (I_cs * std::sqrt(2)));
25  T V_be_crit = V_Te * std::log(V_Te / (I_es * std::sqrt(2)));
26 
27 
28  void
29  addNonLinearStampTo(Stamp<T> & stamp, const Matrix<T> & solutionMatrix,
30  const size_t currentSolutionIndex, T timestep = 0) const {
31  const size_t bp = b - 1;
32  const size_t cp = c - 1;
33  const size_t ep = e - 1;
34 
35  T v_be = 0;
36  T v_bc = 0;
37 
38  if (b > 0) {
39  v_be = solutionMatrix(bp, currentSolutionIndex);
40  v_bc = solutionMatrix(bp, currentSolutionIndex);
41  }
42 
43  if (e > 0) {
44  v_be -= solutionMatrix(ep, currentSolutionIndex);
45  }
46 
47  if (c > 0) {
48  v_bc -= solutionMatrix(cp, currentSolutionIndex);
49  }
50 
51  v_be = std::min(V_be_crit, v_be);
52  v_bc = std::min(V_bc_crit, v_bc);
53 
54  T i_e = -I_es * (std::exp(v_be / V_Te) - 1) +
55  alpha_r * I_cs * (std::exp(v_bc / V_Tc) - 1);
56  T i_c = alpha_f * I_es * (std::exp(v_be / V_Te) - 1) -
57  I_cs * (std::exp(v_bc / V_Tc) - 1);
58  // T i_b = - ( i_e + i_c ); This is unused
59 
60  T g_ee = (I_es / V_Te) * std::exp(v_be / V_Te);
61  T g_ec = alpha_r * (I_cs / V_Tc) * std::exp(v_bc / V_Tc);
62  T g_ce = alpha_f * (I_es / V_Te) * std::exp(v_be / V_Te);
63  T g_cc = (I_cs / V_Tc) * std::exp(v_bc / V_Tc);
64 
65  T I_e = i_e + g_ee * v_be - g_ec * v_bc;
66  T I_c = i_c - g_ce * v_be + g_cc * v_bc;
67 
68  if (e > 0) {
69  stamp.G(ep, ep) += g_ee;
70  stamp.s(ep, 0) += -I_e;
71 
72  if (c > 0) {
73  stamp.G(ep, cp) += -g_ec;
74  }
75 
76  if (b > 0) {
77  stamp.G(ep, bp) += (g_ec - g_ee);
78  }
79  }
80 
81  if (c > 0) {
82  stamp.G(cp, cp) += g_cc;
83  stamp.s(cp, 0) += -I_c;
84 
85  if (e > 0) {
86  stamp.G(cp, ep) += -g_ce;
87  }
88 
89  if (b > 0) {
90  stamp.G(cp, bp) += (g_ce - g_cc);
91  }
92  }
93 
94  if (b > 0) {
95  stamp.G(bp, bp) += g_cc + g_ee - g_ce - g_ec;
96  stamp.s(bp, 0) += I_e + I_c;
97 
98  if (e > 0) {
99  stamp.G(bp, ep) += g_ce - g_ee;
100  }
101 
102  if (c > 0) {
103  stamp.G(bp, cp) += (g_ec - g_cc);
104  }
105  }
106  }
107 
108  void updateStoredState(const Matrix<T> & solutionMatrix,
109  const size_t currentSolutionIndex, T timestep,
110  size_t sizeG_A) {
111  }
112 
113  void addDCAnalysisStampTo(Stamp<T> & stamp, const Matrix<T> & solutionVector,
114  size_t numCurrents) const {
115  addNonLinearStampTo(stamp, solutionVector, 0, 0);
116  }
117 
118  static void
119  addToElements(const std::string & line, CircuitElements<T> & elements,
120  size_t & numNodes, size_t & numCurrents, size_t & numDCCurrents) {
121  std::regex BJTRegex = generateRegex("QN", "n n n");
122  BJTN<T> bjt;
123  std::smatch matches;
124 
125  std::regex_match(line, matches, BJTRegex);
126 
127  bjt.designator = "QN";
128  bjt.designator += matches.str(1);
129 
130  bjt.c = std::stoi(matches.str(2));
131  bjt.b = std::stoi(matches.str(3));
132  bjt.e = std::stoi(matches.str(4));
133 
134  numNodes = std::max(numNodes, std::stoull(matches.str(2)));
135  numNodes = std::max(numNodes, std::stoull(matches.str(3)));
136  numNodes = std::max(numNodes, std::stoull(matches.str(4)));
137 
138 
139  elements.nonLinearElements.emplace_back(std::make_shared<BJTN<T> >(bjt));
140  elements.nodeComponentMap.insert(
141  {{bjt.b, elements.nonLinearElements.back()},
142  {bjt.c, elements.nonLinearElements.back()},
143  {bjt.e, elements.nonLinearElements.back()}});
144  }
145 };
146 
150 template<typename T>
151 struct BJTP : public Component<T> {
152  public:
153  size_t c = 0;
154  size_t b = 0;
155  size_t e = 0;
156 
157  T alpha_f = 0.99;
158  T alpha_r = 0.02;
159 
160  const T I_es = 2e-14;
161  const T V_Te = 26e-3;
162  const T I_cs = 99e-14;
163  const T V_Tc = 26e-3;
164 
165  T V_bc_crit = V_Tc * std::log(V_Tc / (I_cs * std::sqrt(2)));
166  T V_be_crit = V_Te * std::log(V_Te / (I_es * std::sqrt(2)));
167 
168 
169  void
170  addNonLinearStampTo(Stamp<T> & stamp, const Matrix<T> & solutionMatrix,
171  const size_t currentSolutionIndex, T timestep = 0) const {
172  const size_t bp = b - 1;
173  const size_t cp = c - 1;
174  const size_t ep = e - 1;
175 
176  T v_be = 0;
177  T v_bc = 0;
178 
179  if (b > 0) {
180  v_be = solutionMatrix(bp, currentSolutionIndex);
181  v_bc = solutionMatrix(bp, currentSolutionIndex);
182  }
183 
184  if (e > 0) {
185  v_be -= solutionMatrix(ep, currentSolutionIndex);
186  }
187 
188  if (c > 0) {
189  v_bc -= solutionMatrix(cp, currentSolutionIndex);
190  }
191 
192  v_be = std::max(-V_be_crit, v_be);
193  v_bc = std::max(-V_bc_crit, v_bc);
194 
195  T i_F = I_cs * (std::exp(-v_bc / V_Tc) - 1);
196  T i_R = I_es * (std::exp(-v_be / V_Te) - 1);
197  T di_F = -(I_cs / V_Tc) * std::exp(-v_bc / V_Tc);
198  T di_R = -(I_es / V_Te) * std::exp(-v_be / V_Te);
199 
200  T i_e = i_R - alpha_f * i_F;
201  T i_b = (alpha_f - 1) * i_F + (alpha_r - 1) * i_R;
202  T i_c = i_F - alpha_r * i_R;
203 
204  T g_ee = di_F;
205  T g_ec = -alpha_r * di_R;
206  T g_ce = -alpha_f * di_F;
207  T g_cc = di_R;
208  T g_be = (alpha_r - 1) * di_R;
209  T g_bc = (alpha_f - 1) * di_F;
210 
211  T I_e = i_e - g_ee * v_be - g_ec * v_bc;
212  T I_c = i_c - g_ce * v_be - g_cc * v_bc;
213  T I_b = i_b - g_be * v_be - g_bc * v_bc;
214 
215  if (e > 0) {
216  stamp.G(ep, ep) += -g_ee;
217  stamp.s(ep, 0) += -I_e;
218 
219  if (c > 0) {
220  stamp.G(ep, cp) += -g_ec;
221  }
222 
223  if (b > 0) {
224  stamp.G(ep, bp) += g_ec + g_ee;
225  }
226  }
227 
228  if (c > 0) {
229  stamp.G(cp, cp) += -g_cc;
230  stamp.s(cp, 0) += -I_c;
231 
232  if (e > 0) {
233  stamp.G(cp, ep) += -g_ce;
234  }
235 
236  if (b > 0) {
237  stamp.G(cp, bp) += g_ce + g_cc;
238  }
239  }
240 
241  if (b > 0) {
242  stamp.G(bp, bp) += g_be + g_bc;
243  stamp.s(bp, 0) += -I_b;
244 
245  if (e > 0) {
246  stamp.G(bp, ep) += -g_be;
247  }
248 
249  if (c > 0) {
250  stamp.G(bp, cp) += -g_bc;
251  }
252  }
253  }
254 
255  void updateStoredState(const Matrix<T> & solutionMatrix,
256  const size_t currentSolutionIndex, T timestep,
257  size_t sizeG_A) {
258  }
259 
260  void addDCAnalysisStampTo(Stamp<T> & stamp, const Matrix<T> & solutionVector,
261  size_t numCurrents) const {
262  addNonLinearStampTo(stamp, solutionVector, 0, 0);
263  }
264 
265  static void
266  addToElements(const std::string & line, CircuitElements<T> & elements,
267  size_t & numNodes, size_t & numCurrents, size_t & numDCCurrents) {
268  std::regex BJTRegex = generateRegex("QP", "n n n");
269  BJTP<T> bjt;
270  std::smatch matches;
271 
272  std::regex_match(line, matches, BJTRegex);
273 
274  bjt.designator = "QP";
275  bjt.designator += matches.str(1);
276 
277  bjt.c = std::stoi(matches.str(2));
278  bjt.b = std::stoi(matches.str(3));
279  bjt.e = std::stoi(matches.str(4));
280 
281  numNodes = std::max(numNodes, std::stoull(matches.str(2)));
282  numNodes = std::max(numNodes, std::stoull(matches.str(3)));
283  numNodes = std::max(numNodes, std::stoull(matches.str(4)));
284 
285 
286  elements.nonLinearElements.emplace_back(std::make_shared<BJTP<T> >(bjt));
287  elements.nodeComponentMap.insert(
288  {{bjt.b, elements.nonLinearElements.back()},
289  {bjt.c, elements.nonLinearElements.back()},
290  {bjt.e, elements.nonLinearElements.back()}});
291  }
292 };
293 #endif
std::regex generateRegex(std::string indentifier, std::string simplifiedMatching, bool startAnchor=true, bool endAnchor=true)
a helper function to aid in the construction of regexes for parsing netlist files
common weighting for all matrix elements
Definition: QPpassive.m:47
A simple NPN BJT model.
Definition: BJT.hpp:10
size_t e
Definition: BJT.hpp:14
void updateStoredState(const Matrix< T > &solutionMatrix, const size_t currentSolutionIndex, T timestep, size_t sizeG_A)
Updates any stored state based on the current solution index.
Definition: BJT.hpp:108
const T V_Tc
Definition: BJT.hpp:22
T alpha_r
Definition: BJT.hpp:17
const T V_Te
Definition: BJT.hpp:20
T alpha_f
Definition: BJT.hpp:16
size_t b
Definition: BJT.hpp:13
size_t c
Definition: BJT.hpp:12
T V_be_crit
Definition: BJT.hpp:25
static void addToElements(const std::string &line, CircuitElements< T > &elements, size_t &numNodes, size_t &numCurrents, size_t &numDCCurrents)
Definition: BJT.hpp:119
T V_bc_crit
Definition: BJT.hpp:24
void addNonLinearStampTo(Stamp< T > &stamp, const Matrix< T > &solutionMatrix, const size_t currentSolutionIndex, T timestep=0) const
adds this component's non-linear stamp to the target stamp.
Definition: BJT.hpp:29
void addDCAnalysisStampTo(Stamp< T > &stamp, const Matrix< T > &solutionVector, size_t numCurrents) const
adds this component's DC stamp to the target stamp.
Definition: BJT.hpp:113
const T I_es
Definition: BJT.hpp:19
const T I_cs
Definition: BJT.hpp:21
A simple PNP BJT model.
Definition: BJT.hpp:151
T alpha_f
Definition: BJT.hpp:157
const T I_cs
Definition: BJT.hpp:162
void addDCAnalysisStampTo(Stamp< T > &stamp, const Matrix< T > &solutionVector, size_t numCurrents) const
adds this component's DC stamp to the target stamp.
Definition: BJT.hpp:260
const T I_es
Definition: BJT.hpp:160
static void addToElements(const std::string &line, CircuitElements< T > &elements, size_t &numNodes, size_t &numCurrents, size_t &numDCCurrents)
Definition: BJT.hpp:266
size_t e
Definition: BJT.hpp:155
const T V_Tc
Definition: BJT.hpp:163
T V_be_crit
Definition: BJT.hpp:166
void addNonLinearStampTo(Stamp< T > &stamp, const Matrix< T > &solutionMatrix, const size_t currentSolutionIndex, T timestep=0) const
adds this component's non-linear stamp to the target stamp.
Definition: BJT.hpp:170
size_t b
Definition: BJT.hpp:154
T alpha_r
Definition: BJT.hpp:158
void updateStoredState(const Matrix< T > &solutionMatrix, const size_t currentSolutionIndex, T timestep, size_t sizeG_A)
Updates any stored state based on the current solution index.
Definition: BJT.hpp:255
size_t c
Definition: BJT.hpp:153
const T V_Te
Definition: BJT.hpp:161
T V_bc_crit
Definition: BJT.hpp:165
a glorified container for the different types of components.
A template base class to define the fundamental things a component should define.
Definition: Component.hpp:108
std::string designator
The designator as in the netlist for e.g.
Definition: Component.hpp:110
A matrix class with support for LU-decomposition, and left division.
A helper struct to store the preallocated stamps for MNA.
Definition: Component.hpp:23
Matrix< T > s
Definition: Component.hpp:28
Matrix< T > G
Definition: Component.hpp:27