Beispiel #1
0
TEST_F(IdfFixture, IdfObject_FieldSettingWithHiddenPushes) {
  std::stringstream text;
  OptionalIdfObject oObj;
  bool result;

  // SHOULD NOT BE VALID
  text.str("");
  text << "Lights," << std::endl
       << "  MyLight," << std::endl
       << "  MyZone," << std::endl
       << "  MySchedule," << std::endl
       << "  Watts/Person," << std::endl
       << "  ," << std::endl
       << "  ," << std::endl
       << "  10.0," << std::endl
       << "  0.2," << std::endl
       << "  0.6," << std::endl
       << "  0.8;";
  oObj = IdfObject::load(text.str());
  ASSERT_TRUE(oObj);
  IdfObject object = *oObj;
  // impossible field index
  result = object.setString(20,"not a field");
  EXPECT_FALSE(result);
  EXPECT_EQ(static_cast<unsigned>(11),object.numFields());
  result = object.setUnsigned(20,1);
  EXPECT_FALSE(result);
  EXPECT_EQ(static_cast<unsigned>(11),object.numFields());
}
TEST_F(EnergyPlusFixture,ForwardTranslatorTest_TranslateConstruction) {
  openstudio::model::Model model;

  openstudio::model::StandardOpaqueMaterial mat1(model);
  mat1.setName("test layer0");
  mat1.setRoughness("MediumRough");
  mat1.setThickness(0.02);
  mat1.setThermalConductivity(1.5);
  mat1.setDensity(20.0);
  mat1.setSpecificHeat(2.0);

  openstudio::model::StandardOpaqueMaterial mat2(model);
  mat2.setName("test layer1");
  mat2.setRoughness("MediumSmooth");
  mat2.setThickness(0.005);
  mat2.setThermalConductivity(0.3);
  mat2.setDensity(3.0);
  mat2.setSpecificHeat(0.3);

  openstudio::model::Construction construction(model);
  construction.setName("test construction");
  construction.insertLayer(0, mat1);
  construction.insertLayer(1, mat2);

  ForwardTranslator trans;
  Workspace workspace = trans.translateModelObject(construction);
  ASSERT_EQ(1u, workspace.numObjectsOfType(IddObjectType::Construction));

  IdfObject constructionIdf = workspace.getObjectsByType(IddObjectType::Construction)[0];

  EXPECT_EQ(unsigned(3), constructionIdf.numFields());
  EXPECT_EQ("test construction", *(constructionIdf.name()) );
  EXPECT_EQ("test layer0", *(constructionIdf.getString(1)) );
  EXPECT_EQ("test layer1", *(constructionIdf.getString(2)) );
}
Beispiel #3
0
 bool mapFields(const IdfObject& oldObject, IdfObject& newObject)
 {
   bool result = true;
   unsigned numFields = oldObject.numFields();
   for (unsigned i=0; i < numFields; ++i){
     OptionalString oldStr = oldObject.getString(i);
     if (oldStr){
       result = result && newObject.setString(i, *oldStr);
     }
   }
   return result;
 }
TEST_F(IdfFixture, IdfObject_ConstructFromText_MultifieldLines)
{
  std::string text = "Building,Building, !- Name\n\
                      30.0,              !- North Axis (deg) \n\
                      City,              !- Terrain \n\
                      0.04,0.4,          !- Load and temperature convergence values\n\
                      FullExterior,      !- Solar Distribution \n\
                      25;                !- Maximum Number of Warmup Days";
  OptionalIdfObject oObj = IdfObject::load(text);
  ASSERT_TRUE(oObj);
  IdfObject building = *oObj;
  EXPECT_EQ(8u,building.numFields());
  ASSERT_TRUE(building.fieldComment(5,false)); 
  EXPECT_TRUE(building.fieldComment(5,false).get().empty()); // parser should strip !- comments
  ASSERT_TRUE(building.fieldComment(5,true));
  EXPECT_FALSE(building.fieldComment(5,true).get().empty());

  text = "Site:GroundTemperature:BuildingSurface,20.03,20.03,20.13,20.30,20.43,20.52,20.62,20.77,20.78,20.55,20.44,20.20;";
  oObj = IdfObject::load(text);
  ASSERT_TRUE(oObj);
  IdfObject groundTemperature = *oObj;
  EXPECT_EQ(static_cast<unsigned>(12),groundTemperature.numFields());
}
TEST_F(EnergyPlusFixture,ForwardTranslatorTest_TranslateSiteWaterMainsTemperature) {
  openstudio::model::Model model;
  openstudio::model::SiteWaterMainsTemperature watertemp = model.getUniqueModelObject<openstudio::model::SiteWaterMainsTemperature>();

  watertemp.setAnnualAverageOutdoorAirTemperature(9.69);
  watertemp.setMaximumDifferenceInMonthlyAverageOutdoorAirTemperatures(28.1);

  ForwardTranslator trans;
  Workspace workspace = trans.translateModelObject(watertemp);
  ASSERT_EQ(1u, workspace.numObjectsOfType(IddObjectType::Site_WaterMainsTemperature));
    
  IdfObject watertempIdf = workspace.getObjectsByType(IddObjectType::Site_WaterMainsTemperature)[0];
  EXPECT_EQ(unsigned(4), watertempIdf.numFields());

  EXPECT_EQ( "Correlation", *(watertempIdf.getString(0)) );
  EXPECT_EQ( "", *(watertempIdf.getString(1)) );
  EXPECT_EQ( 9.69, *(watertempIdf.getDouble(2)) );
  EXPECT_EQ( 28.1, *(watertempIdf.getDouble(3)) );
}
TEST_F(EnergyPlusFixture,ForwardTranslatorTest_TranslateSite) {
  openstudio::model::Model model;
  openstudio::model::Site site = model.getUniqueModelObject<openstudio::model::Site>();

  site.setName("Test Site");
  site.setLatitude(39.6);
  site.setLongitude(105.2);
  site.setTimeZone(-7.0);
  site.setElevation(1729.74);

  ForwardTranslator trans;
  Workspace workspace = trans.translateModelObject(site);
  ASSERT_EQ(1u, workspace.numObjectsOfType(IddObjectType::Site_Location));
    
  IdfObject siteIdf = workspace.getObjectsByType(IddObjectType::Site_Location)[0];
  EXPECT_EQ(unsigned(5), siteIdf.numFields());

  EXPECT_EQ( "Test Site", *(siteIdf.name()) );
  EXPECT_EQ( 39.6, *(siteIdf.getDouble(1)) );
  EXPECT_EQ( 105.2, *(siteIdf.getDouble(2)) );
  EXPECT_EQ( -7.0, *(siteIdf.getDouble(3)) );
  EXPECT_EQ( 1729.74, *(siteIdf.getDouble(4)) );
}
TEST_F(EnergyPlusFixture,ForwardTranslatorTest_TranslateSiteGroundTemperatureBuildingSurface) {
  openstudio::model::Model model;
  openstudio::model::SiteGroundTemperatureBuildingSurface groundtemp = model.getUniqueModelObject<openstudio::model::SiteGroundTemperatureBuildingSurface>();

  groundtemp.setJanuaryGroundTemperature(19.527);
  groundtemp.setFebruaryGroundTemperature(19.502);
  groundtemp.setMarchGroundTemperature(19.536);
  groundtemp.setAprilGroundTemperature(19.598);
  groundtemp.setMayGroundTemperature(20.002);
  groundtemp.setJuneGroundTemperature(21.64);
  groundtemp.setJulyGroundTemperature(22.225);
  groundtemp.setAugustGroundTemperature(22.375);
  groundtemp.setSeptemberGroundTemperature(21.449);
  groundtemp.setOctoberGroundTemperature(20.121);
  groundtemp.setNovemberGroundTemperature(19.802);
  groundtemp.setDecemberGroundTemperature(19.633);

  ForwardTranslator trans;
  Workspace workspace = trans.translateModelObject(groundtemp);
  ASSERT_EQ(1u, workspace.numObjectsOfType(IddObjectType::Site_GroundTemperature_BuildingSurface));
    
  IdfObject groundtempIdf = workspace.getObjectsByType(IddObjectType::Site_GroundTemperature_BuildingSurface)[0];
  EXPECT_EQ(unsigned(12), groundtempIdf.numFields());

  EXPECT_EQ( 19.527, *(groundtempIdf.getDouble(0)) );
  EXPECT_EQ( 19.502, *(groundtempIdf.getDouble(1)) );
  EXPECT_EQ( 19.536, *(groundtempIdf.getDouble(2)) );
  EXPECT_EQ( 19.598, *(groundtempIdf.getDouble(3)) );
  EXPECT_EQ( 20.002, *(groundtempIdf.getDouble(4)) );
  EXPECT_EQ( 21.64, *(groundtempIdf.getDouble(5)) );
  EXPECT_EQ( 22.225, *(groundtempIdf.getDouble(6)) );
  EXPECT_EQ( 22.375, *(groundtempIdf.getDouble(7)) );
  EXPECT_EQ( 21.449, *(groundtempIdf.getDouble(8)) );
  EXPECT_EQ( 20.121, *(groundtempIdf.getDouble(9)) );
  EXPECT_EQ( 19.802, *(groundtempIdf.getDouble(10)) );
  EXPECT_EQ( 19.633, *(groundtempIdf.getDouble(11)) );
}
TEST_F(EnergyPlusFixture,ForwardTranslatorTest_TranslateSiteGroundReflectance) {
  openstudio::model::Model model;
  openstudio::model::SiteGroundReflectance groundreflect = model.getUniqueModelObject<openstudio::model::SiteGroundReflectance>();

  groundreflect.setJanuaryGroundReflectance(0.11);
  groundreflect.setFebruaryGroundReflectance(0.12);
  groundreflect.setMarchGroundReflectance(0.13);
  groundreflect.setAprilGroundReflectance(0.14);
  groundreflect.setMayGroundReflectance(0.15);
  groundreflect.setJuneGroundReflectance(0.16);
  groundreflect.setJulyGroundReflectance(0.17);
  groundreflect.setAugustGroundReflectance(0.18);
  groundreflect.setSeptemberGroundReflectance(0.19);
  groundreflect.setOctoberGroundReflectance(0.20);
  groundreflect.setNovemberGroundReflectance(0.21);
  groundreflect.setDecemberGroundReflectance(0.22);

  ForwardTranslator trans;
  Workspace workspace = trans.translateModelObject(groundreflect);
  ASSERT_EQ(1u, workspace.numObjectsOfType(IddObjectType::Site_GroundReflectance));
    
  IdfObject groundreflectIdf = workspace.getObjectsByType(IddObjectType::Site_GroundReflectance)[0];
  EXPECT_EQ(unsigned(12), groundreflectIdf.numFields());

  EXPECT_EQ( 0.11, *(groundreflectIdf.getDouble(0)) );
  EXPECT_EQ( 0.12, *(groundreflectIdf.getDouble(1)) );
  EXPECT_EQ( 0.13, *(groundreflectIdf.getDouble(2)) );
  EXPECT_EQ( 0.14, *(groundreflectIdf.getDouble(3)) );
  EXPECT_EQ( 0.15, *(groundreflectIdf.getDouble(4)) );
  EXPECT_EQ( 0.16, *(groundreflectIdf.getDouble(5)) );
  EXPECT_EQ( 0.17, *(groundreflectIdf.getDouble(6)) );
  EXPECT_EQ( 0.18, *(groundreflectIdf.getDouble(7)) );
  EXPECT_EQ( 0.19, *(groundreflectIdf.getDouble(8)) );
  EXPECT_EQ( 0.20, *(groundreflectIdf.getDouble(9)) );
  EXPECT_EQ( 0.21, *(groundreflectIdf.getDouble(10)) );
  EXPECT_EQ( 0.22, *(groundreflectIdf.getDouble(11)) );
}
TEST_F(IdfFixture, IdfObject_UnsignedFieldGetterWithReturnDefaultOption) {
  std::stringstream text;
  text << "ZoneGroup," << std::endl
       << "  MyGroup," << std::endl
       << "  MyList;";
    // default 1
  OptionalIdfObject oObj = IdfObject::load(text.str());
  ASSERT_TRUE(oObj);
  IdfObject object = *oObj;

  // is able to cast default value
  OptionalUnsigned uIdfField = object.getUnsigned(2,true);
  ASSERT_TRUE(uIdfField);
  EXPECT_EQ(static_cast<unsigned>(1),*uIdfField);
  EXPECT_FALSE(object.getUnsigned(2));

  EXPECT_TRUE(object.setString(object.numFields(),"3"));

  // returns set values
  uIdfField = object.getUnsigned(2,true);
  ASSERT_TRUE(uIdfField);
  EXPECT_EQ(static_cast<unsigned>(3),*uIdfField);
  EXPECT_TRUE(object.getUnsigned(2));
}
TEST_F(IdfFixture, IdfObject_FieldSettingWithHiddenPushes) {
  // SHOULD BE VALID
  std::stringstream text;
  text << "ZoneHVAC:HighTemperatureRadiant," << std::endl
       << "  MyRadiantSystem," << std::endl
       << "  MyHVACSchedule," << std::endl
       << "  MyCoreZone," << std::endl
       << "  autosize," << std::endl
       << "  Electric;";
  OptionalIdfObject oObj = IdfObject::load(text.str());
  ASSERT_TRUE(oObj);
  IdfObject object = *oObj;
  EXPECT_EQ(static_cast<unsigned>(5),object.numFields());
  // hidden pushing for setting nonextensible string

  // hidden pushing for setting nonextensible double

  // hidden pushing for setting extensible string
  bool result = object.setString(13,"MyCoreZoneSurface1");
  EXPECT_TRUE(result);
  // adds an extra field to keep groups together
  EXPECT_EQ(static_cast<unsigned>(15),object.numFields());
  OptionalString sValue = object.getString(13);
  ASSERT_TRUE(sValue);
  EXPECT_EQ("MyCoreZoneSurface1",*sValue);
  sValue = object.getString(14);
  ASSERT_TRUE(sValue);
  EXPECT_EQ("",*sValue);

  // hidden pushing for setting extensible double
  result = object.setDouble(18,0.01);
  EXPECT_TRUE(result);
  EXPECT_EQ(static_cast<unsigned>(19),object.numFields());
  OptionalDouble dValue = object.getDouble(18);
  ASSERT_TRUE(dValue);
  EXPECT_NEAR(0.01,*dValue,tol);
  dValue = object.getDouble(16);
  EXPECT_FALSE(dValue);

  // SHOULD NOT BE VALID
  text.str("");
  text << "Lights," << std::endl
       << "  MyLight," << std::endl
       << "  MyZone," << std::endl
       << "  MySchedule," << std::endl
       << "  Watts/Person," << std::endl
       << "  ," << std::endl
       << "  ," << std::endl
       << "  10.0," << std::endl
       << "  0.2," << std::endl
       << "  0.6," << std::endl
       << "  0.8;";
  oObj = IdfObject::load(text.str());
  ASSERT_TRUE(oObj);
  object = *oObj;
  // impossible field index
  result = object.setString(20,"not a field");
  EXPECT_FALSE(result);
  EXPECT_EQ(static_cast<unsigned>(10),object.numFields());
  result = object.setUnsigned(20,1);
  EXPECT_FALSE(result);
  EXPECT_EQ(static_cast<unsigned>(10),object.numFields());
}
TEST_F(IdfFixture, IdfObject_StringFieldGetterWithReturnDefaultOption) {
  // NON-EXTENSIBLE OBJECT
  std::stringstream text;
  text << "Refrigeration:Condenser:AirCooled," << std::endl
       << "  MyCondenser," << std::endl
       << "  ," << std::endl
       << "  ," << std::endl // default is 0.0
       << "  ," << std::endl // default is "Fixed"
       << "  125.0;";        // default is 250.0
                             // default is 0.2
                             //
                             // default is "General"
                             // default is 0.0
                             // default is 0.0
                             // default is 0.0
  OptionalIdfObject oObj = IdfObject::load(text.str());
  ASSERT_TRUE(oObj);
  IdfObject object = *oObj;

  // returns set values
  OptionalString idfField = object.getString(0,true);
  ASSERT_TRUE(idfField);
  EXPECT_EQ("MyCondenser",*idfField);
  idfField = object.getString(1,true);
  ASSERT_TRUE(idfField);
  EXPECT_EQ("",*idfField);
  idfField = object.getString(4,true);
  ASSERT_TRUE(idfField);
  EXPECT_EQ("125.0",*idfField);

  // returns default for fields behind fields with set values
  idfField = object.getString(2,true);
  ASSERT_TRUE(idfField);
  EXPECT_EQ("0.0",*idfField);
  idfField = object.getString(3,true);
  ASSERT_TRUE(idfField);
  EXPECT_EQ("Fixed",*idfField);

  // returns default for non-existent fields
  idfField = object.getString(6,true);
  EXPECT_FALSE(idfField);
  idfField = object.getString(7,true);
  ASSERT_TRUE(idfField);
  EXPECT_EQ("General",*idfField);
  idfField = object.getString(8,true);
  ASSERT_TRUE(idfField);
  EXPECT_EQ("0.0",*idfField);
  idfField = object.getString(10,true);
  ASSERT_TRUE(idfField);
  EXPECT_EQ("0.0",*idfField);
  idfField = object.getString(11,true);
  EXPECT_FALSE(idfField);

  // EXTENSIBLE OBJECT
  text.str("");
  text << "DaylightingDevice:Tubular," << std::endl
       << "  MyTDD," << std::endl
       << "  MyDome," << std::endl
       << "  MyDiffuser," << std::endl
       << "  MyConstruction," << std::endl
       << "  1.0," << std::endl
       << "  2.0;";
       // \default 0.28
       // Transition Zone 1 Name
       // Transition Zone 1 Length
       // ... (extensible 2)
  oObj = IdfObject::load(text.str());
  ASSERT_TRUE(oObj);
  object = *oObj;
  EXPECT_EQ(6u,object.numFields());

  // returns set values
  idfField = object.getString(0,true);
  ASSERT_TRUE(idfField);
  EXPECT_EQ("MyTDD",*idfField);
  idfField = object.getString(5,true);
  ASSERT_TRUE(idfField);
  EXPECT_EQ("2.0",*idfField);

  // returns default for non-existent, non-extensible fields
  idfField = object.getString(6,true);
  ASSERT_TRUE(idfField);
  EXPECT_EQ("0.28",*idfField);
  EXPECT_EQ(6u,object.numFields());
  idfField = object.getString(6);
  EXPECT_FALSE(idfField);

  StringVector newGroup;
  newGroup.push_back("MyFirstTransistionZone");
  newGroup.push_back("1.5");
  ASSERT_FALSE(object.pushExtensibleGroup(newGroup).empty());

  // returns default for fields behind fields with set values
  idfField = object.getString(6,true);
  ASSERT_TRUE(idfField);
  EXPECT_EQ("0.28",*idfField);
  idfField = object.getString(6);
  ASSERT_TRUE(idfField);
  EXPECT_TRUE(idfField->empty());

  // return evaluates to false for extensible fields that do not exist
  idfField = object.getString(10);
  EXPECT_FALSE(idfField);
}