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