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)) );
}
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)) );
}
Ejemplo n.º 3
0
 bool mapFields(const IdfObject& oldObject, IdfObject& newObject, std::vector<std::pair<unsigned, unsigned> > fieldMap)
 {
   bool result = true;
   typedef std::pair<unsigned, unsigned> PairType;
   for (PairType p : fieldMap){
     OptionalString oldStr = oldObject.getString(p.first);
     if (oldStr){
       result = result && newObject.setString(p.second, *oldStr);
     }
   }
   return result;
 }
Ejemplo n.º 4
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;
 }
Ejemplo n.º 5
0
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());
}
Ejemplo n.º 6
0
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);
}
TEST_F(ModelFixture, LifeCycleCost_BadNames)
{
  Model model1;
  Model model2;

  Building building = model1.getUniqueModelObject<Building>();

  {
    boost::optional<LifeCycleCost> cost = LifeCycleCost::createLifeCycleCost("Good Name", building, 1000.0, "CostPerEach", "Construction");
    ASSERT_TRUE(cost);
    EXPECT_EQ("Good Name", cost->nameString());
    ASSERT_TRUE(cost->getString(OS_LifeCycleCostFields::Name));
    EXPECT_EQ("Good Name", cost->getString(OS_LifeCycleCostFields::Name).get());
    IdfObject idfObject = cost->idfObject();
    ASSERT_TRUE(idfObject.getString(OS_LifeCycleCostFields::Name));
    EXPECT_EQ("Good Name", idfObject.getString(OS_LifeCycleCostFields::Name).get());

    std::stringstream ss;
    ss << *cost;
    boost::optional<IdfObject> idf2 = IdfObject::load(ss.str());
    ASSERT_TRUE(idf2);
    ASSERT_TRUE(idf2->getString(OS_LifeCycleCostFields::Name));
    EXPECT_EQ("Good Name", idf2->getString(OS_LifeCycleCostFields::Name).get());

    boost::optional<WorkspaceObject> modelObject = model2.addObject(*idf2);
    ASSERT_TRUE(modelObject);
    EXPECT_EQ("Good Name", modelObject->nameString());
  }

  {
    // &#44;
    boost::optional<LifeCycleCost> cost = LifeCycleCost::createLifeCycleCost("Comma, In, Name", building, 1000.0, "CostPerEach", "Construction");
    ASSERT_TRUE(cost);
    EXPECT_EQ("Comma, In, Name", cost->nameString());
    ASSERT_TRUE(cost->getString(OS_LifeCycleCostFields::Name));
    EXPECT_EQ("Comma, In, Name", cost->getString(OS_LifeCycleCostFields::Name).get());
    IdfObject idfObject = cost->idfObject();
    ASSERT_TRUE(idfObject.getString(OS_LifeCycleCostFields::Name));
    EXPECT_EQ("Comma, In, Name", idfObject.getString(OS_LifeCycleCostFields::Name).get());

    std::stringstream ss;
    ss << *cost;
    boost::optional<IdfObject> idf2 = IdfObject::load(ss.str());
    ASSERT_TRUE(idf2);
    ASSERT_TRUE(idf2->getString(OS_LifeCycleCostFields::Name));
    EXPECT_EQ("Comma, In, Name", idf2->getString(OS_LifeCycleCostFields::Name).get());

    boost::optional<WorkspaceObject> modelObject = model2.addObject(*idf2);
    ASSERT_TRUE(modelObject);
    EXPECT_EQ("Comma, In, Name", modelObject->nameString());
  }

  {
    // &#59;
    boost::optional<LifeCycleCost> cost = LifeCycleCost::createLifeCycleCost("Semicolon; In; Name", building, 1000.0, "CostPerEach", "Construction");
    ASSERT_TRUE(cost);
    EXPECT_EQ("Semicolon; In; Name", cost->nameString());
    ASSERT_TRUE(cost->getString(OS_LifeCycleCostFields::Name));
    EXPECT_EQ("Semicolon; In; Name", cost->getString(OS_LifeCycleCostFields::Name).get());
    IdfObject idfObject = cost->idfObject();
    ASSERT_TRUE(idfObject.getString(OS_LifeCycleCostFields::Name));
    EXPECT_EQ("Semicolon; In; Name", idfObject.getString(OS_LifeCycleCostFields::Name).get());

    std::stringstream ss;
    ss << *cost;
    boost::optional<IdfObject> idf2 = IdfObject::load(ss.str());
    ASSERT_TRUE(idf2);
    ASSERT_TRUE(idf2->getString(OS_LifeCycleCostFields::Name));
    EXPECT_EQ("Semicolon; In; Name", idf2->getString(OS_LifeCycleCostFields::Name).get());

    boost::optional<WorkspaceObject> modelObject = model2.addObject(*idf2);
    ASSERT_TRUE(modelObject);
    EXPECT_EQ("Semicolon; In; Name", modelObject->nameString());
  }

  {
    // &#33;
    boost::optional<LifeCycleCost> cost = LifeCycleCost::createLifeCycleCost("Exclamation! In! Name", building, 1000.0, "CostPerEach", "Construction");
    ASSERT_TRUE(cost);
    EXPECT_EQ("Exclamation! In! Name", cost->nameString());
    ASSERT_TRUE(cost->getString(OS_LifeCycleCostFields::Name));
    EXPECT_EQ("Exclamation! In! Name", cost->getString(OS_LifeCycleCostFields::Name).get());
    IdfObject idfObject = cost->idfObject();
    ASSERT_TRUE(idfObject.getString(OS_LifeCycleCostFields::Name));
    EXPECT_EQ("Exclamation! In! Name", idfObject.getString(OS_LifeCycleCostFields::Name).get());

    std::stringstream ss;
    ss << *cost;
    boost::optional<IdfObject> idf2 = IdfObject::load(ss.str());
    ASSERT_TRUE(idf2);
    ASSERT_TRUE(idf2->getString(OS_LifeCycleCostFields::Name));
    EXPECT_EQ("Exclamation! In! Name", idf2->getString(OS_LifeCycleCostFields::Name).get());

    boost::optional<WorkspaceObject> modelObject = model2.addObject(*idf2);
    ASSERT_TRUE(modelObject);
    EXPECT_EQ("Exclamation! In! Name", modelObject->nameString());
  }

  {
    boost::optional<LifeCycleCost> cost = LifeCycleCost::createLifeCycleCost("Crazy Name [email protected]#$%^&*(),.?;'{}|-_+=<>:\"[]~`", building, 1000.0, "CostPerEach", "Construction");
    ASSERT_TRUE(cost);
    EXPECT_EQ("Crazy Name [email protected]#$%^&*(),.?;'{}|-_+=<>:\"[]~`", cost->nameString());
    ASSERT_TRUE(cost->getString(OS_LifeCycleCostFields::Name));
    EXPECT_EQ("Crazy Name [email protected]#$%^&*(),.?;'{}|-_+=<>:\"[]~`", cost->getString(OS_LifeCycleCostFields::Name).get());
    IdfObject idfObject = cost->idfObject();
    ASSERT_TRUE(idfObject.getString(OS_LifeCycleCostFields::Name));
    EXPECT_EQ("Crazy Name [email protected]#$%^&*(),.?;'{}|-_+=<>:\"[]~`", idfObject.getString(OS_LifeCycleCostFields::Name).get());

    std::stringstream ss;
    ss << *cost;
    boost::optional<IdfObject> idf2 = IdfObject::load(ss.str());
    ASSERT_TRUE(idf2);
    ASSERT_TRUE(idf2->getString(OS_LifeCycleCostFields::Name));
    EXPECT_EQ("Crazy Name [email protected]#$%^&*(),.?;'{}|-_+=<>:\"[]~`", idf2->getString(OS_LifeCycleCostFields::Name).get());

    boost::optional<WorkspaceObject> modelObject = model2.addObject(*idf2);
    ASSERT_TRUE(modelObject);
    EXPECT_EQ("Crazy Name [email protected]#$%^&*(),.?;'{}|-_+=<>:\"[]~`", modelObject->nameString());
  }
}