Skip to content

Commit

Permalink
further renaming of attributes in Storage
Browse files Browse the repository at this point in the history
  • Loading branch information
FBumann committed Sep 28, 2024
1 parent 33e5ca9 commit 928d903
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 35 deletions.
4 changes: 2 additions & 2 deletions examples/Ex01_simple/simple_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@
# # 2. storage #

aSpeicher = Storage('Speicher',
charging_flow= Flow('Q_th_load', bus = Fernwaerme, size=1e4), # load-flow, maximum load-power: 1e4 kW
discharging_flow= Flow('Q_th_unload', bus = Fernwaerme, size=1e4), # unload-flow, maximum load-power: 1e4 kW
charging= Flow('Q_th_load', bus = Fernwaerme, size=1e4), # load-flow, maximum load-power: 1e4 kW
discharging= Flow('Q_th_unload', bus = Fernwaerme, size=1e4), # unload-flow, maximum load-power: 1e4 kW
capacity_in_flow_hours=InvestParameters(fix_effects=20, fixed_size=30, optional=False), # 30 kWh; storage capacity
initial_charge_state=0, # empty storage at first time step
relative_maximum_charge_state=1 / 100 * np.array([80., 70., 80., 80 , 80, 80, 80, 80, 80, 80]),
Expand Down
4 changes: 2 additions & 2 deletions examples/Ex02_complex/example_complex_ModelAndSolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@

# 4.b) storage itself:
aSpeicher = Storage('Speicher', # defining flows:
charging_flow=Flow('Q_th_load', bus=Fernwaerme, size=1e4),
discharging_flow=Flow('Q_th_unload', bus=Fernwaerme, size=1e4),
charging=Flow('Q_th_load', bus=Fernwaerme, size=1e4),
discharging=Flow('Q_th_unload', bus=Fernwaerme, size=1e4),
capacity_in_flow_hours=InvestParameters(
fix_effects=0, # no fix costs
fixed_size=None, # variable size
Expand Down
4 changes: 2 additions & 2 deletions examples/Ex03_full_seg_agg/Model_and_solve.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@
on_values_before_begin=[0])

aSpeicher = Storage('Speicher',
charging_flow=Flow('Q_th_load', size=137, bus=Fernwaerme),
discharging_flow=Flow('Q_th_unload', size=158, bus=Fernwaerme),
charging=Flow('Q_th_load', size=137, bus=Fernwaerme),
discharging=Flow('Q_th_unload', size=158, bus=Fernwaerme),
capacity_in_flow_hours=684, initial_charge_state=137,
minimal_final_charge_state=137, maximal_final_charge_state=158,
eta_load=1, eta_unload=1, relative_loss_per_hour=0.001, prevent_simultaneous_charge_and_discharge=True)
Expand Down
36 changes: 18 additions & 18 deletions flixOpt/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ class Storage(Component):
# costs_default = property(get_costs())
# param_defalt = property(get_params())

new_init_args = ['label', 'exists', 'charging_flow', 'discharging_flow', 'capacity_in_flow_hours', 'relative_minimum_charge_state', 'relative_maximum_charge_state',
new_init_args = ['label', 'exists', 'charging', 'discharging', 'capacity_in_flow_hours', 'relative_minimum_charge_state', 'relative_maximum_charge_state',
'initial_charge_state', 'minimal_final_charge_state', 'maximal_final_charge_state', 'eta_load',
'eta_unload', 'relative_loss_per_hour', 'prevent_simultaneous_charge_and_discharge']

Expand All @@ -296,8 +296,8 @@ class Storage(Component):
# capacity_in_flow_hours: float, 'lastValueOfSim', None
def __init__(self,
label: str,
charging_flow: Flow,
discharging_flow: Flow,
charging: Flow,
discharging: Flow,
capacity_in_flow_hours: Union[Skalar, InvestParameters],
group: Optional[str] = None,
relative_minimum_charge_state: Numeric_TS = 0,
Expand All @@ -316,9 +316,9 @@ def __init__(self,
----------
label : str
description.
charging_flow : Flow
charging : Flow
ingoing flow.
discharging_flow : Flow
discharging : Flow
outgoing flow.
group: str, None
group name to assign components to groups. Used for later analysis of the results
Expand Down Expand Up @@ -358,10 +358,10 @@ def __init__(self,
super().__init__(label, **kwargs)

# invest_parameters to attributes:
self.inputs = [charging_flow]
self.outputs = [discharging_flow]
self.inFlow = charging_flow
self.outFlow = discharging_flow
self.inputs = [charging]
self.outputs = [discharging]
self.charging = charging
self.discharging = discharging
self.capacity_inFlowHours = capacity_in_flow_hours
self.maximum_relative_chargeState = TimeSeries('relative_maximum_charge_state', relative_maximum_charge_state, self)
self.minimum_relative_chargeState = TimeSeries('relative_minimum_charge_state', relative_minimum_charge_state, self)
Expand Down Expand Up @@ -397,7 +397,7 @@ def __init__(self,

if self.avoidInAndOutAtOnce:
self.featureAvoidInAndOut = FeatureAvoidFlowsAtOnce('feature_avoidInAndOutAtOnce', self,
[self.inFlow, self.outFlow])
[self.charging, self.discharging])

if isinstance(self.capacity_inFlowHours, InvestParameters):
self.featureInvest = FeatureInvest('used_capacity_inFlowHours', self, self.capacity_inFlowHours,
Expand All @@ -407,9 +407,9 @@ def __init__(self,
featureOn=None) # hier gibt es kein On-Wert

# Medium-Check:
if not (MediumCollection.checkIfFits(charging_flow.medium, discharging_flow.medium)):
raise Exception('in Storage ' + self.label + ': input.medium = ' + str(charging_flow.medium) +
' and output.medium = ' + str(discharging_flow.medium) + ' don`t fit!')
if not (MediumCollection.checkIfFits(charging.medium, discharging.medium)):
raise Exception('in Storage ' + self.label + ': input.medium = ' + str(charging.medium) +
' and output.medium = ' + str(discharging.medium) + ' don`t fit!')
# TODO: chargeState0 darf nicht größer max usw. abfangen!

self.isStorage = True # for postprocessing
Expand Down Expand Up @@ -519,8 +519,8 @@ def do_modeling(self, system_model):
time_indicesChargeState[
:-1]) # sprich 0 .. end-1 % nach letztem Zeitschritt gibt es noch einen weiteren Ladezustand!
self.model.eqs['charge_state'].add_summand(self.model.variables['charge_state'], 1, time_indicesChargeState[1:]) # 1:end
self.model.eqs['charge_state'].add_summand(self.inFlow.model.variables['val'], -1 * self.eta_load.active_data * system_model.dt_in_hours)
self.model.eqs['charge_state'].add_summand(self.outFlow.model.variables['val'],
self.model.eqs['charge_state'].add_summand(self.charging.model.variables['val'], -1 * self.eta_load.active_data * system_model.dt_in_hours)
self.model.eqs['charge_state'].add_summand(self.discharging.model.variables['val'],
1 / self.eta_unload.active_data * system_model.dt_in_hours) # Achtung hier 1/eta!

# Speicherladezustand am Ende
Expand All @@ -538,11 +538,11 @@ def do_modeling(self, system_model):
self.model.eqs['eq_charge_state_end_min'].add_constant(- self.charge_state_end_min)

# nettoflow:
# eq: nettoFlow(t) - discharging_flow(t) + charging_flow(t) = 0
# eq: nettoFlow(t) - discharging(t) + charging(t) = 0
self.model.add_equation(Equation('nettoFlow', self, system_model, eqType='eq'))
self.model.eqs['nettoFlow'].add_summand(self.model.variables['nettoFlow'], 1)
self.model.eqs['nettoFlow'].add_summand(self.inFlow.model.variables['val'], 1)
self.model.eqs['nettoFlow'].add_summand(self.outFlow.model.variables['val'], -1)
self.model.eqs['nettoFlow'].add_summand(self.charging.model.variables['val'], 1)
self.model.eqs['nettoFlow'].add_summand(self.discharging.model.variables['val'], -1)

if self.featureInvest is not None:
self.featureInvest.do_modeling(system_model)
Expand Down
10 changes: 5 additions & 5 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ def model(self):
Q_fu=Flow('Q_fu', bus=Gas))
aKWK = CHP('CHP_unit', eta_th=0.5, eta_el=0.4, P_el=Flow('P_el', bus=Strom, size=60, relative_minimum=5 / 60),
Q_th=Flow('Q_th', bus=Fernwaerme), Q_fu=Flow('Q_fu', bus=Gas))
aSpeicher = Storage('Speicher', charging_flow=Flow('Q_th_load', bus=Fernwaerme, size=1e4),
discharging_flow=Flow('Q_th_unload', bus=Fernwaerme, size=1e4),
aSpeicher = Storage('Speicher', charging=Flow('Q_th_load', bus=Fernwaerme, size=1e4),
discharging=Flow('Q_th_unload', bus=Fernwaerme, size=1e4),
capacity_in_flow_hours=InvestParameters(fix_effects=20, fixed_size=30, optional=False),
initial_charge_state=0,
relative_maximum_charge_state=1 / 100 * np.array([80., 70., 80., 80, 80, 80, 80, 80, 80, 80]),
Expand Down Expand Up @@ -237,7 +237,7 @@ def basic_model(self):

costsInvestsizeSegments = [[5, 25, 25, 100], {costs: [50, 250, 250, 800], PE: [5, 25, 25, 100]}]
invest_Speicher = InvestParameters(fix_effects=0, effects_in_segments=costsInvestsizeSegments, optional=False, specific_effects={costs: 0.01, CO2: 0.01}, minimum_size=0, maximum_size=1000)
aSpeicher = Storage('Speicher', charging_flow=Flow('Q_th_load', bus=Fernwaerme, size=1e4), discharging_flow=Flow('Q_th_unload', bus=Fernwaerme, size=1e4), capacity_in_flow_hours=invest_Speicher, initial_charge_state=0, maximal_final_charge_state=10, eta_load=0.9, eta_unload=1, relative_loss_per_hour=0.08, prevent_simultaneous_charge_and_discharge=True)
aSpeicher = Storage('Speicher', charging=Flow('Q_th_load', bus=Fernwaerme, size=1e4), discharging=Flow('Q_th_unload', bus=Fernwaerme, size=1e4), capacity_in_flow_hours=invest_Speicher, initial_charge_state=0, maximal_final_charge_state=10, eta_load=0.9, eta_unload=1, relative_loss_per_hour=0.08, prevent_simultaneous_charge_and_discharge=True)

aWaermeLast = Sink('Wärmelast', sink=Flow('Q_th_Last', bus=Fernwaerme, size=1, relative_minimum=0, fixed_relative_value=self.Q_th_Last))
aGasTarif = Source('Gastarif', source=Flow('Q_Gas', bus=Gas, size=1000, effects_per_flow_hour={costs: 0.04, CO2: 0.3}))
Expand Down Expand Up @@ -280,7 +280,7 @@ def segments_of_flows_model(self):

costsInvestsizeSegments = [[5, 25, 25, 100], {costs: [50, 250, 250, 800], PE: [5, 25, 25, 100]}]
invest_Speicher = InvestParameters(fix_effects=0, effects_in_segments=costsInvestsizeSegments, optional=False, specific_effects={costs: 0.01, CO2: 0.01}, minimum_size=0, maximum_size=1000)
aSpeicher = Storage('Speicher', charging_flow=Flow('Q_th_load', bus=Fernwaerme, size=1e4), discharging_flow=Flow('Q_th_unload', bus=Fernwaerme, size=1e4), capacity_in_flow_hours=invest_Speicher, initial_charge_state=0, maximal_final_charge_state=10, eta_load=0.9, eta_unload=1, relative_loss_per_hour=0.08, prevent_simultaneous_charge_and_discharge=True)
aSpeicher = Storage('Speicher', charging=Flow('Q_th_load', bus=Fernwaerme, size=1e4), discharging=Flow('Q_th_unload', bus=Fernwaerme, size=1e4), capacity_in_flow_hours=invest_Speicher, initial_charge_state=0, maximal_final_charge_state=10, eta_load=0.9, eta_unload=1, relative_loss_per_hour=0.08, prevent_simultaneous_charge_and_discharge=True)

aWaermeLast = Sink('Wärmelast', sink=Flow('Q_th_Last', bus=Fernwaerme, size=1, relative_minimum=0, fixed_relative_value=self.Q_th_Last))
aGasTarif = Source('Gastarif', source=Flow('Q_Gas', bus=Gas, size=1000, effects_per_flow_hour={costs: 0.04, CO2: 0.3}))
Expand Down Expand Up @@ -339,7 +339,7 @@ def calculate(self, modeling_type: Literal["full", "segmented", "aggregated"]):

aGaskessel = Boiler('Kessel', eta=0.85, Q_th=Flow(label='Q_th', bus=Fernwaerme), Q_fu=Flow(label='Q_fu', bus=Gas, size=95, relative_minimum=12 / 95, can_switch_off=True, effects_per_switch_on=1000, values_before_begin=[0]))
aKWK = CHP('BHKW2', eta_th=0.58, eta_el=0.22, effects_per_switch_on=24000, P_el=Flow('P_el', bus=Strom), Q_th=Flow('Q_th', bus=Fernwaerme), Q_fu=Flow('Q_fu', bus=Kohle, size=288, relative_minimum=87 / 288), on_values_before_begin=[0])
aSpeicher = Storage('Speicher', charging_flow=Flow('Q_th_load', size=137, bus=Fernwaerme), discharging_flow=Flow('Q_th_unload', size=158, bus=Fernwaerme), capacity_in_flow_hours=684, initial_charge_state=137, minimal_final_charge_state=137, maximal_final_charge_state=158, eta_load=1, eta_unload=1, relative_loss_per_hour=0.001, prevent_simultaneous_charge_and_discharge=True)
aSpeicher = Storage('Speicher', charging=Flow('Q_th_load', size=137, bus=Fernwaerme), discharging=Flow('Q_th_unload', size=158, bus=Fernwaerme), capacity_in_flow_hours=684, initial_charge_state=137, minimal_final_charge_state=137, maximal_final_charge_state=158, eta_load=1, eta_unload=1, relative_loss_per_hour=0.001, prevent_simultaneous_charge_and_discharge=True)

TS_Q_th_Last, TS_P_el_Last = TimeSeriesRaw(Q_th_Last), TimeSeriesRaw(P_el_Last, agg_weight=0.7)
aWaermeLast, aStromLast = Sink('Wärmelast', sink=Flow('Q_th_Last', bus=Fernwaerme, size=1, fixed_relative_value=TS_Q_th_Last)), Sink('Stromlast', sink=Flow('P_el_Last', bus=Strom, size=1, fixed_relative_value=TS_P_el_Last))
Expand Down
12 changes: 6 additions & 6 deletions tests/tests_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ def test_storage(self):
size=5
capacity = 10
storage_exists = Storage(label="Storage_ex", exists=exists, capacity_in_flow_hours=capacity,
charging_flow=Flow(label="in",
size=size,
bus=self.busses["Gas"]),
discharging_flow=Flow(label="out",
size=size,
bus=self.busses["Gas"])
charging=Flow(label="in",
size=size,
bus=self.busses["Gas"]),
discharging=Flow(label="out",
size=size,
bus=self.busses["Gas"])
)

self.es.add_elements(*self.effects.values(), *self.sinks_n_sources.values())
Expand Down

0 comments on commit 928d903

Please sign in to comment.