1 #ifndef _NLCAPACITOR_HPP_INC_
2 #define _NLCAPACITOR_HPP_INC_
28 const size_t currentSolutionIndex, T timestep = 0)
const {
29 const size_t n1p =
n1 - 1;
30 const size_t n2p =
n2 - 1;
35 u = solutionMatrix(n1p, currentSolutionIndex);
39 u -= solutionMatrix(n2p, currentSolutionIndex);
53 T I_eq = -G_eq * u +
i;
56 stamp.
G(n1p, n1p) += G_eq;
57 stamp.
s(n1p, 0) += -I_eq;
60 stamp.
G(n1p, n2p) += -G_eq;
65 stamp.
G(n2p, n2p) += G_eq;
66 stamp.
s(n2p, 0) += +I_eq;
69 stamp.
G(n2p, n1p) += -G_eq;
75 const size_t currentSolutionIndex, T timestep,
77 const size_t n1p =
n1 - 1;
78 const size_t n2p =
n2 - 1;
83 u = solutionMatrix(n1p, currentSolutionIndex);
87 u -= solutionMatrix(n2p, currentSolutionIndex);
100 size_t numCurrents) {
101 const size_t n1p =
n1 - 1;
102 const size_t n2p =
n2 - 1;
107 u = solutionVector(n1p, 0);
111 u -= solutionVector(n2p, 0);
124 size_t numCurrents)
const {
127 stamp.
G(
n1 - 1,
n1 - 1) += 1e-9;
130 stamp.
G(
n2 - 1,
n2 - 1) += 1e-9;
136 size_t & numNodes,
size_t & numCurrents,
size_t & numDCCurrents) {
137 std::regex capacitorRegex =
generateRegex(
"CN",
"n n w w w w");
141 std::regex_match(line, matches, capacitorRegex);
146 cap.
n1 = std::stoi(matches.str(2));
147 cap.
n2 = std::stoi(matches.str(3));
149 numNodes = std::max(numNodes, std::stoull(matches.str(2)));
150 numNodes = std::max(numNodes, std::stoull(matches.str(3)));
152 if constexpr (std::is_same_v<T, double> || std::is_same_v<T, float>) {
153 cap.
C_p = std::stod(matches.str(4));
154 cap.
C_o = std::stod(matches.str(5));
155 cap.
P_10 = std::stod(matches.str(6));
156 cap.
P_11 = std::stod(matches.str(7));
161 static_assert(
"Unsupported Type");
165 elements.nonLinearElements.emplace_back(
169 {cap.
n2,
elements.nonLinearElements.back()}});
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
a glorified container for the different types of components.
A template base class to define the fundamental things a component should define.
std::string designator
The designator as in the netlist for e.g.
A matrix class with support for LU-decomposition, and left division.
a non-linear capacitor model of the form C = C_p + C_o * ( 1.0 + tanh( P_10 + P_11 * u ) )
void addDCAnalysisStampTo(Stamp< T > &stamp, const Matrix< T > &solutionVector, size_t numCurrents) const
adds this component's DC stamp to the target stamp.
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
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.
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.
static void addToElements(const std::string &line, CircuitElements< T > &elements, size_t &numNodes, size_t &numCurrents, size_t &numDCCurrents)
A helper struct to store the preallocated stamps for MNA.