Skip to content
This repository has been archived by the owner on Apr 19, 2020. It is now read-only.

Commit

Permalink
Merge 4aa249a into 6c88e0e
Browse files Browse the repository at this point in the history
  • Loading branch information
sinnott committed Feb 21, 2020
2 parents 6c88e0e + 4aa249a commit f58b0ab
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 20 deletions.
28 changes: 24 additions & 4 deletions src/simulations/modern/DispatchProblem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,12 @@ function update_problem!(
maxcharge = system.storages.charge_capacity[i, t]
chargeefficiency = system.storages.charge_efficiency[i, t]
energychargeable = (maxenergy - stor_energy) / chargeefficiency
timetocharge = round(Int, energychargeable / maxcharge)

if maxcharge == 0
timetocharge = length(system.timestamps) + 1
else
timetocharge = round(Int, energychargeable / maxcharge)
end

charge_capacity =
min(maxcharge, round(Int, energytopower(
Expand All @@ -290,7 +295,12 @@ function update_problem!(
maxdischarge = system.storages.discharge_capacity[i, t]
dischargeefficiency = system.storages.discharge_efficiency[i, t]
energydischargeable = stor_energy * dischargeefficiency
timetodischarge = round(Int, energydischargeable / maxdischarge)

if maxdischarge == 0
timetodischarge = length(system.timestamps) + 1
else
timetodischarge = round(Int, energydischargeable / maxdischarge)
end

discharge_capacity =
min(maxdischarge, round(Int, energytopower(
Expand Down Expand Up @@ -332,7 +342,12 @@ function update_problem!(
maxcharge = system.generatorstorages.charge_capacity[i, t]
chargeefficiency = system.generatorstorages.charge_efficiency[i, t]
energychargeable = (maxenergy - stor_energy) / chargeefficiency
timetocharge = energychargeable / maxcharge

if maxcharge == 0
timetocharge = length(system.timestamps) + 1
else
timetocharge = round(Int, energychargeable / maxcharge)
end

charge_capacity =
min(maxcharge, round(Int, energytopower(
Expand All @@ -350,7 +365,12 @@ function update_problem!(
maxdischarge = system.generatorstorages.discharge_capacity[i, t]
dischargeefficiency = system.generatorstorages.discharge_efficiency[i, t]
energydischargeable = stor_energy * dischargeefficiency
timetodischarge = energydischargeable / maxdischarge

if maxdischarge == 0
timetodischarge = length(system.timestamps) + 1
else
timetodischarge = round(Int, energydischargeable / maxdischarge)
end

discharge_capacity =
min(maxdischarge, round(Int, energytopower(
Expand Down
5 changes: 1 addition & 4 deletions src/simulations/modern/Modern.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function assess(
for _ in 1:threads
@spawn assess(simspec, resultspec, system, samples, results)
end

return finalize(results, simspec, system, threads)

end
Expand Down Expand Up @@ -65,7 +65,6 @@ function assess(
# TODO: Implement simulation-level RNG (Random123?)
rng = GLOBAL_RNG
for (s, _) in samples

initialize!(rng, systemstate, system)

for t in 1:N
Expand All @@ -77,11 +76,9 @@ function assess(
end

reset!(recorder, s)

end

put!(recorders, recorder)

end

function initialize!(
Expand Down
40 changes: 28 additions & 12 deletions src/simulations/modern/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,21 @@ function maxtimetocharge_discharge(system::SystemModel)

if length(system.storages) > 0

stor_charge_durations =
system.storages.energy_capacity ./ system.storages.charge_capacity
stor_charge_max = ceil(Int, maximum(stor_charge_durations))
if any(iszero, system.storages.charge_capacity)
stor_charge_max = length(system.timestamps) + 1
else
stor_charge_durations =
system.storages.energy_capacity ./ system.storages.charge_capacity
stor_charge_max = ceil(Int, maximum(stor_charge_durations))
end

stor_discharge_durations =
system.storages.energy_capacity ./ system.storages.discharge_capacity
stor_discharge_max = ceil(Int, maximum(stor_discharge_durations))
if any(iszero, system.storages.discharge_capacity)
stor_discharge_max = length(system.timestamps) + 1
else
stor_discharge_durations =
system.storages.energy_capacity ./ system.storages.discharge_capacity
stor_discharge_max = ceil(Int, maximum(stor_discharge_durations))
end

else

Expand All @@ -140,13 +148,21 @@ function maxtimetocharge_discharge(system::SystemModel)

if length(system.generatorstorages) > 0

genstor_charge_durations =
system.generatorstorages.energy_capacity ./ system.generatorstorages.charge_capacity
genstor_charge_max = ceil(Int, maximum(genstor_charge_durations))
if any(iszero, system.generatorstorages.charge_capacity)
genstor_charge_max = length(system.timestamps) + 1
else
genstor_charge_durations =
system.generatorstorages.energy_capacity ./ system.generatorstorages.charge_capacity
genstor_charge_max = ceil(Int, maximum(genstor_charge_durations))
end

genstor_discharge_durations =
system.generatorstorages.energy_capacity ./ system.generatorstorages.discharge_capacity
genstor_discharge_max = ceil(Int, maximum(genstor_discharge_durations))
if any(iszero, system.generatorstorages.discharge_capacity)
genstor_discharge_max = length(system.timestamps) + 1
else
genstor_discharge_durations =
system.generatorstorages.energy_capacity ./ system.generatorstorages.discharge_capacity
genstor_discharge_max = ceil(Int, maximum(genstor_discharge_durations))
end

else

Expand Down

0 comments on commit f58b0ab

Please sign in to comment.