/
model.py
370 lines (273 loc) · 10.2 KB
/
model.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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
"""Model schema and the 5 geometry objects that define it."""
from pydantic import BaseModel, Field, validator, constr
from typing import List, Union
from enum import Enum
from ._base import NamedBaseModel
from .bc import Outdoors, Surface, Ground, Adiabatic
from .energy.properties import ShadeEnergyPropertiesAbridged, \
DoorEnergyPropertiesAbridged, ApertureEnergyPropertiesAbridged, \
FaceEnergyPropertiesAbridged, RoomEnergyPropertiesAbridged, \
ModelEnergyProperties
class Plane(BaseModel):
type: constr(regex='^Plane$') = 'Plane'
n: List[float] = Field(
...,
description="Plane normal as 3 (x, y, z) values.",
min_items=3,
max_items=3
)
o: List[float] = Field(
...,
description="Plane origin as 3 (x, y, z) values",
min_items=3,
max_items=3
)
x: List[float] = Field(
default=None,
description="Plane x-axis as 3 (x, y, z) values",
min_items=3,
max_items=3
)
class Face3D(BaseModel):
"""A single planar face in 3D space."""
type: constr(regex='^Face3D$') = 'Face3D'
boundary: List[List[float]] = Field(
...,
description='A list of points representing the outer boundary vertices of '
'the face. The list should include at least 3 points and each point '
'should be a list of 3 (x, y, z) values.'
)
holes: List[List[List[float]]] = Field(
default=None,
description='Optional list of lists with one list for each hole in the face.'
'Each hole should be a list of at least 3 points and each point a list '
'of 3 (x, y, z) values. If None, it will be assumed that there are no '
'holes in the face.'
)
plane: Plane = Field(
default=None,
description='Optional Plane indicating the plane in which the face exists.'
'If None, the plane will usually be derived from the boundary points.'
)
@validator('boundary')
def check_num_items(cls, v):
for i in v:
assert len(i) == 3, 'Number of floats must be 3 for (x, y, z).'
return v
@validator('holes')
def check_num_items_holes(cls, v):
if v is not None:
for pt_list in v:
for pt in pt_list:
assert len(pt) == 3, 'Number of floats must be 3 for (x, y, z).'
return v
class ShadePropertiesAbridged(BaseModel):
type: constr(regex='^ShadePropertiesAbridged$') = 'ShadePropertiesAbridged'
energy: ShadeEnergyPropertiesAbridged = Field(
default=None
)
class Shade(NamedBaseModel):
type: constr(regex='^Shade$') = 'Shade'
geometry: Face3D = Field(
...,
description='Planar Face3D for the geometry.'
)
properties: ShadePropertiesAbridged = Field(
...,
description='Extension properties for particular simulation engines '
'(Radiance, EnergyPlus).'
)
class DoorPropertiesAbridged(BaseModel):
type: constr(regex='^DoorPropertiesAbridged$') = 'DoorPropertiesAbridged'
energy: DoorEnergyPropertiesAbridged = Field(
default=None
)
class Door(NamedBaseModel):
type: constr(regex='^Door$') = 'Door'
geometry: Face3D = Field(
...,
description='Planar Face3D for the geometry.'
)
boundary_condition: Union[Outdoors, Surface]
@validator('boundary_condition')
def suface_bc_objects(cls, v):
if v.type == 'Surface':
assert len(v.boundary_condition_objects) == 3, 'Door Surface boundary ' \
'condition must have 3 boundary_condition_objects.'
return v
is_glass: bool = Field(
False,
description='Boolean to note whether this object is a glass door as opposed '
'to an opaque door.'
)
properties: DoorPropertiesAbridged = Field(
...,
description='Extension properties for particular simulation engines '
'(Radiance, EnergyPlus).'
)
class AperturePropertiesAbridged(BaseModel):
type: constr(regex='^AperturePropertiesAbridged$') = 'AperturePropertiesAbridged'
energy: ApertureEnergyPropertiesAbridged = Field(
default=None
)
class Aperture(NamedBaseModel):
type: constr(regex='^Aperture$') = 'Aperture'
geometry: Face3D = Field(
...,
description='Planar Face3D for the geometry.'
)
boundary_condition: Union[Outdoors, Surface]
@validator('boundary_condition')
def suface_bc_objects(cls, v):
if v.type == 'Surface':
assert len(v.boundary_condition_objects) == 3, 'Aperture Surface boundary ' \
'condition must have 3 boundary_condition_objects.'
return v
is_operable: bool = Field(
False,
description='Boolean to note whether the Aperture can be opened for ventilation.'
)
indoor_shades: List[Shade] = Field(
default=None,
description='Shades assigned to the interior side of this object '
'(eg. window sill, light shelf).'
)
outdoor_shades: List[Shade] = Field(
default=None,
description='Shades assigned to the exterior side of this object '
'(eg. mullions, louvers).'
)
properties: AperturePropertiesAbridged = Field(
...,
description='Extension properties for particular simulation engines '
'(Radiance, EnergyPlus).'
)
class FacePropertiesAbridged(BaseModel):
type: constr(regex='^FacePropertiesAbridged$') = 'FacePropertiesAbridged'
energy: FaceEnergyPropertiesAbridged = Field(
default=None
)
class FaceType(str, Enum):
wall = 'Wall'
floor = 'Floor'
roof_ceiling = 'RoofCeiling'
air_wall = 'AirWall'
class Face(NamedBaseModel):
type: constr(regex='^Face$') = 'Face'
geometry: Face3D = Field(
...,
description='Planar Face3D for the geometry.'
)
face_type: FaceType
boundary_condition: Union[Ground, Outdoors, Adiabatic, Surface]
@validator('boundary_condition')
def suface_bc_objects(cls, v):
if v.type == 'Surface':
assert len(v.boundary_condition_objects) == 2, 'Face Surface boundary ' \
'condition must have 2 boundary_condition_objects.'
return v
apertures: List[Aperture] = Field(
default=None,
description='Apertures assigned to this Face. Should be coplanar with this '
'Face and completely within the boundary of the Face to be valid.'
)
doors: List[Door] = Field(
default=None,
description='Doors assigned to this Face. Should be coplanar with this '
'Face and completely within the boundary of the Face to be valid.'
)
indoor_shades: List[Shade] = Field(
default=None,
description='Shades assigned to the interior side of this object.'
)
outdoor_shades: List[Shade] = Field(
default=None,
description='Shades assigned to the exterior side of this object '
'(eg. balcony, overhang).'
)
properties: FacePropertiesAbridged = Field(
...,
description='Extension properties for particular simulation engines '
'(Radiance, EnergyPlus).'
)
class RoomPropertiesAbridged(BaseModel):
type: constr(regex='^RoomPropertiesAbridged$') = 'RoomPropertiesAbridged'
energy: RoomEnergyPropertiesAbridged = Field(
default=None
)
class Room(NamedBaseModel):
type: constr(regex='^Room$') = 'Room'
faces: List[Face] = Field(
...,
min_items=4,
description='Faces that together form the closed volume of a room.'
)
indoor_shades: List[Shade] = Field(
default=None,
description='Shades assigned to the interior side of this object '
'(eg. partitions, tables).'
)
outdoor_shades: List[Shade] = Field(
default=None,
description='Shades assigned to the exterior side of this object '
'(eg. trees, landscaping).'
)
properties: RoomPropertiesAbridged = Field(
...,
description='Extension properties for particular simulation engines '
'(Radiance, EnergyPlus).'
)
multiplier: int = Field(
1,
ge=1,
description='An integer noting how many times this Room is repeated. '
'Multipliers are used to speed up the calculation when similar Rooms are '
'repeated more than once. Essentially, a given simulation with the '
'Room is run once and then the result is mutliplied by the multiplier.'
)
class ModelProperties(BaseModel):
type: constr(regex='^ModelProperties$') = 'ModelProperties'
energy: ModelEnergyProperties = Field(
default=None
)
class Model(NamedBaseModel):
type: constr(regex='^Model$') = 'Model'
rooms: List[Room] = Field(
default=None,
description='A list of Rooms in the model.'
)
orphaned_faces: List[Face] = Field(
default=None,
description='A list of Faces in the model that lack a parent Room. Note that '
'orphaned Faces are not acceptable for Models that are to be exported '
'for energy simulation.'
)
orphaned_shades: List[Shade] = Field(
default=None,
description='A list of Shades in the model that lack a parent.'
)
orphaned_apertures: List[Aperture] = Field(
default=None,
description='A list of Apertures in the model that lack a parent Face. '
'Note that orphaned Apertures are not acceptable for Models that are '
'to be exported for energy simulation.'
)
orphaned_doors: List[Door] = Field(
default=None,
description='A list of Doors in the model that lack a parent Face. '
'Note that orphaned Doors are not acceptable for Models that are '
'to be exported for energy simulation.'
)
north_angle: float = Field(
default=0,
ge=0,
lt=360,
description='The clockwise north direction in degrees.'
)
properties: ModelProperties = Field(
...,
description='Extension properties for particular simulation engines '
'(Radiance, EnergyPlus).'
)
if __name__ == '__main__':
print(Model.schema_json(indent=2))