Skip to content

Commit

Permalink
Add tests and clean up cpp and ft.
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph-robertson committed Jan 2, 2025
1 parent 6562431 commit a82562b
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,9 @@ namespace energyplus {
// Instantiate an IdfObject of the class to store the values
IdfObject idfObject = createRegisterAndNameIdfObject(openstudio::IddObjectType::ZoneHVAC_EvaporativeCoolerUnit, modelObject);

// Availability Schedule Name: Optional Object
if (boost::optional<Schedule> availabilitySchedule_ = modelObject.availabilitySchedule()) {
if (boost::optional<IdfObject> wo_ = translateAndMapModelObject(availabilitySchedule_.get())) {
idfObject.setString(ZoneHVAC_EvaporativeCoolerUnitFields::AvailabilityScheduleName, wo_->nameString());
}
// Availability Schedule Name: Required Object
if (boost::optional<IdfObject> wo_ = translateAndMapModelObject(modelObject.availabilitySchedule())) {
idfObject.setString(ZoneHVAC_EvaporativeCoolerUnitFields::AvailabilityScheduleName, wo_->nameString());
}

boost::optional<std::string> outdoorAirInletNodeName;
Expand All @@ -81,23 +79,18 @@ namespace energyplus {

// Supply Air Fan Object Type
// Supply Air Fan Name
boost::optional<IdfObject> fan_;
if (boost::optional<HVACComponent> supplyAirFan = modelObject.supplyAirFan()) {
fan_ = translateAndMapModelObject(supplyAirFan.get());
boost::optional<IdfObject> fan_ = translateAndMapModelObject(modelObject.supplyAirFan().get());

if (fan_ && fan_->name()) {
idfObject.setString(ZoneHVAC_EvaporativeCoolerUnitFields::SupplyAirFanObjectType, fan_->iddObject().name());
idfObject.setString(ZoneHVAC_EvaporativeCoolerUnitFields::SupplyAirFanName, fan_->name().get());
}
if (fan_ && fan_->name()) {
idfObject.setString(ZoneHVAC_EvaporativeCoolerUnitFields::SupplyAirFanObjectType, fan_->iddObject().name());
idfObject.setString(ZoneHVAC_EvaporativeCoolerUnitFields::SupplyAirFanName, fan_->name().get());
}

if (modelObject.isDesignSupplyAirFlowRateAutosized()) {
idfObject.setString(ZoneHVAC_EvaporativeCoolerUnitFields::DesignSupplyAirFlowRate, "Autosize");
} else {
// Design Supply Air Flow Rate: boost::optional<double>
if (boost::optional<double> designSupplyAirFlowRate_ = modelObject.designSupplyAirFlowRate()) {
idfObject.setDouble(ZoneHVAC_EvaporativeCoolerUnitFields::DesignSupplyAirFlowRate, designSupplyAirFlowRate_.get());
}
idfObject.setDouble(ZoneHVAC_EvaporativeCoolerUnitFields::DesignSupplyAirFlowRate, modelObject.designSupplyAirFlowRate().get());
}

// Fan Placement: Required String
Expand Down
14 changes: 12 additions & 2 deletions src/model/ZoneHVACEvaporativeCoolerUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,13 @@ namespace model {
bool ok = true;
ok = setAvailabilitySchedule(availabilitySchedule);
OS_ASSERT(ok);

ok = setSupplyAirFan(supplyAirFan);
OS_ASSERT(ok);
if (!ok) {
remove();
LOG_AND_THROW("Unable to set " << briefDescription() << "'s supply air fan to " << supplyAirFan.briefDescription() << ".");
}

autosizeDesignSupplyAirFlowRate();
ok = setFanPlacement("BlowThrough");
OS_ASSERT(ok);
Expand All @@ -406,8 +411,13 @@ namespace model {
OS_ASSERT(ok);
ok = setCoolingLoadControlThresholdHeatTransferRate(100.0);
OS_ASSERT(ok);

ok = setFirstEvaporativeCooler(firstEvaporativeCooler);
OS_ASSERT(ok);
if (!ok) {
remove();
LOG_AND_THROW("Unable to set " << briefDescription() << "'s first evaporative cooler to " << firstEvaporativeCooler.briefDescription() << ".");
}

ok = setShutOffRelativeHumidity(100.0);
OS_ASSERT(ok);
}
Expand Down
113 changes: 113 additions & 0 deletions src/model/test/ZoneHVACEvaporativeCoolerUnit_GTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@
#include "../EvaporativeCoolerDirectResearchSpecial_Impl.hpp"
#include "../EvaporativeCoolerIndirectResearchSpecial.hpp"
#include "../EvaporativeCoolerIndirectResearchSpecial_Impl.hpp"
#include "../Node.hpp"
#include "../Node_Impl.hpp"
#include "../AirLoopHVAC.hpp"
#include "../AirLoopHVAC_Impl.hpp"
#include "../AirLoopHVACZoneSplitter.hpp"
#include "../AirLoopHVACZoneSplitter_Impl.hpp"
#include "../PlantLoop.hpp"
#include "../PlantLoop_Impl.hpp"

using namespace openstudio;
using namespace openstudio::model;
Expand Down Expand Up @@ -132,3 +140,108 @@ TEST_F(ModelFixture, ZoneHVACEvaporativeCoolerUnit_HeatCoolFuelTypes) {
testFuelTypeEquality({}, zoneHVACEvaporativeCoolerUnit.heatingFuelTypes());
testAppGFuelTypeEquality({}, zoneHVACEvaporativeCoolerUnit.appGHeatingFuelTypes());
}

TEST_F(ModelFixture, ZoneHVACEvaporativeCoolerUnit_addToThermalZone) {
Model m;
ZoneHVACEvaporativeCoolerUnit zonehvac(m);

ThermalZone tz(m);
ASSERT_TRUE(zonehvac.addToThermalZone(tz));
ASSERT_TRUE(zonehvac.thermalZone());
ASSERT_EQ(tz, zonehvac.thermalZone().get());
ASSERT_EQ(1u, tz.equipment().size());
zonehvac.removeFromThermalZone();
ASSERT_EQ(0u, tz.equipment().size());

ZoneHVACEvaporativeCoolerUnit zonehvac2(m);
zonehvac2.addToThermalZone(tz);
zonehvac2.remove();
ASSERT_EQ(0u, tz.equipment().size());
}

TEST_F(ModelFixture, ZoneHVACEvaporativeCoolerUnit_clone) {
Model m;
FanComponentModel fan(m);
Schedule availabilitySchedule = m.alwaysOnDiscreteSchedule();
EvaporativeCoolerDirectResearchSpecial firstEvaporativeCooler(model, availabilitySchedule);
ZoneHVACEvaporativeCoolerUnit zonehvac(m, availabilitySchedule, fan, firstEvaporativeCooler);
EvaporativeCoolerIndirectResearchSpecial secondEvaporativeCooler(m);
EXPECT_TRUE(zoneHVACEvaporativeCoolerUnit.setSecondEvaporativeCooler(secondEvaporativeCooler));
EXPECT_EQ(1u, m.getConcreteModelObjects<FanComponentModel>().size());
EXPECT_EQ(1u, m.getConcreteModelObjects<EvaporativeCoolerDirectResearchSpecial>().size());
EXPECT_EQ(1u, m.getConcreteModelObjects<EvaporativeCoolerIndirectResearchSpecial>().size());

ThermalZone tz(m);
EXPECT_TRUE(zonehvac.addToThermalZone(tz));
EXPECT_TRUE(zonehvac.inletModelObject());
EXPECT_TRUE(zonehvac.outletModelObject());
EXPECT_TRUE(zonehvac.thermalZone());
{
Model m2;
auto zonehvacClone = zonehvac.clone(m2).cast<ZoneHVACEvaporativeCoolerUnit>();
EXPECT_FALSE(zonehvacClone.inletModelObject());
EXPECT_FALSE(zonehvacClone.outletModelObject());
EXPECT_FALSE(zonehvacClone.thermalZone());
EXPECT_NE(fan.handle(), zonehvacClone.supplyAirFan().handle());
EXPECT_NE(firstEvaporativeCooler.handle(), zonehvacClone.firstEvaporativeCooler().handle());
EXPECT_NE(secondEvaporativeCooler.handle(), zonehvacClone.secondEvaporativeCooler().handle());
EXPECT_EQ(1u, m2.getConcreteModelObjects<FanComponentModel>().size());
EXPECT_EQ(1u, m2.getConcreteModelObjects<EvaporativeCoolerDirectResearchSpecial>().size());
EXPECT_EQ(1u, m2.getConcreteModelObjects<EvaporativeCoolerIndirectResearchSpecial>().size());
}

{
auto zonehvacClone = zonehvac.clone(m).cast<ZoneHVACEvaporativeCoolerUnit>();
EXPECT_FALSE(zonehvacClone.inletModelObject());
EXPECT_FALSE(zonehvacClone.outletModelObject());
EXPECT_FALSE(zonehvacClone.thermalZone());
EXPECT_NE(fan.handle(), zonehvacClone.supplyAirFan().handle());
EXPECT_NE(firstEvaporativeCooler.handle(), zonehvacClone.firstEvaporativeCooler().handle());
EXPECT_NE(secondEvaporativeCooler.handle(), zonehvacClone.secondEvaporativeCooler().handle());
EXPECT_EQ(1u, m.getConcreteModelObjects<FanComponentModel>().size());
EXPECT_EQ(1u, m.getConcreteModelObjects<EvaporativeCoolerDirectResearchSpecial>().size());
EXPECT_EQ(1u, m.getConcreteModelObjects<EvaporativeCoolerIndirectResearchSpecial>().size());
}
}

TEST_F(ModelFixture, ZoneHVACEvaporativeCoolerUnit_remove) {
Model m;
ZoneHVACEvaporativeCoolerUnit zonehvac(m);

auto size = m.modelObjects().size();
EXPECT_FALSE(zonehvac.remove().empty());
EXPECT_EQ(size - 1, m.modelObjects().size());
EXPECT_EQ(0, m.getConcreteModelObjects<ZoneHVACEvaporativeCoolerUnit>().size());
}

TEST_F(ModelFixture, ZoneHVACEvaporativeCoolerUnit_addToNode) {
Model m;
ZoneHVACEvaporativeCoolerUnit zonehvac(m);

AirLoopHVAC airLoop(m);

Node supplyOutletNode = airLoop.supplyOutletNode();

EXPECT_FALSE(zonehvac.addToNode(supplyOutletNode));
EXPECT_EQ(2, airLoop.supplyComponents().size());

Node inletNode = airLoop.zoneSplitter().lastOutletModelObject()->cast<Node>();

EXPECT_FALSE(zonehvac.addToNode(inletNode));
EXPECT_EQ(5, airLoop.demandComponents().size());

PlantLoop plantLoop(m);
supplyOutletNode = plantLoop.supplyOutletNode();
EXPECT_TRUE(zonehvac.addToNode(supplyOutletNode));
EXPECT_EQ(7, plantLoop.supplyComponents().size());

Node demandOutletNode = plantLoop.demandOutletNode();
EXPECT_FALSE(zonehvac.addToNode(demandOutletNode));
EXPECT_EQ(5, plantLoop.demandComponents().size());

auto zonehvacClone = zonehvac.clone(m).cast<ZoneHVACEvaporativeCoolerUnit>();
supplyOutletNode = plantLoop.supplyOutletNode();

EXPECT_TRUE(zonehvacClone.addToNode(supplyOutletNode));
EXPECT_EQ(9, plantLoop.supplyComponents().size());
}

0 comments on commit a82562b

Please sign in to comment.