diff options
-rw-r--r-- | Project/Bus.h | 5 | ||||
-rw-r--r-- | Project/PowerQuality.cpp | 36 |
2 files changed, 27 insertions, 14 deletions
diff --git a/Project/Bus.h b/Project/Bus.h index 503299e..2423be6 100644 --- a/Project/Bus.h +++ b/Project/Bus.h @@ -57,6 +57,11 @@ struct BusElectricalData { double stabFaultResistance = 0.0; double stabFaultReactance = 0.0; std::vector<std::complex<double> > stabVoltageVector; + + // Power Quality + std::vector<int> harmonicOrder; + std::vector< std::complex<double> > harmonicVoltage; + double thd = 0.0; }; /** diff --git a/Project/PowerQuality.cpp b/Project/PowerQuality.cpp index 33acbe6..4efdc49 100644 --- a/Project/PowerQuality.cpp +++ b/Project/PowerQuality.cpp @@ -29,11 +29,12 @@ void PowerQuality::CalculateHarmonicYbusList(double systemPowerBase) if(load->IsOnline()) { int n = static_cast<Bus*>(load->GetParentList()[0])->GetElectricalData().number; LoadElectricalData data = load->GetPUElectricalData(systemPowerBase); - if(data.loadType == CONST_IMPEDANCE) { - std::complex<double> yLoad = - std::complex<double>(data.activePower, -data.reactivePower / harmYBus.order); - harmYBus.yBus[n][n] += yLoad; - } + wxMessageBox(wxString::Format("%f %f", data.activePower, data.reactivePower)); + std::complex<double> yLoad = + std::complex<double>(data.activePower, -data.reactivePower / harmYBus.order); + std::complex<double> v = static_cast<Bus*>(load->GetParentList()[0])->GetElectricalData().voltage; + yLoad /= (std::abs(v) * std::abs(v)); + harmYBus.yBus[n][n] += yLoad; } } @@ -117,7 +118,8 @@ void PowerQuality::CalculateHarmonicYbusList(double systemPowerBase) -data.turnsRatio * std::sin(radPhaseShift)); // Transformer admitance - std::complex<double> y = 1.0 / std::complex<double>(data.resistance, data.indReactance * harmYBus.order); + std::complex<double> y = + 1.0 / std::complex<double>(data.resistance, data.indReactance * harmYBus.order); harmYBus.yBus[n1][n1] += y / (std::pow(std::abs(a), 2.0)); harmYBus.yBus[n1][n2] += -(y / std::conj(a)); @@ -205,16 +207,22 @@ bool PowerQuality::CalculateDistortions(double systemPowerBase) for(unsigned int i = 0; i < m_harmYbusList.size(); ++i) { vHarmList.push_back(GaussianElimination(m_harmYbusList[i].yBus, iHarmInjList[i])); } - - wxString volt = ""; - for(unsigned int i = 0; i < vHarmList.size(); ++i) { - wxString orderStr = ""; - for(unsigned int j = 0; j < vHarmList[i].size(); ++j) { - orderStr += wxString::Format("%f; ", std::abs(vHarmList[i][j])); + + for(auto it = m_busList.begin(), itEnd = m_busList.end(); it != itEnd; ++it) { + Bus* bus = *it; + auto data = bus->GetElectricalData(); + data.harmonicOrder.clear(); + data.harmonicVoltage.clear(); + double thd = 0.0; + for(unsigned int i = 0; i < vHarmList.size(); ++i) { + thd += std::abs(vHarmList[i][data.number]) * std::abs(vHarmList[i][data.number]); + data.harmonicVoltage.push_back(vHarmList[i][data.number]); + data.harmonicOrder.push_back(static_cast<int>(harmOrders[i])); } - volt += orderStr + "\n"; + //distortion = std::sqrt(distortion) / std::abs(data.voltage); + thd = std::sqrt(thd) * 100.0; + data.thd = thd; } - wxMessageBox(volt); return true; } |