Skip to content

Commit

Permalink
Merge pull request #4550 from NREL/issue-4403
Browse files Browse the repository at this point in the history
Addresses #4403, add Sql helper methods to retrieve U-factors, SHGC, or VT for glazing systems
  • Loading branch information
jmarrec authored Mar 23, 2022
2 parents fca1790 + b3d13c0 commit 6640698
Show file tree
Hide file tree
Showing 11 changed files with 1,829 additions and 0 deletions.
2 changes: 2 additions & 0 deletions resources/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ set(energyplus_resources_src
energyplus/ZoneBoundaryCondition/Bug_486_zone_bdr_test.idf
energyplus/SmallOffice/SmallOffice.idf
energyplus/AllFuelTypes/in.idf
energyplus/FrameAndDivider/in.idf
)

# update the resources
Expand All @@ -256,6 +257,7 @@ RUN_ENERGYPLUS("in.idf" "energyplus/Daylighting_Office" "USA_CO_Golden-NREL.7246
RUN_ENERGYPLUS("in.idf" "energyplus/Daylighting_School" "USA_CO_Golden-NREL.724666_TMY3.epw")
RUN_ENERGYPLUS("in.idf" "energyplus/Office_With_Many_HVAC_Types" "USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.epw")
RUN_ENERGYPLUS("in.idf" "energyplus/AllFuelTypes" "USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.epw")
RUN_ENERGYPLUS("in.idf" "energyplus/FrameAndDivider" "USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.epw")

# add target
add_custom_target(openstudio_energyplus_resources
Expand Down
1,598 changes: 1,598 additions & 0 deletions resources/energyplus/FrameAndDivider/in.idf

Large diffs are not rendered by default.

62 changes: 62 additions & 0 deletions src/model/SubSurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1343,6 +1343,51 @@ namespace model {
return boost::none;
}

boost::optional<double> SubSurface_Impl::assemblyUFactor() const {
return getExteriorFenestrationValue("Assembly U-Factor");
}

boost::optional<double> SubSurface_Impl::assemblySHGC() const {
return getExteriorFenestrationValue("Assembly SHGC");
}

boost::optional<double> SubSurface_Impl::assemblyVisibleTransmittance() const {
return getExteriorFenestrationValue("Assembly Visible Transmittance");
}

/** Gets the fenestration value from the sql file **/
boost::optional<double> SubSurface_Impl::getExteriorFenestrationValue(std::string columnName) const {
boost::optional<double> result;

// Get the object name
if (!name()) {
LOG(Warn, "This object does not have a name, cannot retrieve the fenestration value '" + columnName + "'.");
return result;
}

// Get the object name and transform to the way it is recorded
// in the sql file
std::string rowName = name().get();
boost::to_upper(rowName);

// Check that the model has a sql file
if (!model().sqlFile()) {
LOG(Warn, "This model has no sql file, cannot retrieve the fenestration value '" + columnName + "'.");
return result;
}

std::string s = R"(SELECT Value FROM TabularDataWithStrings
WHERE ReportName='EnvelopeSummary'
AND ReportForString='Entire Facility'
AND TableName='Exterior Fenestration'
AND RowName=?
AND ColumnName=?)";

result = model().sqlFile().get().execAndReturnFirstDouble(s, rowName, columnName);

return result;
}

} // namespace detail

SubSurface::SubSurface(const std::vector<Point3d>& vertices, const Model& model) : PlanarSurface(SubSurface::iddObjectType(), vertices, model) {
Expand Down Expand Up @@ -1759,5 +1804,22 @@ namespace model {
return getImpl<detail::SubSurface_Impl>()->airflowNetworkSurface();
}

boost::optional<double> SubSurface::assemblyUFactor() const {
return getImpl<detail::SubSurface_Impl>()->assemblyUFactor();
}

boost::optional<double> SubSurface::assemblySHGC() const {
return getImpl<detail::SubSurface_Impl>()->assemblySHGC();
}

boost::optional<double> SubSurface::assemblyVisibleTransmittance() const {
return getImpl<detail::SubSurface_Impl>()->assemblyVisibleTransmittance();
}

/** Gets the fenestration value from the sql file **/
boost::optional<double> SubSurface::getExteriorFenestrationValue(std::string columnName) const {
return getImpl<detail::SubSurface_Impl>()->getExteriorFenestrationValue(columnName);
}

} // namespace model
} // namespace openstudio
13 changes: 13 additions & 0 deletions src/model/SubSurface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ namespace model {

bool isNumberofVerticesAutocalculated() const;

boost::optional<double> assemblyUFactor() const;

boost::optional<double> assemblySHGC() const;

boost::optional<double> assemblyVisibleTransmittance() const;

//@}
/** @name Setters */
//@{
Expand Down Expand Up @@ -283,6 +289,13 @@ namespace model {

// DLM: todo add methods to create light shelves by projection factor

//@}
/** @name Queries */
//@{

/** Gets the fenestration value from the sql file **/
boost::optional<double> getExteriorFenestrationValue(std::string columnName) const;

protected:
/// @cond
typedef detail::SubSurface_Impl ImplType;
Expand Down
15 changes: 15 additions & 0 deletions src/model/SubSurface_Impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@ namespace model {

bool isNumberofVerticesAutocalculated() const;

// Assembly methods

boost::optional<double> assemblyUFactor() const;

boost::optional<double> assemblySHGC() const;

boost::optional<double> assemblyVisibleTransmittance() const;

//@}
/** @name Setters */
//@{
Expand Down Expand Up @@ -299,6 +307,13 @@ namespace model {

boost::optional<AirflowNetworkSurface> airflowNetworkSurface() const;

//@}
/** @name Queries */
//@{

/** Gets the fenestration value from the sql file **/
boost::optional<double> getExteriorFenestrationValue(std::string columnName) const;

protected:
private:
friend class openstudio::model::SubSurface;
Expand Down
34 changes: 34 additions & 0 deletions src/model/test/SubSurface_GTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
#include "../Model_Impl.hpp"
#include "../ThermalZone.hpp"

#include "../../energyplus/ReverseTranslator.hpp"
#include "../../utilities/sql/SqlFile.hpp"

#include "../../utilities/geometry/Geometry.hpp"
#include "../../utilities/geometry/Point3d.hpp"
#include "../../utilities/geometry/Vector3d.hpp"
Expand Down Expand Up @@ -1531,3 +1534,34 @@ TEST_F(ModelFixture, Issue_4361_Multi_Subsurfaces_Overlapping) {
windowWallRatio = surface.windowToWallRatio();
EXPECT_NEAR(windowWallRatio, 0.2742, 0.01);
}

TEST_F(ModelFixture, 4403_FenestrationAssembly) {
// Test for #4403 - Add Sql helper methods to retrieve U-factors, SHGC, or VT for glazing systems

// This one has fenestration that includes WindowProperty:FrameAndDivider
openstudio::path idfPath = resourcesPath() / toPath("energyplus/FrameAndDivider/in.idf");
energyplus::ReverseTranslator reverseTranslator;
ASSERT_NO_THROW(reverseTranslator.loadModel(idfPath));
OptionalModel _model = reverseTranslator.loadModel(idfPath);
ASSERT_TRUE(_model);
Model model = _model.get();

openstudio::path sqlPath = resourcesPath() / toPath("energyplus/FrameAndDivider/eplusout.sql");
openstudio::SqlFile sqlFile = openstudio::SqlFile(sqlPath);
ASSERT_TRUE(sqlFile.connectionOpen());

model.setSqlFile(sqlFile);
ASSERT_TRUE(model.sqlFile());

OptionalSubSurface subSurface = model.getModelObjectByName<SubSurface>("Story 1 Core Space Exterior Wall Window");
ASSERT_TRUE(subSurface);

ASSERT_TRUE(subSurface->assemblyUFactor());
EXPECT_EQ(2.546, subSurface->assemblyUFactor().get());

ASSERT_TRUE(subSurface->assemblySHGC());
EXPECT_EQ(0.350, subSurface->assemblySHGC().get());

ASSERT_TRUE(subSurface->assemblyVisibleTransmittance());
EXPECT_EQ(0.440, subSurface->assemblyVisibleTransmittance().get());
}
32 changes: 32 additions & 0 deletions src/utilities/sql/SqlFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1385,4 +1385,36 @@ bool SqlFile::hasIlluminanceMapYear() const {
return true;
}

boost::optional<double> SqlFile::getExteriorFenestrationValue(const std::string& subSurfaceName, const std::string& columnName) const {
boost::optional<double> result;
if (m_impl) {
result = m_impl->getExteriorFenestrationValue(subSurfaceName, columnName);
}
return result;
}

boost::optional<double> SqlFile::assemblyUFactor(const std::string& subSurfaceName) const {
boost::optional<double> result;
if (m_impl) {
result = m_impl->assemblyUFactor(subSurfaceName);
}
return result;
}

boost::optional<double> SqlFile::assemblySHGC(const std::string& subSurfaceName) const {
boost::optional<double> result;
if (m_impl) {
result = m_impl->assemblySHGC(subSurfaceName);
}
return result;
}

boost::optional<double> SqlFile::assemblyVisibleTransmittance(const std::string& subSurfaceName) const {
boost::optional<double> result;
if (m_impl) {
result = m_impl->assemblyVisibleTransmittance(subSurfaceName);
}
return result;
}

} // namespace openstudio
12 changes: 12 additions & 0 deletions src/utilities/sql/SqlFile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,18 @@ class UTILITIES_API SqlFile
// Check if the SqlFile contains 'Year' field for DaylightMapHourlyReports (added Year in 9.2.0)
bool hasIlluminanceMapYear() const;

// return a fenestration value for matching subSurfaceName (RowName) and columnName
boost::optional<double> getExteriorFenestrationValue(const std::string& subSurfaceName, const std::string& columnName) const;

// return an Assembly U-Factor value for matching subSurfaceName (RowName)
boost::optional<double> assemblyUFactor(const std::string& subSurfaceName) const;

// return an Assembly SHGC value for matching subSurfaceName (RowName)
boost::optional<double> assemblySHGC(const std::string& subSurfaceName) const;

// return an Assembly Visible Transmittance value for matching subSurfaceName (RowName)
boost::optional<double> assemblyVisibleTransmittance(const std::string& rowName) const;

/// close the file
bool close();

Expand Down
31 changes: 31 additions & 0 deletions src/utilities/sql/SqlFile_Impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,37 @@ namespace detail {
return m_hasIlluminanceMapYear;
}

boost::optional<double> SqlFile_Impl::assemblyUFactor(const std::string& subSurfaceName) const {
return getExteriorFenestrationValue(subSurfaceName, "Assembly U-Factor");
}

boost::optional<double> SqlFile_Impl::assemblySHGC(const std::string& subSurfaceName) const {
return getExteriorFenestrationValue(subSurfaceName, "Assembly SHGC");
}

boost::optional<double> SqlFile_Impl::assemblyVisibleTransmittance(const std::string& subSurfaceName) const {
return getExteriorFenestrationValue(subSurfaceName, "Assembly Visible Transmittance");
}

boost::optional<double> SqlFile_Impl::getExteriorFenestrationValue(const std::string& subSurfaceName, const std::string& columnName) const {
boost::optional<double> result;

// Get the object name and transform to the way it is recorded
// in the sql file
std::string queryRowName = boost::to_upper_copy(subSurfaceName);

std::string s = R"(SELECT Value FROM TabularDataWithStrings
WHERE ReportName='EnvelopeSummary'
AND ReportForString='Entire Facility'
AND TableName='Exterior Fenestration'
AND RowName=?
AND ColumnName=?)";

result = execAndReturnFirstDouble(s, queryRowName, columnName);

return result;
}

bool SqlFile_Impl::isValidConnection() {
std::string energyPlusVersion = this->energyPlusVersion();
if (energyPlusVersion.empty()) {
Expand Down
12 changes: 12 additions & 0 deletions src/utilities/sql/SqlFile_Impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,18 @@ namespace detail {
// DaylightMapHourlyReports added Year in 9.2.0
bool hasIlluminanceMapYear() const;

// return a fenestration value for matching subSurfaceName (RowName) and columnName
boost::optional<double> getExteriorFenestrationValue(const std::string& subSurfaceName, const std::string& columnName) const;

// return an Assembly U-Factor value for matching subSurfaceName (RowName)
boost::optional<double> assemblyUFactor(const std::string& subSurfaceName) const;

// return an Assembly SHGC value for matching subSurfaceName (RowName)
boost::optional<double> assemblySHGC(const std::string& subSurfaceName) const;

// return an Assembly Visible Transmittance value for matching subSurfaceName (RowName)
boost::optional<double> assemblyVisibleTransmittance(const std::string& subSurfaceName) const;

private:
void init();

Expand Down
18 changes: 18 additions & 0 deletions src/utilities/sql/Test/SqlFile_GTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -805,3 +805,21 @@ TEST_F(SqlFileFixture, 4298_YearField) {
ASSERT_TRUE(reportingFreqs);
EXPECT_EQ(0, reportingFreqs->size());
}

TEST_F(SqlFileFixture, 4403_FenestrationAssembly) {
// Test for #4403 - Add Sql helper methods to retrieve U-factors, SHGC, or VT for glazing systems

// This one has fenestration that includes WindowProperty:FrameAndDivider
openstudio::path path = resourcesPath() / toPath("energyplus/FrameAndDivider/eplusout.sql");
sqlFile = openstudio::SqlFile(path);
ASSERT_TRUE(sqlFile.connectionOpen());

ASSERT_TRUE(sqlFile.assemblyUFactor("Story 1 Core Space Exterior Wall Window"));
EXPECT_EQ(2.546, sqlFile.assemblyUFactor("Story 1 Core Space Exterior Wall Window").get());

ASSERT_TRUE(sqlFile.assemblySHGC("Story 1 Core Space Exterior Wall Window"));
EXPECT_EQ(0.350, sqlFile.assemblySHGC("Story 1 Core Space Exterior Wall Window").get());

ASSERT_TRUE(sqlFile.assemblyVisibleTransmittance("Story 1 Core Space Exterior Wall Window"));
EXPECT_EQ(0.440, sqlFile.assemblyVisibleTransmittance("Story 1 Core Space Exterior Wall Window").get());
}

0 comments on commit 6640698

Please sign in to comment.