Skip to content

Commit

Permalink
solve rebase errors
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Moraga <[email protected]>
  • Loading branch information
martinmoraga committed Mar 27, 2023
1 parent 4c8df43 commit 5f993b6
Show file tree
Hide file tree
Showing 15 changed files with 112 additions and 48 deletions.
12 changes: 8 additions & 4 deletions dpsim-models/include/dpsim-models/DP/DP_Ph1_ResIndSeries.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ namespace Ph1 {
void mnaCompInitialize(Real omega, Real timeStep, Attribute<Matrix>::Ptr leftVector) override;
void mnaCompInitializeHarm(Real omega, Real timeStep, std::vector<Attribute<Matrix>::Ptr> leftVectors) override;
/// Stamps system matrix
void mnaCompApplySystemMatrixStamp(Matrix& systemMatrix) override;
void mnaCompApplySystemMatrixStampHarm(Matrix& systemMatrix, Int freqIdx) override;
void mnaCompApplySystemMatrixStamp(SparseMatrixRow& systemMatrix) override;
void mnaCompApplySystemMatrixStampHarm(SparseMatrixRow& systemMatrix, Int freqIdx) override;
/// Stamps right side (source) vector
void mnaCompApplyRightSideVectorStamp(Matrix& rightVector) override;
void mnaCompApplyRightSideVectorStampHarm(Matrix& rightVector) override;
Expand Down Expand Up @@ -108,8 +108,12 @@ namespace Ph1 {
std::vector< Attribute<Matrix>::Ptr > mLeftVectors;
};

// #### MNA Tear Section ####
void mnaTearApplyMatrixStamp(Matrix& tearMatrix) override;
// #### Tearing methods ####
void mnaTearInitialize(Real omega, Real timestep) override;
void mnaTearApplyMatrixStamp(SparseMatrixRow& tearMatrix) override;
void mnaTearApplyVoltageStamp(Matrix& voltageVector) override;
void mnaTearPostStep(Complex voltage, Complex current) override;

};
}
}
Expand Down
2 changes: 1 addition & 1 deletion dpsim-models/include/dpsim-models/DP/DP_Ph1_Resistor.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ namespace Ph1 {
};

// #### MNA Tear Section ####
void mnaTearApplyMatrixStamp(SparseMatrixRow& tearMatrix);
void mnaTearApplyMatrixStamp(SparseMatrixRow& tearMatrix) override;

// #### DAE Section ####
///Residual Function for DAE Solver
Expand Down
2 changes: 0 additions & 2 deletions dpsim-models/include/dpsim-models/EMT/EMT_Ph1_VoltageSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ namespace Ph1 {
class VoltageSource :
public MNASimPowerComp<Real>,
public SharedFactory<VoltageSource> {
private:
Real mTimeStep;
protected:
void updateVoltage(Real time);
public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace CPS {
/// Initializes internal variables of the component
void mnaCompInitialize(Real omega, Real timeStep, Attribute<Matrix>::Ptr leftSideVector) override;
/// Stamps system matrix
void mnaCompApplySystemMatrixStamp(Matrix& systemMatrix) override;
void mnaCompApplySystemMatrixStamp(SparseMatrixRow& systemMatrix) override;
/// Stamps right side (source) vector
void mnaCompApplyRightSideVectorStamp(Matrix& rightVector) override;
/// Update interface voltage from MNA system result
Expand Down
2 changes: 1 addition & 1 deletion dpsim-models/include/dpsim-models/EMT/EMT_Ph3_Resistor.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Resistor :
/// Initializes internal variables of the component
void mnaCompInitialize(Real omega, Real timeStep, Attribute<Matrix>::Ptr leftSideVector) override;
/// Stamps system matrix
void mnaCompApplySystemMatrixStamp(Matrix& systemMatrix) override;
void mnaCompApplySystemMatrixStamp(SparseMatrixRow& systemMatrix) override;
/// Stamps right side (source) vector
void mnaCompApplyRightSideVectorStamp(Matrix& rightVector) override { }
/// Update interface voltage from MNA system result
Expand Down
4 changes: 2 additions & 2 deletions dpsim-models/include/dpsim-models/SP/SP_Ph1_Inductor.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ namespace Ph1 {
void mnaCompPostStep(Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector);
/// Add MNA post step dependencies
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute<Matrix>::Ptr &leftVector);

void mnaTearApplyMatrixStamp(Matrix& tearMatrix) override;
//
void mnaTearApplyMatrixStamp(SparseMatrixRow& tearMatrix) override;
};
}
}
Expand Down
4 changes: 2 additions & 2 deletions dpsim-models/include/dpsim-models/SP/SP_Ph1_ResIndSeries.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace Ph1 {
/// Initializes MNA specific variables
void mnaCompInitialize(Real omega, Real timeStep, Attribute<Matrix>::Ptr leftVector) override;
/// Stamps system matrix
void mnaCompApplySystemMatrixStamp(Matrix& systemMatrix) override;
void mnaCompApplySystemMatrixStamp(SparseMatrixRow& systemMatrix) override;
/// Update interface voltage from MNA system result
void mnaCompUpdateVoltage(const Matrix& leftVector) override;
/// Update interface current from MNA system result
Expand All @@ -57,7 +57,7 @@ namespace Ph1 {
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute<Matrix>::Ptr &leftVector) override;

// #### MNA Tear Section ####
void mnaTearApplyMatrixStamp(Matrix& tearMatrix) override;
void mnaTearApplyMatrixStamp(SparseMatrixRow& tearMatrix) override;
};
}
}
Expand Down
4 changes: 2 additions & 2 deletions dpsim-models/include/dpsim-models/SP/SP_Ph1_Resistor.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ namespace Ph1 {
///
void mnaCompInitialize(Real omega, Real timeStep, Attribute<Matrix>::Ptr leftVector) override;
/// Stamps system matrix
void mnaCompApplySystemMatrixStamp(Matrix& systemMatrix) override;
void mnaCompApplySystemMatrixStamp(SparseMatrixRow& systemMatrix) override;
/// Update interface voltage from MNA system result
void mnaCompUpdateVoltage(const Matrix& leftVector) override;
/// Update interface current from MNA system result
Expand All @@ -80,7 +80,7 @@ namespace Ph1 {
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute<Matrix>::Ptr &leftVector) override;

// #### MNA Tear Section ####
void mnaTearApplyMatrixStamp(Matrix& tearMatrix) override;
void mnaTearApplyMatrixStamp(SparseMatrixRow& tearMatrix) override;

};
}
Expand Down
3 changes: 1 addition & 2 deletions dpsim-models/src/DP/DP_Ph1_PiLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ void DP::Ph1::PiLine::mnaTearInitialize(Real omega, Real timeStep) {
}

void DP::Ph1::PiLine::mnaTearApplyMatrixStamp(SparseMatrixRow& tearMatrix) {
mSubSeriesResistor->mnaTearApplyMatrixStamp(tearMatrix);
mSubSeriesInductor->mnaTearApplyMatrixStamp(tearMatrix);
mSubSeriesElement->mnaTearApplyMatrixStamp(tearMatrix);
}

void DP::Ph1::PiLine::mnaTearApplyVoltageStamp(Matrix& voltageVector) {
Expand Down
1 change: 0 additions & 1 deletion dpsim-models/src/DP/DP_Ph1_ResIndSeries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,5 +298,4 @@ void DP::Ph1::ResIndSeries::mnaTearApplyVoltageStamp(Matrix& voltageVector) {
void DP::Ph1::ResIndSeries::mnaTearPostStep(Complex voltage, Complex current) {
(**mIntfVoltage)(0, 0) = voltage;
(**mIntfCurrent)(0, 0) = mEquivCond(0,0) * voltage + mEquivCurrent(0,0);

}
4 changes: 1 addition & 3 deletions dpsim-models/src/EMT/EMT_Ph1_VoltageSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ SimPowerComp<Real>::Ptr EMT::Ph1::VoltageSource::clone(String name) {
void EMT::Ph1::VoltageSource::mnaCompInitialize(Real omega, Real timeStep, Attribute<Matrix>::Ptr leftVector) {
updateMatrixNodeIndices();
(**mIntfVoltage)(0,0) = Math::abs(**mVoltageRef) * cos(Math::phase(**mVoltageRef));

mTimeStep = timeStep;
}

void EMT::Ph1::VoltageSource::mnaCompApplySystemMatrixStamp(SparseMatrixRow& systemMatrix) {
Expand Down Expand Up @@ -68,7 +66,7 @@ void EMT::Ph1::VoltageSource::updateVoltage(Real time) {
Complex voltageRef = mVoltageRef->get();
Real srcFreq = mSrcFreq->get();
if (srcFreq > 0)
(**mIntfVoltage)(0,0) = Math::abs(voltageRef) * cos((time) * 2.*PI*srcFreq + Math::phase(voltageRef));
(**mIntfVoltage)(0,0) = Math::abs(voltageRef) * cos(time * 2. * PI * srcFreq + Math::phase(voltageRef));
else
(**mIntfVoltage)(0,0) = voltageRef.real();
}
Expand Down
2 changes: 1 addition & 1 deletion dpsim-models/src/EMT/EMT_Ph3_ResIndSeries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void EMT::Ph3::ResIndSeries::mnaCompInitialize(Real omega, Real timeStep, Attrib
mSLog->flush();
}

void EMT::Ph3::ResIndSeries::mnaCompApplySystemMatrixStamp(Matrix& systemMatrix) {
void EMT::Ph3::ResIndSeries::mnaCompApplySystemMatrixStamp(SparseMatrixRow& systemMatrix) {

// Set diagonal entries
if (terminalNotGrounded(0)) {
Expand Down
4 changes: 2 additions & 2 deletions dpsim-models/src/SP/SP_Ph1_ResIndSeries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void SP::Ph1::ResIndSeries::mnaCompInitialize(Real omega, Real timeStep, Attribu
Logger::phasorToString((**mIntfCurrent)(0, 0)));
}

void SP::Ph1::ResIndSeries::mnaCompApplySystemMatrixStamp(Matrix& systemMatrix) {
void SP::Ph1::ResIndSeries::mnaCompApplySystemMatrixStamp(SparseMatrixRow& systemMatrix) {
Complex conductance = 1. / mImpedance;

for (UInt freq = 0; freq < mNumFreqs; freq++) {
Expand Down Expand Up @@ -132,6 +132,6 @@ void SP::Ph1::ResIndSeries::mnaCompUpdateCurrent(const Matrix& leftVector) {
}

// #### Tear Methods ####
void SP::Ph1::ResIndSeries::mnaTearApplyMatrixStamp(Matrix& tearMatrix) {
void SP::Ph1::ResIndSeries::mnaTearApplyMatrixStamp(SparseMatrixRow& tearMatrix) {
Math::addToMatrixElement(tearMatrix, mTearIdx, mTearIdx, mImpedance);
}
106 changes: 86 additions & 20 deletions examples/Notebooks/Circuits/Validation_RL_Element.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
"resistance = 10\n",
"inductance = 1e-3\n",
"capacitance = 5e-6\n",
"frequency = 50"
"frequency = 50\n",
"epsilon = 1e-12"
]
},
{
Expand Down Expand Up @@ -319,16 +320,19 @@
},
{
"cell_type": "code",
"execution_count": 45,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# calculate the RMSE between both models\n",
"err_current = ts.rmse(ts_dpsim_comps[\"l1.i_intf_shift\"], ts_dpsim_dp[\"rl.i_intf_shift\"])\n",
"err_voltage = ts.rmse(ts_dpsim_comps[\"n3.v_shift\"], ts_dpsim_dp[\"n2.v_shift\"])\n",
"\n",
"assert err_current < 0.00001\n",
"assert err_voltage < 0.00001"
"print(err_current)\n",
"print(err_voltage)\n",
"\n",
"assert err_current < epsilon\n",
"assert err_voltage < epsilon"
]
},
{
Expand Down Expand Up @@ -450,9 +454,9 @@
"# Components\n",
"vs = dpsimpy.emt.ph3.VoltageSource('vs', dpsimpy.LogLevel.off)\n",
"vs.set_parameters(V_ref=dpsimpy.Math.single_phase_variable_to_three_phase(complex(10, 0)), f_src=frequency)\n",
"rl = dpsimpy.emt.ph3.ResInductor('rl', dpsimpy.LogLevel.off)\n",
"rl = dpsimpy.emt.ph3.ResInductor('rl', dpsimpy.LogLevel.debug)\n",
"rl.set_parameters(R=dpsimpy.Math.single_phase_parameter_to_three_phase(resistance), L=dpsimpy.Math.single_phase_parameter_to_three_phase(inductance))\n",
"c1 = dpsimpy.emt.ph3.Capacitor('c1', dpsimpy.LogLevel.off)\n",
"c1 = dpsimpy.emt.ph3.Capacitor('c1', dpsimpy.LogLevel.debug)\n",
"c1.set_parameters(C=dpsimpy.Math.single_phase_parameter_to_three_phase(capacitance))\n",
"\n",
"# Connections\n",
Expand All @@ -473,7 +477,7 @@
"sim = dpsimpy.Simulation(name_emt, dpsimpy.LogLevel.off)\n",
"sim.set_system(system)\n",
"sim.set_domain(dpsimpy.Domain.EMT)\n",
"sim.set_time_step(0.00001)\n",
"sim.set_time_step(0.0001)\n",
"sim.set_final_time(0.02)\n",
"sim.add_logger(logger)\n",
"sim.run()"
Expand Down Expand Up @@ -503,7 +507,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Plot Results"
"### Plot Results phase a"
]
},
{
Expand All @@ -512,10 +516,10 @@
"metadata": {},
"outputs": [],
"source": [
"ts_dpsim_emt_ref[\"l1.i_intf_0\"].label = 'i - REF'\n",
"ts_dpsim_emt_ref[\"n3.v_0\"].label = 'vc - REF'\n",
"ts_dpsim_emt[\"rl.i_intf_0\"].label = 'i RL Element'\n",
"ts_dpsim_emt[\"n2.v_0\"].label = 'vc RL Element'\n",
"ts_dpsim_emt_ref[\"l1.i_intf_0\"].label = 'i (phase a) - REF'\n",
"ts_dpsim_emt_ref[\"n3.v_0\"].label = 'vc (phase a) - REF'\n",
"ts_dpsim_emt[\"rl.i_intf_0\"].label = 'i (phase a) RL Element'\n",
"ts_dpsim_emt[\"n2.v_0\"].label = 'vc (phase a) RL Element'\n",
"\n",
"pt.plot_timeseries(3, ts_dpsim_emt_ref[\"n3.v_0\"])\n",
"pt.plot_timeseries(3, ts_dpsim_emt[\"n2.v_0\"], plt_linestyle='--')\n",
Expand All @@ -524,6 +528,42 @@
"pt.plot_timeseries(4, ts_dpsim_emt[\"rl.i_intf_0\"], plt_linestyle='--')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ts_dpsim_emt_ref[\"l1.i_intf_1\"].label = 'i (phase b) - REF'\n",
"ts_dpsim_emt_ref[\"n3.v_1\"].label = 'vc (phase b) - REF'\n",
"ts_dpsim_emt[\"rl.i_intf_1\"].label = 'i (phase b) RL Element'\n",
"ts_dpsim_emt[\"n2.v_1\"].label = 'vc RL (phase b) Element'\n",
"\n",
"pt.plot_timeseries(3, ts_dpsim_emt_ref[\"n3.v_1\"])\n",
"pt.plot_timeseries(3, ts_dpsim_emt[\"n2.v_1\"], plt_linestyle='--')\n",
"\n",
"pt.plot_timeseries(4, ts_dpsim_emt_ref[\"l1.i_intf_1\"])\n",
"pt.plot_timeseries(4, ts_dpsim_emt[\"rl.i_intf_1\"], plt_linestyle='--')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ts_dpsim_emt_ref[\"l1.i_intf_2\"].label = 'i (phase c) - REF'\n",
"ts_dpsim_emt_ref[\"n3.v_2\"].label = 'vc (phase c) - REF'\n",
"ts_dpsim_emt[\"rl.i_intf_2\"].label = 'i (phase c) RL Element'\n",
"ts_dpsim_emt[\"n2.v_2\"].label = 'vc RL (phase c) Element'\n",
"\n",
"pt.plot_timeseries(3, ts_dpsim_emt_ref[\"n3.v_2\"])\n",
"pt.plot_timeseries(3, ts_dpsim_emt[\"n2.v_2\"], plt_linestyle='--')\n",
"\n",
"pt.plot_timeseries(4, ts_dpsim_emt_ref[\"l1.i_intf_2\"])\n",
"pt.plot_timeseries(4, ts_dpsim_emt[\"rl.i_intf_2\"], plt_linestyle='--')"
]
},
{
"attachments": {},
"cell_type": "markdown",
Expand All @@ -534,16 +574,39 @@
},
{
"cell_type": "code",
"execution_count": 46,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# calculate the RMSE between both models\n",
"# calculate the RMSE between both models phase a\n",
"err_current = ts.rmse(ts_dpsim_emt_ref[\"l1.i_intf_0\"], ts_dpsim_emt[\"rl.i_intf_0\"])\n",
"err_voltage = ts.rmse(ts_dpsim_emt_ref[\"n3.v_0\"], ts_dpsim_emt[\"n2.v_0\"])\n",
"\n",
"assert err_current < 0.001\n",
"assert err_voltage < 0.001"
"print(err_current)\n",
"print(err_voltage)\n",
"\n",
"assert err_current < epsilon\n",
"assert err_voltage < epsilon\n",
"\n",
"# calculate the RMSE between both models phase b\n",
"err_current = ts.rmse(ts_dpsim_emt_ref[\"l1.i_intf_1\"], ts_dpsim_emt[\"rl.i_intf_1\"])\n",
"err_voltage = ts.rmse(ts_dpsim_emt_ref[\"n3.v_1\"], ts_dpsim_emt[\"n2.v_1\"])\n",
"\n",
"print(err_current)\n",
"print(err_voltage)\n",
"\n",
"assert err_current < epsilon\n",
"assert err_voltage < epsilon\n",
"\n",
"# calculate the RMSE between both models phase a\n",
"err_current = ts.rmse(ts_dpsim_emt_ref[\"l1.i_intf_2\"], ts_dpsim_emt[\"rl.i_intf_2\"])\n",
"err_voltage = ts.rmse(ts_dpsim_emt_ref[\"n3.v_2\"], ts_dpsim_emt[\"n2.v_2\"])\n",
"\n",
"print(err_current)\n",
"print(err_voltage)\n",
"\n",
"assert err_current < epsilon\n",
"assert err_voltage < epsilon"
]
},
{
Expand Down Expand Up @@ -756,16 +819,19 @@
},
{
"cell_type": "code",
"execution_count": 44,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# calculate the RMSE between both models\n",
"err_current = ts.rmse(ts_dpsim_sp_ref[\"l1.i_intf_shift\"], ts_dpsim_sp[\"rl.i_intf_shift\"])\n",
"err_voltage = ts.rmse(ts_dpsim_sp_ref[\"n3.v_shift\"], ts_dpsim_sp[\"n2.v_shift\"])\n",
"\n",
"assert err_current < 0.00001\n",
"assert err_voltage < 0.00001"
"print(err_current)\n",
"print(err_voltage)\n",
"\n",
"assert err_current < epsilon\n",
"assert err_voltage < epsilon"
]
}
],
Expand All @@ -785,7 +851,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13 (main, May 18 2022, 00:00:00) \n[GCC 11.3.1 20220421 (Red Hat 11.3.1-2)]"
"version": "3.9.13"
},
"orig_nbformat": 4,
"vscode": {
Expand Down
Loading

0 comments on commit 5f993b6

Please sign in to comment.