TEST_F(IdfFixture, IdfFile_ObjectComments) { OptionalIdfFile oFile = IdfFile::load(resourcesPath()/toPath("utilities/Idf/CommentTest.idf")); ASSERT_TRUE(oFile); // header // CommentOnlyObject // Version // Timestep w/ comment // SimulationControl // RunPeriod w/ comment // Building w/ comment std::stringstream ss; // check header ss << "! File Header" << std::endl << "! Written by Elaine T. Hale, 15 September 2010"; EXPECT_EQ(ss.str(),oFile->header()); // check objects IdfObjectVector objects = oFile->objects(); EXPECT_EQ(static_cast<unsigned>(5),objects.size()); ASSERT_TRUE(objects.size() >= 5); EXPECT_TRUE(objects[0].iddObject().type() == IddObjectType::CommentOnly); EXPECT_TRUE(objects[1].iddObject().type() == IddObjectType::Timestep); EXPECT_EQ("! Timestep should be > 1.",objects[1].comment()); EXPECT_TRUE(objects[2].iddObject().type() == IddObjectType::SimulationControl); EXPECT_TRUE(objects[3].iddObject().type() == IddObjectType::RunPeriod); EXPECT_EQ("! When to start, when to stop, when to trust the weather file.",objects[3].comment()); EXPECT_TRUE(objects[4].iddObject().type() == IddObjectType::Building); EXPECT_EQ("! This building has no surfaces, no volume, no nothing.",objects[4].comment()); // print out result for debugging purposes boost::filesystem::ofstream outFile(resourcesPath()/toPath("utilities/Idf/CommentTest_Roundtrip.idf")); ASSERT_TRUE(outFile?true:false); oFile->print(outFile); }
void WeatherFileFinder::extractDetails( const IdfFile &t_idffile, ToolVersion &t_version, boost::optional<std::string> &t_filelocationname, boost::optional<std::string> &t_weatherfilename) { IdfObjectVector versionObjects = t_idffile.getObjectsByType(IddObjectType::Version); if(versionObjects.size() == 1){ OptionalString version = versionObjects[0].getString(VersionFields::VersionIdentifier, true); if (version){ boost::regex majorMinorBuildRegex("^(\\d*?)\\.(\\d*?)\\.(\\d*?)$"); boost::regex majorMinorRegex("^(\\d*?)\\.(\\d*?)$"); boost::regex majorRegex("^(\\d*?)$"); boost::smatch matches; if (boost::regex_search(*version, matches, majorMinorBuildRegex)){ unsigned major = boost::lexical_cast<unsigned>(std::string(matches[1].first, matches[1].second)); unsigned minor = boost::lexical_cast<unsigned>(std::string(matches[2].first, matches[2].second)); unsigned build = boost::lexical_cast<unsigned>(std::string(matches[3].first, matches[3].second)); t_version = ToolVersion(major, minor, build); }else if(boost::regex_search(*version, matches, majorMinorRegex)){ unsigned major = boost::lexical_cast<unsigned>(std::string(matches[1].first, matches[1].second)); unsigned minor = boost::lexical_cast<unsigned>(std::string(matches[2].first, matches[2].second)); t_version = ToolVersion(major, minor); }else if(boost::regex_search(*version, matches, majorRegex)){ unsigned major = boost::lexical_cast<unsigned>(std::string(matches[1].first, matches[1].second)); t_version = ToolVersion(major); } } } IdfObjectVector locationObjects = t_idffile.getObjectsByType(IddObjectType::Site_Location); if(locationObjects.size() == 1){ OptionalString locationname = locationObjects[0].getString(Site_LocationFields::Name, true); if (locationname && !locationname->empty()){ LOG(Debug, "Location name field from IDF: " << *locationname); t_filelocationname = locationname; } } std::string header = t_idffile.header(); std::vector<std::string> headerlines; boost::split(headerlines, header, boost::is_any_of("\n\r"), boost::algorithm::token_compress_on); for (std::vector<std::string>::const_iterator itr = headerlines.begin(); itr != headerlines.end(); ++itr) { boost::smatch matches; if (boost::regex_match(*itr, matches, boost::regex(".*!\\s+WeatherFileName=(.*)"),boost::regex_constants::match_all)) { std::string match = matches[1]; t_weatherfilename = match; break; } } }
TEST_F(IdfFixture, IdfFile_BasicTests_FromScratch) { IdfFile idfFile(IddFileType::EnergyPlus); // automatically adds version EXPECT_TRUE(idfFile.empty()); idfFile.addObject(IdfObject(IddObjectType::Building)); idfFile.addObject(IdfObject(IddObjectType::Zone)); idfFile.insertObjectByIddObjectType(IdfObject(IddObjectType::Construction)); idfFile.addObject(IdfObject(IddObjectType::Material)); EXPECT_FALSE(idfFile.empty()); EXPECT_EQ(static_cast<unsigned>(4),idfFile.numObjects()); // version not reported out IdfObjectVector objs = idfFile.objects(); ASSERT_EQ(static_cast<unsigned>(4),objs.size()); EXPECT_TRUE(objs[0].iddObject().type() == IddObjectType::Building); EXPECT_TRUE(objs[1].iddObject().type() == IddObjectType::Construction); EXPECT_TRUE(objs[2].iddObject().type() == IddObjectType::Zone); EXPECT_TRUE(objs[3].iddObject().type() == IddObjectType::Material); }
TEST_F(ModelFixture, MeterFromModel) { Model model; IdfObjectVector idfObjects; idfObjects.push_back(IdfObject(IddObjectType::OS_Meter)); idfObjects.back().setString(OS_MeterFields::Name,"Electricity:Facility"); idfObjects.back().setString(OS_MeterFields::ReportingFrequency,"monthly"); idfObjects.back().setString(OS_MeterFields::MeterFileOnly,"false"); LOG(Debug,"Meter text: " << std::endl << idfObjects.back()); idfObjects.push_back(IdfObject(IddObjectType::OS_Meter)); idfObjects.back().setString(OS_MeterFields::Name,"Gas:Building"); idfObjects.back().setString(OS_MeterFields::ReportingFrequency,"hourly"); idfObjects.push_back(IdfObject(IddObjectType::OS_Meter)); idfObjects.back().setString(OS_MeterFields::Name,"InteriorLights:Electricity"); idfObjects.back().setString(OS_MeterFields::ReportingFrequency,"runperiod"); idfObjects.back().setString(OS_MeterFields::MeterFileOnly,"false"); idfObjects.back().setString(OS_MeterFields::Cumulative,"true"); idfObjects.push_back(IdfObject(IddObjectType::OS_Meter)); idfObjects.back().setString(OS_MeterFields::Name,"General:InteriorLights:Electricity:Zone:North Zone"); idfObjects.back().setString(OS_MeterFields::ReportingFrequency,"daily"); idfObjects.back().setString(OS_MeterFields::Cumulative,"true"); EXPECT_EQ(static_cast<unsigned>(4), idfObjects.size()); HandleVector handles = getHandles(model.addObjects(idfObjects)); ASSERT_EQ(static_cast<unsigned>(4), handles.size()); EXPECT_EQ(static_cast<unsigned>(4), model.getModelObjects<Meter>().size()); //"Output:Meter,Electricity:Facility,monthly;" OptionalMeter meter = model.getModelObject<Meter>(handles[0]); ASSERT_TRUE(meter); EXPECT_EQ("Electricity:Facility", meter->name()); EXPECT_FALSE(meter->cumulative()); EXPECT_FALSE(meter->specificEndUse()); EXPECT_FALSE(meter->endUseType()); ASSERT_TRUE(meter->fuelType()); EXPECT_EQ(FuelType::Electricity, meter->fuelType().get().value()); ASSERT_TRUE(meter->installLocationType()); EXPECT_EQ(InstallLocationType::Facility, meter->installLocationType().get().value()); EXPECT_FALSE(meter->specificInstallLocation()); //"Output:Meter:MeterFileOnly,Gas:Building,hourly;" meter = model.getModelObject<Meter>(handles[1]); ASSERT_TRUE(meter); EXPECT_EQ("Gas:Building", meter->name()); EXPECT_FALSE(meter->cumulative()); EXPECT_FALSE(meter->specificEndUse()); EXPECT_FALSE(meter->endUseType()); ASSERT_TRUE(meter->fuelType()); EXPECT_EQ(FuelType::Gas, meter->fuelType().get().value()); ASSERT_TRUE(meter->installLocationType()); EXPECT_EQ(InstallLocationType::Building, meter->installLocationType().get().value()); EXPECT_FALSE(meter->specificInstallLocation()); //"Output:Meter:Cumulative,InteriorLights:Electricity,runperiod;" meter = model.getModelObject<Meter>(handles[2]); ASSERT_TRUE(meter); EXPECT_EQ("InteriorLights:Electricity", meter->name()); EXPECT_TRUE(meter->cumulative()); EXPECT_FALSE(meter->specificEndUse()); ASSERT_TRUE(meter->endUseType()); EXPECT_EQ(EndUseType::InteriorLights, meter->endUseType().get().value()); ASSERT_TRUE(meter->fuelType()); EXPECT_EQ(FuelType::Electricity, meter->fuelType().get().value()); EXPECT_FALSE(meter->installLocationType()); EXPECT_FALSE(meter->specificInstallLocation()); //"Output:Meter:Cumulative:MeterFileOnly,General:InteriorLights:Electricity:Zone:North Zone,daily;" meter = model.getModelObject<Meter>(handles[3]); ASSERT_TRUE(meter); EXPECT_EQ("General:InteriorLights:Electricity:Zone:North Zone", meter->name()); EXPECT_TRUE(meter->cumulative()); ASSERT_TRUE(meter->specificEndUse()); EXPECT_EQ("General", meter->specificEndUse().get()); ASSERT_TRUE(meter->endUseType()); EXPECT_EQ(EndUseType::InteriorLights, meter->endUseType().get().value()); ASSERT_TRUE(meter->fuelType()); EXPECT_EQ(FuelType::Electricity, meter->fuelType().get().value()); ASSERT_TRUE(meter->installLocationType()); EXPECT_EQ(InstallLocationType::Zone, meter->installLocationType().get().value()); ASSERT_TRUE(meter->specificInstallLocation()); EXPECT_EQ("North Zone", meter->specificInstallLocation().get()); }