Commit 597ff4b6 authored by Markus Mirz's avatar Markus Mirz
Browse files

Merge branch 'fix-static-switch-num' into 'master'

MNASolver: Increase maximum switch number to theoretical limit

Closes #171 and #116

See merge request !173
parents 7efa0286 e7aba8d4
......@@ -21,7 +21,13 @@
#include <cps/SimSignalComp.h>
#include <cps/SimPowerComp.h>
#define SWITCH_NUM 16
/* std::size_t is the largest data type. No container can store
* more than std::size_t elements. Define the number of switches
* as the log_2 of this value so that we end up with maximally
* std::size_t matrices. The overhead of statically defining this
* value should be minimal.
**/
#define SWITCH_NUM sizeof(std::size_t)*8
namespace DPsim {
/// Solver class using Modified Nodal Analysis (MNA).
......
......@@ -52,7 +52,7 @@ void MnaSolver<VarType>::initialize() {
// The system topology is prepared and we create the MNA matrices.
createEmptyVectors();
createEmptySystemMatrix();
// Register attribute for solution vector
if (mFrequencyParallel) {
mSLog->info("Computing network harmonics in parallel.");
......@@ -165,14 +165,21 @@ void MnaSolver<VarType>::initializeSystem() {
mRightSideVector.setZero();
if (mFrequencyParallel) {
for (UInt i = 0; i < std::pow(2,mSwitches.size()); i++) {
for(Int freq = 0; freq < mSystem.mFrequencies.size(); freq++)
/* just a sanity check in case we change the static
* initialization of the switch number in the future */
if (mSwitches.size() > sizeof(std::size_t)*8) {
throw SystemError("Too many Switches.");
}
/* iterate over all possible switch state combinations */
for (std::size_t i = 0; i < (1ULL << mSwitches.size()); i++) {
for(Int freq = 0; freq < mSystem.mFrequencies.size(); freq++) {
mSwitchedMatricesHarm[std::bitset<SWITCH_NUM>(i)][freq].setZero();
}
}
}
else {
for (UInt i = 0; i < std::pow(2,mSwitches.size()); i++)
} else {
for (std::size_t i = 0; i < (1ULL << mSwitches.size()); i++) {
mSwitchedMatrices[std::bitset<SWITCH_NUM>(i)].setZero();
}
}
if (mFrequencyParallel) {
......@@ -308,8 +315,9 @@ void MnaSolver<Real>::createEmptySystemMatrix() {
if (mSwitches.size() > SWITCH_NUM)
throw SystemError("Too many Switches.");
for (UInt i = 0; i < std::pow(2,mSwitches.size()); i++)
for (std::size_t i = 0; i < (1ULL << mSwitches.size()); i++) {
mSwitchedMatrices[std::bitset<SWITCH_NUM>(i)] = Matrix::Zero(mNumMatrixNodeIndices, mNumMatrixNodeIndices);
}
}
template<>
......@@ -326,8 +334,9 @@ void MnaSolver<Complex>::createEmptySystemMatrix() {
}
}
else {
for (UInt i = 0; i < std::pow(2,mSwitches.size()); i++)
for (std::size_t i = 0; i < (1ULL << mSwitches.size()); i++) {
mSwitchedMatrices[std::bitset<SWITCH_NUM>(i)] = Matrix::Zero(2*(mNumMatrixNodeIndices + mNumHarmMatrixNodeIndices), 2*(mNumMatrixNodeIndices + mNumHarmMatrixNodeIndices));
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment