-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomponents.py
330 lines (244 loc) · 9.52 KB
/
components.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
class Material(object):
"""
Represent a material with its thickness and its thermal conductivity
"""
def __init__(self, thermal_conductivity=None, thickness=None):
"""
:param thermal_conductivity: thermal conductivity in SI units, must be positive
:param thickness: thickness in SI units, must be strictly positive
"""
self.parent = None
self.thermal_conductivity = thermal_conductivity
self.thickness = thickness
def calculate_thermal_conductivity_insulance(self):
"""
Calculate the thermal conductivity insulance
:returns: the thermal conductivity insulance in SI units
"""
return self.thickness / self.thermal_conductivity
def modify(self, variable, value):
"""
Modify a variable of the material
:param variable: the variable to modify
:param value: the new value of the variable
"""
self.__dict__[variable] = value
class MaterialCollection(object):
"""
Represent a collection of overlaid material with the same surface
Warning! It shouldn't be accessed directly
"""
def __init__(self, materials=[]):
"""
:param materials: list of Material objects
:param surface: surface of the collection in SI units, must be strictly positive
"""
self.parent = None
self.surface = None
self.materials = []
for material in materials:
self.add(material)
def calculate_thermal_conductivity_insulance(self):
"""
Calculate the thermal conductivity insulance
:returns: thermal conductivity insulance in SI units
"""
thermal_conductivity_insulance = 0
for material in self.materials:
thermal_conductivity_insulance += material.calculate_thermal_conductivity_insulance()
return thermal_conductivity_insulance
def calculate_thermal_insulance(self):
"""
Calculate the thermal insulance (with conductivity and convection)
:returns: thermal insulance in SI units
"""
thermal_conductivity_insulance = self.calculate_thermal_conductivity_insulance()
thermal_inside_convection_insulance = 1 / 10
thermal_outside_convection_insulance = 1 / 80
return thermal_conductivity_insulance + thermal_inside_convection_insulance + thermal_outside_convection_insulance
def calculate_flux_surface(self, temperature_variation=0):
"""
Calculate the thermal flux by surface unit
:param temperature_variation: absolute difference between inside and outsite temperatures, must be strictly positive
:returns: thermal flux by surface unit in SI units
"""
return temperature_variation / self.calculate_thermal_insulance()
def calculate_flux(self, temperature_variation=0):
"""
Calculate the thermal flux
:param temperature_variation: absolute difference between inside and outsite temperatures, must be strictly positive
:returns: thermal flux in SI units
"""
return self.calculate_flux_surface(temperature_variation) * self.surface
def add(self, child):
"""
Add a material to the collection
:param child: a Material object
"""
self.materials.append(child)
child.parent = self
def remove(self, child):
"""
Remove a material from the collection
:param child: a Material object
"""
self.materials.remove(child)
child.parent = None
class Opening(MaterialCollection):
"""
Represent an opening, a material collection with the surface defined
"""
def __init__(self, surface=None):
super().__init__()
self.surface = surface
def modify(self, variable, value):
"""
Modify a variable of the opening
:param variable: the variable to modify
:param value: the new value of the variable
"""
self.__dict__[variable] = value
class Roof(MaterialCollection):
"""
Represent the roof of a building
"""
def calculate_flux(self, *args):
self.surface = self.parent.width * self.parent.length
return super().calculate_flux(args)
class Floor(MaterialCollection):
"""
Represent the floor of a building
"""
def calculate_thermal_insulance(self):
thermal_conductivity_insulance = self.calculate_thermal_conductivity_insulance()
thermal_inside_convection_insulance = 1 / 10
return thermal_conductivity_insulance + thermal_inside_convection_insulance
def calculate_flux(self, temperature_variation=0):
self.surface = self.parent.width * self.parent.length
return super().calculate_flux(temperature_variation)
class Wall(MaterialCollection):
"""
Represent the wall of a building
"""
pass
class Side(object):
"""
Represent the side of a building which is the wall and all the openings
"""
def __init__(self, height=None, wall=None, openings=[]):
self.parent = None
self.height = height
self.wall = None
if wall:
self.add(wall)
self.openings = []
for opening in openings:
self.add(opening)
def calculate_flux(self, temperature_variation=0):
"""
Calculate the thermal flux
:param temperature_variation: absolute difference between inside and outsite temperatures, must be strictly positive
:returns: thermal flux in SI units
"""
openings_surfaces = [opening.surface for opening in self.openings]
self.wall.surface = 2*self.height*(self.parent.width+self.parent.length) - sum(openings_surfaces)
flux = 0
flux += self.wall.calculate_flux(temperature_variation)
for opening in self.openings:
flux += opening.calculate_flux(temperature_variation)
return flux
def add(self, child):
"""
Add the wall or an opening to the side
:param child: a Wall or an Opening object
"""
if isinstance(child, Wall):
self.wall = child
child.parent = self
elif isinstance(child, Opening):
self.openings.append(child)
child.parent = self
def remove(self, child):
"""
Remove the wall or an opening from the side
:param child: a Wall or an Opening object
"""
if isinstance(child, Wall):
self.wall = None
child.parent = None
elif isinstance(child, Opening):
self.openings.remove(child)
child.parent = None
def modify(self, variable, value):
"""
Modify a variable of the side
:param variable: the variable to modify
:param value: the new value of the variable
"""
self.__dict__[variable] = value
class Building(object):
"""
Represent a building with a roof, a floor and a side
"""
def __init__(self, width=None, length=None, roof=None, side=None, floor=None):
self.width = width
self.length = length
self.roof = None
if roof:
self.add(roof)
self.side = None
if side:
self.add(side)
self.floor = None
if floor:
self.add(floor)
def calculate_flux(self, temperature_inside=20, temperature_outside=10, temperature_underground=15):
"""
Calculate the thermal flux
:param temperature_inside: temperature inside the building
:param temperature_outside: temperature outside the building
:param temperature_underground: temperature underground the building
:returns: thermal flux in SI units
"""
flux = 0
temperature_between_in_and_out = abs(temperature_inside - temperature_outside)
flux += self.roof.calculate_flux(temperature_between_in_and_out)
flux += self.side.calculate_flux(temperature_between_in_and_out)
temperature_between_in_and_underground = abs(temperature_inside - temperature_underground)
flux += self.floor.calculate_flux(temperature_between_in_and_underground)
return flux
def add(self, child):
"""
Add the roof, the side or the floor to the building
:param child: a Roof, a Side or a Floor object
"""
if isinstance(child, Roof):
self.roof = child
child.parent = self
elif isinstance(child, Side):
self.side = child
child.parent = self
elif isinstance(child, Floor):
self.floor = child
child.parent = self
def remove(self, child):
"""
Remove the roof, the side or the floor from the building
:param child: a Roof, a Side or a Floor object
"""
if isinstance(child, Roof):
self.roof = None
child.parent = None
elif isinstance(child, Side):
self.side = None
child.parent = None
elif isinstance(child, Floor):
self.floor = None
child.parent = None
def modify(self, variable, value):
"""
Modify a variable of the building
:param variable: the variable to modify
:param value: the new value of the variable
"""
self.__dict__[variable] = value