Commit 77a9d270 authored by Jan Dinkelbach's avatar Jan Dinkelbach
Browse files

averaged inverter with redundant pll component as state stace model

parent 544bce25
......@@ -24,10 +24,18 @@ using namespace CPS::CIM;
int main(int argc, char* argv[]) {
Examples::SGIB::ScenarioConfig scenario;
Real finalTime = 2.0;
// Real finalTime = 0.003;
Real finalTime = 2;
Real timeStep = 0.001;
CommandLineArgs args(argc, argv);
if (argc > 1) {
timeStep = args.timeStep;
finalTime = args.duration;
}
// ----- POWERFLOW FOR INITIALIZATION -----
Real timeStepPF = 2.0;
Real timeStepPF = finalTime;
Real finalTimePF = finalTime+timeStepPF;
String simNamePF = "DP_Slack_PiLine_VSI_with_PF_Init_PF";
Logger::setLogDir("logs/" + simNamePF);
......@@ -74,7 +82,7 @@ int main(int argc, char* argv[]) {
simPF.run();
// ----- DYNAMIC SIMULATION -----
Real timeStepDP = 0.001;
Real timeStepDP = timeStep;
Real finalTimeDP = finalTime+timeStepDP;
String simNameDP = "DP_Slack_PiLine_VSI_with_PF_Init_DP";
Logger::setLogDir("logs/" + simNameDP);
......@@ -116,6 +124,8 @@ int main(int argc, char* argv[]) {
Examples::CIGREMV::logPVAttributes(loggerDP, pv);
loggerDP->addAttribute("pv_pll_output", pv->attribute("pll_output"));
// load step sized in absolute terms
// std::shared_ptr<SwitchEvent> loadStepEvent = Examples::createEventAddPowerConsumption("n2", 1-timeStepDP, 1000.0e3, systemDP, Domain::DP);
......
......@@ -103,3 +103,4 @@
#include <cps/Signal/Exciter.h>
#include <cps/Signal/TurbineGovernor.h>
#include <cps/Signal/FIRFilter.h>
#include <cps/Signal/Integrator.h>
......@@ -18,6 +18,7 @@
#include <cps/DP/DP_Ph1_Transformer.h>
#include <cps/Base/Base_AvVoltageSourceInverterDQ.h>
#include <cps/PowerProfile.h>
#include <cps/Signal/PLL.h>
namespace CPS {
namespace DP {
......@@ -28,6 +29,10 @@ namespace Ph1 {
public MNAInterface,
public SharedFactory<AvVoltageSourceInverterDQ> {
protected:
// ### Control Subcomponents ###
/// PLL
std::shared_ptr<Signal::PLL> mPLL;
// ### Electrical Subcomponents ###
/// Controlled voltage source
std::shared_ptr<DP::Ph1::ControlledVoltageSource> mSubCtrledVoltageSource;
......@@ -80,9 +85,6 @@ namespace Ph1 {
std::vector<const Matrix*> mRightVectorStamps;
public:
/// Setter for parameters of control loops
void setControllerParameters(Real Kp_pll, Real Ki_pll, Real Kp_powerCtrl, Real Ki_powerCtrl, Real Kp_currCtrl, Real Ki_currCtrl, Real Omega_cutoff);
///
std::vector<PQData> mLoadProfile;
......@@ -101,6 +103,8 @@ namespace Ph1 {
SimPowerComp<Complex>::Ptr clone(String copySuffix);
///
void setParameters(Real sysOmega, Real sysVoltNom, Real Pref, Real Qref);
/// Setter for parameters of control loops
void setControllerParameters(Real Kp_pll, Real Ki_pll, Real Kp_powerCtrl, Real Ki_powerCtrl, Real Kp_currCtrl, Real Ki_currCtrl, Real Omega_cutoff);
///
void setTransformerParameters(Real nomVoltageEnd1, Real nomVoltageEnd2,
Real ratedPower, Real ratioAbs, Real ratioPhase, Real resistance, Real inductance, Real omega);
......@@ -143,9 +147,13 @@ namespace Ph1 {
Complex rotatingFrame2to1(Complex f, Real theta1, Real theta2);
///
void step(Real time, Int timeStepCount);
/// Control pre step operations
void controlPreStep(Real time, Int timeStepCount);
/// Perform step of controller
void controlStep(Real time, Int timeStepCount);
/// Add control step dependencies
void addControlPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes);
/// Add control step dependencies
void addControlStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes);
// #### Profile handling ####
......@@ -162,6 +170,18 @@ namespace Ph1 {
///
void updatePowerGeneration();
class ControlPreStep : public CPS::Task {
public:
ControlPreStep(AvVoltageSourceInverterDQ& AvVoltageSourceInverterDQ) :
Task(AvVoltageSourceInverterDQ.mName + ".ControlPreStep"), mAvVoltageSourceInverterDQ(AvVoltageSourceInverterDQ) {
mAvVoltageSourceInverterDQ.addControlPreStepDependencies(mPrevStepDependencies, mAttributeDependencies, mModifiedAttributes);
}
void execute(Real time, Int timeStepCount) { mAvVoltageSourceInverterDQ.controlPreStep(time, timeStepCount); };
private:
AvVoltageSourceInverterDQ& mAvVoltageSourceInverterDQ;
};
class ControlStep : public CPS::Task {
public:
ControlStep(AvVoltageSourceInverterDQ& AvVoltageSourceInverterDQ) :
......
/* Copyright 2017-2020 Institute for Automation of Complex Power Systems,
* EONERC, RWTH Aachen University
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*********************************************************************************/
#pragma once
#include <vector>
#include <cps/SimPowerComp.h>
#include <cps/SimSignalComp.h>
#include <cps/Task.h>
namespace CPS {
namespace Signal {
class Integrator :
public SimSignalComp,
public SharedFactory<Integrator> {
protected:
/// Integration time step
Real mTimeStep;
/// Previous Input
Real mInputPrev;
/// Current Input
Real mInputCurr;
/// Previous State
Real mStatePrev;
/// Current State
Real mStateCurr;
/// Previous Output
Real mOutputPrev;
/// Current Output
Real mOutputCurr;
public:
Integrator(String name, Logger::Level logLevel = Logger::Level::off);
/// Setter for integration step parameter
void setParameters(Real timestep);
/// Setter for initial values
void setInitialValues(Real input_init, Real state_init, Real output_init);
/// pre step operations
void signalPreStep(Real time, Int timeStepCount);
/// step operations
void signalStep(Real time, Int timeStepCount);
/// pre step dependencies
void signalAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes);
/// add step dependencies
void signalAddStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes);
Task::List getTasks();
class PreStep : public Task {
public:
PreStep(Integrator& integrator) :
Task(integrator.mName + ".PreStep"), mIntegrator(integrator) {
mIntegrator.signalAddPreStepDependencies(mPrevStepDependencies, mAttributeDependencies, mModifiedAttributes);
}
void execute(Real time, Int timeStepCount) { mIntegrator.signalPreStep(time, timeStepCount); };
private:
Integrator& mIntegrator;
};
class Step : public Task {
public:
Step(Integrator& integrator) :
Task(integrator.mName + ".Step"), mIntegrator(integrator) {
mIntegrator.signalAddStepDependencies(mPrevStepDependencies, mAttributeDependencies, mModifiedAttributes);
}
void execute(Real time, Int timeStepCount) { mIntegrator.signalStep(time, timeStepCount); };
private:
Integrator& mIntegrator;
};
};
}
}
/* Copyright 2017-2020 Institute for Automation of Complex Power Systems,
* EONERC, RWTH Aachen University
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*********************************************************************************/
#pragma once
#include <vector>
#include <cps/SimPowerComp.h>
#include <cps/SimSignalComp.h>
#include <cps/Task.h>
namespace CPS {
namespace Signal {
class PLL :
public SimSignalComp,
public SharedFactory<PLL> {
protected:
/// Proportional constant of PI controller
Real mKp;
/// Integration constant of PI controller
Real mKi;
/// Nominal frequency
Real mOmegaNom;
/// Integration time step
Real mTimeStep;
/// Previous Input
Matrix mInputPrev = Matrix::Zero(2,1);
/// Current Input
Matrix mInputCurr = Matrix::Zero(2,1);
/// Previous State
Matrix mStatePrev = Matrix::Zero(2,1);
/// Current State
Matrix mStateCurr = Matrix::Zero(2,1);
/// Previous Output
Matrix mOutputPrev = Matrix::Zero(2,1);
/// Current Output
Matrix mOutputCurr = Matrix::Zero(2,1);
/// matrix A of state space model
Matrix mA = Matrix::Zero(2, 2);
/// matrix B of state space model
Matrix mB = Matrix::Zero(2, 2);
/// matrix C of state space model
Matrix mC = Matrix::Zero(2, 2);
/// matrix D of state space model
Matrix mD = Matrix::Zero(2, 2);
public:
PLL(String name, Logger::Level logLevel = Logger::Level::off);
/// Setter for PLL parameters
void setParameters(Real kpPLL, Real kiPLL, Real omegaNom);
/// Setter for simulation parameters
void setSimulationParameters(Real timestep);
/// Setter for initial values
void setInitialValues(Real input_init, Matrix state_init, Matrix output_init);
/// Composition of A, B, C, D matrices based on PLL parameters
void composeStateSpaceMatrices();
/// pre step operations
void signalPreStep(Real time, Int timeStepCount);
/// step operations
void signalStep(Real time, Int timeStepCount);
/// pre step dependencies
void signalAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes);
/// add step dependencies
void signalAddStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes);
Task::List getTasks();
class PreStep : public Task {
public:
PreStep(PLL& pll) :
Task(pll.mName + ".PreStep"), mPLL(pll) {
mPLL.signalAddPreStepDependencies(mPrevStepDependencies, mAttributeDependencies, mModifiedAttributes);
}
void execute(Real time, Int timeStepCount) { mPLL.signalPreStep(time, timeStepCount); };
private:
PLL& mPLL;
};
class Step : public Task {
public:
Step(PLL& pll) :
Task(pll.mName + ".Step"), mPLL(pll) {
mPLL.signalAddStepDependencies(mPrevStepDependencies, mAttributeDependencies, mModifiedAttributes);
}
void execute(Real time, Int timeStepCount) { mPLL.signalStep(time, timeStepCount); };
private:
PLL& mPLL;
};
};
}
}
......@@ -109,6 +109,8 @@ list(APPEND CPS_SOURCES
Signal/Exciter.cpp
Signal/FIRFilter.cpp
Signal/TurbineGovernor.cpp
Signal/PLL.cpp
Signal/Integrator.cpp
)
if(WITH_CIM)
......
......@@ -27,6 +27,16 @@ DP::Ph1::AvVoltageSourceInverterDQ::AvVoltageSourceInverterDQ(String uid, String
mIntfVoltage = MatrixComp::Zero(1, 1);
mIntfCurrent = MatrixComp::Zero(1, 1);
// Create electrical sub components
mSubResistorF = DP::Ph1::Resistor::make(mName + "_resF", mLogLevel);
mSubResistorC = DP::Ph1::Resistor::make(mName + "_resC", mLogLevel);
mSubCapacitorF = DP::Ph1::Capacitor::make(mName + "_capF", mLogLevel);
mSubInductorF = DP::Ph1::Inductor::make(mName + "_indF", mLogLevel);
mSubCtrledVoltageSource = DP::Ph1::ControlledVoltageSource::make(mName + "_src", mLogLevel);
// Create control sub components
mPLL = Signal::PLL::make("pv_PLL", mLogLevel);
// additional input variables
addAttribute<Matrix>("Vcdq", &mVcdq, Flags::read | Flags::write);
addAttribute<Matrix>("Ircdq", &mIrcdq, Flags::read | Flags::write);
......@@ -53,6 +63,14 @@ DP::Ph1::AvVoltageSourceInverterDQ::AvVoltageSourceInverterDQ(String uid, String
addAttribute<Real>("Omega_nom", &mOmegaN, Flags::read | Flags::write);
addAttribute<Real>("P_ref", &mPref, Flags::read | Flags::write);
addAttribute<Real>("Q_ref", &mQref, Flags::read | Flags::write);
// PLL
addAttribute<Matrix>("pll_output", Flags::read | Flags::write);
addAttribute<Real>("Vc_q", &mVcdq(1, 0), Flags::read | Flags::write);
// Connect control subcomponents
mPLL->setAttributeRef("input_ref", attribute<Real>("Vc_q"));
setAttributeRef("pll_output", mPLL->attribute<Matrix>("output_curr"));
}
void DP::Ph1::AvVoltageSourceInverterDQ::setParameters(Real sysOmega, Real sysVoltNom, Real Pref, Real Qref) {
......@@ -134,10 +152,12 @@ void DP::Ph1::AvVoltageSourceInverterDQ::initialize(Matrix frequencies) {
mIntfCurrent = MatrixComp::Zero(1, mNumFreqs);
}
void DP::Ph1::AvVoltageSourceInverterDQ::updateInputStateSpaceModel(const Matrix& leftVector, Real time) {
void DP::Ph1::AvVoltageSourceInverterDQ::updateInputStateSpaceModel(Real time) {
Complex vcdq, ircdq;
vcdq = rotatingFrame2to1(Math::complexFromVectorElement(leftVector, mVirtualNodes[4]->matrixNodeIndex()), mThetaPLL, mOmegaN * time);
// vcdq = rotatingFrame2to1(Math::complexFromVectorElement(leftVector, mVirtualNodes[4]->matrixNodeIndex()), mThetaPLL, mOmegaN * time);
// vcdq = rotatingFrame2to1(mSubCapacitorF->attribute<MatrixComp>("v_intf")->get()(0, 0), mThetaPLL, mOmegaN * time);
vcdq = rotatingFrame2to1(mVirtualNodes[4]->initialSingleVoltage(), mThetaPLL, mOmegaN * time);
ircdq = rotatingFrame2to1(-1. * mSubResistorC->attribute<MatrixComp>("i_intf")->get()(0, 0), mThetaPLL, mOmegaN * time);
mVcdq(0, 0) = vcdq.real();
......@@ -146,7 +166,7 @@ void DP::Ph1::AvVoltageSourceInverterDQ::updateInputStateSpaceModel(const Matrix
mIrcdq(0, 0) = ircdq.real();
mIrcdq(1, 0) = ircdq.imag();
mIntfVoltage(0,0) = Math::complexFromVectorElement(leftVector, mTerminals[0]->node()->matrixNodeIndex());
// mIntfVoltage(0,0) = Math::complexFromVectorElement(leftVector, mTerminals[0]->node()->matrixNodeIndex());
updateBMatrixStateSpaceModel();
}
......@@ -160,11 +180,15 @@ void DP::Ph1::AvVoltageSourceInverterDQ::initializeStateSpaceModel(Real omega, R
// get current and voltage inputs to state space model
// done here to ensure quantites are already initialized by initializeFromPowerFlow
MatrixComp Irc = - mSubResistorC->attribute<MatrixComp>("i_intf")->get();
mIrcdq(0, 0) = Irc(0, 0).real();
mIrcdq(1, 0) = Irc(0, 0).imag();
mVcdq(0, 0) = mVirtualNodes[4]->initialSingleVoltage().real();
mVcdq(1, 0) = mVirtualNodes[4]->initialSingleVoltage().imag();
mIrcdq(0, 0) = - mSubResistorC->attribute<MatrixComp>("i_intf")->get()(0,0).real();
mIrcdq(1, 0) = - mSubResistorC->attribute<MatrixComp>("i_intf")->get()(0,0).imag();
if (mWithConnectionTransformer) {
mVcdq(0, 0) = mVirtualNodes[4]->initialSingleVoltage().real();
mVcdq(1, 0) = mVirtualNodes[4]->initialSingleVoltage().imag();
} else {
mVcdq(0, 0) = mVirtualNodes[3]->initialSingleVoltage().real();
mVcdq(1, 0) = mVirtualNodes[3]->initialSingleVoltage().imag();
}
// update B matrix due to its dependence on Irc
updateBMatrixStateSpaceModel();
......@@ -174,7 +198,8 @@ void DP::Ph1::AvVoltageSourceInverterDQ::initializeStateSpaceModel(Real omega, R
mSLog->info("Initialization of input: \n" + Logger::matrixToString(mU));
// initialization of states
mThetaPLL = mThetaPLLInit;
// mThetaPLL = mThetaPLLInit;
mThetaPLL = std::arg(mVirtualNodes[4]->initialSingleVoltage());
mPhiPLL = mPhiPLLInit;
mP = mPInit;
mQ = mQInit;
......@@ -260,6 +285,7 @@ void DP::Ph1::AvVoltageSourceInverterDQ::initializeFromPowerflow(Real frequency)
// set initial interface quantities
mIntfVoltage(0, 0) = initialSingleVoltage(0);
// TODO: check usage of terminal current
mIntfCurrent(0, 0) = - std::conj(Complex(mPref, mQref) / mIntfVoltage(0,0));
Complex filterInterfaceInitialVoltage;
......@@ -292,21 +318,18 @@ void DP::Ph1::AvVoltageSourceInverterDQ::initializeFromPowerflow(Real frequency)
mVirtualNodes[2]->setInitialVoltage(vfInit);
mVirtualNodes[3]->setInitialVoltage(vcInit);
// Create sub components
mSubResistorF = DP::Ph1::Resistor::make(mName + "_resF", mLogLevel);
mSubResistorC = DP::Ph1::Resistor::make(mName + "_resC", mLogLevel);
mSubCapacitorF = DP::Ph1::Capacitor::make(mName + "_capF", mLogLevel);
mSubInductorF = DP::Ph1::Inductor::make(mName + "_indF", mLogLevel);
mSubCtrledVoltageSource = DP::Ph1::ControlledVoltageSource::make(mName + "_src", mLogLevel);
// Set parameters of control subcomponents
mPLL->setParameters(mKpPLL, mKiPLL, mOmegaN);
mPLL->composeStateSpaceMatrices();
// set filter parameters
// Set parameters electrical subcomponents
mSubResistorC->setParameters(mRc);
mSubResistorF->setParameters(mRf);
mSubInductorF->setParameters(mLf);
mSubCapacitorF->setParameters(mCf);
mSubCtrledVoltageSource->setParameters(mIntfVoltage);
// connect subcomponents
// Connect electrical subcomponents
mSubCtrledVoltageSource->connect({ SimNode::GND, mVirtualNodes[1] });
mSubCtrledVoltageSource->setVirtualNodeAt(mVirtualNodes[0], 0);
mSubResistorF->connect({ mVirtualNodes[1], mVirtualNodes[2] });
......@@ -317,7 +340,12 @@ void DP::Ph1::AvVoltageSourceInverterDQ::initializeFromPowerflow(Real frequency)
else
mSubResistorC->connect({ mVirtualNodes[3], mTerminals[0]->node()});
// initialize subcomponents
// Initialize control subcomponents
Matrix matrixStateInit = Matrix::Zero(2,1);
matrixStateInit(0,0) = std::arg(mVirtualNodes[4]->initialSingleVoltage());
mPLL->setInitialValues(mVirtualNodes[4]->initialSingleVoltage().imag(), matrixStateInit, Matrix::Zero(2,1));
// Initialize electrical subcomponents
mSubCtrledVoltageSource->initialize(mFrequencies);
mSubResistorF->initialize(mFrequencies);
mSubInductorF->initialize(mFrequencies);
......@@ -365,6 +393,7 @@ void DP::Ph1::AvVoltageSourceInverterDQ::mnaInitialize(Real omega, Real timeStep
// initialize state space controller
initializeStateSpaceModel(omega, timeStep, leftVector);
mPLL->setSimulationParameters(timeStep);
// collect right side vectors of subcomponents
mRightVectorStamps.push_back(&mSubCapacitorF->attribute<Matrix>("right_vector")->get());
......@@ -375,9 +404,12 @@ void DP::Ph1::AvVoltageSourceInverterDQ::mnaInitialize(Real omega, Real timeStep
// collect tasks
mMnaTasks.push_back(std::make_shared<MnaPreStep>(*this));
mMnaTasks.push_back(std::make_shared<ControlStep>(*this));
mMnaTasks.push_back(std::make_shared<MnaPostStep>(*this, leftVector));
// TODO: these are actually no MNA tasks
mMnaTasks.push_back(std::make_shared<ControlPreStep>(*this));
mMnaTasks.push_back(std::make_shared<ControlStep>(*this));
mRightVector = Matrix::Zero(leftVector->get().rows(), 1);
}
......@@ -398,13 +430,32 @@ void DP::Ph1::AvVoltageSourceInverterDQ::mnaApplyRightSideVectorStamp(Matrix& ri
rightVector += *stamp;
}
void DP::Ph1::AvVoltageSourceInverterDQ::addControlPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) {
// add pre-step dependencies of subcomponents
mPLL->signalAddPreStepDependencies(prevStepDependencies, attributeDependencies, modifiedAttributes);
}
void DP::Ph1::AvVoltageSourceInverterDQ::controlPreStep(Real time, Int timeStepCount) {
// add pre-step of subcomponents
mPLL->signalPreStep(time, timeStepCount);
}
void DP::Ph1::AvVoltageSourceInverterDQ::addControlStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) {
attributeDependencies.push_back(mPLL->attribute<Matrix>("output_prev"));
// add step dependencies of component itself
prevStepDependencies.push_back(this->attribute("i_intf"));
prevStepDependencies.push_back(this->attribute("v_intf"));
modifiedAttributes.push_back(this->attribute("controller_output"));
}
void DP::Ph1::AvVoltageSourceInverterDQ::controlStep(Real time, Int timeStepCount) {
void DP::Ph1::AvVoltageSourceInverterDQ::controlStep(Real time, Int timeStepCount) {
this->updateInputStateSpaceModel(time);
// add step of subcomponents
mPLL->signalStep(time, timeStepCount);
this->step(time, timeStepCount);
// Transformation interface inverse
this->mControllerOutput(0,0) = this->rotatingFrame2to1(Complex(this->mVsdq(0, 0), this->mVsdq(1, 0)), this->mOmegaN * time, this->mThetaPLL);
}
......
/* Copyright 2017-2020 Institute for Automation of Complex Power Systems,
* EONERC, RWTH Aachen University
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*********************************************************************************/
#include <cps/Signal/Integrator.h>
using namespace CPS;
using namespace CPS::Signal;
Integrator::Integrator(String name, Logger::Level logLevel) :
SimSignalComp(name, name, logLevel) {
addAttribute<Real>("input_ref", Flags::read | Flags::write);
addAttribute<Real>("input_prev", &mInputPrev, Flags::read | Flags::write);
addAttribute<Real>("state_prev", &mStatePrev, Flags::read | Flags::write);
addAttribute<Real>("output_prev", &mOutputPrev, Flags::read | Flags::write);
addAttribute<Real>("input_curr", &mInputCurr, Flags::read | Flags::write);
addAttribute<Real>("state_curr", &mStateCurr, Flags::read | Flags::write);
addAttribute<Real>("output_curr", &mOutputCurr, Flags::read | Flags::write);
}
void Integrator::setParameters(Real timestep) {
mTimeStep = timestep;
mSLog->info("Integration step = {}", mTimeStep);
}
void Integrator::setInitialValues(Real input_init, Real state_init, Real output_init) {
mInputCurr = input_init;
mStateCurr = state_init;
mOutputCurr = output_init;
mSLog->info("Initial values:");
mSLog->info("inputCurrInit = {}, stateCurrInit = {}, outputCurrInit = {}", mInputCurr, mStateCurr, mOutputCurr);
}
void Integrator::signalAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) {
prevStepDependencies.push_back(attribute("input_curr"));
prevStepDependencies.push_back(attribute("output_curr"));
modifiedAttributes.push_back(attribute("input_prev"));
modifiedAttributes.push_back(attribute("output_prev"));
};
void Integrator::signalPreStep(Real time, Int timeStepCount) {
mInputPrev = mInputCurr;
mStatePrev = mStateCurr;
mOutputPrev = mOutputCurr;
}
void Integrator::signalAddStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) {
attributeDependencies.push_back(attribute("input_ref"));
modifiedAttributes.push_back(attribute("input_curr"));
modifiedAttributes.push_back(attribute("output_curr"));
};
void Integrator::signalStep(Real time, Int timeStepCount) {
mInputCurr = attribute<Real>("input_ref")->get();
mSLog->info("Time {}:", time);
mSLog->info("Input values: inputCurr = {}, inputPrev = {}, statePrev = {}", mInputCurr, mInputPrev, mStatePrev);
mStateCurr = mStatePrev + mTimeStep/2.0*mInputCurr + mTimeStep/2.0*mInputPrev;
mOutputCurr = mStateCurr;
mSLog->info("State values: stateCurr = {}", mStateCurr);
mSLog->info("Output values: outputCurr = {}:", mOutputCurr);
}
Task::List Integrator::getTasks() {
return Task::List({std::make_shared<PreStep>(*this), std::make_shared<Step>(*this)});
}
\ No newline at end of file
/* Copyright 2017-2020 Institute for Automation of Complex Power Systems,
* EONERC, RWTH Aachen University
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*********************************************************************************/
#include <cps/Signal/PLL.h>
using namespace CPS;
using namespace CPS::Signal;
PLL::PLL(String name, Logger::Level logLevel) :
SimSignalComp(name, name, logLevel) {
addAttribute<Real>("input_ref", Flags::read | Flags::write);