DPsim
Loading...
Searching...
No Matches
MNASolverPlugin.h
1/* Copyright 2017-2021 Institute for Automation of Complex Power Systems,
2 * EONERC, RWTH Aachen University
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
7 *********************************************************************************/
8
9#pragma once
10
11#include <dpsim/MNASolverDirect.h>
12#include <dpsim/MNASolverDynInterface.h>
13
14namespace DPsim {
15
16template <typename VarType>
17class MnaSolverPlugin : public MnaSolverDirect<VarType> {
18protected:
19 using Solver::mSLog;
20 String mPluginName;
21 struct dpsim_mna_plugin *mPlugin;
22 void *mDlHandle;
23
25 void initialize() override;
26 void recomputeSystemMatrix(Real time) override;
27 void solve(Real time, Int timeStepCount) override;
28
29public:
30 MnaSolverPlugin(String pluginName, String name,
31 CPS::Domain domain = CPS::Domain::DP,
32 CPS::Logger::Level logLevel = CPS::Logger::Level::info);
33
34 virtual ~MnaSolverPlugin();
35
36 CPS::Task::List getTasks() override;
37
38 class SolveTask : public CPS::Task {
39 public:
40 SolveTask(MnaSolverPlugin<VarType> &solver)
41 : Task(solver.mName + ".Solve"), mSolver(solver) {
42
43 for (auto it : solver.mMNAComponents) {
44 if (it->getRightVector()->get().size() != 0)
45 mAttributeDependencies.push_back(it->getRightVector());
46 }
47 for (auto node : solver.mNodes) {
48 mModifiedAttributes.push_back(node->mVoltage);
49 }
50 mModifiedAttributes.push_back(solver.mLeftSideVector);
51 }
52
53 void execute(Real time, Int timeStepCount) {
54 mSolver.solve(time, timeStepCount);
55 }
56
57 private:
58 MnaSolverPlugin<VarType> &mSolver;
59 };
60
61 class LogTask : public CPS::Task {
62 public:
63 LogTask(MnaSolverPlugin<VarType> &solver)
64 : Task(solver.mName + ".Log"), mSolver(solver) {
65 mAttributeDependencies.push_back(solver.mLeftSideVector);
66 mModifiedAttributes.push_back(Scheduler::external);
67 }
68
69 void execute(Real time, Int timeStepCount) {
70 mSolver.log(time, timeStepCount);
71 }
72
73 private:
74 MnaSolverPlugin<VarType> &mSolver;
75 };
76};
77
78} // namespace DPsim
Tasks to be defined by every component.
Definition Task.h:25
MnaSolverDirect(String name, CPS::Domain domain=CPS::Domain::DP, CPS::Logger::Level logLevel=CPS::Logger::Level::info)
CPS::MNAInterface::List mMNAComponents
List of MNA components with static stamp into system matrix.
Definition MNASolver.h:69
CPS::Attribute< Matrix >::Ptr mLeftSideVector
Solution vector of unknown quantities.
Definition MNASolver.h:196
CPS::SimNode< VarType >::List mNodes
List of simulation nodes.
Definition MNASolver.h:65
CPS::Task::List getTasks() override
Get tasks for scheduler.
void solve(Real time, Int timeStepCount) override
Solves system for single frequency.
void recomputeSystemMatrix(Real time) override
Recomputes systems matrix.
void initialize() override
Initialize cuSparse-library.
String mName
Name for logging.
Definition Solver.h:39
CPS::Logger::Log mSLog
Logger.
Definition Solver.h:45