You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Mooi-Kickstart/.ipynb_checkpoints/waterstorage_dev3-checkpoin...

661 lines
16 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"from notepad import WaterStorage\n",
"\n",
"%load_ext autoreload\n",
"%autoreload 2"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Developments steps to take: \n",
"* Test the WaterStorage\n",
"* Create some example for WaterStorage\n",
"* Define interactions WaterStorage <> Heatpump\n",
"* Create some example for WaterStorage + Heatpump\n",
"* Develop the interactions --> Create working examples"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## WaterStorage"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Functional requirements for the WaterStorage:\n",
"* Given: \n",
" * Size / capacity\n",
" * Temperature in/out\n",
" * Max power\n",
" * Roundtripp efficiency\n",
"* It should be able to execute commands, like: \n",
" * Charge\n",
" * Discharge\n",
" * Whats the storage level? \n",
" * Assign financials \n",
" * Take into account storage losses (time dependent)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"waterstorage = WaterStorage(\n",
" name='MyStorage',\n",
" max_power=10,\n",
" min_power=-10,\n",
" roundtrip_eff=0.90,\n",
" energy_density = 50 * 10e-3,\n",
" volume = 500,\n",
" lifetime = 25,\n",
" temperature = 368, #K\n",
" min_storagelevel = 5,\n",
" max_storagelevel = 23\n",
" \n",
")\n"
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {},
"outputs": [],
"source": [
"waterstorage.set_freq('15T')"
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"15"
]
},
"execution_count": 40,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"waterstorage.set_storagelevel(15)\n",
"waterstorage.storagelevel"
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"32.0"
]
},
"execution_count": 41,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"waterstorage.charging_power_limit"
]
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"32.0"
]
},
"execution_count": 42,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"waterstorage.charge(100)"
]
},
{
"cell_type": "code",
"execution_count": 43,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"23"
]
},
"execution_count": 43,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"waterstorage.storagelevel"
]
},
{
"cell_type": "code",
"execution_count": 44,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.0"
]
},
"execution_count": 44,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"waterstorage.charge(100)"
]
},
{
"cell_type": "code",
"execution_count": 45,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"50.0"
]
},
"execution_count": 45,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"waterstorage.discharge(50)"
]
},
{
"cell_type": "code",
"execution_count": 46,
"metadata": {},
"outputs": [],
"source": [
"from notepad import Heatpump\n"
]
},
{
"cell_type": "code",
"execution_count": 47,
"metadata": {},
"outputs": [],
"source": [
"hp = Heatpump(\"heatpump1\", 50, 1, 10)\n",
"\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 48,
"metadata": {},
"outputs": [],
"source": [
"Tsink = 413 #K\n",
"Tsource = 333 #K\n",
"Tref = 273 #K\n",
"hp_capacity = 31 #MW\n",
"demand = 25 #MW\n",
"Cp = 4190 #J/kgK\n",
"MW_to_J_per_s = 1000_000\n",
"hp_capacity *= MW_to_J_per_s\n",
"demand *= MW_to_J_per_s"
]
},
{
"cell_type": "code",
"execution_count": 49,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"52.84691442209342"
]
},
"execution_count": 49,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def hp_mass_flow (hp_capacity, Tsink, Tref, Cp):\n",
" return hp_capacity /(Cp*(Tsink - Tref)) \n",
"hp_mass_flow = hp_mass_flow (hp_capacity, Tsink, Tref, Cp)\n",
"hp_mass_flow"
]
},
{
"cell_type": "code",
"execution_count": 50,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"42.61847937265598"
]
},
"execution_count": 50,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def process_mass_flow (demand, Tsink, Tref, Cp):\n",
" return demand /(Cp*(Tsink - Tref)) \n",
"process_mass_flow = process_mass_flow (demand, Tsink, Tref, Cp)\n",
"process_mass_flow\n",
"# What would be the difference here with using equation or a function?"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"6.000000000000001"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"charge_mass_flow = hp_mass_flow - process_mass_flow\n",
"charged_heat = (charge_mass_flow * Cp * (Tsink - Tref)) / MW_to_J_per_s\n",
"charged_heat"
]
},
{
"cell_type": "code",
"execution_count": 51,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"13.263157894736842"
]
},
"execution_count": 51,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"efficiency = 0.9\n",
"Tstorage = 95 + 273\n",
"discharged_heat = 5.866 * efficiency #MW\n",
"discharged_heat *= MW_to_J_per_s \n",
"discharge_mass_flow = discharged_heat /(Cp*(Tstorage - Tref))\n",
"discharge_mass_flow\n",
"\n",
"# energy is balanced here, mass in is smaller than mass out meaning that there should be extra inlet to ensure the water level\n",
"#This energy loss is because storage is charged with high temperature and discharged with low.\n",
"# heat loss can be neglected assuming that storage is well-insulated."
]
},
{
"cell_type": "code",
"execution_count": 102,
"metadata": {},
"outputs": [],
"source": [
"# new_Tsource = (Tstorage * discharge_mass_flow + Tsource * process_mass_flow) / (discharge_mass_flow + process_mass_flow)\n",
"# new_Tsource"
]
},
{
"cell_type": "code",
"execution_count": 103,
"metadata": {},
"outputs": [],
"source": [
"# COP_new = Tsink / (Tsink - new_Tsource)\n",
"# COP_new"
]
},
{
"cell_type": "code",
"execution_count": 52,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"dict_keys(['name', 'id', 'max_power', 'min_power', 'modes', 'roundtrip_eff', 'volume', 'lifetime', 'temperature', 'energy_density', 'max_storage_capacity', 'max_storagelevel', 'min_storagelevel', 'storagelevel', 'storage_level', 'freq', 'time_factor'])"
]
},
"execution_count": 52,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"waterstorage.__dict__.keys()"
]
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"250.0"
]
},
"execution_count": 38,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# max_storage_capacity is in MWh and it should inherit MWh to MW conversion from Assets\n",
"# MW = MWh / self.time_factor\n",
"waterstorage.max_storage_capacity"
]
},
{
"cell_type": "code",
"execution_count": 58,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'name': 'heatpump1', 'max_th_power': 50, 'min_th_power': 10, 'cop_curve': 1}"
]
},
"execution_count": 58,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#create an heat pump object\n",
"\n",
"heatpump = Heatpump(\"heatpump1\", 50, 1, 10)\n",
"heatpump.__dict__"
]
},
{
"cell_type": "code",
"execution_count": 61,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(-25.0, 25)"
]
},
"execution_count": 61,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def test_heatpump_and_waterstorage_system(Tsink, Tsource, process_demand_MW, e_price, waterstorage_level):\n",
" \"\"\"\n",
" 1. Follow a certain logic based on given price:\n",
" - If price is low --> Heatpump at full power, and charge the heatbuffer\n",
" - If price is high --> Discharge the heat buffer, and increase Tsource, which will increase COP\n",
" 2. Above logic should adhere to a couple of constraints:\n",
" - Storage levels\n",
" - Capacity of the heat pump \n",
" - Process demand\n",
" - ....\n",
" 3. This function should contain: \n",
" - Heat pump \n",
" - Water storage\n",
" - Interactions / logic between them\n",
" 4. Output of the function:\n",
" - Power of the heatpump \n",
" - \"New\" water storage level\n",
" \"\"\"\n",
" waterstorage.storage_level = waterstorage_level\n",
" \n",
" if e_price < 50:\n",
" hp_load = heatpump.max_th_power #bunu yoxla heat pump-a birbasa set load demek olmur. Ve funksiyada heatpump obyekti var ama o evvel initialize olunmayib\n",
" energy_to_storage = hp_load - process_demand_MW\n",
" waterstorage.charge(energy_to_storage)\n",
" waterstorage.charged_energy = waterstorage.MW_to_MWh(energy_to_storage)\n",
" waterstorage_level = waterstorage.storage_level\n",
" new_cl = waterstorage.storage_level + waterstorage.charged_energy\n",
" if e_price > 100:\n",
" energy_from_storage = discharged_heat\n",
" waterstorage_level = waterstorage.storage_level\n",
" waterstorage.discharged_energy = waterstorage.MW_to_MWh(energy_from_storage)\n",
" new_cl = waterstorage.storage_level - waterstorage.discharged_energy\n",
" def Tsource_calculation(Tstorage, discharge_mass_flow, Tsource, process_mass_flow):\n",
" return (\n",
" (Tstorage * discharge_mass_flow + Tsource * process_mass_flow)\n",
" / (discharge_mass_flow + process_mass_flow)\n",
" )\n",
" new_Tsource = Tsource_calculation(Tstorage, discharge_mass_flow, Tsource, process_mass_flow)\n",
" def COP_calculation (Tsink, new_Tsource):\n",
" return Tsink / (Tsink - new_Tsource)\n",
" new_COP = COP_calculation (Tsink, new_Tsource)\n",
" hp_load = heatpump.set_heat_output(process_demand_MW, new_COP) #bu da hemcinin set load assetin funksiyasidir, \n",
" #heatpump da overwrite edilib. men evezinde yazdim ki set_heat_output\n",
" #sen gor hansi funksiya sene lazimdir.\n",
"\n",
" return hp_load, waterstorage_level\n",
" \n",
"hp_load, waterstorage_level = test_heatpump_and_waterstorage_system(\n",
" Tsink = 140+273, \n",
" Tsource = 60+273, \n",
" process_demand_MW = 25, \n",
" e_price = 150, \n",
" waterstorage_level = 5\n",
")\n",
"\n",
"# Expected behaviour: \n",
" # hp_heat_output == demand\n",
" # hp source temparture > than before\n",
" # waterstorage_level < than before\n",
" # hp cop > higher than before\n",
"hp_load"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## WaterStorage + Heatpump system"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Functional requirements for the WaterStorage + Heatpump system:\n",
"1. Goal (Funtional requirements): \n",
" * Given (context)\n",
" * price (forecast), \n",
" * source and sink temperature (provided by process), \n",
" * process heat demand, \n",
" * storage level of the water storage (temperature level)\n",
"* I want to know:\n",
" * Heat output from the heatpump (in MW)\n",
" * New storage level / temperature level\n",
" * Electricity consumption of the heatpump"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Previous examples"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# def hp_mass_flow (hp_capacity, Tsink, Tref, Cp):\n",
"# return hp_capacity /(Cp*(Tsink - Tref)) \n",
"# hp_mass_flow (31_000_000, 413, 273, 4190)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# def process_mass_flow (demand, Tsink, Tref, Cp):\n",
"# return demand /(Cp*(Tsink - Tref)) \n",
"# process_mass_flow (25_000_000, 413, 273, 4190)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# charge_mass_flow = 52 - 42 #should be written as function\n",
"# def charge_heat (charge_mass_flow, Cp, Tsink, Tref, MW_to_J_per_s):\n",
"# return (charge_mass_flow * Cp * (Tsink - Tref)) / MW_to_J_per_s\n",
"# charge_heat (10, 4190, 413, 273, 1000_000)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Tsource_new = (discharge_mass_flow * T_discharge + Tsource * source_mass_flow) / (discharge_mass_flow + source_mass_flow)\n",
"Tsource_new = (13 * 95 + 60*42) / (13+42)\n",
"Tsource_new"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# chargelevel = self.chargelevel\n",
"# max_charging = chargelevel - self.max_chargelevel\n",
"# max_discharging = chargelevel - self.min_chargelevel"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Funtionality: Set the storage level\n",
"waterstorage.storagelevel = 15\n",
"waterstorage.max_storagelevel = 23.2\n",
"waterstorage.min_storagelevel = 5\n",
"# waterstorage.max_charging = waterstorage.max_storagelevel - waterstorage.storagelevel\n",
"# waterstorage.max_discharging = waterstorage.max_storagelevel - waterstorage.min_storagelevel\n",
"waterstorage.max_discharging"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Functionality: Charge the storage\n",
"waterstorage.storage_level = 15\n",
"waterstorage.charge = 5\n",
"waterstorage.storage_level += waterstorage.charge\n",
"waterstorage.storage_level"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Functionality: Discharge the storage\n",
"waterstorage.storage_level = 15\n",
"waterstorage.discharge = 4\n",
"waterstorage.storage_level -= waterstorage.discharge\n",
"waterstorage.storage_level"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.12"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {},
"version_major": 2,
"version_minor": 0
}
}
},
"nbformat": 4,
"nbformat_minor": 4
}