Skip to content

Commit

Permalink
Use Scheduler for eigenvalue extraction at each time step
Browse files Browse the repository at this point in the history
-Create a class ExtractEigenvaluesTask, inheriting from Task class and nested in MNASolverDirect.

Signed-off-by: Georgii Tishenin <[email protected]>
  • Loading branch information
georgii-tishenin committed Jan 29, 2024
1 parent 932e430 commit 4f0d47e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
2 changes: 2 additions & 0 deletions dpsim/include/dpsim/MNASolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ namespace DPsim {
virtual std::shared_ptr<CPS::Task> createLogTask() = 0;
/// Create a solve task for this solver implementation
virtual std::shared_ptr<CPS::Task> createSolveTaskHarm(UInt freqIdx) = 0;
/// Create a task for eigenvalues extraction
virtual std::shared_ptr<CPS::Task> createExtractEigenvaluesTask() = 0;

// #### Scheduler Task Methods ####
/// Solves system for single frequency
Expand Down
21 changes: 21 additions & 0 deletions dpsim/include/dpsim/MNASolverDirect.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ namespace DPsim {
std::shared_ptr<CPS::Task> createLogTask() override;
/// Create a solve task for this solver implementation
std::shared_ptr<CPS::Task> createSolveTaskHarm(UInt freqIdx) override;
/// Create a task for eigenvalue extraction
std::shared_ptr<CPS::Task> createExtractEigenvaluesTask() override;
/// Logging of system matrices and source vector
void logSystemMatrices() override;
/// Solves system for single frequency
Expand Down Expand Up @@ -257,6 +259,25 @@ namespace DPsim {
MnaSolverDirect<VarType>& mSolver;
};

///
class ExtractEigenvaluesTask : public CPS::Task
{
public:
ExtractEigenvaluesTask(MnaSolverDirect<VarType> &solver) : Task(solver.mName + ".ExtractEigenvalues"), mSolver(solver)
{
mAttributeDependencies.push_back(solver.mLeftSideVector);
mModifiedAttributes.push_back(Scheduler::external);
}

void execute(Real time, Int timeStepCount)
{
mSolver.extractEigenvalues(time, timeStepCount);
}

private:
MnaSolverDirect<VarType> &mSolver;
};

///
class LogTask : public CPS::Task {
public:
Expand Down
4 changes: 4 additions & 0 deletions dpsim/src/MNASolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,10 @@ Task::List MnaSolver<VarType>::getTasks() {
l.push_back(createSolveTaskRecomp());
} else {
l.push_back(createSolveTask());
if (mEigenvalueExtractionMode == CPS::EigenvalueExtractionMode::AtEveryStep)
{
l.push_back(createExtractEigenvaluesTask());
}
l.push_back(createLogTask());
}
return l;
Expand Down
11 changes: 6 additions & 5 deletions dpsim/src/MNASolverDirect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,12 @@ std::shared_ptr<CPS::Task> MnaSolverDirect<VarType>::createSolveTaskHarm(UInt fr
return std::make_shared<MnaSolverDirect<VarType>::SolveTaskHarm>(*this, freqIdx);
}

template <typename VarType>
std::shared_ptr<CPS::Task> MnaSolverDirect<VarType>::createExtractEigenvaluesTask()
{
return std::make_shared<MnaSolverDirect<VarType>::ExtractEigenvaluesTask>(*this);
}

template <typename VarType>
std::shared_ptr<CPS::Task> MnaSolverDirect<VarType>::createLogTask()
{
Expand Down Expand Up @@ -290,11 +296,6 @@ void MnaSolverDirect<VarType>::solve(Real time, Int timeStepCount) {
mNodes[nodeIdx]->mnaUpdateVoltage(**mLeftSideVector);

// Components' states will be updated by the post-step tasks

if (Solver::mEigenvalueExtractionMode == CPS::EigenvalueExtractionMode::AtEveryStep)
{
extractEigenvalues(time, timeStepCount); // TODO: [Georgii] create task instead of calling in solve()
}
}

template <typename VarType>
Expand Down

0 comments on commit 4f0d47e

Please sign in to comment.