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;
80 CPS::PhaseType mPhaseType;
81
82 void init(CPS::SystemTopology &system);
83
84 void initSubnets(const std::vector<CPS::SystemTopology> &subnets);
85 void collectVirtualNodes(int net);
86 void assignMatrixNodeIndices(int net);
87 void setSubnetSize(int net, UInt nodes);
88
89 void setLogColumns();
90
91 void createMatrices();
92 void createTearMatrices(UInt totalSize);
93
94 void initComponents();
95
96 void initMatrices();
97 void applyTearComponentStamp(UInt compIdx);
98
99 void log(Real time, Int timeStepCount) override;
100
101public:
103 const CPS::Attribute<Matrix>::Ptr mMappedTearCurrents;
104
106 const CPS::Attribute<Matrix>::Ptr mOrigLeftSideVector;
107
108 DiakopticsSolver(String name, CPS::SystemTopology system,
109 CPS::IdentifiedObject::List tearComponents, Real timeStep,
110 CPS::Logger::Level logLevel);
111
112 CPS::Task::List getTasks() override;
113
114 class SubnetSolveTask : public CPS::Task {
115 public:
116 SubnetSolveTask(DiakopticsSolver<VarType> &solver, UInt net)
117 : Task(solver.mName + ".SubnetSolve_" + std::to_string(net)),
118 mSolver(solver), mSubnet(solver.mSubnets[net]) {
119 for (auto it : mSubnet.components) {
120 if (it->getRightVector()->get().size() != 0) {
121 mAttributeDependencies.push_back(it->getRightVector());
122 }
123 }
124 mModifiedAttributes.push_back(solver.mOrigLeftSideVector);
125 }
126
127 void execute(Real time, Int timeStepCount);
128
129 private:
130 DiakopticsSolver<VarType> &mSolver;
131 Subnet &mSubnet;
132 };
133
134 // TODO better name
135 class PreSolveTask : public CPS::Task {
136 public:
137 PreSolveTask(DiakopticsSolver<VarType> &solver)
138 : Task(solver.mName + ".PreSolve"), mSolver(solver) {
139 mAttributeDependencies.push_back(solver.mOrigLeftSideVector);
140 mModifiedAttributes.push_back(solver.mMappedTearCurrents);
141 }
142
143 void execute(Real time, Int timeStepCount);
144
145 private:
146 DiakopticsSolver<VarType> &mSolver;
147 };
148
149 class SolveTask : public CPS::Task {
150 public:
151 SolveTask(DiakopticsSolver<VarType> &solver, UInt net)
152 : Task(solver.mName + ".Solve_" + std::to_string(net)), mSolver(solver),
153 mSubnet(solver.mSubnets[net]) {
154 mAttributeDependencies.push_back(solver.mMappedTearCurrents);
155 mModifiedAttributes.push_back(mSubnet.leftVector);
156 }
157
158 void execute(Real time, Int timeStepCount);
159
160 private:
161 DiakopticsSolver<VarType> &mSolver;
162 Subnet &mSubnet;
163 };
164
165 class PostSolveTask : public CPS::Task {
166 public:
167 PostSolveTask(DiakopticsSolver<VarType> &solver)
168 : Task(solver.mName + ".PostSolve"), mSolver(solver) {
169 for (auto &net : solver.mSubnets) {
170 mAttributeDependencies.push_back(net.leftVector);
171 }
172 mModifiedAttributes.push_back(Scheduler::external);
173 }
174
175 void execute(Real time, Int timeStepCount);
176
177 private:
178 DiakopticsSolver<VarType> &mSolver;
179 };
180
181 class LogTask : public CPS::Task {
182 public:
183 LogTask(DiakopticsSolver<VarType> &solver)
184 : Task(solver.mName + ".Log"), mSolver(solver) {
185 for (auto &net : solver.mSubnets) {
186 mAttributeDependencies.push_back(net.leftVector);
187 }
188 mModifiedAttributes.push_back(Scheduler::external);
189 }
190
191 void execute(Real time, Int timeStepCount);
192
193 private:
194 DiakopticsSolver<VarType> &mSolver;
195 };
196};
197} // 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