JUK1
Diode.hpp
Go to the documentation of this file.
1 #ifndef _DIODE_HPP_INC_
2 #define _DIODE_HPP_INC_
5 
6 
10 template<typename T>
11 struct Diode : public Component<T> {
12  public:
13  size_t n1 = 0;
14  size_t n2 = 0;
15 
16  const T I_sat = 2.52e-9;
17  const T V_T = 25.8563e-3;
18  const T eta = 2;
19 
20  T V_crit = eta * V_T * std::log(eta * V_T / (I_sat * std::sqrt(2)));
21 
22 
23  void
24  addNonLinearStampTo(Stamp<T> & stamp, const Matrix<T> & solutionMatrix,
25  const size_t currentSolutionIndex, T timestep = 0) const {
26  const size_t n1p = n1 - 1;
27  const size_t n2p = n2 - 1;
28 
29  T v = 0;
30 
31  if (n1 > 0) {
32  v = solutionMatrix(n1p, currentSolutionIndex);
33  }
34 
35  if (n2 > 0) {
36  v -= solutionMatrix(n2p, currentSolutionIndex);
37  }
38 
39  v = std::min(V_crit, v);
40 
41  T G_eq = (I_sat / (eta * V_T)) * std::exp(v / (eta * V_T));
42  T I_eq = I_sat * (std::exp(v / (eta * V_T)) - 1) - G_eq * v;
43 
44  if (n1 > 0) {
45  stamp.G(n1p, n1p) += G_eq;
46  stamp.s(n1p, 0) += -I_eq;
47  }
48 
49  if (n2 > 0) {
50  stamp.G(n2p, n2p) += G_eq;
51  stamp.s(n2p, 0) += +I_eq;
52  }
53 
54  if (n1 > 0 && n2 > 0) {
55  stamp.G(n1p, n2p) += -G_eq;
56  stamp.G(n2p, n1p) += -G_eq;
57  }
58  }
59 
60  void updateStoredState(const Matrix<T> & solutionMatrix,
61  const size_t currentSolutionIndex, T timestep,
62  size_t sizeG_A) {
63  }
64 
65  void addDCAnalysisStampTo(Stamp<T> & stamp, const Matrix<T> & solutionVector,
66  size_t numCurrents) const {
67  addNonLinearStampTo(stamp, solutionVector, 0, 0);
68  }
69 
70  static void
71  addToElements(const std::string & line, CircuitElements<T> & elements,
72  size_t & numNodes, size_t & numCurrents, size_t & numDCCurrents) {
73  std::regex diodeRegex = generateRegex("D", "n n");
74  Diode<T> diode;
75  std::smatch matches;
76 
77  std::regex_match(line, matches, diodeRegex);
78 
79  diode.designator = "D";
80  diode.designator += matches.str(1);
81 
82  diode.n1 = std::stoi(matches.str(2));
83  diode.n2 = std::stoi(matches.str(3));
84 
85  numNodes = std::max(numNodes, std::stoull(matches.str(2)));
86  numNodes = std::max(numNodes, std::stoull(matches.str(3)));
87 
88  elements.nonLinearElements.emplace_back(std::make_shared<Diode<T> >(diode));
89  elements.nodeComponentMap.insert(
90  {{diode.n1, elements.nonLinearElements.back()},
91  {diode.n2, elements.nonLinearElements.back()}});
92  }
93 };
94 
95 #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
v
Definition: comp.m:4
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
An ebbers moll diode model.
Definition: Diode.hpp:11
static void addToElements(const std::string &line, CircuitElements< T > &elements, size_t &numNodes, size_t &numCurrents, size_t &numDCCurrents)
Definition: Diode.hpp:71
const T I_sat
Definition: Diode.hpp:16
const T V_T
Definition: Diode.hpp:17
const T eta
Definition: Diode.hpp:18
size_t n2
Definition: Diode.hpp:14
size_t n1
Definition: Diode.hpp:13
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: Diode.hpp:60
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: Diode.hpp:24
T V_crit
Definition: Diode.hpp:20
void addDCAnalysisStampTo(Stamp< T > &stamp, const Matrix< T > &solutionVector, size_t numCurrents) const
adds this component's DC stamp to the target stamp.
Definition: Diode.hpp:65
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