GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 6 / 0 / 6
Functions: 100.0% 6 / 0 / 6
Branches: 100.0% 1 / 0 / 1

src/utilities/floorspace/FSModel.hpp
Line Branch Exec Source
1 /***********************************************************************************************************************
2 * OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC.
3 * See also https://openstudio.net/license
4 ***********************************************************************************************************************/
5
6 #ifndef UTILITIES_FLOORSPACE_FSMODEL_HPP
7 #define UTILITIES_FLOORSPACE_FSMODEL_HPP
8
9 #include "../UtilitiesAPI.hpp"
10 #include "../core/Logger.hpp"
11 #include <json/json.h>
12 #include "FSVisitor.hpp"
13
14 #include <boost/optional.hpp>
15
16 #include <vector>
17
18 namespace openstudio {
19
20 // forward declaration
21 class Point3d;
22 class Vector3d;
23 class FSModel;
24
25 // Base class for all floorspace model items
26 class UTILITIES_API FSBase : public FSDispatchable
27 {
28 public:
29 explicit FSBase() = default;
30 explicit FSBase(const Json::Value& root);
31
32 const std::string& name() const;
33 const std::string& handle() const;
34 const std::string& id() const;
35 const std::string& color() const;
36
37 void setName(const std::string& name);
38 void setHandle(const std::string& handle);
39 void setId(const std::string& id);
40 void setColor(const std::string& color);
41
42 protected:
43 std::string m_name;
44 std::string m_handle;
45 std::string m_id;
46 std::string m_color;
47 };
48
49 // Base class for all geometry items
50 class UTILITIES_API FSGeometryBase
51 {
52 public:
53 6520 explicit FSGeometryBase() = default;
54 explicit FSGeometryBase(const Json::Value& root);
55 void load(const Json::Value& root);
56
57 const std::string& id() const;
58
59 private:
60 std::string m_id;
61 };
62
63 class UTILITIES_API FSVertex : public FSGeometryBase
64 {
65 public:
66 explicit FSVertex(const Json::Value& root, const FSModel& model);
67 void load(const Json::Value& root, const FSModel& model);
68
69 double x() const;
70 double y() const;
71
72 void setX(double x);
73 void setY(double y);
74 void setXY(double x, double y);
75
76 private:
77 double m_x = 0.0;
78 double m_y = 0.0;
79 };
80
81 class FSGeometry;
82
83 class UTILITIES_API FSEdge : public FSGeometryBase
84 {
85 public:
86 explicit FSEdge(const Json::Value& root, const FSGeometry& geometry);
87 explicit FSEdge(FSVertex& v1, FSVertex& v2);
88 void load(const Json::Value& root, const FSGeometry& geometry);
89
90 std::vector<FSVertex> getVertices() const;
91 const FSVertex& firstVertex() const;
92 const FSVertex& secondVertex() const;
93 Vector3d edgeVector() const;
94 Point3d vertex(double alpha) const;
95
96 private:
97 std::vector<FSVertex> m_vertices;
98 };
99
100 // Reference to an edge by a face, combines the edge and the edge order (direction)
101 class UTILITIES_API FSEdgeReference
102 {
103 public:
104 explicit FSEdgeReference(FSEdge edge, int edgeOrder);
105 const FSEdge& edge() const;
106 int edgeOrder() const;
107 // Gets the next vertex as determined by the edge order
108 const FSVertex& getNextVertex() const;
109
110 private:
111 FSEdge m_edge;
112 int m_edgeOrder = 1;
113 };
114
115 class UTILITIES_API FSFace : public FSGeometryBase
116 {
117 public:
118 explicit FSFace(const Json::Value& root, const FSGeometry& geometry);
119 void load(const Json::Value& root, const FSGeometry& geometry);
120 std::vector<FSEdgeReference> edgeRefs() const;
121 void setEdgeRefs(std::vector<FSEdgeReference> edgeRefs);
122
123 private:
124 std::vector<FSEdgeReference> m_edgeRefs;
125 };
126
127 class UTILITIES_API FSGeometry : public FSGeometryBase
128 {
129 public:
130 72 explicit FSGeometry() = default;
131 explicit FSGeometry(const Json::Value& root, const FSModel& model);
132 void load(const Json::Value& root, const FSModel& model);
133
134 // gets a vertex by id
135 boost::optional<FSVertex> vertex(const std::string& id) const;
136 // gets a vertex by coordinates
137 boost::optional<FSVertex> vertex(const Point3d& point) const;
138 // gets an edge by edge id
139 boost::optional<FSEdge> edge(const std::string& id) const;
140 // gets an edge by vertices
141 boost::optional<FSEdge> edge(const FSVertex& v1, const FSVertex& v2) const;
142 // gets a face by id
143 boost::optional<FSFace> face(const std::string& id) const;
144
145 private:
146 std::vector<FSVertex> m_vertices;
147 std::vector<FSEdge> m_edges;
148 std::vector<FSFace> m_faces;
149 };
150
151 // Represents things that other things can be assigned to, such as thermal zone, building unit etc
152 // might not be needed, I thought this woulkd impolement some common property
153 class UTILITIES_API FSAssignment : public FSBase
154 {
155 public:
156 explicit FSAssignment() = default;
157 explicit FSAssignment(const Json::Value& root);
158
159 private:
160 };
161
162 class UTILITIES_API FSThermalZone : public FSAssignment
163 {
164 public:
165 explicit FSThermalZone(const Json::Value& root);
166
167 void Accept(FSVisitor& visitor) const override;
168 };
169
170 class UTILITIES_API FSBuildingUnit : public FSAssignment
171 {
172 public:
173 explicit FSBuildingUnit(const Json::Value& root);
174
175 void Accept(FSVisitor& visitor) const override;
176 };
177
178 class UTILITIES_API FSBuildingType : public FSAssignment
179 {
180 public:
181 explicit FSBuildingType(const Json::Value& root);
182
183 void Accept(FSVisitor& visitor) const override;
184 };
185
186 class UTILITIES_API FSSpaceType : public FSAssignment
187 {
188 public:
189 explicit FSSpaceType(const Json::Value& root);
190
191 void Accept(FSVisitor& visitor) const override;
192 };
193
194 class UTILITIES_API FSConstructionSet : public FSAssignment
195 {
196 public:
197 explicit FSConstructionSet(const Json::Value& root);
198
199 void Accept(FSVisitor& visitor) const override;
200 };
201
202 class FSStory;
203 class FSSpace;
204
205 class UTILITIES_API FSDaylightingControlDefinition : public FSBase
206 {
207 public:
208 explicit FSDaylightingControlDefinition(const Json::Value& root, const FSModel& model);
209
210 void Accept(FSVisitor& visitor) const override;
211
212 double illuminanceSetpoint() const;
213 double height() const;
214
215 private:
216 double m_illuminanceSetpoint = 300.0;
217 double m_height = 0.0;
218 };
219
220 class UTILITIES_API FSDaylightingControl : public FSBase
221 {
222 public:
223 explicit FSDaylightingControl(const Json::Value& root, const FSModel& model, const FSStory& story);
224
225 void Accept(FSVisitor& visitor) const override;
226
227 boost::optional<FSVertex> vertex() const;
228 boost::optional<FSDaylightingControlDefinition> definition() const;
229 Point3d point() const;
230
231 private:
232 boost::optional<FSVertex> m_vertex;
233 boost::optional<FSDaylightingControlDefinition> m_definition;
234 };
235
236 class UTILITIES_API FSSpace : public FSBase
237 {
238 public:
239 explicit FSSpace(const Json::Value& root, const FSModel& model, FSStory& story);
240 void Accept(FSVisitor& visitor) const override;
241
242 boost::optional<FSThermalZone> thermalZone() const;
243 boost::optional<FSBuildingUnit> buildingUnit() const;
244 boost::optional<FSSpaceType> spaceType() const;
245 boost::optional<FSConstructionSet> constructionSet() const;
246 boost::optional<FSFace> face() const;
247 int multiplier() const;
248 double belowFloorPlenumHeight() const;
249 double floorToCeilingHeight() const;
250 double aboveCeilingHeight() const;
251 double offset() const;
252 bool openToBelow() const;
253 std::vector<FSDaylightingControl> daylightingControls() const;
254
255 private:
256 boost::optional<FSThermalZone> m_thermalZone;
257 boost::optional<FSBuildingUnit> m_buildingUnit;
258 boost::optional<FSSpaceType> m_spaceType;
259 boost::optional<FSConstructionSet> m_constructionSet;
260 boost::optional<FSFace> m_face;
261
262 double m_below_floor_plenum_height = 0.0;
263 double m_floor_to_ceiling_height = 0.0;
264 double m_above_ceiling_plenum_height = 0.0;
265 double m_offset = 0.0;
266 bool m_openToBelow = false;
267 int m_multiplier = 1;
268 std::vector<FSDaylightingControl> m_daylightingControls;
269 void simplifyFace(const FSGeometry& geometry);
270 };
271
272 class UTILITIES_API FSWindowDefinition : public FSBase
273 {
274 public:
275 explicit FSWindowDefinition(const Json::Value& root, const FSModel& model);
276 void Accept(FSVisitor& visitor) const override;
277
278 std::string windowDefinitionMode() const;
279 double wwr() const;
280 double sillHeight() const;
281 double windowSpacing() const;
282 double height() const;
283 double width() const;
284 std::string windowType() const;
285 double overhangProjectionFactor() const;
286 double finProjectionFactor() const;
287
288 private:
289 std::string m_windowDefinitionMode; // Single Window, Repeating Window, Window To Wall Ratio
290 std::string m_windowType; // Fixed, Operable
291 double m_wwr = 0.0;
292 double m_sillHeight = 0.0;
293 double m_windowSpacing = 0.0;
294 double m_height = 0.0;
295 double m_width = 0.0;
296 double m_overhangProjectionFactor = 0.0;
297 double m_finProjectionFactor = 0.0;
298 };
299
300 // Represents something that fills an opening - door or window
301 class UTILITIES_API FSFiller : public FSBase
302 {
303 public:
304 explicit FSFiller() = default;
305 explicit FSFiller(const Json::Value& root, const FSStory& story);
306
307 boost::optional<FSEdge> edge() const;
308 boost::optional<FSSpace> space() const;
309 std::vector<double> alphas() const;
310 // Calculates and returns the center vertex position of the window or door
311 Point3d centerVertex(double alpha) const;
312
313 protected:
314 boost::optional<FSEdge> m_edge;
315 boost::optional<FSSpace> m_space;
316 // For repeating windows alphas is a list otherwise it is a single value
317 // not quite sure th ebest way to handle this yet so have both properties
318 double m_alpha = 0.5;
319 std::vector<double> m_alphas;
320 };
321
322 class UTILITIES_API FSWindow : public FSFiller
323 {
324 public:
325 explicit FSWindow(const Json::Value& root, const FSModel& model, FSStory& story);
326 void Accept(FSVisitor& visitor) const override;
327
328 boost::optional<FSWindowDefinition> windowDefinition() const;
329
330 private:
331 boost::optional<FSWindowDefinition> m_windowDefinition;
332 };
333
334 class UTILITIES_API FSDoorDefinition : public FSBase
335 {
336 public:
337 explicit FSDoorDefinition(const Json::Value& root, const FSModel& model);
338
339 void Accept(FSVisitor& visitor) const override;
340
341 double height() const;
342 double width() const;
343 const std::string& doorType() const;
344
345 private:
346 double m_height = 2.0;
347 double m_width = 1.0;
348 std::string m_doorType; // Door, Glass Door, Overhead Door
349 };
350
351 class UTILITIES_API FSDoor : public FSFiller
352 {
353 public:
354 explicit FSDoor(const Json::Value& root, const FSModel& model, FSStory& story);
355
356 void Accept(FSVisitor& visitor) const override;
357 boost::optional<FSDoorDefinition> doorDefinition() const;
358
359 private:
360 boost::optional<FSDoorDefinition> m_doorDefinition;
361 };
362
363 class UTILITIES_API FSShading : public FSBase
364 {
365 public:
366 explicit FSShading(const Json::Value& root, const FSModel& model, const FSStory& story);
367 double belowFloorPlenumHeight() const;
368 double floorToCeilingHeight() const;
369 double aboveCeilingPlenumHeight() const;
370 void Accept(FSVisitor& visitor) const override;
371 boost::optional<FSFace> face() const;
372
373 private:
374 boost::optional<FSFace> m_face;
375 double m_floor_to_ceiling_height = 0.0;
376 double m_below_floor_plenum_height = 0.0;
377 double m_above_ceiling_plenum_height = 0.0;
378 };
379
380 class UTILITIES_API FSStory : public FSBase
381 {
382 public:
383 explicit FSStory(const Json::Value& root, const FSModel& model);
384 void Accept(FSVisitor& visitor) const override;
385
386 double belowFloorPlenumHeight() const;
387 double floorToCeilingHeight() const;
388 double aboveCeilingPlenumHeight() const;
389 double floorToFloorHeight() const;
390 double nominalZCoordinate() const;
391 int multiplier() const;
392 bool imageVisible() const;
393 const FSGeometry& geometry() const;
394 std::vector<FSSpace> spaces() const;
395 std::vector<FSWindow> windows() const;
396 std::vector<FSDoor> doors() const;
397 std::vector<FSShading> shadings() const;
398
399 private:
400 bool m_image_visible = false;
401 int m_multiplier = 1;
402
403 double m_below_floor_plenum_height = 0.0;
404 double m_floor_to_ceiling_height = 3.0;
405 double m_above_ceiling_plenum_height = 0.0;
406 double m_nominalZCoordinate = 0.0;
407
408 FSGeometry m_geometry;
409 std::vector<FSSpace> m_spaces;
410 std::vector<FSWindow> m_windows;
411 std::vector<FSDoor> m_doors;
412 std::vector<FSShading> m_shadings;
413 };
414
415 class UTILITIES_API FSConfig
416 {
417 public:
418 29 explicit FSConfig() = default;
419 explicit FSConfig(const Json::Value& root);
420
421 std::string units() const;
422 std::string language() const;
423 bool unitsEditable() const;
424 double northAxis() const;
425
426 private:
427 std::string m_units;
428 bool m_unitsEditable = false;
429 std::string m_language;
430 double m_north_axis = 0.0;
431 };
432
433 class UTILITIES_API FSGround
434 {
435 public:
436 29 explicit FSGround() = default;
437 explicit FSGround(const Json::Value& root, const FSModel& model);
438
439 double floorOffset() const;
440 double azimuthAngle() const;
441 double tiltSlope() const;
442
443 private:
444 double m_floor_offset = 0.0;
445 double m_azimuth_angle = 0.0;
446 double m_tilt_slope = 0.0;
447 };
448
449 class UTILITIES_API FSProject
450 {
451 public:
452 29 explicit FSProject() = default;
453 explicit FSProject(const Json::Value& root, const FSModel& model);
454 void load(const Json::Value& root, const FSModel& model);
455
456 double northAxis() const;
457 FSConfig& config();
458 FSGround& ground();
459
460 private:
461 double m_north_axis = 0.0;
462 FSConfig m_config;
463 FSGround m_ground;
464 };
465
466 class UTILITIES_API FSModel
467 {
468 public:
469 /// default constructor
470
1/1
✓ Branch 11 taken 29 times.
29 explicit FSModel() = default;
471 explicit FSModel(const std::string& json);
472
473 void Accept(FSVisitor& visitor) const;
474
475 void load(const std::string& json);
476
477 std::vector<FSThermalZone> thermalZones() const;
478 std::vector<FSBuildingUnit> buildingUnits() const;
479 std::vector<FSBuildingType> buildingTypes() const;
480 std::vector<FSSpaceType> spaceTypes() const;
481 std::vector<FSConstructionSet> constructionSets() const;
482 std::vector<FSStory> stories() const;
483 std::vector<FSDaylightingControlDefinition> daylightingControlDefinitions() const;
484 std::vector<FSWindowDefinition> windowDefinitions() const;
485 std::vector<FSDoorDefinition> doorDefinitions() const;
486
487 boost::optional<FSThermalZone> thermalZone(const std::string& thermalZoneId) const;
488 boost::optional<FSBuildingUnit> buildingUnit(const std::string& buildingUnitId) const;
489 boost::optional<FSBuildingType> buildingType(const std::string& buildingTypeId) const;
490 boost::optional<FSSpaceType> spaceType(const std::string& spaceTypeId) const;
491 boost::optional<FSConstructionSet> constructionSet(const std::string& constructionSetId) const;
492 boost::optional<FSDaylightingControlDefinition> daylightingControlDefinition(const std::string& daylightingControlDefinitionId) const;
493 boost::optional<FSWindowDefinition> windowDefinition(const std::string& windowDefinitionId) const;
494 boost::optional<FSDoorDefinition> doorDefinition(const std::string& doorDefinitionId) const;
495 boost::optional<FSProject> project() const;
496 double lengthToMeters() const;
497
498 private:
499 REGISTER_LOGGER("utilities.FSModel");
500
501 FSProject m_project;
502 std::vector<FSThermalZone> m_thermalZones;
503 std::vector<FSBuildingUnit> m_buildingUnits;
504 std::vector<FSBuildingType> m_buildingTypes;
505 std::vector<FSSpaceType> m_spaceTypes;
506 std::vector<FSConstructionSet> m_constructionSets;
507 std::vector<FSDaylightingControlDefinition> m_daylightingControlDefinitions;
508 std::vector<FSWindowDefinition> m_windowDefinitions;
509 std::vector<FSDoorDefinition> m_doorDefinitions;
510 std::vector<FSStory> m_stories;
511 Json::Value m_value;
512 double m_lengthToMeters = 1.0;
513 void setUnits();
514 };
515
516 } // namespace openstudio
517
518 #endif
519