Skip to content

Commit

Permalink
added new DroopController signal class
Browse files Browse the repository at this point in the history
Signed-off-by: martin.moraga <[email protected]>
  • Loading branch information
martinmoraga committed Mar 22, 2024
1 parent fca578d commit 7de5f87
Show file tree
Hide file tree
Showing 17 changed files with 858 additions and 549 deletions.
41 changes: 25 additions & 16 deletions dpsim-models/include/dpsim-models/Base/Base_VSIControlDQ.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,23 @@

#pragma once

namespace CPS {
namespace Base {
#include <dpsim-models/Definitions.h>

class VSIControlParameters {
namespace CPS
{
namespace Base
{

class VSIControlParameters
{
public:
VSIControlParameters() { };
VSIControlParameters(){};
virtual ~VSIControlParameters() = default;
};
};

/// @brief Base model for VSI controllers in dq reference frame
class VSIControlDQ {
/// @brief Base model for VSI controllers in dq reference frame
class VSIControlDQ
{

protected:
///
Expand All @@ -27,20 +33,23 @@ namespace Base {
Bool mModelAsCurrentSource;

public:

///
virtual void setParameters(std::shared_ptr<Base::VSIControlParameters> parameters) = 0;

///
virtual void calculateVBRconstants(){};

/// Initializes
virtual void initialize(const Complex& Vsref_dq, const Complex& Vcap_dq,
const Complex& Ifilter_dq, Real time_step, Bool modelAsCurrentSource) = 0;
virtual void initialize(const Complex &Vsref_dq, const Complex &Vcap_dq,
const Complex &Ifilter_dq, Real time_step, Bool modelAsCurrentSource) = 0;

/// Returns voltage of the voltage source if mModelAsCurrentSource=false,
/// and current of equivalent current source if mModelAsCurrentSource=true
virtual Complex step(const Complex& Vcap_dq, const Complex& Ifilter_dq) = 0;

};
}
virtual Complex step(const Complex &Vcap_dq, const Complex &Ifilter_dq) = 0;
virtual Complex stepVBR(const Complex &Vcap_dq, const Complex &Ifilter_dq)
{
return Complex(0, 0);
};
};
}
}


219 changes: 114 additions & 105 deletions dpsim-models/include/dpsim-models/Base/Base_VSIVoltageSourceInverterDQ.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,111 +12,120 @@
#include <dpsim-models/Logger.h>
#include <dpsim-models/AttributeList.h>
#include <dpsim-models/Base/Base_VSIControlDQ.h>
#include <dpsim-models/Signal/DroopController.h>
#include <dpsim-models/SimNode.h>

namespace CPS {
namespace Base {

/// @brief Base model of average grid forming inverter
template <typename VarType>
class VSIVoltageSourceInverterDQ {
private:
/// Component logger
Logger::Log mLogger;

protected:
// ### General Parameters ###
/// mModelAsCurrentSource=true --> Inverter is modeled as current source, otherwise as voltage source
Bool mModelAsCurrentSource;
/// Simulation step
Real mTimeStep;
/// Nominal Omega
Real mOmegaN;

// ### Inverter Parameters ###
/// Nominal frequency
Real mOmegaNom;
/// Nominal voltage
Real mVnom;
/// Voltage d reference
Real mVdRef;
/// Voltage q reference
Real mVqRef;
/// Active power reference
Real mPref;

// ### Inverter Flags ###
/// Flag for usage of interface resistor Rc
Bool mWithInterfaceResistor = false;
/// Flag for control droop usage
Bool mWithDroop = false;

// Filter parameters
Real mLf;
Real mCf;
Real mRf;
Real mRc;

// ### Inverter Variables ###
/// Omega
const Attribute<Real>::Ptr mOmega;
/// System angle (rotating at nominal omega)
const Attribute<Real>::Ptr mThetaSys;
/// Inverter angle (rotating at inverter omega)
const Attribute<Real>::Ptr mThetaInv;
/// Voltage/Current as control output after transformation interface
const Attribute<MatrixComp>::Ptr mSourceValue;
/// Voltage/Current as control output after transformation interface
const Attribute<Complex>::Ptr mSourceValue_dq;
/// Measured voltage in dq reference frame
const Attribute<Complex>::Ptr mVcap_dq;
/// Measured current in dq reference frame
const Attribute<Complex>::Ptr mIfilter_dq;
/// inverter terminal active power
const Attribute<Complex>::Ptr mPower;

// ### Voltage Controller Variables ###

// #### Controllers ####
/// Determines if VSI control is activated
Bool mWithControl = true;

/// Signal component modelling voltage regulator and exciter
std::shared_ptr<Base::VSIControlDQ> mVSIController;

public:
explicit VSIVoltageSourceInverterDQ(Logger::Log Log, CPS::AttributeList::Ptr attributeList,
Bool modelAsCurrentSource, Bool withInterfaceResistor) :
mLogger(Log),
mModelAsCurrentSource(modelAsCurrentSource),
mWithInterfaceResistor(withInterfaceResistor),
mOmega(attributeList->create<Real>("Omega", 0)),
mThetaSys(attributeList->create<Real>("ThetaSys", 0)),
mThetaInv(attributeList->create<Real>("ThetaInv", 0)),
mSourceValue(attributeList->create<MatrixComp>("SourceValue", MatrixComp::Zero(1,1))),
mSourceValue_dq(attributeList->create<Complex>("SourceValue_dq", Complex(0,0))),
mVcap_dq(attributeList->create<Complex>("Vcap_dq", 0)),
mIfilter_dq(attributeList->create<Complex>("Ifilter_dq", 0)),
mPower(attributeList->create<Complex>("Power", 0)){ };

/// Setter for general parameters of inverter
void setParameters(Real sysOmega, Real VdRef, Real VqRef);
/// Setter for filter parameters
void setFilterParameters(Real Lf, Real Cf, Real Rf, Real Rc);

// ### Controllers ###
/// Add VSI Controller
void addVSIController(std::shared_ptr<Base::VSIControlDQ> VSIController);

protected:
///
virtual void createSubComponents() = 0;
///
int determineNumberOfVirtualNodes();
///
void initializeFilterVariables(const Complex & interfaceVoltage,
const Complex & interfaceCurrent,
typename SimNode<VarType>::List virtualNodesList);
};
}
namespace CPS
{
namespace Base
{

/// @brief Base model of average grid forming inverter
template <typename VarType>
class VSIVoltageSourceInverterDQ
{
private:
/// Component logger
Logger::Log mLogger;

protected:
// ### General Parameters ###
/// mModelAsCurrentSource=true --> Inverter is modeled as current source, otherwise as voltage source
Bool mModelAsCurrentSource;
/// Simulation step
Real mTimeStep;
/// Nominal Omega
Real mOmegaN;

// ### Inverter Parameters ###
/// Nominal frequency
Real mOmegaNom;
/// Nominal voltage
Real mVnom;
/// Voltage d reference
Real mVdRef;
/// Voltage q reference
Real mVqRef;
/// Active power reference
Real mPref;

// ### Inverter Flags ###
/// Flag for usage of interface resistor Rc
Bool mWithInterfaceResistor = false;
/// Flag for control droop usage
Bool mWithDroop = false;

// Filter parameters
Real mLf;
Real mCf;
Real mRf;
Real mRc;

// ### Inverter Variables ###
/// Omega
const Attribute<Real>::Ptr mOmega;
/// System angle (rotating at nominal omega)
const Attribute<Real>::Ptr mThetaSys;
/// Inverter angle (rotating at inverter omega)
const Attribute<Real>::Ptr mThetaInv;
/// Voltage/Current as control output after transformation interface
const Attribute<MatrixComp>::Ptr mSourceValue;
/// Voltage/Current as control output after transformation interface
const Attribute<Complex>::Ptr mSourceValue_dq;
/// Measured voltage in dq reference frame
const Attribute<Complex>::Ptr mVcap_dq;
/// Measured current in dq reference frame
const Attribute<Complex>::Ptr mIfilter_dq;
/// inverter terminal active power
const Attribute<Complex>::Ptr mPower;

// ### Voltage Controller Variables ###

// #### Controllers ####
/// Determines if VSI control is activated
Bool mWithControl = true;
/// Determines if Droop Control is activated
Bool mWithDroopControl = false;

/// Signal component modelling vsi controller (grid forming or grid following mode)
std::shared_ptr<Base::VSIControlDQ> mVSIController;
/// Signal component modelling the droop controller
std::shared_ptr<Signal::DroopController> mDroopController;

public:
explicit VSIVoltageSourceInverterDQ(Logger::Log Log, CPS::AttributeList::Ptr attributeList,
Bool modelAsCurrentSource, Bool withInterfaceResistor) : mLogger(Log),
mModelAsCurrentSource(modelAsCurrentSource),
mWithInterfaceResistor(withInterfaceResistor),
mOmega(attributeList->create<Real>("Omega", 0)),
mThetaSys(attributeList->create<Real>("ThetaSys", 0)),
mThetaInv(attributeList->create<Real>("ThetaInv", 0)),
mSourceValue(attributeList->create<MatrixComp>("SourceValue", MatrixComp::Zero(1, 1))),
mSourceValue_dq(attributeList->create<Complex>("SourceValue_dq", Complex(0, 0))),
mVcap_dq(attributeList->create<Complex>("Vcap_dq", 0)),
mIfilter_dq(attributeList->create<Complex>("Ifilter_dq", 0)),
mPower(attributeList->create<Complex>("Power", 0)){};

/// Setter for general parameters of inverter
void setParameters(Real sysOmega, Real VdRef, Real VqRef);
/// Setter for filter parameters
void setFilterParameters(Real Lf, Real Cf, Real Rf, Real Rc);

// ### Controllers ###
/// VSI Controller
void addVSIController(std::shared_ptr<Base::VSIControlDQ> VSIController);
/// Droop Controller
void addDroopController(std::shared_ptr<Signal::DroopController> DroopController);

protected:
///
virtual void createSubComponents() = 0;
///
int determineNumberOfVirtualNodes();
///
void initializeFilterVariables(const Complex &interfaceVoltage,
const Complex &interfaceCurrent,
typename SimNode<VarType>::List virtualNodesList);
};
}
}
8 changes: 6 additions & 2 deletions dpsim-models/include/dpsim-models/Components.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <dpsim-models/SP/SP_Ph1_NetworkInjection.h>
#include <dpsim-models/SP/SP_Ph1_VoltageSource.h>
#include <dpsim-models/SP/SP_Ph1_VSIVoltageControlDQ.h>
#include <dpsim-models/SP/SP_Ph1_VSIVoltageControlVBR.h>
#include <dpsim-models/SP/SP_Ph1_SynchronGeneratorTrStab.h>
#include <dpsim-models/SP/SP_Ph1_ReducedOrderSynchronGeneratorVBR.h>
#include <dpsim-models/SP/SP_Ph1_SynchronGenerator3OrderVBR.h>
Expand Down Expand Up @@ -74,6 +75,7 @@
#include <dpsim-models/DP/DP_Ph1_SVC.h>
#include <dpsim-models/DP/DP_Ph1_varResSwitch.h>
#include <dpsim-models/DP/DP_Ph1_VSIVoltageControlDQ.h>
#include <dpsim-models/DP/DP_Ph1_VSIVoltageControlVBR.h>
#include <dpsim-models/DP/DP_Ph3_Capacitor.h>
#include <dpsim-models/DP/DP_Ph3_Inductor.h>
#include <dpsim-models/DP/DP_Ph3_VoltageSource.h>
Expand All @@ -82,7 +84,7 @@
#include <dpsim-models/DP/DP_Ph3_SeriesSwitch.h>
#include <dpsim-models/DP/DP_Ph3_SynchronGeneratorDQTrapez.h>
#ifdef WITH_SUNDIALS
#include <dpsim-models/DP/DP_Ph3_SynchronGeneratorDQODE.h>
#include <dpsim-models/DP/DP_Ph3_SynchronGeneratorDQODE.h>
#endif
#include <dpsim-models/EMT/EMT_Ph1_Capacitor.h>
#include <dpsim-models/EMT/EMT_Ph1_CurrentSource.h>
Expand All @@ -97,6 +99,7 @@
#include <dpsim-models/EMT/EMT_Ph3_AvVoltSourceInverterStateSpace.h>
#include <dpsim-models/EMT/EMT_Ph3_AvVoltageSourceInverterDQ.h>
#include <dpsim-models/EMT/EMT_Ph3_VSIVoltageControlDQ.h>
#include <dpsim-models/EMT/EMT_Ph3_VSIVoltageControlVBR.h>
#include <dpsim-models/EMT/EMT_Ph3_Resistor.h>
#include <dpsim-models/EMT/EMT_Ph3_SeriesResistor.h>
#include <dpsim-models/EMT/EMT_Ph3_ResIndSeries.h>
Expand All @@ -115,7 +118,7 @@
#include <dpsim-models/EMT/EMT_Ph3_SynchronGeneratorDQ.h>
#include <dpsim-models/EMT/EMT_Ph3_SynchronGeneratorDQTrapez.h>
#ifdef WITH_SUNDIALS
#include <dpsim-models/EMT/EMT_Ph3_SynchronGeneratorDQODE.h>
#include <dpsim-models/EMT/EMT_Ph3_SynchronGeneratorDQODE.h>
#endif
#include <dpsim-models/EMT/EMT_Ph3_SynchronGeneratorIdeal.h>
#include <dpsim-models/EMT/EMT_Ph3_SynchronGeneratorVBR.h>
Expand Down Expand Up @@ -152,3 +155,4 @@
#include <dpsim-models/Signal/VoltageControllerVSI.h>
#include <dpsim-models/Signal/VSIControlType1.h>
#include <dpsim-models/Signal/VSIControlType2.h>
#include <dpsim-models/Signal/DroopController.h>
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@

#include <dpsim-models/CompositePowerComp.h>
#include <dpsim-models/Solver/MNAInterface.h>
#include <dpsim-models/DP/DP_Ph1_VoltageSource.h>
#include <dpsim-models/DP/DP_Ph1_ResIndSeries.h>
#include <dpsim-models/DP/DP_Ph1_Resistor.h>
#include <dpsim-models/DP/DP_Ph1_Capacitor.h>
#include <dpsim-models/DP/DP_Ph1_VoltageSource.h>
#include <dpsim-models/Base/Base_VSIVoltageSourceInverterDQ.h>
#include <dpsim-models/Signal/VoltageControllerVSI.h>

namespace CPS {
namespace DP {
Expand All @@ -23,8 +22,8 @@ namespace Ph1 {
public CompositePowerComp<Complex>,
public Base::VSIVoltageSourceInverterDQ<Complex>,
public SharedFactory<VSIVoltageControlDQ> {
protected:

protected:
// ### Electrical Subcomponents ###
/// Controlled voltage source
std::shared_ptr<DP::Ph1::VoltageSource> mSubCtrledVoltageSource;
Expand Down
Loading

0 comments on commit 7de5f87

Please sign in to comment.