コード例 #1
0
TEST_F(EnergyPlusFixture,ReverseTranslator_WindowConstruction)
{
  StrictnessLevel level(StrictnessLevel::Draft);
  IddFileType iddFileType(IddFileType::EnergyPlus);
  Workspace workspace(level,iddFileType);

  IdfObject glazing(IddObjectType::WindowMaterial_Glazing);
  IdfObject gas(IddObjectType::WindowMaterial_Gas);
  glazing.setName("Glazing Material");
  gas.setName("Gas Material");
  IdfObject construction(IddObjectType::Construction);
  ASSERT_EQ(0u,construction.numExtensibleGroups());
  EXPECT_FALSE(construction.pushExtensibleGroup(StringVector(1u,glazing.name().get())).empty());
  EXPECT_FALSE(construction.pushExtensibleGroup(StringVector(1u,gas.name().get())).empty());
  EXPECT_FALSE(construction.pushExtensibleGroup(StringVector(1u,glazing.name().get())).empty());
  IdfObjectVector objects;
  objects.push_back(glazing);
  objects.push_back(gas);
  objects.push_back(construction);
  EXPECT_EQ(3u,workspace.addObjects(objects).size());

  ReverseTranslator reverseTranslator;
  Model model = reverseTranslator.translateWorkspace(workspace);

  ASSERT_EQ(1u, model.getModelObjects<Construction>().size());
  Construction mConstruction = model.getModelObjects<Construction>()[0];
  EXPECT_EQ(3u,mConstruction.layers().size());
  EXPECT_EQ(2u, model.getModelObjects<FenestrationMaterial>().size());
}
コード例 #2
0
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);
}
コード例 #3
0
ファイル: IdfFile.cpp プロジェクト: airguider/OpenStudio
std::vector<IdfObject> IdfFile::getObjectsByName(const std::string& name) const {
  IdfObjectVector result;
  BOOST_FOREACH(const IdfObject& object,m_objects) {
    OptionalString objectName = object.name();
    if (objectName && openstudio::istringEqual(name,*objectName)) {
      result.push_back(object);
    }
  }
コード例 #4
0
  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;
      }
    }
  }
コード例 #5
0
ファイル: IdfFile.cpp プロジェクト: airguider/OpenStudio
std::vector<IdfObject> IdfFile::getObjectsByType(const IddObject& objectType) const {
  IdfObjectVector result;
  BOOST_FOREACH(const IdfObject& object,objects()) {
    if (object.iddObject() == objectType) {
      result.push_back(object);
    }
  }
  return result;
}
コード例 #6
0
ファイル: IdfFile.cpp プロジェクト: airguider/OpenStudio
std::vector<IdfObject> IdfFile::getObjectsByType(IddObjectType objectType) const {
  IdfObjectVector result;
  for (IdfObjectVector::const_iterator it = m_objects.begin(),
       itEnd = m_objects.end(); it != itEnd; ++it) {
    if (it->iddObject().type() == objectType) {
      result.push_back(*it);
    }
  }
  return result;
}
コード例 #7
0
ファイル: IdfFile.cpp プロジェクト: airguider/OpenStudio
std::vector<IdfObject> IdfFile::objects() const {
  IdfObjectVector result = m_objects;
  for (std::set<unsigned>::const_reverse_iterator it = m_versionObjectIndices.rbegin(),
       itEnd = m_versionObjectIndices.rend(); it != itEnd; ++it)
  {
    IdfObjectVector::iterator oit = result.begin();
    for (unsigned i = 0; i < *it; ++i, ++oit);
    OS_ASSERT(oit->iddObject().isVersionObject() ||
                 ((oit->iddObject().type() == IddObjectType::Catchall) &&
                  (oit->numFields() > 0u) &&
                  (boost::regex_match(oit->getString(0).get(),iddRegex::versionObjectName()))));
    result.erase(oit);
  }
  return result;
}
コード例 #8
0
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);
}
コード例 #9
0
TEST(ProgressBar, WorkspaceTest)
{
  ProgressBar2 pb;
  EXPECT_FALSE(pb.called());

  StrictnessLevel level(StrictnessLevel::Draft);
  IddFileType fileType(IddFileType::EnergyPlus);
  Workspace workspace(level,fileType);
  workspace.connectProgressBar(pb);

  IdfObjectVector objects;
  objects.push_back(IdfObject(IddObjectType::Zone));
  workspace.addObjects(objects);

  System::msleep(10);

  EXPECT_TRUE(pb.called());
}
コード例 #10
0
ファイル: Meter_GTest.cpp プロジェクト: ORNL-BTRIC/OpenStudio
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());
}