Commit d91bfa78 authored by Markus Mirz's avatar Markus Mirz
Browse files

refactor variable element interface

parent a4c4690f
......@@ -18,7 +18,7 @@
#include <dpsim/DataLogger.h>
#include <cps/AttributeList.h>
#include <cps/Solver/MNASwitchInterface.h>
#include <cps/Solver/MNAVariableElementInterface.h>
#include <cps/Solver/MNAVariableCompInterface.h>
#include <cps/SimSignalComp.h>
#include <cps/SimPowerComp.h>
......@@ -64,12 +64,12 @@ namespace DPsim {
/// and indicate the solver to choose a different system matrix
CPS::MNASwitchInterface::List mSwitches;
/// List of MNA components with SwitchInterface
CPS::MNAInterface::List mMNACompSwitches;
CPS::MNAInterface::List mMNAIntfSwitches;
/// List of components that indicate the solver to recompute the system matrix
/// depending on their state
CPS::MNAVariableElementInterface::List mVariableElements;
/// List of MNA components with VariableElementInterface
CPS::MNAInterface::List mMNACompVariableElements;
CPS::MNAVariableCompInterface::List mVariableComps;
/// List of MNA components with VariableCompInterface
CPS::MNAInterface::List mMNAIntfVariableComps;
/// List of signal type components that do not directly interact
/// with the MNA solver
CPS::SimSignalComp::List mSimSignalComps;
......
......@@ -26,7 +26,7 @@ namespace DPsim {
/// Recomputes systems matrix
void updateSystemMatrix(Real time);
/// Collects the status of variable MNA elements to decide if system matrix has to be recomputed
void updateVariableElementStatus();
void updateVariableCompStatus();
/// Initialization of system matrices and source vector
void initializeSystemWithDynamicMatrix();
......
......@@ -273,14 +273,14 @@ void MnaSolver<VarType>::identifyTopologyObjects() {
if (swComp) {
mSwitches.push_back(swComp);
auto mnaComp = std::dynamic_pointer_cast<CPS::MNAInterface>(swComp);
if (mnaComp) mMNACompSwitches.push_back(mnaComp);
if (mnaComp) mMNAIntfSwitches.push_back(mnaComp);
}
auto varComp = std::dynamic_pointer_cast<CPS::MNAVariableElementInterface>(comp);
auto varComp = std::dynamic_pointer_cast<CPS::MNAVariableCompInterface>(comp);
if (varComp) {
mVariableElements.push_back(varComp);
mVariableComps.push_back(varComp);
auto mnaComp = std::dynamic_pointer_cast<CPS::MNAInterface>(varComp);
if (mnaComp) mMNACompVariableElements.push_back(mnaComp);
if (mnaComp) mMNAIntfVariableComps.push_back(mnaComp);
}
if (!(swComp || varComp)) {
......
......@@ -26,13 +26,13 @@ void MnaSolverSysRecomp<VarType>::initializeSystem() {
this->mSLog->info("Number of variable Elements: {}"
"\nNumber of MNA components: {}",
this->mVariableElements.size(),
this->mVariableComps.size(),
this->mMNAComponents.size());
this->mSLog->info("Stamping MNA fixed components");
for (auto comp : this->mMNAComponents) {
// Do not stamp variable elements yet
auto varcomp = std::dynamic_pointer_cast<MNAVariableElementInterface>(comp);
auto varcomp = std::dynamic_pointer_cast<MNAVariableCompInterface>(comp);
if (varcomp) continue;
comp->mnaApplySystemMatrixStamp(this->mSwitchedMatrices[std::bitset<SWITCH_NUM>(0)]);
......@@ -45,7 +45,7 @@ void MnaSolverSysRecomp<VarType>::initializeSystem() {
// Now stamp variable elements
this->mSLog->info("Stamping variable elements");
for (auto varElem : this->mMNACompVariableElements) {
for (auto varElem : this->mMNAIntfVariableComps) {
varElem->mnaApplySystemMatrixStamp(this->mSwitchedMatrices[std::bitset<SWITCH_NUM>(0)]);
}
this->mLuFactorizations[std::bitset<SWITCH_NUM>(0)] = Eigen::PartialPivLU<Matrix>(this->mSwitchedMatrices[std::bitset<SWITCH_NUM>(0)]);
......@@ -57,8 +57,8 @@ void MnaSolverSysRecomp<VarType>::initializeSystem() {
}
template <typename VarType>
void MnaSolverSysRecomp<VarType>::updateVariableElementStatus() {
for (auto varElem : this->mVariableElements) {
void MnaSolverSysRecomp<VarType>::updateVariableCompStatus() {
for (auto varElem : this->mVariableComps) {
if (varElem->hasParameterChanged()) {
auto idObj = std::dynamic_pointer_cast<IdentifiedObject>(varElem);
this->mSLog->info("Component ({:s} {:s}) value changed -> Update System Matrix",
......@@ -76,7 +76,7 @@ void MnaSolverSysRecomp<VarType>::updateSystemMatrix(Real time) {
this->mSwitchedMatrices[std::bitset<SWITCH_NUM>(0)] = this->mBaseSystemMatrix;
// Create system matrix with changed variable elements
for (auto comp : this->mMNACompVariableElements) {
for (auto comp : this->mMNAIntfVariableComps) {
comp->mnaApplySystemMatrixStamp(this->mSwitchedMatrices[std::bitset<SWITCH_NUM>(0)]);
auto idObj = std::dynamic_pointer_cast<IdentifiedObject>(comp);
this->mSLog->debug("Updating {:s} {:s} in system matrix (variabel component)",
......@@ -106,7 +106,7 @@ void MnaSolverSysRecomp<VarType>::solve(Real time, Int timeStepCount) {
this->mNodes[nodeIdx]->mnaUpdateVoltage(this->mLeftSideVector);
if (!this->mIsInInitialization) {
updateVariableElementStatus();
updateVariableCompStatus();
if (mUpdateSysMatrix)
updateSystemMatrix(time);
}
......@@ -122,7 +122,7 @@ Task::List MnaSolverSysRecomp<VarType>::getTasks() {
for (auto task : comp->mnaTasks())
l.push_back(task);
}
for (auto comp : this->mMNACompVariableElements) {
for (auto comp : this->mMNAIntfVariableComps) {
for (auto task : comp->mnaTasks())
l.push_back(task);
}
......
......@@ -9,7 +9,7 @@
#pragma once
#include <cps/Solver/MNAInterface.h>
#include <cps/Solver/MNAVariableElementInterface.h>
#include <cps/Solver/MNAVariableCompInterface.h>
#include <cps/Base/Base_Ph1_SVC.h>
#include <cps/DP/DP_Ph1_Capacitor.h>
#include <cps/DP/DP_Ph1_Inductor.h>
......@@ -28,7 +28,7 @@ namespace Ph1 {
/// frequency and the current source changes for each iteration.
class SVC :
public Base::Ph1::SVC,
public MNAVariableElementInterface,
public MNAVariableCompInterface,
public SimPowerComp<Complex>,
public SharedFactory<SVC> {
protected:
......
......@@ -13,12 +13,12 @@
namespace CPS {
/// MNA interface to be used by elements that require recomputing of the system matrix
class MNAVariableElementInterface {
class MNAVariableCompInterface {
public:
typedef std::shared_ptr<MNAVariableElementInterface> Ptr;
typedef std::shared_ptr<MNAVariableCompInterface> Ptr;
typedef std::vector<Ptr> List;
/// Returns true if one of the element paramters has changed
virtual Bool hasParameterChanged() = 0;
};
}
\ No newline at end of file
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment