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

wip: fixing storage issues. changing work station

parent a4da301b
......@@ -1159,31 +1159,10 @@ void Node::calculateStoragePower(size_t timeStep)
{
if (currentResidual < 0. && m_storage[i]->isReadyToCharge(timeStep)) // charge
{
//power well within range
if (fabs(currentResidual) >= m_storage[i]->getMinPowerChargeConst()
&& fabs(currentResidual) < m_storage[i]->getMaxPowerCharge(timeStep)
&& currentResidual < 0.) //tz >= minPower -> otherwise no minPower
{
powerOfPlant = currentResidual;
m_storage[i]->charge(fabs(powerOfPlant), timeStep);
storageLoad += powerOfPlant;
currentResidual = 0.;
}
//power equal or greater than maxPower
else if (fabs(currentResidual) >= m_storage[i]->getMinPowerChargeConst()
&& m_storage[i]->getMaxPowerCharge(timeStep) > 0.
&& m_storage[i]->getMinPowerChargeConst() <= m_storage[i]->getMaxPowerCharge(timeStep))
{
powerOfPlant = -(m_storage[i]->getMaxPowerCharge(timeStep));
m_storage[i]->charge(fabs(powerOfPlant), timeStep);
storageLoad += powerOfPlant;
currentResidual -= powerOfPlant;
if (isCloseEnoughToEqual(currentResidual, 0.)) currentResidual = 0.;
}
else //power less than minimum
{
storageLoad += 0.;
}
powerOfPlant = m_storage[i]->charge(fabs(currentResidual), timeStep);
storageLoad -= powerOfPlant;
currentResidual += powerOfPlant;
if (isCloseEnoughToEqual(currentResidual, 0.)) currentResidual = 0.;
}
else if (currentResidual > 0. && m_storage[i]->canStartDischgargingAtStep(timeStep)) // discharge
{
......@@ -1207,45 +1186,10 @@ void Node::calculateStoragePower(size_t timeStep)
}
else //tz - do as before
{
if (currentResidual >= m_storage[i]->getMinPowerDischarge(timeStep)
&& currentResidual < m_storage[i]->getMaxPowerDischarge(timeStep)
&& currentResidual > 0.)
{
powerOfPlant = currentResidual;
m_storage[i]->discharge(powerOfPlant, timeStep);
storageLoad += powerOfPlant;
currentResidual = 0.;
}
//power equal or greater than maxPower
else if (currentResidual >= m_storage[i]->getMaxPowerDischarge(timeStep)
&& m_storage[i]->getMaxPowerDischarge(timeStep) > 0.
&& currentResidual > 0.)
{
powerOfPlant = m_storage[i]->getMaxPowerDischarge(timeStep);
m_storage[i]->discharge(powerOfPlant, timeStep);
storageLoad += powerOfPlant;
currentResidual -= powerOfPlant;
if (isCloseEnoughToEqual(currentResidual, 0.)) currentResidual = 0.;
}
//power less than minPower
else if (m_storage[i]->getMaxPowerDischarge(timeStep) > 0.
&& currentResidual > 0.
&& !isBetterStorageAvailabe(i, currentResidual, timeStep))
{
powerOfPlant = m_storage[i]->getMinPowerDischarge( timeStep);
m_storage[i]->discharge(powerOfPlant, timeStep);
storageLoad += powerOfPlant;
currentResidual -= powerOfPlant;
if (isCloseEnoughToEqual(currentResidual, 0.))
{
currentResidual = 0.;
}
correctFromStorage(i, timeStep, timeStep);
}
else //power less than minimum
{
storageLoad += 0.;
}
powerOfPlant = m_storage[i]->discharge(powerOfPlant, timeStep);
storageLoad += powerOfPlant;
currentResidual -= powerOfPlant;
if (isCloseEnoughToEqual(currentResidual, 0.)) currentResidual = 0.;
}
}
}
......
......@@ -202,28 +202,32 @@ Storage::Storage(const Storage * rhs,
m_dischargeCostStartup.assign(nSteps, 0.); //tc
}
void Storage::charge(double power, size_t step)
double Storage::charge(double nodeExcessPower, size_t step)
{
if (power < 0.)
if (nodeExcessPower < 0.)
{
return;
return 0.;
}
//defining helper value, since previous step of first step is last step
double lastStorageLevel = (step == 0) ? m_initialStorageLevel : m_storageLevel[step - 1];
// just a pre-caution
if (power > m_maxPowerCharge) power = m_maxPowerCharge;
double plantPower = nodeExcessPower;
double maxPower = getMaxPowerCharge(step);
double minPower = getMinPowerCharge(step);
if (plantPower > maxPower) plantPower = maxPower;
// storage has enough capacity to take all
if (power * m_preferences->getStepTime() * getEfficiencyCharge(step, power)
<= m_storageCapacity - lastStorageLevel)
// power withing range
if (plantPower * m_preferences->getStepTime() * getEfficiencyCharge(step, nodeExcessPower)
<= m_storageCapacity - lastStorageLevel
&& plantPower >= minPower)
{
m_storageLevel[step] = lastStorageLevel
+ power * m_preferences->getStepTime() * getEfficiencyCharge(step, power);
+ plantPower * m_preferences->getStepTime()
* getEfficiencyCharge(step, plantPower);
m_lastStepOfPower = step;
}
else if (m_storageCapacity - lastStorageLevel > getMinPowerCharge(step)
* m_preferences->getStepTime())
else if (m_storageCapacity - lastStorageLevel >= minPower * m_preferences->getStepTime()
&& plantPower >= minPower)
{
m_storageLevel[step] = m_storageCapacity;
double powerReserve = (m_storageCapacity - lastStorageLevel) / m_preferences->getStepTime();
......@@ -231,83 +235,73 @@ void Storage::charge(double power, size_t step)
// guess at the efficiency. This should be somewhat accurate enough
double efficiency = getEfficiencyCharge(step,
powerReserve
/ m_efficiencyCharge.getEfficiencyBottomRight());
/ m_efficiencyCharge.getEfficiencyTopLeft());
if (isCloseEnoughToEqual(efficiency, 0.))
{
power = std::min(power, powerReserve / 1e-5); // 1 permille as effictive min efficiency
plantPower = std::min(plantPower, powerReserve / 1e-5); // 1 permille as effictive min efficiency
}
else
{
power = powerReserve / efficiency;
plantPower = powerReserve / efficiency;
}
m_lastStepOfPower = step;
}
else
{
power = 0.;
nodeExcessPower = 0.;
}
//setting values accordingly to result
m_load[step] = -power;
m_load[step] = -plantPower;
//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;
m_fullLoadHoursCharge += plantPower * m_preferences->getStepTime() / m_nominalPowerCharge;
return plantPower;
}
void Storage::discharge(double power, size_t step)
double Storage::discharge(double nodeResidualPower, size_t step)
{
if (power < 0.)
{
return;
}
if (step == 0)
if (nodeResidualPower < 0.)
{
if (power * m_preferences->getStepTime() * getEfficiencyDischarge(step, power) < m_initialStorageLevel)
{
m_storageLevel[step] = m_initialStorageLevel
- power * m_preferences->getStepTime()
/ getEfficiencyDischarge(step, power);
m_lastStepOfPower = step;
}
else if (m_initialStorageLevel > 0.)
{
double powerNew = power;
do
{
power = powerNew;
powerNew = m_initialStorageLevel
/ m_preferences->getStepTime() * getEfficiencyDischarge(step, power);
} while(fabs(power - powerNew) > 0.01 * power);
power = powerNew;
m_storageLevel[step] = 0.;
m_lastStepOfPower = step;
}
else
{
m_storageLevel[step] = 0.;
power = 0.;
}
return 0.;
}
else if (power * m_preferences->getStepTime() * getEfficiencyDischarge(step, power) <= m_storageLevel[step - 1])
//defining helper value, since previous step of first step is last step
double lastStorageLevel = (step == 0) ? m_initialStorageLevel : m_storageLevel[step - 1];
double plantPower = nodeResidualPower;
double maxPower = getMaxPowerDischarge(step);
double minPower = getMinPowerDischarge(step);
if (nodeResidualPower > maxPower) plantPower = maxPower;
if (nodeResidualPower < minPower) plantPower = 0.;
if (plantPower * m_preferences->getStepTime() / getEfficiencyDischarge(step, plantPower) <= lastStorageLevel
&& plantPower >= minPower)
{
m_storageLevel[step] = m_storageLevel[step - 1]
- power * m_preferences->getStepTime()
/ getEfficiencyDischarge(step, power);
m_storageLevel[step] = lastStorageLevel
- plantPower * m_preferences->getStepTime()
/ getEfficiencyDischarge(step, plantPower);
m_lastStepOfPower = step;
}
else if (m_storageLevel[step - 1] > 0.)
else if (lastStorageLevel > 0.
&& lastStorageLevel / m_preferences->getStepTime()
/ m_efficiencyDischarge.getEfficiencyTopLeft() >= minPower)
{
double powerNew = power;
double powerNew = plantPower;
do
{
power = powerNew;
powerNew = m_storageLevel[step - 1]
/ m_preferences->getStepTime() * getEfficiencyDischarge(step, power); //"power" for efficiency not entirely correct, though
} while(fabs(power - powerNew) > 0.01 * power);
power = powerNew;
plantPower = powerNew;
powerNew = lastStorageLevel
/ m_preferences->getStepTime() * getEfficiencyDischarge(step, plantPower);
} while (fabs(plantPower - powerNew) > 0.01 * plantPower);
plantPower = powerNew;
m_storageLevel[step] = 0.;
m_lastStepOfPower = step;
}
m_load[step] = power;
m_fullLoadHoursDischarge += power * m_preferences->getStepTime() / m_nominalPowerDischarge;
else
{
m_storageLevel[step] = 0.;
plantPower = 0.;
}
m_load[step] = plantPower;
m_fullLoadHoursDischarge += plantPower * m_preferences->getStepTime() / m_nominalPowerDischarge;
return plantPower;
}
void Storage::turnOff(int step, bool charging)
......
......@@ -47,8 +47,8 @@ public:
const SimulationPreferences * preferences);
//set Funktionen
void charge(double power, size_t step);
void discharge(double power, size_t step);
double charge(double nodeExcessPower, size_t step);
double discharge(double nodeResidualPower, size_t step);
void turnOff(int step, bool charging = false);
void selfDischarge(int step);
void setForecastLoad(int step, double load); //tz - setter for forecast result "load"
......
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