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.
660 lines
17 KiB
Plaintext
660 lines
17 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 38,
|
|
"id": "c243d17f-dec8-48dc-829c-a2c5fec7fbbb",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"class SchoolPerson:\n",
|
|
" \n",
|
|
" schoolpopulation = 0\n",
|
|
" \n",
|
|
" def __init__(self, name, age ):\n",
|
|
" self.name = name\n",
|
|
" self.age = age\n",
|
|
" \n",
|
|
" \n",
|
|
" SchoolPerson.schoolpopulation +=1 \n",
|
|
" print(f'Initialized person:{self.name}')\n",
|
|
" \n",
|
|
" \n",
|
|
" def tellName(self):\n",
|
|
" print(f'Name: {self.name} , age: {self.age}')\n",
|
|
" \n",
|
|
" @classmethod\n",
|
|
" def Count(cls):\n",
|
|
" print('number of people:', cls.schoolpopulation)\n",
|
|
"\n",
|
|
" \n",
|
|
"class SchoolTeacher(SchoolPerson):\n",
|
|
" def __init__(self, name, age, salary):\n",
|
|
" SchoolPerson.__init__(self, name ,age)\n",
|
|
" self.salary = salary\n",
|
|
" \n",
|
|
" def tellName(self):\n",
|
|
" print(f'Name: {self.name} , age: {self.age}, salary: {self.salary}')\n",
|
|
" super().tellName()\n",
|
|
" \n",
|
|
" @classmethod\n",
|
|
" def Count(cls):\n",
|
|
" super().Count()\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 39,
|
|
"id": "f462528b-e981-4d99-ae88-806e13e254fe",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Initialized person:Nazim\n",
|
|
"Initialized person:Rasim\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"c = SchoolPerson('Nazim', 30)\n",
|
|
"c.name\n",
|
|
"d = SchoolPerson('Rasim', 23)\n",
|
|
"\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 40,
|
|
"id": "cd2d7a8b-25f6-4438-b0b3-9ab1a4c5a33a",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"number of people: 2\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"SchoolPerson.Count()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 41,
|
|
"id": "c937bf4b-4cd2-4e6e-9ece-31689eb55b5e",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Initialized person:John\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"f = SchoolTeacher('John', 35, 1111)\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 42,
|
|
"id": "a8eb084e-d233-4225-baa7-35c290e45ffb",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"number of people: 3\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"SchoolTeacher.Count()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 11,
|
|
"id": "ddff6fb6-d01d-408b-8d08-2dc226edf07b",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"{'name': 'Nazim', 'age': 30}"
|
|
]
|
|
},
|
|
"execution_count": 11,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"c.__dict__"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 56,
|
|
"id": "0413f66c-9390-4444-a712-ab4e85a9ed32",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"x = 23\n",
|
|
"\n",
|
|
"class Addition:\n",
|
|
" \n",
|
|
" x = 10\n",
|
|
" \n",
|
|
" def __init__(self, x):\n",
|
|
" self.x = x\n",
|
|
" \n",
|
|
" def addY_1(self, y):\n",
|
|
" print('Result:', self.x + y)\n",
|
|
" \n",
|
|
" @classmethod\n",
|
|
" def addY_2(cls, y):\n",
|
|
" print('Result:', cls.x + y)\n",
|
|
" \n",
|
|
" @staticmethod\n",
|
|
" def addY_3(y):\n",
|
|
" print('Result:', x + y)\n",
|
|
" \n",
|
|
" "
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 57,
|
|
"id": "2114ab51-ccd7-4b41-a20e-272c8ae1a88b",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"n = Addition(23)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 58,
|
|
"id": "aeeb5ada-84d9-4750-b9c7-d38ee24db7fc",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Result: 25\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"n.addY_1(2)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 61,
|
|
"id": "e103e15c-a1e5-494b-b40a-60b5702509cd",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Result: 25\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"# n.addY_2(2)\n",
|
|
"\n",
|
|
"n.addY_3(2)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 55,
|
|
"id": "e1c04684-739a-4ff5-aedf-ebeb44cf1512",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Result: 32\n",
|
|
"Result: 12\n",
|
|
"Result: 12\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"t = Addition(30)\n",
|
|
"t.addY_1(2)\n",
|
|
"t.addY_2(2)\n",
|
|
"Addition.addY_2(2)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 9,
|
|
"id": "50936cf6-d267-4a74-8c99-90dc063c55a6",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"/------- \\\n",
|
|
"=========\n",
|
|
"\\-------//\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"def buterbrod(icfunksiya):\n",
|
|
" def corekle():\n",
|
|
" print('/------- \\\\')\n",
|
|
" icfunksiya()\n",
|
|
" print('\\-------//')\n",
|
|
" return corekle()\n",
|
|
"\n",
|
|
"\n",
|
|
"\n",
|
|
" \n",
|
|
"@buterbrod\n",
|
|
"def pendirli():\n",
|
|
" print('=========')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "2a5f08ba-b25f-4a8f-8cbf-a72ac75cf68f",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"id": "34cb1c1e-9466-4ef2-be5f-3009f47434f7",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"from itertools import count\n",
|
|
"class Asset:\n",
|
|
" \"\"\"Generic class for producing/consuming assets. Specific asset classes can\n",
|
|
" inherit from this class.\n",
|
|
"\n",
|
|
" Parameters:\n",
|
|
" -----------\n",
|
|
" max_power : int/float\n",
|
|
" Maximum asset power in MW electric\n",
|
|
" min_power : int/float\n",
|
|
" Minimium asset load in MW electric\n",
|
|
"\n",
|
|
" Usage:\n",
|
|
" ------\n",
|
|
" Use the set_load and get_load methods to set and get asset status in MW.\n",
|
|
"\n",
|
|
" Convention is negative values for inputs (consumption) and positive\n",
|
|
" values for outputs (production).\n",
|
|
" \"\"\"\n",
|
|
"\n",
|
|
" _freq_to_multiplier = {\"H\": 1, \"15T\": (1 / 4), \"1T\": (1 / 60)}\n",
|
|
" _ids = count(0)\n",
|
|
"\n",
|
|
" def __init__(self, name, max_power, min_power):\n",
|
|
" if min_power > max_power:\n",
|
|
" raise ValueError(\"'min_power' can not be larger than 'max_power'.\")\n",
|
|
"\n",
|
|
" self.name = name\n",
|
|
" self.id = next(self._ids)\n",
|
|
" self.max_power = max_power\n",
|
|
" self.min_power = min_power\n",
|
|
" self.modes = {\"max\": max_power, \"min\": min_power}\n",
|
|
"\n",
|
|
" def __repr__(self):\n",
|
|
" return f\"{self.__class__.__name__}(self, max_power={self.max_power}, min_power={self.min_power})\"\n",
|
|
"\n",
|
|
" def set_load(self, load):\n",
|
|
" \"\"\"Set Asset load in MW.\n",
|
|
"\n",
|
|
" Convention is negative value for consumption and positive value\n",
|
|
" for production. Subclasses might use a different convention if\n",
|
|
" this seems more intiutive.\n",
|
|
"\n",
|
|
" Returns the load that is set in MW.\n",
|
|
" \"\"\"\n",
|
|
" if load < self.min_power or load > self.max_power:\n",
|
|
" warnings.warn(\n",
|
|
" f\"Chosen Asset load for {self.name} is out of range. \"\n",
|
|
" f\"Should be between {self.min_power} and {self.max_power}. \"\n",
|
|
" f\"Function will return boundary load level for now.\"\n",
|
|
" )\n",
|
|
" load = min(max(load, self.min_power), self.max_power)\n",
|
|
" return load\n",
|
|
"\n",
|
|
" def set_mode(self, mode):\n",
|
|
" \"\"\" \"\"\"\n",
|
|
" load = self.modes[mode]\n",
|
|
" return self.set_load(load)\n",
|
|
"\n",
|
|
" def MW_to_MWh(self, MW):\n",
|
|
" \"\"\"Performs conversion from MW to MWh using the time_factor variable.\"\"\"\n",
|
|
" return MW * self.time_factor\n",
|
|
"\n",
|
|
" def MWh_to_MW(self, MWh):\n",
|
|
" \"\"\"Performs conversion from MWh to MW using the time_factor variable.\"\"\"\n",
|
|
" return MWh / self.time_factor\n",
|
|
"\n",
|
|
" def set_freq(self, freq):\n",
|
|
" \"\"\"\n",
|
|
" Function that aligns time frequency between Model and Asset.\n",
|
|
" Can be '1T', '15T' or 'H'\n",
|
|
" The time_factor variable is used in subclasses to perform MW to MWh conversions.\n",
|
|
" \"\"\"\n",
|
|
" self.freq = freq\n",
|
|
" self.time_factor = Asset._freq_to_multiplier[freq]\n",
|
|
"\n",
|
|
" def set_financials(self, capex, opex, devex, lifetime=None, depreciate=True, salvage_value=0):\n",
|
|
" \"\"\"Set financial data of the asset.\"\"\"\n",
|
|
" self.capex = capex\n",
|
|
" self.opex = opex\n",
|
|
" self.devex = devex\n",
|
|
" self.lifetime = lifetime\n",
|
|
" self.depreciate = depreciate\n",
|
|
" self.salvage_value = salvage_value"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 3,
|
|
"id": "81a28df0-2ed6-42f4-bd8e-22bcfc992f79",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"class WaterStorage(Asset):\n",
|
|
" \n",
|
|
" def __init__(\n",
|
|
" self, \n",
|
|
" name,\n",
|
|
" max_power,\n",
|
|
" min_power,\n",
|
|
" roundtrip_eff,\n",
|
|
" lifetime,\n",
|
|
" power_capex, \n",
|
|
" energy_capex,\n",
|
|
" opex,\n",
|
|
" heat_demand = 23.5*1.06,\n",
|
|
" heat_st_capacity = 70, \n",
|
|
" storage_size = 22650\n",
|
|
" ):\n",
|
|
" super().__init__(name, max_power, min_power)\n",
|
|
" self.rt_eff = roundtrip_eff\n",
|
|
" self.lifetime = lifetime\n",
|
|
" self.power_capex = power_capex #Euro/kW\n",
|
|
" self.energy_capex = energy_capex #Euro/kWh\n",
|
|
" self.opex = opex\n",
|
|
" self.heat_demand = heat_demand #MW\n",
|
|
" self.heat_st_cap = heat_st_cap #kWh/m3\n",
|
|
" self.storage_size= storage_size #m3\n",
|
|
" \n",
|
|
" def __repr__(self):\n",
|
|
" return (\n",
|
|
" # f\"{self.__class__.__name__}(name={self.name}, max_power={self.max_power}, \"\n",
|
|
" # f\"min_power={self.min_power}, efficiency={self.efficiency})\"\n",
|
|
" f\"\"\"{self.__class__.__name__}(name={self.name}, max_power={self.max_power}, \n",
|
|
" min_power={self.min_power}, efficiency={self.efficiency})\"\"\"\n",
|
|
" )\n",
|
|
" \n",
|
|
" def set_capacity(self, capacity):\n",
|
|
" if not isinstance(capacity, (int, float)):\n",
|
|
" raise TypeError('Should be float')\n",
|
|
" if capacity < 0:\n",
|
|
" raise ValueError('Capacity has to be positive')\n",
|
|
" self.capacity = capacity\n",
|
|
" \n",
|
|
" def cost_function(self):\n",
|
|
" return self.heat_demand * self.power_capex * 1e6 + self.heat_st_cap * self.storage_size * self.energy_capex\n",
|
|
" \n",
|
|
" \n",
|
|
" \n",
|
|
" "
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 10,
|
|
"id": "ed141f44-e508-4613-9eb8-bf7adf39e1d3",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"s = WaterStorage\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 89,
|
|
"id": "de204644-8b68-419f-82ee-772072b25a2e",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"{'name': 'WaterStorage',\n",
|
|
" 'id': 3,\n",
|
|
" 'max_power': 350,\n",
|
|
" 'min_power': 122,\n",
|
|
" 'modes': {'max': 300, 'min': 122},\n",
|
|
" 'freq': '1T',\n",
|
|
" 'time_factor': 0.016666666666666666}"
|
|
]
|
|
},
|
|
"execution_count": 89,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"c.__dict__"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 84,
|
|
"id": "2ab516f0-3f28-41d3-ba30-0622773eed82",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"d = Asset('Pump', 200, 20)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 85,
|
|
"id": "9e325374-f7ea-46b1-9763-c13d24f051c7",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"{'name': 'Pump',\n",
|
|
" 'id': 1,\n",
|
|
" 'max_power': 200,\n",
|
|
" 'min_power': 20,\n",
|
|
" 'modes': {'max': 200, 'min': 20}}"
|
|
]
|
|
},
|
|
"execution_count": 85,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"d.__dict__"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 96,
|
|
"id": "9fac7681-f324-4f73-9566-0843077afca3",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"class Eboiler(Asset):\n",
|
|
" \"\"\"Subclass for an E-boiler.\"\"\"\n",
|
|
"\n",
|
|
" def __init__(self, name, max_power, min_power=0, efficiency=0.99):\n",
|
|
" super().__init__(name, min_power=-max_power, max_power=-min_power)\n",
|
|
" self.efficiency = efficiency\n",
|
|
" self.max_thermal_output = max_power * 0.99\n",
|
|
"\n",
|
|
" def __repr__(self):\n",
|
|
" return (\n",
|
|
" f\"{self.__class__.__name__}(name={self.name}, max_power={self.max_power}, \"\n",
|
|
" f\"min_power={self.min_power}, efficiency={self.efficiency})\"\n",
|
|
" )\n",
|
|
"\n",
|
|
" def set_load(self, load):\n",
|
|
" \"\"\"Set load in MWe, returns (load, heat_output) in MWe and MWth\n",
|
|
"\n",
|
|
" Convention is negative numbers for consumption.\n",
|
|
" Inserting a positive value will return an exception.\n",
|
|
" \"\"\"\n",
|
|
"\n",
|
|
" if load > 0:\n",
|
|
" raise ValueError(\n",
|
|
" f\"Eboiler.set_load() only accepts negative numbers by convention. \"\n",
|
|
" f\"{load} was inserted.\"\n",
|
|
" )\n",
|
|
"\n",
|
|
" load = super().set_load(load)\n",
|
|
" heat_output = -load * self.efficiency\n",
|
|
" return (load, heat_output)\n",
|
|
"\n",
|
|
" def set_heat_output(self, heat_output):\n",
|
|
" \"\"\"Set heat output in MWth, returns tuple (heat_output, eload) in MW\"\"\"\n",
|
|
" load = -heat_output / self.efficiency\n",
|
|
" load, heat_output = self.set_load(load)\n",
|
|
" return heat_output, load"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 91,
|
|
"id": "904d8541-4d1b-4d1e-a7a3-e9fe939689bb",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"e = Eboiler('eboyul', 300)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 97,
|
|
"id": "9c5866c7-026b-41b4-b5c6-1476e82ff0ac",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"{'name': 'eboyul',\n",
|
|
" 'id': 4,\n",
|
|
" 'max_power': 0,\n",
|
|
" 'min_power': -300,\n",
|
|
" 'modes': {'max': 0, 'min': -300},\n",
|
|
" 'efficiency': 0.99,\n",
|
|
" 'max_thermal_output': 297.0}"
|
|
]
|
|
},
|
|
"execution_count": 97,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"e.__dict__"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 98,
|
|
"id": "0f9a1714-bd18-4487-9f1c-24ca0ca31473",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"e.set_financials(300,400,500)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 99,
|
|
"id": "f135160a-484f-4cbc-8df1-cfab32195423",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"{'name': 'eboyul',\n",
|
|
" 'id': 4,\n",
|
|
" 'max_power': 0,\n",
|
|
" 'min_power': -300,\n",
|
|
" 'modes': {'max': 0, 'min': -300},\n",
|
|
" 'efficiency': 0.99,\n",
|
|
" 'max_thermal_output': 297.0,\n",
|
|
" 'capex': 300,\n",
|
|
" 'opex': 400,\n",
|
|
" 'devex': 500,\n",
|
|
" 'lifetime': None,\n",
|
|
" 'depreciate': True,\n",
|
|
" 'salvage_value': 0}"
|
|
]
|
|
},
|
|
"execution_count": 99,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"e.__dict__"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "5ae82d8a-36d1-4456-97e6-d93679b1d211",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
}
|
|
],
|
|
"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.5"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|