1 #ifndef _TIMESERIESVOLTAGESOURCE_INC_
2 #define _TIMESERIESVOLTAGESOURCE_INC_
20 T
lerp(
size_t lowIndex, T timeVal)
const {
26 return dataSeries[lowIndex] + diffDS * diffTV / diffTS;
30 const size_t currentSolutionIndex, T timestep)
const {
35 T timeMod = std::fmod(currentSolutionIndex * timestep,
timeSeries.back());
37 (timeSeriesIndex != 0 &&
39 timeSeriesIndex = (timeSeriesIndex + 1) %
timeSeries.size();
43 stamp.
G(n1p, stamp.
sizeG_A + currentIndexp) += 1;
44 stamp.
G(stamp.
sizeG_A + currentIndexp, n1p) += 1;
48 stamp.
G(n2p, stamp.
sizeG_A + currentIndexp) += -1;
49 stamp.
G(stamp.
sizeG_A + currentIndexp, n2p) += -1;
52 stamp.
s(stamp.
sizeG_A + currentIndexp, 0) +=
lerp(timeSeriesIndex, timeMod);
56 const size_t currentSolutionIndex, T timestep,
58 while (std::fmod(currentSolutionIndex * timestep,
timeSeries.back()) >
61 std::fmod(currentSolutionIndex * timestep,
timeSeries.back()) <
68 size_t numCurrents)
const {
74 size_t & numNodes,
size_t & numCurrents,
size_t & numDCCurrents) {
76 std::regex timeSeriesVoltageSourceRegex =
generateRegex(
"VT",
"n n w s",
82 std::regex_search(line, matches, timeSeriesVoltageSourceRegex);
87 voltageSource.
n1 = std::stoi(matches.str(2));
88 voltageSource.
n2 = std::stoi(matches.str(3));
90 numNodes = std::max(numNodes, std::stoull(matches.str(2)));
91 numNodes = std::max(numNodes, std::stoull(matches.str(3)));
94 if constexpr (std::is_same_v<T, double> || std::is_same_v<T, float>) {
95 timescale = std::stod(matches.str(4));
97 static_assert(
"Unsupported Type");
103 std::regex endOfLineRegex(R
"(^(.*)$)");
104 std::regex_search(matches.suffix().first, line.cend(), matches,
107 std::string seriesPath = matches.str(1);
110 elements.dynamicElements.emplace_back(
113 {{voltageSource.n1, elements.dynamicElements.back()},
114 {voltageSource.n2, elements.dynamicElements.back()}});
118 std::ifstream file(seriesPath);
124 while (!file.eof()) {
125 if (!std::isdigit(file.peek())) {
126 std::getline(file, line);
132 while (!std::isdigit(file.peek()) &&
133 !(file.peek() ==
'-' || file.peek() ==
'+')) {
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 helper struct to store the preallocated stamps for MNA.
A time series voltage source model.
size_t lastTimeSeriesIndex
T lerp(size_t lowIndex, T timeVal) const
void readInTimeSeries(T timescale, const std::string &seriesPath)
void addDCAnalysisStampTo(Stamp< T > &stamp, const Matrix< T > &solutionVector, size_t numCurrents) const
adds this component's DC 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.
std::vector< T > dataSeries
static void addToElements(const std::string &line, CircuitElements< T > &elements, size_t &numNodes, size_t &numCurrents, size_t &numDCCurrents)
void addDynamicStampTo(Stamp< T > &stamp, const Matrix< T > &solutionMatrix, const size_t currentSolutionIndex, T timestep) const
Adds this component's dynamic stamp to the target stamp.
std::vector< T > timeSeries