Skip to content

Commit

Permalink
Adhere to Black
Browse files Browse the repository at this point in the history
  • Loading branch information
p-snft committed Oct 8, 2024
1 parent bafeb20 commit 6c71981
Show file tree
Hide file tree
Showing 37 changed files with 2,050 additions and 1,386 deletions.
147 changes: 84 additions & 63 deletions examples/absorption_heatpump_and_chiller/absorption_chiller.py
Original file line number Diff line number Diff line change
@@ -1,140 +1,161 @@

# import absorption_heatpumps_and_chillers as abs_hp_chiller
import oemof.thermal.absorption_heatpumps_and_chillers as abs_hp_chiller
import oemof.solph as solph
import pandas as pd
import os
import matplotlib.pyplot as plt


def absorption_chiller_example():
solver = 'cbc'
solver = "cbc"
debug = False
number_of_time_steps = 48
solver_verbose = True

date_time_index = pd.date_range('1/1/2012', periods=number_of_time_steps,
freq='H')
date_time_index = pd.date_range(
"1/1/2012", periods=number_of_time_steps, freq="H"
)
energysystem = solph.EnergySystem(timeindex=date_time_index)

# Read data file
filename_data = os.path.join(os.path.dirname(__file__), 'data/AC_example.csv')
filename_data = os.path.join(
os.path.dirname(__file__), "data/AC_example.csv"
)
data = pd.read_csv(filename_data)

filename_charpara = os.path.join(os.path.dirname(__file__),
'data/characteristic_parameters.csv')
filename_charpara = os.path.join(
os.path.dirname(__file__), "data/characteristic_parameters.csv"
)
charpara = pd.read_csv(filename_charpara)
chiller_name = 'Kuehn'
chiller_name = "Kuehn"

# Buses with three different temperature levels
b_th_high = solph.Bus(label="hot")
# b_th_medium = solph.Bus(label="cool")
b_th_low = solph.Bus(label="chilled")
energysystem.add(b_th_high, b_th_low)

energysystem.add(solph.components.Source(
label='driving_heat',
outputs={b_th_high: solph.Flow(variable_costs=0)}))
energysystem.add(solph.components.Source(
label='cooling_shortage',
outputs={b_th_low: solph.Flow(variable_costs=20)}))
energysystem.add(
solph.components.Source(
label="driving_heat",
outputs={b_th_high: solph.Flow(variable_costs=0)},
)
)
energysystem.add(
solph.components.Source(
label="cooling_shortage",
outputs={b_th_low: solph.Flow(variable_costs=20)},
)
)
# energysystem.add(solph.components.Sink(
# label='dry_cooling_tower',
# inputs={b_th_medium: solph.Flow(variable_costs=0)}))
energysystem.add(solph.components.Sink(
label='cooling_demand',
inputs={b_th_low: solph.Flow(fix=1, nominal_value=35)}))
energysystem.add(
solph.components.Sink(
label="cooling_demand",
inputs={b_th_low: solph.Flow(fix=1, nominal_value=35)},
)
)

# Mean cooling water temperature in degC (dry cooling tower)
temp_difference = 4
t_cooling = [t + temp_difference for t in data['air_temperature']]
t_cooling = [t + temp_difference for t in data["air_temperature"]]
n = len(t_cooling)

# Pre-Calculations
ddt = abs_hp_chiller.calc_characteristic_temp(
t_hot=[85],
t_cool=t_cooling,
t_chill=[15] * n,
coef_a=charpara[(charpara['name'] == chiller_name)]['a'].values[0],
coef_e=charpara[(charpara['name'] == chiller_name)]['e'].values[0],
method='kuehn_and_ziegler')
coef_a=charpara[(charpara["name"] == chiller_name)]["a"].values[0],
coef_e=charpara[(charpara["name"] == chiller_name)]["e"].values[0],
method="kuehn_and_ziegler",
)
Q_dots_evap = abs_hp_chiller.calc_heat_flux(
ddts=ddt,
coef_s=charpara[(charpara['name'] == chiller_name)]['s_E'].values[0],
coef_r=charpara[(charpara['name'] == chiller_name)]['r_E'].values[0],
method='kuehn_and_ziegler')
coef_s=charpara[(charpara["name"] == chiller_name)]["s_E"].values[0],
coef_r=charpara[(charpara["name"] == chiller_name)]["r_E"].values[0],
method="kuehn_and_ziegler",
)
Q_dots_gen = abs_hp_chiller.calc_heat_flux(
ddts=ddt,
coef_s=charpara[(charpara['name'] == chiller_name)]['s_G'].values[0],
coef_r=charpara[(charpara['name'] == chiller_name)]['r_G'].values[0],
method='kuehn_and_ziegler')
coef_s=charpara[(charpara["name"] == chiller_name)]["s_G"].values[0],
coef_r=charpara[(charpara["name"] == chiller_name)]["r_G"].values[0],
method="kuehn_and_ziegler",
)
COPs = [Qevap / Qgen for Qgen, Qevap in zip(Q_dots_gen, Q_dots_evap)]
nominal_Q_dots_evap = 10
actual_value = [Q_e / nominal_Q_dots_evap for Q_e in Q_dots_evap]

# Absorption Chiller
energysystem.add(solph.components.Transformer(
label="AC",
inputs={b_th_high: solph.Flow()},
outputs={b_th_low: solph.Flow(nominal_value=nominal_Q_dots_evap,
max=actual_value,
variable_costs=5)},
conversion_factors={b_th_low: COPs}))
energysystem.add(
solph.components.Transformer(
label="AC",
inputs={b_th_high: solph.Flow()},
outputs={
b_th_low: solph.Flow(
nominal_value=nominal_Q_dots_evap,
max=actual_value,
variable_costs=5,
)
},
conversion_factors={b_th_low: COPs},
)
)

model = solph.Model(energysystem)

model.solve(solver=solver, solve_kwargs={'tee': solver_verbose})
model.solve(solver=solver, solve_kwargs={"tee": solver_verbose})

energysystem.results['main'] = solph.processing.results(model)
energysystem.results['meta'] = solph.processing.meta_results(model)
energysystem.results["main"] = solph.processing.results(model)
energysystem.results["meta"] = solph.processing.meta_results(model)

energysystem.dump(dpath=None, filename=None)


# ****************************************************************************
# ********** PART 2 - Processing the results *********************************
# ****************************************************************************

energysystem = solph.EnergySystem()
energysystem.restore(dpath=None, filename=None)

results = energysystem.results['main']
results = energysystem.results["main"]

high_temp_bus = solph.views.node(results, 'hot')
low_temp_bus = solph.views.node(results, 'chilled')
high_temp_bus = solph.views.node(results, "hot")
low_temp_bus = solph.views.node(results, "chilled")

string_results = solph.views.convert_keys_to_strings(
energysystem.results['main'])
AC_output = string_results[
'AC', 'chilled']['sequences'].values
demand_cooling = string_results[
'chilled', 'cooling_demand']['sequences'].values
ASHP_input = string_results[
'hot', 'AC']['sequences'].values

energysystem.results["main"]
)
AC_output = string_results["AC", "chilled"]["sequences"].values
demand_cooling = string_results["chilled", "cooling_demand"][
"sequences"
].values
ASHP_input = string_results["hot", "AC"]["sequences"].values

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable ASHP_input is not used.

fig2, axs = plt.subplots(3, 1, figsize=(8, 5), sharex=True)
axs[0].plot(AC_output, label='cooling output')
axs[0].plot(demand_cooling, linestyle='--', label='cooling demand')
axs[1].plot(COPs, linestyle='-.')
axs[2].plot(data['air_temperature'])
axs[0].set_title('Cooling capacity and demand')
axs[1].set_title('Coefficient of Performance')
axs[2].set_title('Air Temperature')
axs[0].plot(AC_output, label="cooling output")
axs[0].plot(demand_cooling, linestyle="--", label="cooling demand")
axs[1].plot(COPs, linestyle="-.")
axs[2].plot(data["air_temperature"])
axs[0].set_title("Cooling capacity and demand")
axs[1].set_title("Coefficient of Performance")
axs[2].set_title("Air Temperature")
axs[0].legend()

axs[0].grid()
axs[1].grid()
axs[2].grid()
axs[0].set_ylabel('Cooling capacity in kW')
axs[1].set_ylabel('COP')
axs[2].set_ylabel('Temperature in $°$C')
axs[2].set_xlabel('Time in h')
axs[0].set_ylabel("Cooling capacity in kW")
axs[1].set_ylabel("COP")
axs[2].set_ylabel("Temperature in $°$C")
axs[2].set_xlabel("Time in h")
plt.tight_layout()
plt.show()

print('********* Main results *********')
print(high_temp_bus['sequences'].sum(axis=0))
print(low_temp_bus['sequences'].sum(axis=0))
print("********* Main results *********")
print(high_temp_bus["sequences"].sum(axis=0))
print(low_temp_bus["sequences"].sum(axis=0))


if __name__ == "__main__":
Expand Down
Original file line number Diff line number Diff line change
@@ -1,83 +1,95 @@

import oemof.thermal.absorption_heatpumps_and_chillers as abs_hp_chiller
import matplotlib.pyplot as plt
import os
import pandas as pd


def cooling_cap_example():
filename = os.path.join(os.path.dirname(__file__),
'data/characteristic_parameters.csv')
filename = os.path.join(
os.path.dirname(__file__), "data/characteristic_parameters.csv"
)
charpara = pd.read_csv(filename)
chiller_name = 'Kuehn'
chiller_name = "Kuehn"

t_cooling = [23, 25, 27, 29, 31, 33, 35, 36, 37, 38, 39, 40]

ddt_75 = abs_hp_chiller.calc_characteristic_temp(
t_hot=[75],
t_cool=t_cooling,
t_chill=[15],
coef_a=charpara[(charpara['name'] == chiller_name)]['a'].values[0],
coef_e=charpara[(charpara['name'] == chiller_name)]['e'].values[0],
method='kuehn_and_ziegler')
coef_a=charpara[(charpara["name"] == chiller_name)]["a"].values[0],
coef_e=charpara[(charpara["name"] == chiller_name)]["e"].values[0],
method="kuehn_and_ziegler",
)
Q_dots_evap_75 = abs_hp_chiller.calc_heat_flux(
ddts=ddt_75,
coef_s=charpara[(charpara['name'] == chiller_name)]['s_E'].values[0],
coef_r=charpara[(charpara['name'] == chiller_name)]['r_E'].values[0],
method='kuehn_and_ziegler')
coef_s=charpara[(charpara["name"] == chiller_name)]["s_E"].values[0],
coef_r=charpara[(charpara["name"] == chiller_name)]["r_E"].values[0],
method="kuehn_and_ziegler",
)
Q_dots_gen_75 = abs_hp_chiller.calc_heat_flux(
ddts=ddt_75,
coef_s=charpara[(charpara['name'] == chiller_name)]['s_G'].values[0],
coef_r=charpara[(charpara['name'] == chiller_name)]['r_G'].values[0],
method='kuehn_and_ziegler')
COPs_75 = [Qevap / Qgen for Qgen, Qevap in zip(Q_dots_gen_75, Q_dots_evap_75)]
coef_s=charpara[(charpara["name"] == chiller_name)]["s_G"].values[0],
coef_r=charpara[(charpara["name"] == chiller_name)]["r_G"].values[0],
method="kuehn_and_ziegler",
)
COPs_75 = [
Qevap / Qgen for Qgen, Qevap in zip(Q_dots_gen_75, Q_dots_evap_75)
]

ddt_80 = abs_hp_chiller.calc_characteristic_temp(
t_hot=[80],
t_cool=t_cooling,
t_chill=[15],
coef_a=charpara[(charpara['name'] == chiller_name)]['a'].values[0],
coef_e=charpara[(charpara['name'] == chiller_name)]['e'].values[0],
method='kuehn_and_ziegler')
coef_a=charpara[(charpara["name"] == chiller_name)]["a"].values[0],
coef_e=charpara[(charpara["name"] == chiller_name)]["e"].values[0],
method="kuehn_and_ziegler",
)
Q_dots_evap_80 = abs_hp_chiller.calc_heat_flux(
ddts=ddt_80,
coef_s=charpara[(charpara['name'] == chiller_name)]['s_E'].values[0],
coef_r=charpara[(charpara['name'] == chiller_name)]['r_E'].values[0],
method='kuehn_and_ziegler')

coef_s=charpara[(charpara["name"] == chiller_name)]["s_E"].values[0],
coef_r=charpara[(charpara["name"] == chiller_name)]["r_E"].values[0],
method="kuehn_and_ziegler",
)

fig1 = plt.figure(figsize=(8, 6))
fig1.set_size_inches(8, 6, forward=True)
ax1 = fig1.add_subplot(111)
ax1.grid(axis='y')
ax1.grid(axis="y")

line1 = ax1.plot(t_cooling,
Q_dots_evap_80,
linestyle='dotted',
marker='d',
color='black',
label='Cooling capacity ($80°$C driving heat)')
line2 = ax1.plot(t_cooling,
Q_dots_evap_75,
linestyle='dashed',
marker='d',
color='black',
label='Cooling capacity ($75°$C driving heat)')
plt.ylabel('Cooling capacity in kW')
line1 = ax1.plot(

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable line1 is not used.
t_cooling,
Q_dots_evap_80,
linestyle="dotted",
marker="d",
color="black",
label="Cooling capacity ($80°$C driving heat)",
)
line2 = ax1.plot(

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable line2 is not used.
t_cooling,
Q_dots_evap_75,
linestyle="dashed",
marker="d",
color="black",
label="Cooling capacity ($75°$C driving heat)",
)
plt.ylabel("Cooling capacity in kW")
ax2 = fig1.add_subplot(111, sharex=ax1, frameon=False)
line3 = ax2.plot(t_cooling,
COPs_75,
linestyle='-',
marker='o',
color='black',
label='COP ($75°$C driving heat)')
line3 = ax2.plot(

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable line3 is not used.
t_cooling,
COPs_75,
linestyle="-",
marker="o",
color="black",
label="COP ($75°$C driving heat)",
)
ax2.yaxis.tick_right()
ax2.yaxis.set_label_position('right')
plt.ylabel('COP')
plt.xlabel('Cooling water temperature in $°$C')
plt.title('Chiller performance at varying cooling water temperatures')
ax2.legend(loc='upper right')
ax1.legend(loc='lower left')
ax2.yaxis.set_label_position("right")
plt.ylabel("COP")
plt.xlabel("Cooling water temperature in $°$C")
plt.title("Chiller performance at varying cooling water temperatures")
ax2.legend(loc="upper right")
ax1.legend(loc="lower left")

ax2.set_ylim(0.4, 0.8)
ax1.set_ylim(0, 24)
Expand Down
Loading

0 comments on commit 6c71981

Please sign in to comment.