Commit ced7376c authored by Jan Dinkelbach's avatar Jan Dinkelbach Committed by Markus Mirz
Browse files

update emt3ph voltage source

parent 39acad66
......@@ -107,7 +107,7 @@ void simElementsEMT3ph() {
// Components
auto vs = EMT::Ph3::VoltageSource::make("vs1");
vs->setParameters(CPS::Math::polar(100000, 0), 50);
vs->setParameters(Reader::singlePhaseVariableToThreePhase(CPS::Math::polar(100000, 0)), 50);
auto load = EMT::Ph3::Resistor::make("Rload");
load->setParameters(Reader::singlePhaseParameterToThreePhase(10000));
......
......@@ -31,7 +31,7 @@ void voltageSourceResistorEMT3ph() {
// Components
auto vs = EMT::Ph3::VoltageSource::make("vs1");
vs->setParameters(CPS::Math::polar(100000, -PI/2.), 50);
vs->setParameters(Reader::singlePhaseVariableToThreePhase(CPS::Math::polar(100000, 0)), 50);
auto res = EMT::Ph3::Resistor::make("R1");
res->setParameters(Reader::singlePhaseParameterToThreePhase(100));
......@@ -70,7 +70,7 @@ void voltageSourceResistorDP1ph() {
// Components
auto vs = DP::Ph1::VoltageSource::make("vs1");
vs->setParameters(CPS::Math::polar(100000, -PI/2.));
vs->setParameters(CPS::Math::polar(100000, 0));
auto res = DP::Ph1::Resistor::make("R1");
res->setParameters(100);
......@@ -110,7 +110,7 @@ void voltageSourceInductorEMT3ph() {
// Components
auto vs = EMT::Ph3::VoltageSource::make("vs1", Logger::Level::debug);
vs->setParameters(CPS::Math::polar(100000, 0), 50);
vs->setParameters(Reader::singlePhaseVariableToThreePhase(CPS::Math::polar(100000, 0)), 50);
auto res = EMT::Ph3::Resistor::make("R1");
res->setParameters(Reader::singlePhaseParameterToThreePhase(5));
......@@ -202,7 +202,7 @@ void voltageSourceCapacitorEMT3ph() {
// Components
auto vs = EMT::Ph3::VoltageSource::make("vs1", Logger::Level::debug);
vs->setParameters(CPS::Math::polar(100000, 0), 50);
vs->setParameters(Reader::singlePhaseVariableToThreePhase(CPS::Math::polar(100000, 0)), 50);
auto res = EMT::Ph3::Resistor::make("R1");
res->setParameters(Reader::singlePhaseParameterToThreePhase(5));
......
......@@ -31,7 +31,7 @@ namespace CPS {
void updateVoltage(Matrix vabc);
/// Magnitude of the sinusoidal voltage (peak-value, phase-to-ground)
Attribute<Complex>::Ptr mVoltageRef;
Attribute<MatrixComp>::Ptr mVoltageRef;
/// Frequency of the sinusoidal voltage
Attribute<Real>::Ptr mSrcFreq;
public:
......@@ -41,7 +41,7 @@ namespace CPS {
VoltageSource(String name, Logger::Level logLevel = Logger::Level::off)
: VoltageSource(name, name, logLevel) { }
void setParameters(Complex voltageRef, Real srcFreq = -1);
void setParameters(MatrixComp voltageRef, Real srcFreq = -1);
SimPowerComp<Real>::Ptr clone(String name);
// #### General ####
......
......@@ -19,40 +19,52 @@ EMT::Ph3::VoltageSource::VoltageSource(String uid, String name, Logger::Level lo
mIntfVoltage = Matrix::Zero(3, 1);
mIntfCurrent = Matrix::Zero(3, 1);
addAttribute<Complex>("V_ref", Flags::read | Flags::write);
addAttribute<MatrixComp>("V_ref", Flags::read | Flags::write);
addAttribute<Real>("f_src", Flags::read | Flags::write);
}
void EMT::Ph3::VoltageSource::setParameters(Complex voltageRef, Real srcFreq) {
attribute<Complex>("V_ref")->set(voltageRef);
void EMT::Ph3::VoltageSource::setParameters(MatrixComp voltageRef, Real srcFreq) {
attribute<MatrixComp>("V_ref")->set(voltageRef);
attribute<Real>("f_src")->set(srcFreq);
mSLog->info("\nVoltage reference phasor [V]: {:s}"
"\nFrequency [Hz]: {:s}",
Logger::phasorToString(voltageRef),
Logger::matrixCompToString(voltageRef),
Logger::realToString(srcFreq));
mParametersSet = true;
}
void EMT::Ph3::VoltageSource::initializeFromNodesAndTerminals(Real frequency) {
mVoltageRef = attribute<Complex>("V_ref");
mVoltageRef = attribute<MatrixComp>("V_ref");
mSrcFreq = attribute<Real>("f_src");
mSrcFreq->set(frequency);
mSLog->info("\n--- Initialization from node voltages ---");
// TODO: this approach currently does not work, if voltage ref set from outside without using setParameters,
// since mParametersSet remains false then
if (!mParametersSet) {
mVoltageRef->set(initialSingleVoltage(1) - initialSingleVoltage(0));
mSrcFreq->set(frequency);
MatrixComp vInitABC = MatrixComp::Zero(3, 1);
vInitABC(0, 0) = initialSingleVoltage(0);
vInitABC(1, 0) = initialSingleVoltage(0) * SHIFT_TO_PHASE_B;
vInitABC(2, 0) = initialSingleVoltage(0) * SHIFT_TO_PHASE_C;
mVoltageRef->set(vInitABC);
mSLog->info("\nReference voltage: {:s}"
"\nTerminal 0 voltage: {:s}",
Logger::matrixCompToString(mVoltageRef->get()),
Logger::phasorToString(initialSingleVoltage(0)));
} else {
mSLog->info("\nInitialization from node voltages omitted (parameter already set)."
"\nReference voltage: {:s}",
Logger::matrixCompToString(mVoltageRef->get()));
}
mSLog->info("\nVoltage reference phasor [V]: {:s}"
"\nFrequency [Hz]: {:s}",
Logger::phasorToString(mVoltageRef->get()),
Logger::realToString(mSrcFreq->get()));
mSLog->info("\n--- Initialization from node voltages ---");
mSLog->flush();
}
SimPowerComp<Real>::Ptr EMT::Ph3::VoltageSource::clone(String name) {
auto copy = VoltageSource::make(name, mLogLevel);
copy->setParameters(attribute<Complex>("V_ref")->get(), attribute<Real>("f_src")->get());
copy->setParameters(attribute<MatrixComp>("V_ref")->get(), attribute<Real>("f_src")->get());
return copy;
}
......@@ -62,25 +74,11 @@ void EMT::Ph3::VoltageSource::mnaInitialize(Real omega, Real timeStep, Attribute
updateMatrixNodeIndices();
mVoltageRef = attribute<Complex>("V_ref");
mSrcFreq = attribute<Real>("f_src");
mIntfVoltage(0, 0) = RMS3PH_TO_PEAK1PH * Math::abs(mVoltageRef->get()) * cos(Math::phase(mVoltageRef->get()));
mIntfVoltage(1, 0) = RMS3PH_TO_PEAK1PH * Math::abs(mVoltageRef->get()) * cos(Math::phase(mVoltageRef->get()) - 2. / 3. * M_PI);
mIntfVoltage(2, 0) = RMS3PH_TO_PEAK1PH * Math::abs(mVoltageRef->get()) * cos(Math::phase(mVoltageRef->get()) + 2. / 3. * M_PI);
mMnaTasks.push_back(std::make_shared<MnaPreStep>(*this));
mMnaTasks.push_back(std::make_shared<MnaPostStep>(*this, leftVector));
mRightVector = Matrix::Zero(leftVector->get().rows(), 1);
mSLog->info(
"\n--- MNA initialization ---"
"\nInitial voltage {:s}"
"\nInitial current {:s}"
"\n--- MNA initialization finished ---",
Logger::matrixToString(mIntfVoltage),
Logger::matrixToString(mIntfCurrent));
mSLog->flush();
}
void EMT::Ph3::VoltageSource::mnaApplySystemMatrixStamp(Matrix& systemMatrix) {
......@@ -123,19 +121,16 @@ void EMT::Ph3::VoltageSource::mnaApplyRightSideVectorStamp(Matrix& rightVector)
}
void EMT::Ph3::VoltageSource::updateVoltage(Real time) {
Complex voltageRef = mVoltageRef->get();
Real srcFreq = mSrcFreq->get();
if (srcFreq > 0) {
mIntfVoltage(0, 0) = RMS3PH_TO_PEAK1PH * Math::abs(voltageRef) * cos(time * 2. * PI * srcFreq + Math::phase(voltageRef));
mIntfVoltage(1, 0) = RMS3PH_TO_PEAK1PH * Math::abs(voltageRef) * cos(time * 2. * PI * srcFreq + Math::phase(voltageRef) - 2. / 3. * M_PI);
mIntfVoltage(2, 0) = RMS3PH_TO_PEAK1PH * Math::abs(voltageRef) * cos(time * 2. * PI * srcFreq + Math::phase(voltageRef) + 2. / 3. * M_PI);
if (mSrcFreq->get() < 0) {
mIntfVoltage = RMS3PH_TO_PEAK1PH * mVoltageRef->get().real();
}
else {
mIntfVoltage(0, 0) = RMS3PH_TO_PEAK1PH * voltageRef.real();
mIntfVoltage(1, 0) = RMS3PH_TO_PEAK1PH * voltageRef.real();
mIntfVoltage(2, 0) = RMS3PH_TO_PEAK1PH * voltageRef.real();
mIntfVoltage(0, 0) =
RMS3PH_TO_PEAK1PH * Math::abs(mVoltageRef->get()(0, 0)) * cos(time * 2. * PI * mSrcFreq->get() + Math::phase(mVoltageRef->get())(0, 0));
mIntfVoltage(1, 0) =
RMS3PH_TO_PEAK1PH * Math::abs(mVoltageRef->get()(1, 0)) * cos(time * 2. * PI * mSrcFreq->get() + Math::phase(mVoltageRef->get())(1, 0));
mIntfVoltage(2, 0) =
RMS3PH_TO_PEAK1PH * Math::abs(mVoltageRef->get()(2, 0)) * cos(time * 2. * PI * mSrcFreq->get() + Math::phase(mVoltageRef->get())(2, 0));
}
mSLog->debug(
......
Markdown is supported
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