DPsim
Loading...
Searching...
No Matches
DiakopticsSolver.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-models/AttributeList.h>
12#include <dpsim-models/SimSignalComp.h>
13#include <dpsim-models/Solver/MNAInterface.h>
14#include <dpsim/DataLogger.h>
15#include <dpsim/Solver.h>
16
17#include <unordered_map>
18
19namespace DPsim {
20template <typename VarType>
21class DiakopticsSolver : public Solver, public CPS::AttributeList {
22private:
23 struct Subnet {
25 typename CPS::SimNode<VarType>::List nodes;
27 CPS::MNAInterface::List components;
29 UInt sysSize;
31 UInt mCmplOff;
33 UInt mRealNetNodeNum;
35 UInt mVirtualNodeNum;
37 UInt sysOff;
39 CPS::LUFactorized luFactorization;
41 std::vector<const Matrix *> rightVectorStamps;
43 CPS::Attribute<Matrix>::Ptr leftVector;
44 };
45
47 Real mSystemFrequency;
49 CPS::SystemTopology mSystem;
50
52 std::shared_ptr<DataLogger> mLeftVectorLog;
54 std::shared_ptr<DataLogger> mRightVectorLog;
55
56 std::vector<Subnet> mSubnets;
57 std::unordered_map<typename CPS::SimNode<VarType>::Ptr, Subnet *>
58 mNodeSubnetMap;
59 typename CPS::SimPowerComp<VarType>::List mTearComponents;
60 CPS::SimSignalComp::List mSimSignalComps;
61
62 Matrix mRightSideVector;
63 Matrix mLeftSideVector;
65 Matrix mSystemMatrix;
67 Matrix mSystemInverse;
69 Matrix mTearTopology;
71 CPS::SparseMatrixRow mTearImpedance;
74 CPS::LUFactorized mTotalTearImpedance;
76 Matrix mTearCurrents;
78 Matrix mTearVoltages;
79
80 void init(CPS::SystemTopology &system);
81
82 void initSubnets(const std::vector<CPS::SystemTopology> &subnets);
83 void collectVirtualNodes(int net);
84 void assignMatrixNodeIndices(int net);
85 void setSubnetSize(int net, UInt nodes);
86
87 void setLogColumns();
88
89 void createMatrices();
90 void createTearMatrices(UInt totalSize);
91
92 void initComponents();
93
94 void initMatrices();
95 void applyTearComponentStamp(UInt compIdx);
96
97 void log(Real time, Int timeStepCount) override;
98
99public:
101 const CPS::Attribute<Matrix>::Ptr mMappedTearCurrents;
102
104 const CPS::Attribute<Matrix>::Ptr mOrigLeftSideVector;
105
106 DiakopticsSolver(String name, CPS::SystemTopology system,
107 CPS::IdentifiedObject::List tearComponents, Real timeStep,
108 CPS::Logger::Level logLevel);
109
110 CPS::Task::List getTasks() override;
111
112 class SubnetSolveTask : public CPS::Task {
113 public:
114 SubnetSolveTask(DiakopticsSolver<VarType> &solver, UInt net)
115 : Task(solver.mName + ".SubnetSolve_" + std::to_string(net)),
116 mSolver(solver), mSubnet(solver.mSubnets[net]) {
117 for (auto it : mSubnet.components) {
118 if (it->getRightVector()->get().size() != 0) {
119 mAttributeDependencies.push_back(it->getRightVector());
120 }
121 }
122 mModifiedAttributes.push_back(solver.mOrigLeftSideVector);
123 }
124
125 void execute(Real time, Int timeStepCount);
126
127 private:
128 DiakopticsSolver<VarType> &mSolver;
129 Subnet &mSubnet;
130 };
131
132 // TODO better name
133 class PreSolveTask : public CPS::Task {
134 public:
135 PreSolveTask(DiakopticsSolver<VarType> &solver)
136 : Task(solver.mName + ".PreSolve"), mSolver(solver) {
137 mAttributeDependencies.push_back(solver.mOrigLeftSideVector);
138 mModifiedAttributes.push_back(solver.mMappedTearCurrents);
139 }
140
141 void execute(Real time, Int timeStepCount);
142
143 private:
144 DiakopticsSolver<VarType> &mSolver;
145 };
146
147 class SolveTask : public CPS::Task {
148 public:
149 SolveTask(DiakopticsSolver<VarType> &solver, UInt net)
150 : Task(solver.mName + ".Solve_" + std::to_string(net)), mSolver(solver),
151 mSubnet(solver.mSubnets[net]) {
152 mAttributeDependencies.push_back(solver.mMappedTearCurrents);
153 mModifiedAttributes.push_back(mSubnet.leftVector);
154 }
155
156 void execute(Real time, Int timeStepCount);
157
158 private:
159 DiakopticsSolver<VarType> &mSolver;
160 Subnet &mSubnet;
161 };
162
163 class PostSolveTask : public CPS::Task {
164 public:
165 PostSolveTask(DiakopticsSolver<VarType> &solver)
166 : Task(solver.mName + ".PostSolve"), mSolver(solver) {
167 for (auto &net : solver.mSubnets) {
168 mAttributeDependencies.push_back(net.leftVector);
169 }
170 mModifiedAttributes.push_back(Scheduler::external);
171 }
172
173 void execute(Real time, Int timeStepCount);
174
175 private:
176 DiakopticsSolver<VarType> &mSolver;
177 };
178
179 class LogTask : public CPS::Task {
180 public:
181 LogTask(DiakopticsSolver<VarType> &solver)
182 : Task(solver.mName + ".Log"), mSolver(solver) {
183 for (auto &net : solver.mSubnets) {
184 mAttributeDependencies.push_back(net.leftVector);
185 }
186 mModifiedAttributes.push_back(Scheduler::external);
187 }
188
189 void execute(Real time, Int timeStepCount);
190
191 private:
192 DiakopticsSolver<VarType> &mSolver;
193 };
194};
195} // namespace DPsim
Base class of objects having attributes to access member variables.
Tasks to be defined by every component.
Definition Task.h:25
CPS::Task::List getTasks() override
Get tasks for scheduler.
const CPS::Attribute< Matrix >::Ptr mOrigLeftSideVector
Solutions of the split systems.
const CPS::Attribute< Matrix >::Ptr mMappedTearCurrents
Currents through the removed network (as "seen" from the other subnets)
String mName
Name for logging.
Definition Solver.h:39