Skip to content

Commit

Permalink
fixed minor details
Browse files Browse the repository at this point in the history
Signed-off-by: Lennart Schumacher <[email protected]>
  • Loading branch information
Lennart Schumacher committed Jul 2, 2022
1 parent 9994f5f commit 48595d5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
8 changes: 4 additions & 4 deletions Source/MNASolverEigenPartialNICSLU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#define BRA 2
#define FP 1
#define AMD 0
#define ORDERING FP
#define ORDERING AMD

using namespace DPsim;
using namespace CPS;
Expand Down Expand Up @@ -60,17 +60,17 @@ void MnaSolverEigenPartialNICSLU<VarType>::stampVariableSystemMatrix() {
// Calculate factorization of current matrix

/* Preprocessing with different ordering methods
* -> last argument of analyzePatternPartial
* -> last argument of analyzePatternPartial [ORDERING]
* 0: regular AMD
* 1: partial ordering
* 2: bottom-right arranging
* maybe make those macros: #define BRA 2, ...
* 3: canadian method (not an ordering per se, but it's set as a parameter in NICSLU, so it knows what to do)
* */
this->mLuFactorizationVariableSystemMatrix.analyzePatternPartial(this->mVariableSystemMatrix, this->mListVariableSystemMatrixEntries, ORDERING);

// factorization with factorization path computation
auto start = std::chrono::steady_clock::now();
this->mLuFactorizationVariableSystemMatrix.factorize_partial(this->mVariableSystemMatrix, this->mListVariableSystemMatrixEntries);
this->mLuFactorizationVariableSystemMatrix.factorize_partial(this->mVariableSystemMatrix);
auto end = std::chrono::steady_clock::now();

// compute factorization (+ path comp.) time
Expand Down
36 changes: 29 additions & 7 deletions Source/MNASolverEigenSparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ void MnaSolverEigenSparse<VarType>::switchedMatrixStamp(std::size_t index, std::

// Compute LU-factorization for system matrix
mLuFactorizations[bit][0]->analyzePattern(sys);
auto start = std::chrono::steady_clock::now();
mLuFactorizations[bit][0]->factorize(sys);
auto end = std::chrono::steady_clock::now();
std::chrono::duration<double> diff = end-start;
mLUTimes.push_back(diff.count());
}

template <typename VarType>
Expand Down Expand Up @@ -79,7 +83,11 @@ void MnaSolverEigenSparse<VarType>::stampVariableSystemMatrix() {

// Calculate factorization of current matrix
mLuFactorizationVariableSystemMatrix.analyzePattern(mVariableSystemMatrix);
auto start = std::chrono::steady_clock::now();
mLuFactorizationVariableSystemMatrix.factorize(mVariableSystemMatrix);
auto end = std::chrono::steady_clock::now();
std::chrono::duration<double> diff = end-start;
mLUTimes.push_back(diff.count());
}

template <typename VarType>
Expand All @@ -97,7 +105,12 @@ void MnaSolverEigenSparse<VarType>::solveWithSystemMatrixRecomputation(Real time
recomputeSystemMatrix(time);

// Calculate new solution vector
mLeftSideVector = mLuFactorizationVariableSystemMatrix.solve(mRightSideVector);
auto start = std::chrono::steady_clock::now();
mLeftSideVector = mLuFactorizationVariableSystemMatrix.solve(mRightSideVector);

auto end = std::chrono::steady_clock::now();
std::chrono::duration<double> diff = end-start;
mSolveTimes.push_back(diff.count());

// TODO split into separate task? (dependent on x, updating all v attributes)
for (UInt nodeIdx = 0; nodeIdx < mNumNetNodes; ++nodeIdx)
Expand All @@ -121,7 +134,13 @@ void MnaSolverEigenSparse<VarType>::recomputeSystemMatrix(Real time) {

// Refactorization of matrix assuming that structure remained
// constant by omitting analyzePattern

auto start = std::chrono::steady_clock::now();
// Compute LU-factorization for system matrix
mLuFactorizationVariableSystemMatrix.factorize(mVariableSystemMatrix);
auto end = std::chrono::steady_clock::now();
std::chrono::duration<double> diff = end-start;
mRecomputationTimes.push_back(diff.count());
++mNumRecomputations;
}

Expand Down Expand Up @@ -204,9 +223,13 @@ void MnaSolverEigenSparse<VarType>::solve(Real time, Int timeStepCount) {
if (!mIsInInitialization)
MnaSolver<VarType>::updateSwitchStatus();

auto start = std::chrono::steady_clock::now();
if (mSwitchedMatrices.size() > 0)
mLeftSideVector = mLuFactorizations[mCurrentSwitchStatus][0]->solve(mRightSideVector);

auto end = std::chrono::steady_clock::now();
std::chrono::duration<double> diff = end-start;
mSolveTimes.push_back(diff.count());

// TODO split into separate task? (dependent on x, updating all v attributes)
for (UInt nodeIdx = 0; nodeIdx < mNumNetNodes; ++nodeIdx)
Expand Down Expand Up @@ -264,6 +287,10 @@ void MnaSolverEigenSparse<VarType>::logSystemMatrices() {
mSLog->info("Right side vector: \n{}", mRightSideVector);
}
}
}

template class DPsim::MnaSolverEigenSparse<Real>;
template class DPsim::MnaSolverEigenSparse<Complex>;

template <typename VarType>
void MnaSolverEigenSparse<VarType>::logLUTime()
Expand All @@ -288,7 +315,6 @@ void MnaSolverEigenSparse<VarType>::logSolveTime(){
mSLog->info("Maximum solve time: {:.12f}", solveMax);
mSLog->info("Number of solves: {:d}", mSolveTimes.size());
}

template <typename VarType>
void MnaSolverEigenSparse<VarType>::logRecomputationTime(){
Real recompSum = 0.0;
Expand All @@ -305,8 +331,4 @@ void MnaSolverEigenSparse<VarType>::logRecomputationTime(){
mSLog->info("Maximum refactorization time: {:.12f}", recompMax);
mSLog->info("Number of refactorizations: {:d}", mRecomputationTimes.size());
}
}
}

template class DPsim::MnaSolverEigenSparse<Real>;
template class DPsim::MnaSolverEigenSparse<Complex>;
}
2 changes: 1 addition & 1 deletion models/Include/cps/Definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ namespace CPS {
///
typedef Eigen::SparseLU<SparseMatrix> LUFactorizedSparse;
///
typedef Eigen::NICSLU<Matrix> LUFactorizedNICSLU;
typedef Eigen::NICSLU<SparseMatrix> LUFactorizedNICSLU;
///
typedef Eigen::Matrix<Real, Eigen::Dynamic, 1> Vector;
///
Expand Down

0 comments on commit 48595d5

Please sign in to comment.