Ejemplo n.º 1
0
TEST_F(ModelFixture, Construction_AddObjects) {
  IdfFile idfFile; // OpenStudio Idd is default

  // Can still use name references directly in IdfObjects. Will get turned into pointer/by handle
  // references on import into Workspace.
  IdfObject object(IddObjectType::OS_Construction);
  object.setName("Exterior Wall");
  unsigned index = OS_ConstructionFields::SurfaceRenderingName + 1;
  object.setString(index,"M01 100mm brick"); ++index;
  object.setString(index,"M15 200mm heavyweight concrete"); ++index;
  object.setString(index,"I02 50mm insulation board"); ++index;
  object.setString(index,"F04 Wall air space resistance"); ++index;
  object.setString(index,"G01a 19mm gypsum board"); ++index;
  idfFile.addObject(object);

  object = IdfObject(IddObjectType::OS_Material);
  object.setName("M01 100mm brick");
  object.setString(OS_MaterialFields::Roughness,"MediumRough");
  object.setDouble(OS_MaterialFields::Thickness,0.1016);
  object.setDouble(OS_MaterialFields::Conductivity,0.89);
  object.setDouble(OS_MaterialFields::Density,1920.0);
  object.setDouble(OS_MaterialFields::SpecificHeat,790.0);
  idfFile.addObject(object);

  object = IdfObject(IddObjectType::OS_Material);
  object.setName("M15 200mm heavyweight concrete");
  object.setString(OS_MaterialFields::Roughness,"MediumRough");
  object.setDouble(OS_MaterialFields::Thickness,0.2032);
  object.setDouble(OS_MaterialFields::Conductivity,1.95);
  object.setDouble(OS_MaterialFields::Density,2240.0);
  object.setDouble(OS_MaterialFields::SpecificHeat,900.0);
  idfFile.addObject(object);

  object = IdfObject(IddObjectType::OS_Material);
  object.setName("I02 50mm insulation board");
  object.setString(OS_MaterialFields::Roughness,"MediumRough");
  object.setDouble(OS_MaterialFields::Thickness,0.0508);
  object.setDouble(OS_MaterialFields::Conductivity,0.03);
  object.setDouble(OS_MaterialFields::Density,43.0);
  object.setDouble(OS_MaterialFields::SpecificHeat,1210.0);
  idfFile.addObject(object);

  object = IdfObject(IddObjectType::OS_Material_AirGap);
  object.setName("F04 Wall air space resistance");
  object.setDouble(OS_Material_AirGapFields::ThermalResistance,0.15);
  idfFile.addObject(object);

  object = IdfObject(IddObjectType::OS_Material);
  object.setName("G01a 19mm gypsum board");
  object.setString(OS_MaterialFields::Roughness,"MediumSmooth");
  object.setDouble(OS_MaterialFields::Thickness,0.019);
  object.setDouble(OS_MaterialFields::Conductivity,0.16);
  object.setDouble(OS_MaterialFields::Density,800.0);
  object.setDouble(OS_MaterialFields::SpecificHeat,1090.0);
  idfFile.addObject(object);

  // first add to a workspace
  Workspace workspace(StrictnessLevel::Draft, IddFileType::OpenStudio);
  workspace.addObjects(idfFile.objects());
  EXPECT_EQ(workspace.numObjects(), idfFile.numObjects());
  ASSERT_EQ(1u, workspace.getObjectsByType(IddObjectType::OS_Construction).size());
  WorkspaceObject workspaceObject = workspace.getObjectsByType(IddObjectType::OS_Construction)[0];
  ASSERT_EQ(8u, workspaceObject.numFields());
  for (int i = 3; i < 8; ++i){
    EXPECT_FALSE(workspaceObject.isEmpty(i)) << "Index " << i << " is empty for:" << std::endl << workspaceObject;
  }

  // now add to a model
  Model model;
  model.addObjects(idfFile.objects());
  EXPECT_EQ(model.numObjects(), idfFile.numObjects());
  ASSERT_EQ(1u, model.getModelObjects<Construction>().size());
  Construction construction = model.getModelObjects<Construction>()[0];
  ASSERT_EQ(8u, construction.numFields());
  for (int i = 3; i < 8; ++i){
    EXPECT_FALSE(construction.isEmpty(i)) << "Index " << i << " is empty for:" << std::endl << construction;
  }
  ASSERT_EQ(5u, construction.layers().size());
  std::vector<Material> layers = construction.layers();
  for (int i = 0; i < 5; ++i){
    EXPECT_TRUE(layers[i].name()) << "Layer " << i << " has no name:" << std::endl << layers[i];
  }

}