JUK1
VoltageSource.hpp
Go to the documentation of this file.
1 #ifndef _VOLTAGESOURCE_HPP_INC_
2 #define _VOLTAGESOURCE_HPP_INC_
5 
9 template<typename T>
10 struct VoltageSource : public Component<T> {
11  public:
12  T value = 0;
13 
14  size_t n1 = 0;
15  size_t n2 = 0;
16  size_t currentIndex = 0;
17 
18  void addStaticStampTo(Stamp<T> & stamp) const {
19  // the p means prime ( ' ) and is used for the index - 1
20  size_t n1p = n1 - 1;
21  size_t n2p = n2 - 1;
22  size_t currentIndexp = currentIndex - 1;
23 
24  if (n1) {
25  stamp.G(n1p, stamp.sizeG_A + currentIndexp) += 1;
26  stamp.G(stamp.sizeG_A + currentIndexp, n1p) += 1;
27  }
28  if (n2) {
29  stamp.G(n2p, stamp.sizeG_A + currentIndexp) += -1;
30  stamp.G(stamp.sizeG_A + currentIndexp, n2p) += -1;
31  }
32 
33  stamp.s(stamp.sizeG_A + currentIndexp, 0) += value;
34  }
35 
36  void addDCAnalysisStampTo(Stamp<T> & stamp, const Matrix<T> & solutionVector,
37  size_t numCurrents) const {
38  addStaticStampTo(stamp);
39  }
40 
41  static void
42  addToElements(const std::string & line, CircuitElements<T> & elements,
43  size_t & numNodes, size_t & numCurrents, size_t & numDCCurrents) {
44  // std::regex voltageSourceRegex( R"(^V(.*?)\s(\d+?)\s(\d+?)\s(.+?)\s?$)" );
45  std::regex voltageSourceRegex = generateRegex("V", "n n w");
46  VoltageSource<T> voltageSource;
47  std::smatch matches;
48 
49  std::regex_match(line, matches, voltageSourceRegex);
50 
51  voltageSource.designator = "V";
52  voltageSource.designator += matches.str(1);
53 
54  voltageSource.n1 = std::stoi(matches.str(2));
55  voltageSource.n2 = std::stoi(matches.str(3));
56 
57 
58  numNodes = std::max(numNodes, std::stoull(matches.str(2)));
59  numNodes = std::max(numNodes, std::stoull(matches.str(3)));
60 
61  if constexpr (std::is_same_v<T, double> || std::is_same_v<T, float>) {
62  voltageSource.value = std::stod(matches.str(4));
63  } else {
64  static_assert("Unsupported Type");
65  }
66 
67  voltageSource.currentIndex = ++numCurrents;
68 
69  elements.staticElements.emplace_back(
70  std::make_shared<VoltageSource<T> >(voltageSource));
71  elements.nodeComponentMap.insert(
72  {{voltageSource.n1, elements.staticElements.back()},
73  {voltageSource.n2, elements.staticElements.back()}});
74  }
75 };
76 
77 #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 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
size_t sizeG_A
Definition: Component.hpp:24
Matrix< T > G
Definition: Component.hpp:27
An ideal voltageSource.
void addStaticStampTo(Stamp< T > &stamp) const
Adds this component's static stamp to the target stamp.
static void addToElements(const std::string &line, CircuitElements< T > &elements, size_t &numNodes, size_t &numCurrents, size_t &numDCCurrents)
void addDCAnalysisStampTo(Stamp< T > &stamp, const Matrix< T > &solutionVector, size_t numCurrents) const
adds this component's DC stamp to the target stamp.