Skip to content

Commit

Permalink
solve rebase conflicts
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Moraga <[email protected]>
  • Loading branch information
martinmoraga committed May 25, 2023
1 parent 2fc6ce1 commit 0a33674
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ namespace CPS {
private:
///
CPS::Signal::SignalGenerator::Ptr mSrcSig;

public:
// TODO: MAKE THIS FUNCTION PRIVATE (BUT NETWORKINJECTION NEED THIS FUNCTION...)
// Updates voltage according to reference phasor and frequency
void updateVoltage(Real time);
public:
const CPS::Attribute<MatrixComp>::Ptr mVoltageRef;
const CPS::Attribute<Real>::Ptr mSrcFreq;
Expand Down
5 changes: 3 additions & 2 deletions dpsim-models/src/EMT/EMT_Ph1_Capacitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ using namespace CPS;

EMT::Ph1::Capacitor::Capacitor(String uid, String name, Logger::Level logLevel)
: MNASimPowerComp<Real>(uid, name, true, true, logLevel),
Base::Ph1::Capacitor(mAttributes)
mIntfDerVoltage(Attribute<Matrix>::create("dv_intf", mAttributes)), {
Base::Ph1::Capacitor(mAttributes),
mIntfDerVoltage(mAttributes->create<Matrix>("dv_intf")) {

mEquivCurrent = 0;
**mIntfVoltage = Matrix::Zero(1,1);
**mIntfCurrent = Matrix::Zero(1,1);
Expand Down
2 changes: 1 addition & 1 deletion dpsim-models/src/EMT/EMT_Ph1_Inductor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ using namespace CPS;
EMT::Ph1::Inductor::Inductor(String uid, String name, Logger::Level logLevel)
: MNASimPowerComp<Real>(uid, name, true, true, logLevel),
Base::Ph1::Inductor(mAttributes),
mIntfDerCurrent(Attribute<Matrix>::create("di_intf", mAttributes)) {
mIntfDerCurrent(mAttributes->create<Matrix>("di_intf")) {

mEquivCurrent = 0;
**mIntfVoltage = Matrix::Zero(1,1);
Expand Down
2 changes: 1 addition & 1 deletion dpsim-models/src/EMT/EMT_Ph1_VoltageSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void EMT::Ph1::VoltageSource::setInitialComplexIntfCurrent(Complex initCurrent)
(**mIntfCurrent)(0, 0) = initCurrent.real();

// Calculate initial derivative of current = -omega*Imag(Complex_voltage)
Real omega = 2 * PI * attribute<Real>("f_src")->get();
Real omega = 2 * PI * **mSrcFreq;

mIntfDerCurrent = Matrix::Zero(1, 1);
mIntfDerCurrent(0,0) = -omega * initCurrent.imag();
Expand Down
3 changes: 2 additions & 1 deletion dpsim-models/src/EMT/EMT_Ph3_Capacitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ using namespace CPS;
EMT::Ph3::Capacitor::Capacitor(String uid, String name, Logger::Level logLevel)
: MNASimPowerComp<Real>(uid, name, true, true, logLevel),
Base::Ph3::Capacitor(mAttributes),
mIntfDerVoltage(Attribute<Matrix>::create("dv_intf", mAttributes)) {
mIntfDerVoltage(mAttributes->create<Matrix>("dv_intf")) {

mPhaseType = PhaseType::ABC;
setTerminalNumber(2);
mEquivCurrent = Matrix::Zero(3, 1);
Expand Down
2 changes: 1 addition & 1 deletion dpsim-models/src/EMT/EMT_Ph3_Inductor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ using namespace CPS;
EMT::Ph3::Inductor::Inductor(String uid, String name, Logger::Level logLevel)
: MNASimPowerComp<Real>(uid, name, true, true, logLevel),
Base::Ph3::Inductor(mAttributes),
mIntfDerCurrent(Attribute<Matrix>::create("di_intf", mAttributes)) {
mIntfDerCurrent(mAttributes->create<Matrix>("di_intf")) {

mPhaseType = PhaseType::ABC;
setTerminalNumber(2);
Expand Down
16 changes: 16 additions & 0 deletions dpsim-models/src/EMT/EMT_Ph3_RXLoad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ void EMT::Ph3::RXLoad::daeInitialize(double time, double state[], double dstate_
absoluteTolerances[offset+1] = mAbsTolerance;
absoluteTolerances[offset+2] = mAbsTolerance;

// TODO: MAKE mConductance a member variable
Matrix mConductance = Matrix::Zero(3, 3);
Math::invertMatrix(mResistance, mConductance);

mSLog->info(
"\n--- daeInitialize ---"
"\nmReactance(0,0) > 0 --> state variable are inductor currents"
Expand Down Expand Up @@ -317,6 +321,10 @@ void EMT::Ph3::RXLoad::daeResidual(double sim_time,
// current offset for component
int c_offset = off[0] + off[1];

// TODO: MAKE mConductance a member variable
Matrix mConductance = Matrix::Zero(3, 3);
Math::invertMatrix(mResistance, mConductance);

if ((**mActivePower)(0, 0) != 0) {
// add currents through resistor to nodal equations
resid[matrixNodeIndex(0, 0)] += state[matrixNodeIndex(0, 0)] * mConductance(0,0);
Expand Down Expand Up @@ -346,6 +354,10 @@ void EMT::Ph3::RXLoad::daeJacobian(double current_time, const double state[],
// current offset for component
int c_offset = off[0] + off[1];

// TODO: MAKE mConductance a member variable
Matrix mConductance = Matrix::Zero(3, 3);
Math::invertMatrix(mResistance, mConductance);

if ((**mActivePower)(0, 0) != 0) {
SM_ELEMENT_D(jacobian, matrixNodeIndex(0, 0), matrixNodeIndex(0, 0)) += mConductance(0,0);
SM_ELEMENT_D(jacobian, matrixNodeIndex(0, 1), matrixNodeIndex(0, 1)) += mConductance(1,1);
Expand Down Expand Up @@ -376,6 +388,10 @@ void EMT::Ph3::RXLoad::daeJacobian(double current_time, const double state[],
void EMT::Ph3::RXLoad::daePostStep(double Nexttime, const double state[],
const double dstate_dt[], int& offset) {

// TODO: MAKE mConductance a member variable
Matrix mConductance = Matrix::Zero(3, 3);
Math::invertMatrix(mResistance, mConductance);

(**mIntfVoltage)(0, 0) = state[matrixNodeIndex(0, 0)];
(**mIntfVoltage)(1, 0) = state[matrixNodeIndex(0, 1)];
(**mIntfVoltage)(2, 0) = state[matrixNodeIndex(0, 2)];
Expand Down
10 changes: 10 additions & 0 deletions dpsim-models/src/EMT/EMT_Ph3_Resistor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ void EMT::Ph3::Resistor::daeResidual(double sim_time,
const double state[], const double dstate_dt[],
double resid[], std::vector<int>& off) {

// TODO: MAKE mConductance a member variable
Matrix mConductance = Matrix::Zero(3, 3);
Math::invertMatrix(**mResistance, mConductance);
if (terminalNotGrounded(1)) {
resid[matrixNodeIndex(1,0)] += state[matrixNodeIndex(1,0)] * mConductance(0,0) + state[matrixNodeIndex(1,1)] * mConductance(0,1) + state[matrixNodeIndex(1,2)] * mConductance(0,2);
resid[matrixNodeIndex(1,1)] += state[matrixNodeIndex(1,0)] * mConductance(1,0) + state[matrixNodeIndex(1,1)] * mConductance(1,1) + state[matrixNodeIndex(1,2)] * mConductance(1,2);
Expand All @@ -203,6 +206,9 @@ void EMT::Ph3::Resistor::daeResidual(double sim_time,
void EMT::Ph3::Resistor::daeJacobian(double current_time, const double state[],
const double dstate_dt[], SUNMatrix jacobian, double cj, std::vector<int>& off) {

// TODO: MAKE mConductance a member variable
Matrix mConductance = Matrix::Zero(3, 3);
Math::invertMatrix(**mResistance, mConductance);
if (terminalNotGrounded(1)) {
SM_ELEMENT_D(jacobian, matrixNodeIndex(1,0), matrixNodeIndex(1,0)) += mConductance(0,0);
SM_ELEMENT_D(jacobian, matrixNodeIndex(1,0), matrixNodeIndex(1,1)) += mConductance(0,1);
Expand Down Expand Up @@ -264,5 +270,9 @@ void EMT::Ph3::Resistor::daePostStep(double Nexttime, const double state[], cons
(**mIntfVoltage)(2, 0) -= state[matrixNodeIndex(0, 2)];

}

// TODO: MAKE mConductance a member variable
Matrix mConductance = Matrix::Zero(3, 3);
Math::invertMatrix(**mResistance, mConductance);
**mIntfCurrent = mConductance * **mIntfVoltage;
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ void EMT::Ph3::SynchronGenerator3OrderVBR::daeResidual(double sim_time,
**mIntfCurrent = mBase_I * mDq0ToAbc * **mIdq0;

// residual function for Eq_t
resid[c_offset] = mTd0_t * dstate_dt[c_offset] + state[c_offset] - mEf + (mLd - mLd_t) * (**mIdq0)(0,0);
resid[c_offset] = mTd0_t * dstate_dt[c_offset] + state[c_offset] - **mEf + (mLd - mLd_t) * (**mIdq0)(0,0);

// residual function for omega
**mElecTorque = ((**mVdq0)(0,0) * (**mIdq0)(0,0) + (**mVdq0)(1,0) * (**mIdq0)(1,0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ void EMT::Ph3::SynchronGenerator4OrderVBR::daeResidual(double sim_time,
//resid[c_offset] = mTq0_t * dstate_dt[c_offset] + state[c_offset] - (mLq - mLq_t) * (**mIdq0)(1,0);
//resid[c_offset+1] = mTd0_t * dstate_dt[c_offset+1] + state[c_offset+1] - mEf + (mLd - mLd_t) * (**mIdq0)(0,0);
resid[c_offset] = mTq0_t * dstate_dt[c_offset] + state[c_offset] - (mLq - mLq_t) * state[c_offset+5];
resid[c_offset+1] = mTd0_t * dstate_dt[c_offset+1] + state[c_offset+1] - mEf + (mLd - mLd_t) * state[c_offset+4];
resid[c_offset+1] = mTd0_t * dstate_dt[c_offset+1] + state[c_offset+1] - **mEf + (mLd - mLd_t) * state[c_offset+4];

// residual function for omega
(**mIdq0)(0,0) = state[c_offset+4];
Expand Down
2 changes: 1 addition & 1 deletion dpsim-models/src/EMT/EMT_Ph3_VoltageSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ void EMT::Ph3::VoltageSource::setInitialComplexIntfCurrent(Complex initCurrent)
(**mIntfCurrent)(2, 0) = (initCurrent*SHIFT_TO_PHASE_C).real();

// Calculate initial derivative of current = -omega*Imag(Complex_voltage)
Real omega = 2 * PI * attribute<Real>("f_src")->get();
Real omega = 2 * PI * **mSrcFreq;

mIntfDerCurrent = Matrix::Zero(3,1);
mIntfDerCurrent(0,0) = -omega * initCurrent.imag();
Expand Down
3 changes: 3 additions & 0 deletions dpsim/include/dpsim/Simulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@

using json = nlohmann::json;

// TODO: where is realtype defined?
using realtype = CPS::Real;

namespace DPsim {
/// Forward declaration of CommandLineArgs from Utils
class CommandLineArgs;
Expand Down
2 changes: 1 addition & 1 deletion dpsim/src/pybind/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ PYBIND11_MODULE(dpsimpy, m) {
.def("set_solver_component_behaviour", &DPsim::Simulation::setSolverAndComponentBehaviour)
.def("set_direct_solver_implementation", &DPsim::Simulation::setDirectLinearSolverImplementation)
.def("set_direct_linear_solver_configuration", &DPsim::Simulation::setDirectLinearSolverConfiguration)
.def("log_lu_times", &DPsim::Simulation::logLUTimes);
.def("log_lu_times", &DPsim::Simulation::logLUTimes)
.def("set_relative_rolerance", &DPsim::Simulation::setRelativeTolerance, "rel_tol"_a)
.def("set_ida_max_conv_fails", &DPsim::Simulation::setIDAMaxConvFails, "ida_max_conv_fails"_a)
.def("set_ida_non_lin_conv_coef", &DPsim::Simulation::setIDANonlinConvCoef, "ida_non_lin_conv_coef"_a)
Expand Down

0 comments on commit 0a33674

Please sign in to comment.