JUK1
Component.hpp
Go to the documentation of this file.
1 #ifndef _COMPONENT_HPP_INC_
2 #define _COMPONENT_HPP_INC_
5 #include <regex>
6 #include <algorithm>
7 #include <map>
8 
9 template<typename T>
10 struct Component;
11 
22 template<typename T>
23 struct Stamp {
24  size_t sizeG_A;
25  size_t sizeG_D;
26 
29 
36  Stamp(size_t _sizeG_A, size_t _sizeG_D)
37  : sizeG_A(_sizeG_A), sizeG_D(_sizeG_D),
38  G(_sizeG_A + _sizeG_D, _sizeG_A + _sizeG_D, 0),
39  s(_sizeG_A + _sizeG_D, 1, 0) {
40  }
41 
43  void clear() {
44  G.fill(0);
45  s.fill(0);
46  }
47 
52  void add(const Stamp<T> & rhs) {
53  G.add(rhs.G, G);
54  s.add(rhs.s, s);
55  }
56 
60  void addStaticStamp(const std::shared_ptr<Component<T> > & rhs) {
61  rhs->addStaticStampTo(*this);
62  }
63 
67  void addDynamicStamp(const std::shared_ptr<Component<T> > & rhs,
68  const Matrix<T> & solutionMatrix,
69  const size_t currentSolutionIndex, T timestep) {
70  rhs->addDynamicStampTo(*this, solutionMatrix, currentSolutionIndex,
71  timestep);
72  }
73 
77  void addNonLinearStamp(const std::shared_ptr<Component<T> > & rhs,
78  const Matrix<T> & solutionMatrix,
79  const size_t currentSolutionIndex, T timestep = 0) {
80  rhs->addNonLinearStampTo(*this, solutionMatrix, currentSolutionIndex,
81  timestep);
82  }
83 
87  void
88  addDCAnalysisStamp(const std::shared_ptr<Component<T> > & rhs,
89  const Matrix<T> & solutionMatrix, const size_t numCurrents) {
90  rhs->addDCAnalysisStampTo(*this, solutionMatrix, numCurrents);
91  }
92 
97  return G.leftDivide(s);
98  }
99 };
100 
101 template<typename T>
102 struct CircuitElements;
107 template<typename T>
108 struct Component {
110  std::string designator = "";
111 
115  virtual void addStaticStampTo(Stamp<T> & destination) const {
116  }
117 
124  virtual void
125  addDynamicStampTo(Stamp<T> & destination, const Matrix<T> & solutionMatrix,
126  const size_t currentSolutionIndex, T timestep) const {
127  }
128 
135  virtual void
136  addNonLinearStampTo(Stamp<T> & destination, const Matrix<T> & solutionMatrix,
137  const size_t currentSolutionIndex, T timestep = 0) const {
138  throw std::exception("not implemented");
139  }
140 
148  virtual void updateStoredState(const Matrix<T> & solutionMatrix,
149  const size_t currentSolutionIndex, T timestep,
150  size_t numCurrents) {
151  }
152 
158  virtual void
159  addDCAnalysisStampTo(Stamp<T> & destination, const Matrix<T> & solutionVector,
160  size_t numCurrents) const {
161  throw std::exception("not implemented");
162  }
163 
170  virtual void updateDCStoredState(const Matrix<T> & solutionVector,
171  size_t sizeG_A, size_t numCurrents) {
172  }
173 
177  virtual void setTimestep(T timestep) {
178  }
179 
188  static void
189  addToElements(const std::string & line, CircuitElements<T> & elements,
190  size_t & numNodes, size_t & numCurrents, size_t & numDCCurrents) {
191  throw std::exception("not implemented");
192  }
193 
194  virtual ~Component() {};
195 };
196 
197 #endif
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
static void addToElements(const std::string &line, CircuitElements< T > &elements, size_t &numNodes, size_t &numCurrents, size_t &numDCCurrents)
Called as a helper to add the component to the elements class.
Definition: Component.hpp:189
virtual ~Component()
Definition: Component.hpp:194
virtual void addNonLinearStampTo(Stamp< T > &destination, const Matrix< T > &solutionMatrix, const size_t currentSolutionIndex, T timestep=0) const
adds this component's non-linear stamp to the target stamp.
Definition: Component.hpp:136
virtual void setTimestep(T timestep)
initialises the component
Definition: Component.hpp:177
virtual void addStaticStampTo(Stamp< T > &destination) const
Adds this component's static stamp to the target stamp.
Definition: Component.hpp:115
virtual void addDCAnalysisStampTo(Stamp< T > &destination, const Matrix< T > &solutionVector, size_t numCurrents) const
adds this component's DC stamp to the target stamp.
Definition: Component.hpp:159
virtual void updateDCStoredState(const Matrix< T > &solutionVector, size_t sizeG_A, size_t numCurrents)
a function to update the stored state of a component based on a DC value
Definition: Component.hpp:170
virtual void addDynamicStampTo(Stamp< T > &destination, const Matrix< T > &solutionMatrix, const size_t currentSolutionIndex, T timestep) const
Adds this component's dynamic stamp to the target stamp.
Definition: Component.hpp:125
virtual void updateStoredState(const Matrix< T > &solutionMatrix, const size_t currentSolutionIndex, T timestep, size_t numCurrents)
Updates any stored state based on the current solution index.
Definition: Component.hpp:148
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
void addDCAnalysisStamp(const std::shared_ptr< Component< T > > &rhs, const Matrix< T > &solutionMatrix, const size_t numCurrents)
A helper function to add a DC component to the stamp.
Definition: Component.hpp:88
void addDynamicStamp(const std::shared_ptr< Component< T > > &rhs, const Matrix< T > &solutionMatrix, const size_t currentSolutionIndex, T timestep)
A helper function to add a dynamic component to the stamp.
Definition: Component.hpp:67
void clear()
Clears the stamps to 0s.
Definition: Component.hpp:43
Matrix< T > s
Definition: Component.hpp:28
Matrix< T > solve()
An alias for left dividing G by s.
Definition: Component.hpp:96
size_t sizeG_A
Definition: Component.hpp:24
Stamp(size_t _sizeG_A, size_t _sizeG_D)
Sets the initial size of the stamp pair.
Definition: Component.hpp:36
Matrix< T > G
Definition: Component.hpp:27
size_t sizeG_D
Definition: Component.hpp:25
void addNonLinearStamp(const std::shared_ptr< Component< T > > &rhs, const Matrix< T > &solutionMatrix, const size_t currentSolutionIndex, T timestep=0)
A helper function to add a non-linear component to the stamp.
Definition: Component.hpp:77
void add(const Stamp< T > &rhs)
Combines two stamps together into the current stamp. This is not done via the operator,...
Definition: Component.hpp:52
void addStaticStamp(const std::shared_ptr< Component< T > > &rhs)
A helper function to add a static component to the stamp.
Definition: Component.hpp:60