Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/66804960_SkylightsBugs' into dev…
Browse files Browse the repository at this point in the history
…elop
  • Loading branch information
DavidGoldwasser committed Mar 5, 2014
2 parents 470d239 + d4ef506 commit bdca098
Show file tree
Hide file tree
Showing 10 changed files with 618 additions and 73 deletions.
75 changes: 4 additions & 71 deletions openstudiocore/src/model/Building.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -688,76 +688,9 @@ namespace detail {
return Transformation::rotation(Vector3d(0,0,1), -degToRad(this->northAxis()));
}

std::vector<std::vector<Point3d> > Building_Impl::generateSkylightPattern(double skylightToFloorRatio, double desiredWidth, double desiredHeight) const
std::vector<std::vector<Point3d> > Building_Impl::generateSkylightPattern(double skylightToProjectedFloorRatio, double desiredWidth, double desiredHeight) const
{
std::vector<std::vector<Point3d> > result;

if (skylightToFloorRatio <= 0.0){
return result;
}else if (skylightToFloorRatio >= 1.0){
return result;
}

if (desiredWidth <= 0){
return result;
}

if (desiredHeight <= 0){
return result;
}

// find extents of building
double xmin = std::numeric_limits<double>::max();
double xmax = std::numeric_limits<double>::min();
double ymin = std::numeric_limits<double>::max();
double ymax = std::numeric_limits<double>::min();
BOOST_FOREACH(const Space& space, this->spaces()){
Transformation transformation = space.buildingTransformation();
BOOST_FOREACH(const Surface& surface, space.surfaces()){
if (istringEqual("RoofCeiling", surface.surfaceType()) &&
istringEqual("Outdoors", surface.outsideBoundaryCondition())){
std::vector<Point3d> vertices = transformation*surface.vertices();
BOOST_FOREACH(const Point3d& vertex, vertices){
xmin = std::min(xmin, vertex.x());
xmax = std::max(xmax, vertex.x());
ymin = std::min(ymin, vertex.y());
ymax = std::max(ymax, vertex.y());
}
}
}
}
if ((xmin > xmax) || (ymin > ymax)){
return result;
}

double floorPrintWidth = (xmax-xmin);
double floorPrintHeight = (ymax-ymin);
double floorPrintArea = floorPrintWidth * floorPrintHeight;
double desiredArea = desiredWidth * desiredHeight;
double numSkylights = skylightToFloorRatio*floorPrintArea/desiredArea;
double numSkylightsX = std::sqrt(skylightToFloorRatio)*floorPrintWidth/desiredWidth;
double numSkylightsY = std::sqrt(skylightToFloorRatio)*floorPrintHeight/desiredHeight;

double xSpace = (floorPrintWidth - numSkylightsX*desiredWidth)/numSkylightsX;
double ySpace = (floorPrintHeight - numSkylightsY*desiredHeight)/numSkylightsY;

for (double x = xSpace/2.0; x < floorPrintWidth - xSpace/2.0; x += desiredWidth + xSpace){
for (double y = ySpace/2.0; y < floorPrintHeight - ySpace/2.0; y += desiredHeight + ySpace){

double x2 = std::min(x+desiredWidth, floorPrintWidth - xSpace/2.0);
double y2 = std::min(y+desiredHeight, floorPrintHeight - ySpace/2.0);

std::vector<Point3d> skylight;
skylight.push_back(Point3d(x,y,0));
skylight.push_back(Point3d(x2,y,0));
skylight.push_back(Point3d(x2,y2,0));
skylight.push_back(Point3d(x,y2,0));

result.push_back(skylight);
}
}

return result;
return openstudio::model::generateSkylightPattern(this->spaces(), 0.0, skylightToProjectedFloorRatio, desiredWidth, desiredHeight);
}

openstudio::Quantity Building_Impl::northAxis_SI() const
Expand Down Expand Up @@ -1166,9 +1099,9 @@ Transformation Building::transformation() const
return getImpl<detail::Building_Impl>()->transformation();
}

std::vector<std::vector<Point3d> > Building::generateSkylightPattern(double skylightToFloorRatio, double desiredWidth, double desiredHeight) const
std::vector<std::vector<Point3d> > Building::generateSkylightPattern(double skylightToProjectedFloorRatio, double desiredWidth, double desiredHeight) const
{
return getImpl<detail::Building_Impl>()->generateSkylightPattern(skylightToFloorRatio, desiredWidth, desiredHeight);
return getImpl<detail::Building_Impl>()->generateSkylightPattern(skylightToProjectedFloorRatio, desiredWidth, desiredHeight);
}

/// @cond
Expand Down
2 changes: 1 addition & 1 deletion openstudiocore/src/model/Building.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ class MODEL_API Building : public ParentObject {

/// Returns a suggested pattern for skylights targeting a skylight to floor ratio with desired sizes.
/// Pattern will be in Building coordinates, on the z = 0 plane, with normal in positive z direction.
std::vector<std::vector<Point3d> > generateSkylightPattern(double skylightToFloorRatio, double desiredWidth, double desiredHeight) const;
std::vector<std::vector<Point3d> > generateSkylightPattern(double skylightToProjectedFloorRatio, double desiredWidth, double desiredHeight) const;

//@}
protected:
Expand Down
2 changes: 1 addition & 1 deletion openstudiocore/src/model/Building_Impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ namespace detail {

Transformation transformation() const;

std::vector<std::vector<Point3d> > generateSkylightPattern(double skylightToFloorRatio, double desiredWidth, double desiredHeight) const;
std::vector<std::vector<Point3d> > generateSkylightPattern(double skylightToProjectedFloorRatio, double desiredWidth, double desiredHeight) const;

protected:
private:
Expand Down
95 changes: 95 additions & 0 deletions openstudiocore/src/model/Space.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3384,6 +3384,101 @@ void unmatchSurfaces(std::vector<Space>& spaces)
}
}

std::vector<std::vector<Point3d> > generateSkylightPattern(const std::vector<Space>& spaces,
double directionOfRelativeNorth,
double skylightToProjectedFloorRatio,
double desiredWidth, double desiredHeight)
{
std::vector<std::vector<Point3d> > result;

if (skylightToProjectedFloorRatio <= 0.0){
return result;
}else if (skylightToProjectedFloorRatio >= 1.0){
return result;
}

if (desiredWidth <= 0){
return result;
}

if (desiredHeight <= 0){
return result;
}

if (spaces.empty()){
return result;
}

// rotate negative amount around the z axis, EnergyPlus defines rotation clockwise
Transformation buildingToGridTransformation = Transformation::rotation(Vector3d(0,0,1), -openstudio::degToRad(directionOfRelativeNorth));

// rotate positive amount around the z axis, EnergyPlus defines rotation clockwise
Transformation gridToBuildingTransformation = buildingToGridTransformation.inverse();

// find extents in grid coordinate system
double xmin = std::numeric_limits<double>::max();
double xmax = std::numeric_limits<double>::min();
double ymin = std::numeric_limits<double>::max();
double ymax = std::numeric_limits<double>::min();
BOOST_FOREACH(const Space& space, spaces){
Transformation spaceToBuildingTransformation = space.buildingTransformation();
Transformation transformation = buildingToGridTransformation*spaceToBuildingTransformation;
BOOST_FOREACH(const Surface& surface, space.surfaces()){
if (istringEqual("RoofCeiling", surface.surfaceType()) &&
istringEqual("Outdoors", surface.outsideBoundaryCondition())){
std::vector<Point3d> vertices = transformation*surface.vertices();
BOOST_FOREACH(const Point3d& vertex, vertices){
xmin = std::min(xmin, vertex.x());
xmax = std::max(xmax, vertex.x());
ymin = std::min(ymin, vertex.y());
ymax = std::max(ymax, vertex.y());
}
}
}
}
if ((xmin > xmax) || (ymin > ymax)){
return result;
}

double floorPrintWidth = (xmax-xmin);
double floorPrintHeight = (ymax-ymin);
double floorPrintArea = floorPrintWidth * floorPrintHeight;
double desiredArea = desiredWidth * desiredHeight;
double numSkylights = skylightToProjectedFloorRatio*floorPrintArea/desiredArea;

double numSkylightsX = std::sqrt(skylightToProjectedFloorRatio)*floorPrintWidth/desiredWidth;
double numSkylightsY = std::sqrt(skylightToProjectedFloorRatio)*floorPrintHeight/desiredHeight;

// space is distance from end of one skylight to beginning of next
double xSpace = (floorPrintWidth - numSkylightsX*desiredWidth)/(std::ceil(numSkylightsX));
double ySpace = (floorPrintHeight - numSkylightsY*desiredHeight)/(std::ceil(numSkylightsY));

if ((xSpace <= 0.0) || (ySpace <= 0.0)){
return result;
}

for (double x = xmin + xSpace/2.0; x < xmax - xSpace/2.0; x += desiredWidth + xSpace){
for (double y = ymin + ySpace/2.0; y < ymax - ySpace/2.0; y += desiredHeight + ySpace){

double x2 = std::min(x+desiredWidth, xmax - xSpace/2.0);
double y2 = std::min(y+desiredHeight, ymax - ySpace/2.0);

// skylight in grid coordinates
std::vector<Point3d> skylight;
skylight.push_back(Point3d(x,y,0));
skylight.push_back(Point3d(x2,y,0));
skylight.push_back(Point3d(x2,y2,0));
skylight.push_back(Point3d(x,y2,0));

// put results into building coordinates
result.push_back(gridToBuildingTransformation*skylight);
}
}

return result;
}


} // model
} // openstudio

11 changes: 11 additions & 0 deletions openstudiocore/src/model/Space.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,17 @@ MODEL_API void matchSurfaces(std::vector<Space>& spaces);
/** Un-match surfaces and sub surfaces within spaces. */
MODEL_API void unmatchSurfaces(std::vector<Space>& spaces);

/// Returns a suggested pattern for skylights targeting a skylight to floor ratio with desired sizes.
/// Pattern will be generated in the grid coordinate system, specified by directionOfRelativeNorth.
/// directionOfRelativeNorth is rotation of grid clockwise from the Building North Axis, in units of degrees.
/// If you want to align skylights with building coordinate system pass directionOfRelativeNorth = 0.
/// If you want to align skylights with a space's coordinate system pass in that space's directionofRelativeNorth.
/// Resulting pattern will be in Building coordinates, on the z = 0 plane, with normal in positive z direction.
MODEL_API std::vector<std::vector<Point3d> > generateSkylightPattern(const std::vector<Space>& spaces,
double directionOfRelativeNorth,
double skylightToProjectedFloorRatio,
double desiredWidth, double desiredHeight);

/** \relates Space*/
typedef boost::optional<Space> OptionalSpace;

Expand Down
6 changes: 6 additions & 0 deletions openstudiocore/src/model/SubSurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,12 @@ std::vector<SubSurface> applySkylightPattern(const std::vector<std::vector<Point
std::vector<SubSurface> result;

BOOST_FOREACH(const Space& space, spaces){

if (space.isPlenum()){
LOG_FREE(Warn, "OpenStudio.applySkylightPattern", "Cannot apply skylights to plenum space");
continue;
}

Transformation transformation = space.buildingTransformation();
Transformation inverseTransformation = transformation.inverse();

Expand Down
66 changes: 66 additions & 0 deletions openstudiocore/src/model/Surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,62 @@ namespace detail {
return wwr;
}

double Surface_Impl::skylightToRoofRatio() const
{
double result = 0.0;

if (!istringEqual(this->surfaceType(), "RoofCeiling")){
return result;
}

double grossArea = this->grossArea();

if (grossArea == 0){
return result;
}

double skylightArea = 0.0;
BOOST_FOREACH(const SubSurface& subSurface, this->subSurfaces()){
if (istringEqual(subSurface.subSurfaceType(), "Skylight")){
skylightArea += subSurface.multiplier() * subSurface.netArea();
}
}

result = skylightArea / grossArea;

return result;
}

double Surface_Impl::skylightToProjectedFloorRatio() const
{
double result = 0.0;

if (!istringEqual(this->surfaceType(), "RoofCeiling")){
return result;
}

Point3dVector vertices = this->vertices();
Plane horizontal(Point3d(0,0,0), Vector3d(0,0,1));
std::vector<Point3d> projectedVertics = horizontal.project(vertices);

boost::optional<double> grossArea = getArea(projectedVertics);

if (!grossArea || grossArea.get() == 0){
return result;
}

double skylightArea = 0.0;
BOOST_FOREACH(const SubSurface& subSurface, this->subSurfaces()){
if (istringEqual(subSurface.subSurfaceType(), "Skylight")){
skylightArea += subSurface.multiplier() * subSurface.netArea();
}
}

result = skylightArea / grossArea.get();

return result;
}

boost::optional<SubSurface> Surface_Impl::setWindowToWallRatio(double wwr)
{
return setWindowToWallRatio(wwr, 0.762, true);
Expand Down Expand Up @@ -2003,6 +2059,16 @@ double Surface::windowToWallRatio() const
return getImpl<detail::Surface_Impl>()->windowToWallRatio();
}

double Surface::skylightToRoofRatio() const
{
return getImpl<detail::Surface_Impl>()->skylightToRoofRatio();
}

double Surface::skylightToProjectedFloorRatio() const
{
return getImpl<detail::Surface_Impl>()->skylightToRoofRatio();
}

boost::optional<SubSurface> Surface::setWindowToWallRatio(double wwr)
{
return getImpl<detail::Surface_Impl>()->setWindowToWallRatio(wwr);
Expand Down
10 changes: 10 additions & 0 deletions openstudiocore/src/model/Surface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,16 @@ class MODEL_API Surface : public PlanarSurface {
0 if this surface is not a wall. */
double windowToWallRatio() const;

/** Get the skylight to roof ratio for this surface. Calculated as
sum(surface.skylights.netArea)/surface.grossArea if this surface is a roof, returns
0 if this surface is not a roof. */
double skylightToRoofRatio() const;

/** Get the skylight to projected floor ratio for this surface. Calculated as
sum(surface.skylights.netArea)/project(surface to z=0 plane).grossArea if this surface is a roof, returns
0 if this surface is not a roof. */
double skylightToProjectedFloorRatio() const;

/** Sets the window to wall ratio for this surface using a single banded window.
* Uses applyViewAndDaylightingGlassRatios for implementation. */
boost::optional<SubSurface> setWindowToWallRatio(double wwr);
Expand Down
4 changes: 4 additions & 0 deletions openstudiocore/src/model/Surface_Impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ namespace detail {

double windowToWallRatio() const;

double skylightToRoofRatio() const;

double skylightToProjectedFloorRatio() const;

boost::optional<SubSurface> setWindowToWallRatio(double wwr);

boost::optional<SubSurface> setWindowToWallRatio(double wwr, double desiredHeightOffset, bool heightOffsetFromFloor);
Expand Down
Loading

0 comments on commit bdca098

Please sign in to comment.