Skip to content

Commit

Permalink
RT Tests for SurfaceProperty:SurroundingSurfaces and SurfaceProperty:…
Browse files Browse the repository at this point in the history
…LocalEnvironment
  • Loading branch information
jmarrec committed Feb 18, 2022
1 parent 75e900d commit 3285797
Show file tree
Hide file tree
Showing 2 changed files with 218 additions and 0 deletions.
93 changes: 93 additions & 0 deletions src/energyplus/Test/SurfacePropertyLocalEnvironment_GTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,25 @@
#include "../../model/ThermalZone.hpp"
#include "../../model/Space.hpp"
#include "../../model/SurfacePropertyLocalEnvironment.hpp"
#include "../../model/SurfacePropertyLocalEnvironment_Impl.hpp"
#include "../../model/SurfacePropertySurroundingSurfaces.hpp"
#include "../../model/SurfacePropertySurroundingSurfaces_Impl.hpp"
#include "../../model/ScheduleConstant.hpp"
#include "../../model/Surface.hpp"
#include "../../model/Surface_Impl.hpp"
#include "../../model/SubSurface.hpp"

#include "../../utilities/idf/WorkspaceObject.hpp"
#include "../../utilities/geometry/Point3d.hpp"
#include "../../utilities/idf/IdfExtensibleGroup.hpp"
#include "../../utilities/idf/WorkspaceExtensibleGroup.hpp"

#include <utilities/idd/IddEnums.hxx>
#include <utilities/idd/IddFactory.hxx>
#include <utilities/idd/SurfaceProperty_LocalEnvironment_FieldEnums.hxx>
#include <utilities/idd/SurfaceProperty_SurroundingSurfaces_FieldEnums.hxx>
#include <utilities/idd/BuildingSurface_Detailed_FieldEnums.hxx>
#include <utilities/idd/Schedule_Constant_FieldEnums.hxx>

#include <vector>

Expand Down Expand Up @@ -157,3 +165,88 @@ TEST_F(EnergyPlusFixture, ForwardTranslator_SurfacePropertyLocalEnvironment) {
EXPECT_EQ(wo_sp_->iddObject().type(), IddObjectType::SurfaceProperty_SurroundingSurfaces);
}
}

TEST_F(EnergyPlusFixture, ReverseTranslator_SurfacePropertyLocalEnvironment) {

ReverseTranslator rt;

Workspace w(StrictnessLevel::None, IddFileType::EnergyPlus);

auto wo_zone = w.addObject(IdfObject(IddObjectType::Zone)).get();
wo_zone.setName("Thermal Zone 1");

auto wo_sf = w.addObject(IdfObject(IddObjectType::BuildingSurface_Detailed)).get();
wo_sf.setName("Surface 1");
EXPECT_TRUE(wo_sf.setString(BuildingSurface_DetailedFields::SurfaceType, "Wall"));
EXPECT_TRUE(wo_sf.setString(BuildingSurface_DetailedFields::ConstructionName, ""));
EXPECT_TRUE(wo_sf.setPointer(BuildingSurface_DetailedFields::ZoneName, wo_zone.handle()));
EXPECT_TRUE(wo_sf.setString(BuildingSurface_DetailedFields::OutsideBoundaryCondition, "Outdoors"));
EXPECT_TRUE(wo_sf.setString(BuildingSurface_DetailedFields::OutsideBoundaryConditionObject, ""));
EXPECT_TRUE(wo_sf.setString(BuildingSurface_DetailedFields::SunExposure, "SunExposed"));
EXPECT_TRUE(wo_sf.setString(BuildingSurface_DetailedFields::WindExposure, "WindExposed"));
EXPECT_TRUE(wo_sf.setString(BuildingSurface_DetailedFields::ViewFactortoGround, ""));
EXPECT_TRUE(wo_sf.setString(BuildingSurface_DetailedFields::NumberofVertices, ""));
IdfExtensibleGroup group1 = wo_sf.pushExtensibleGroup(); // vertex 1
group1.setDouble(0, 0);
group1.setDouble(1, 2);
group1.setDouble(2, 0);
IdfExtensibleGroup group2 = wo_sf.pushExtensibleGroup(); // vertex 2
group2.setDouble(0, 0);
group2.setDouble(1, 0);
group2.setDouble(2, 0);
IdfExtensibleGroup group3 = wo_sf.pushExtensibleGroup(); // vertex 3
group3.setDouble(0, 2);
group3.setDouble(1, 0);
group3.setDouble(2, 0);
IdfExtensibleGroup group4 = wo_sf.pushExtensibleGroup(); // vertex 4
group4.setDouble(0, 2);
group4.setDouble(1, 2);
group4.setDouble(2, 0);

auto wo_sp = w.addObject(IdfObject(IddObjectType::SurfaceProperty_SurroundingSurfaces)).get();
wo_sp.setName("SfProps");

EXPECT_TRUE(wo_sp.setDouble(SurfaceProperty_SurroundingSurfacesFields::SkyViewFactor, 0.5));
EXPECT_TRUE(wo_sp.setDouble(SurfaceProperty_SurroundingSurfacesFields::GroundViewFactor, 0.2));

auto w_eg = wo_sp.pushExtensibleGroup().cast<WorkspaceExtensibleGroup>();
EXPECT_TRUE(w_eg.setString(SurfaceProperty_SurroundingSurfacesExtensibleFields::SurroundingSurfaceName, "External Surface 1"));
EXPECT_TRUE(w_eg.setDouble(SurfaceProperty_SurroundingSurfacesExtensibleFields::SurroundingSurfaceViewFactor, 0.25));

auto tempSch1 = w.addObject(IdfObject(IddObjectType::Schedule_Constant)).get();
tempSch1.setName("tempSch1");
EXPECT_TRUE(tempSch1.setDouble(Schedule_ConstantFields::HourlyValue, 13.5));
EXPECT_TRUE(w_eg.setPointer(SurfaceProperty_SurroundingSurfacesExtensibleFields::SurroundingSurfaceTemperatureScheduleName, tempSch1.handle()));

auto wo_localEnv = w.addObject(IdfObject(IddObjectType::SurfaceProperty_LocalEnvironment)).get();
wo_localEnv.setName("LocalEnv");

auto externalShadingSch = w.addObject(IdfObject(IddObjectType::Schedule_Constant)).get();
externalShadingSch.setName("externalShadingSch");
EXPECT_TRUE(externalShadingSch.setDouble(Schedule_ConstantFields::HourlyValue, 0.5));
EXPECT_TRUE(wo_localEnv.setPointer(SurfaceProperty_LocalEnvironmentFields::ExternalShadingFractionScheduleName, externalShadingSch.handle()));

EXPECT_TRUE(wo_localEnv.setPointer(SurfaceProperty_LocalEnvironmentFields::ExteriorSurfaceName, wo_sf.handle()));

EXPECT_TRUE(wo_localEnv.setPointer(SurfaceProperty_LocalEnvironmentFields::SurroundingSurfacesObjectName, wo_sp.handle()));

// RT
Model m = rt.translateWorkspace(w);

ASSERT_EQ(1, m.getConcreteModelObjects<SurfacePropertySurroundingSurfaces>().size());
ASSERT_EQ(1, m.getConcreteModelObjects<SurfacePropertyLocalEnvironment>().size());
auto surfaces = m.getConcreteModelObjects<Surface>();
ASSERT_EQ(1, surfaces.size());
auto& surface = surfaces[0];

ASSERT_TRUE(surface.surfacePropertyLocalEnvironment());
auto localEnv = surface.surfacePropertyLocalEnvironment().get();
EXPECT_EQ("LocalEnv", localEnv.nameString());
EXPECT_EQ(surface, localEnv.exteriorSurface());

ASSERT_TRUE(localEnv.externalShadingFractionSchedule());
EXPECT_EQ("externalShadingSch", localEnv.externalShadingFractionSchedule()->nameString());

ASSERT_TRUE(localEnv.surfacePropertySurroundingSurfaces());
EXPECT_EQ("SfProps", localEnv.surfacePropertySurroundingSurfaces()->nameString());
}
125 changes: 125 additions & 0 deletions src/energyplus/Test/SurfacePropertySurroundingSurfaces_GTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,23 @@
#include "../../model/Space.hpp"
#include "../../model/SurfacePropertyLocalEnvironment.hpp"
#include "../../model/SurfacePropertySurroundingSurfaces.hpp"
#include "../../model/SurfacePropertySurroundingSurfaces_Impl.hpp"
#include "../../model/ScheduleConstant.hpp"
#include "../../model/Surface.hpp"
#include "../../model/Surface_Impl.hpp"
#include "../../model/SubSurface.hpp"

#include "../../utilities/idf/WorkspaceObject.hpp"
#include "../../utilities/geometry/Point3d.hpp"
#include "../../utilities/idf/IdfExtensibleGroup.hpp"
#include "../../utilities/idf/WorkspaceExtensibleGroup.hpp"

#include <utilities/idd/IddEnums.hxx>
#include <utilities/idd/IddFactory.hxx>
#include <utilities/idd/SurfaceProperty_LocalEnvironment_FieldEnums.hxx>
#include <utilities/idd/SurfaceProperty_SurroundingSurfaces_FieldEnums.hxx>
#include <utilities/idd/BuildingSurface_Detailed_FieldEnums.hxx>
#include <utilities/idd/Schedule_Constant_FieldEnums.hxx>

#include <vector>

Expand Down Expand Up @@ -195,3 +200,123 @@ TEST_F(EnergyPlusFixture, ForwardTranslator_SurfacePropertySurroundingSurfaces)
}
}
}

TEST_F(EnergyPlusFixture, ReverseTranslator_SurfacePropertySurroundingSurfaces) {

ReverseTranslator rt;

Workspace w(StrictnessLevel::None, IddFileType::EnergyPlus);

auto wo_zone = w.addObject(IdfObject(IddObjectType::Zone)).get();
wo_zone.setName("Thermal Zone 1");

auto wo_sf = w.addObject(IdfObject(IddObjectType::BuildingSurface_Detailed)).get();
wo_sf.setName("Surface 1");
EXPECT_TRUE(wo_sf.setString(BuildingSurface_DetailedFields::SurfaceType, "Wall"));
EXPECT_TRUE(wo_sf.setString(BuildingSurface_DetailedFields::ConstructionName, ""));
EXPECT_TRUE(wo_sf.setPointer(BuildingSurface_DetailedFields::ZoneName, wo_zone.handle()));
EXPECT_TRUE(wo_sf.setString(BuildingSurface_DetailedFields::OutsideBoundaryCondition, "Outdoors"));
EXPECT_TRUE(wo_sf.setString(BuildingSurface_DetailedFields::OutsideBoundaryConditionObject, ""));
EXPECT_TRUE(wo_sf.setString(BuildingSurface_DetailedFields::SunExposure, "SunExposed"));
EXPECT_TRUE(wo_sf.setString(BuildingSurface_DetailedFields::WindExposure, "WindExposed"));
EXPECT_TRUE(wo_sf.setString(BuildingSurface_DetailedFields::ViewFactortoGround, ""));
EXPECT_TRUE(wo_sf.setString(BuildingSurface_DetailedFields::NumberofVertices, ""));
IdfExtensibleGroup group1 = wo_sf.pushExtensibleGroup(); // vertex 1
group1.setDouble(0, 0);
group1.setDouble(1, 2);
group1.setDouble(2, 0);
IdfExtensibleGroup group2 = wo_sf.pushExtensibleGroup(); // vertex 2
group2.setDouble(0, 0);
group2.setDouble(1, 0);
group2.setDouble(2, 0);
IdfExtensibleGroup group3 = wo_sf.pushExtensibleGroup(); // vertex 3
group3.setDouble(0, 2);
group3.setDouble(1, 0);
group3.setDouble(2, 0);
IdfExtensibleGroup group4 = wo_sf.pushExtensibleGroup(); // vertex 4
group4.setDouble(0, 2);
group4.setDouble(1, 2);
group4.setDouble(2, 0);

auto wo_sp = w.addObject(IdfObject(IddObjectType::SurfaceProperty_SurroundingSurfaces)).get();

EXPECT_TRUE(wo_sp.setDouble(SurfaceProperty_SurroundingSurfacesFields::SkyViewFactor, 0.5));

auto skyTempSch = w.addObject(IdfObject(IddObjectType::Schedule_Constant)).get();
skyTempSch.setName("skyTempSch");
EXPECT_TRUE(skyTempSch.setDouble(Schedule_ConstantFields::HourlyValue, 23.5));
EXPECT_TRUE(wo_sp.setPointer(SurfaceProperty_SurroundingSurfacesFields::SkyTemperatureScheduleName, skyTempSch.handle()));

EXPECT_TRUE(wo_sp.setDouble(SurfaceProperty_SurroundingSurfacesFields::GroundViewFactor, 0.2));

auto groundTempSch = w.addObject(IdfObject(IddObjectType::Schedule_Constant)).get();
groundTempSch.setName("groundTempSch");
EXPECT_TRUE(groundTempSch.setDouble(Schedule_ConstantFields::HourlyValue, 25.5));
EXPECT_TRUE(wo_sp.setPointer(SurfaceProperty_SurroundingSurfacesFields::GroundTemperatureScheduleName, groundTempSch.handle()));

auto tempSch1 = w.addObject(IdfObject(IddObjectType::Schedule_Constant)).get();
tempSch1.setName("tempSch1");
EXPECT_TRUE(tempSch1.setDouble(Schedule_ConstantFields::HourlyValue, 13.5));

auto tempSch2 = w.addObject(IdfObject(IddObjectType::Schedule_Constant)).get();
tempSch2.setName("tempSch2");
EXPECT_TRUE(tempSch2.setDouble(Schedule_ConstantFields::HourlyValue, 33.5));

struct Group
{
Group(std::string s, double v, std::string sch) : surroundingSurfaceName(std::move(s)), viewFactor(v), scheduleName(std::move(sch)) {}

std::string surroundingSurfaceName;
double viewFactor;
std::string scheduleName;
};

std::vector<Group> check_groups;

for (int i = 1; i <= 5; ++i) {
auto w_eg = wo_sp.pushExtensibleGroup().cast<WorkspaceExtensibleGroup>();
std::string sfName = "External Surface " + std::to_string(i);
EXPECT_TRUE(w_eg.setString(SurfaceProperty_SurroundingSurfacesExtensibleFields::SurroundingSurfaceName, sfName));

double viewFactor = 0.01 * i;
EXPECT_TRUE(w_eg.setDouble(SurfaceProperty_SurroundingSurfacesExtensibleFields::SurroundingSurfaceViewFactor, viewFactor));

if (i % 2 == 0) {
EXPECT_TRUE(w_eg.setPointer(SurfaceProperty_SurroundingSurfacesExtensibleFields::SurroundingSurfaceTemperatureScheduleName, tempSch1.handle()));
check_groups.emplace_back(sfName, viewFactor, tempSch1.nameString());
} else {
EXPECT_TRUE(w_eg.setPointer(SurfaceProperty_SurroundingSurfacesExtensibleFields::SurroundingSurfaceTemperatureScheduleName, tempSch2.handle()));
check_groups.emplace_back(sfName, viewFactor, tempSch2.nameString());
}
}

Model m = rt.translateWorkspace(w);

EXPECT_EQ(1, m.getConcreteModelObjects<Surface>().size());

auto sps = m.getConcreteModelObjects<SurfacePropertySurroundingSurfaces>();
ASSERT_EQ(1, sps.size());
auto& sp = sps[0];

ASSERT_TRUE(sp.skyViewFactor());
EXPECT_EQ(0.5, sp.skyViewFactor());
ASSERT_TRUE(sp.skyTemperatureSchedule());
EXPECT_EQ("skyTempSch", sp.skyTemperatureSchedule()->nameString());

ASSERT_TRUE(sp.groundViewFactor());
EXPECT_EQ(0.2, sp.groundViewFactor());
ASSERT_TRUE(sp.groundTemperatureSchedule());
EXPECT_EQ("groundTempSch", sp.groundTemperatureSchedule()->nameString());

ASSERT_EQ(5, sp.numberofSurroundingSurfaceGroups());
auto groups = sp.surroundingSurfaceGroups();
ASSERT_EQ(5, groups.size());

for (size_t i = 0; i < 5; ++i) {
auto& group = groups[i];
auto& check_group = check_groups[i];
EXPECT_EQ(check_group.surroundingSurfaceName, group.surroundingSurfaceName());
EXPECT_EQ(check_group.viewFactor, group.viewFactor());
EXPECT_EQ(check_group.scheduleName, group.temperatureSchedule().nameString());
}
}

0 comments on commit 3285797

Please sign in to comment.