Commit b3abbfea authored by Gerrit Erichsen's avatar Gerrit Erichsen
Browse files

Added some corrections to storage. It still won't discharge though, unfortunately

parent fa85c106
......@@ -123,16 +123,18 @@ double EfficiencyField::getEfficiency(double x, double y) const
//set x indices
indexX2 = findUpperIndex(x, m_xAxis);
if (indexX2 > m_xAxis.size()) return 0.;
indexX1 = indexX2 - 1;
indexX1 = (indexX2 > 0) ? indexX2 - 1 : 0;
//set y indices
indexY2 = findUpperIndex(y, m_yAxis);
if (indexY2 > m_yAxis.size()) return 0.;
indexY1 = indexY2 - 1;
indexY1 = (indexY2 > 0) ? indexY2 - 1 : 0;
//calculate 2-D interpolation, first major case x1 matches x
if (isCloseEnoughToEqual(x, m_xAxis[indexX1]))
if (isCloseEnoughToEqual(x, m_xAxis[indexX1])
|| indexX1 == indexX2)
{
//first case within major case 1: y1 also matches y
if (isCloseEnoughToEqual(y, m_yAxis[indexY1]))
if (isCloseEnoughToEqual(y, m_yAxis[indexY1])
|| indexY1 == indexY2)
{
return m_values[indexX1][indexY1];
}
......@@ -149,7 +151,8 @@ double EfficiencyField::getEfficiency(double x, double y) const
else if (isCloseEnoughToEqual(x, m_xAxis[indexX2]))
{
//first case within major case 2: y1 also matches y
if (isCloseEnoughToEqual(y, m_yAxis[indexY1]))
if (isCloseEnoughToEqual(y, m_yAxis[indexY1])
|| indexY1 == indexY2)
{
return m_values[indexX2][indexY1];
}
......
......@@ -69,10 +69,10 @@ Storage::Storage(string name, double nominalPower, double nominalPowerDischarge,
m_preferences(preferences)
// m_operationPlanPeriodIsValid(true) //tz
{
m_minPowerCharge = m_efficiencyCharge.getMinX() * nominalPower;
m_maxPowerCharge = m_efficiencyCharge.getMaxX() * nominalPower;
m_minPowerDischarge = m_efficiencyDischarge.getMinX() * nominalPowerDischarge;
m_maxPowerDischarge = m_efficiencyDischarge.getMaxX() * nominalPowerDischarge;
m_minPowerCharge = m_efficiencyCharge.getMinY() * nominalPower;
m_maxPowerCharge = m_efficiencyCharge.getMaxY() * nominalPower;
m_minPowerDischarge = m_efficiencyDischarge.getMinY() * nominalPowerDischarge;
m_maxPowerDischarge = m_efficiencyDischarge.getMaxY() * nominalPowerDischarge;
size_t nSteps = static_cast<size_t>(m_preferences->getNumberOfTimeSteps());
m_load.assign(nSteps, 0.);
......@@ -218,13 +218,15 @@ void Storage::charge(double power, size_t step)
if (power * m_preferences->getStepTime() * getEfficiencyCharge(step, power)
<= m_storageCapacity - lastStorageLevel)
{
m_storageLevel[step] = lastStorageLevel + power * m_preferences->getStepTime() * getEfficiencyCharge(step, power);
m_storageLevel[step] = lastStorageLevel
+ power * m_preferences->getStepTime() * getEfficiencyCharge(step, power);
m_lastStepOfPower = step;
}
else if (m_storageCapacity - lastStorageLevel > 0.)
{
m_storageLevel[step] = m_storageCapacity;
power = (m_storageCapacity - lastStorageLevel) / m_preferences->getStepTime() / getEfficiencyCharge(step, power); //"power" for efficiency not entirely correct, though
power = (m_storageCapacity - lastStorageLevel) / m_preferences->getStepTime()
/ getEfficiencyCharge(step, power); //"power" for efficiency not entirely correct, though
m_lastStepOfPower = step;
}
else
......@@ -233,6 +235,7 @@ void Storage::charge(double power, size_t step)
}
//setting values accordingly to result
m_load[step] = -power;
if (power > 0) cout << "Charged at " << step << " with " << power << "MW. Now having " << m_storageLevel[step] << "MWh in the bank" << endl;
m_fullLoadHoursCharge += power * m_preferences->getStepTime() / m_nominalPowerCharge;
}
......@@ -291,6 +294,7 @@ void Storage::discharge(double power, size_t step)
m_lastStepOfPower = step;
}
m_load[step] = power;
if (power > 0) cout << "Charged at " << step << " with " << power << "MW. Now having " << m_storageLevel[step] << "MWh in the bank" << endl;
m_fullLoadHoursDischarge += power * m_preferences->getStepTime() / m_nominalPowerDischarge;
}
......@@ -467,19 +471,19 @@ double Storage::getMinPowerChargeConst() const
double Storage::getMinPowerCharge(int step) const
{
//defining helper value, since previous step of first step is last step
double lastStorageLevel;
double lastStorageLevel = (step == 0) ? m_initialStorageLevel : m_storageLevel[step - 1];
double powerByGradient = 0.;
if (step == 0)
{
lastStorageLevel = m_initialStorageLevel;
if ((m_storageCapacity - lastStorageLevel) / m_preferences->getStepTime()
< m_minPowerCharge) return 0.;
}
else
{
lastStorageLevel = m_storageLevel[step - 1];
powerByGradient = m_load[step - 1]
- m_nominalPowerCharge * m_gradientCharge * 0.01 * 60. * m_preferences->getStepTime();
double powerBase = (m_load[step - 1] < 0) ? fabs(m_load[step - 1]) : 0;
powerByGradient = powerBase
- m_nominalPowerCharge * m_gradientCharge
* 0.01 * 60. * m_preferences->getStepTime();
if ((m_storageCapacity - lastStorageLevel) / m_preferences->getStepTime()
< std::max(m_minPowerCharge, powerByGradient)) return 0.;
}
......@@ -489,17 +493,7 @@ double Storage::getMinPowerCharge(int step) const
double Storage::getMaxPowerCharge(int step) const
{
//defining helper value, since previous step of first step is last step
double lastStorageLevel;
if (step == 0)
{
// lastStorageLevel = m_storageLevel.back();
lastStorageLevel = m_initialStorageLevel; //tz
}
else
{
lastStorageLevel = m_storageLevel[step - 1];
}
double lastStorageLevel = (step == 0) ? m_initialStorageLevel : m_storageLevel[step - 1];
double power = (m_storageCapacity - lastStorageLevel) / m_preferences->getStepTime();
return std::min(m_maxPowerCharge, power / getEfficiencyCharge(step, power));
}
......@@ -528,16 +522,8 @@ double Storage::getMinPowerDischarge(int step)
double Storage::getMaxPowerDischarge(int step) const
{
//defining helper value, since previous step of first step is last step
double lastStorageLevel;
if (step == 0)
{
// lastStorageLevel = m_storageLevel.back();
lastStorageLevel = m_initialStorageLevel; //tz
}
else
{
lastStorageLevel = m_storageLevel[step - 1];
}
double lastStorageLevel = (step == 0) ? m_initialStorageLevel : m_storageLevel[step - 1];
double powerLimitFromCapacity = lastStorageLevel / m_preferences->getStepTime();
if (powerLimitFromCapacity < m_minPowerDischarge)
{
......@@ -546,10 +532,14 @@ double Storage::getMaxPowerDischarge(int step) const
double powerLimitFromLoad = m_maxPowerDischarge;
if (step > 0 && !isCloseEnoughToEqual(m_gradientDischarge, 0.))
{
powerLimitFromLoad = m_load[step - 1] + m_gradientDischarge * 0.01 * m_nominalPowerCharge * m_preferences->getStepTime() * 60.;
double powerBase = (m_load[step - 1] > 0) ? m_load[step - 1] : 0;
powerLimitFromLoad = powerBase + m_gradientDischarge * 0.01
* m_nominalPowerDischarge
* m_preferences->getStepTime() * 60.;
powerLimitFromLoad = std::min(powerLimitFromLoad, m_maxPowerDischarge);
}
return std::min(powerLimitFromLoad, powerLimitFromCapacity * getEfficiencyDischarge(step, powerLimitFromCapacity));
return std::min(powerLimitFromLoad, powerLimitFromCapacity
* getEfficiencyDischarge(step, powerLimitFromCapacity));
}
double Storage::getEfficiencyCharge(size_t step, double power) const
......@@ -566,8 +556,8 @@ double Storage::getEfficiencyCharge(size_t step, double power) const
if (m_preferences->getLevelOfInterpolation() == 1)
{
return m_efficiencyCharge.getEfficiency(power / m_nominalPowerCharge,
lastStorageLevel / m_storageCapacity);
return m_efficiencyCharge.getEfficiency(lastStorageLevel / m_storageCapacity,
power / m_nominalPowerCharge);
}
else //level = 0 --> const value required
{
......@@ -593,8 +583,8 @@ double Storage::getEfficiencyDischarge(size_t step, double power) const
if (m_preferences->getLevelOfInterpolation() == 1)
{
return m_efficiencyDischarge.getEfficiency(power / m_nominalPowerDischarge,
lastStorageLevel / m_storageCapacity);
return m_efficiencyDischarge.getEfficiency(lastStorageLevel / m_storageCapacity,
power / m_nominalPowerDischarge);
}
else //level = 0 --> const value required
{
......@@ -851,7 +841,9 @@ bool Storage::isReadyToCharge(int step) const
bool Storage::canStartDischgargingAtStep(int step) const
{
if (step == 0) return (m_initialStorageLevel > m_minPowerDischarge / getEfficiencyDischarge(0, m_minPowerDischarge) * m_preferences->getStepTime());
if (step == 0) return (m_initialStorageLevel > m_minPowerDischarge
/ getEfficiencyDischarge(0, m_minPowerDischarge)
* m_preferences->getStepTime());
//pre-check if energy levels are enough
if (getMaxPowerDischarge(step) <= 0.) return false;
//pre-check if charging
......
......@@ -169,7 +169,7 @@ size_t findUpperIndex(const double & target, const vector<double> & values)
{
//ge - find index in vector of eta profile where the speed is higher than targetSpeed
size_t index = values.size() + 1;
//ge - precaution test: is targetSpeed legal?
//ge - precaution test: is target legal?
if (target < values.front()
|| target > values.back())
{
......
......@@ -291,6 +291,13 @@ bool AbstractCharLItem::load2DFile(QString fileName, EfficiencyField & field)
}
}
file.close();
QVector<double> xAxisQt = QVector<double>::fromStdVector(xAxis);
QVector<double> yAxisQt = QVector<double>::fromStdVector(xAxis);
QVector<QVector<double>> valuesQt;
for (std::vector<double> & vec : values)
{
valuesQt.append(QVector<double>::fromStdVector(vec));
}
if (values.size() != yAxis.size()) return false;
field.setData(xAxis, yAxis, values);
}
......
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