Ejemplo n.º 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());
}
boost::optional<IdfObject> ForwardTranslator::translateConstruction( Construction & modelObject )
{
  IdfObject construction( openstudio::IddObjectType::Construction );
  m_idfObjects.push_back(construction);

  for (LifeCycleCost lifeCycleCost : modelObject.lifeCycleCosts()){
    translateAndMapModelObject(lifeCycleCost);
  }

  construction.setName(modelObject.name().get());

  MaterialVector layers = modelObject.layers();

  unsigned fieldIndex = 1;
  for(unsigned layerIndex = 0; layerIndex < layers.size(); ++layerIndex ) {
    Material material = layers[layerIndex];
    translateAndMapModelObject(material);
    construction.setString(fieldIndex++, material.name().get());
  }

  return boost::optional<IdfObject>(construction);
}
TEST_F(ModelFixture,ResourceObject_Clone) {
  Model original;
  Construction construction(original);
  construction.standardsInformation();
  StandardOpaqueMaterial material(original);
  bool ok = construction.setLayers(MaterialVector(1u,material));
  EXPECT_TRUE(ok);
  EXPECT_EQ(3u,original.numObjects()) << original;
  EXPECT_EQ(1u,construction.numLayers()) << construction;

  // clone into original
  Construction newConstruction = construction.clone(original).cast<Construction>();
  // self cloned
  EXPECT_FALSE(newConstruction == construction);
  EXPECT_TRUE(newConstruction.model() == construction.model());
  // child cloned
  EXPECT_EQ(2u,original.getModelObjects<StandardsInformationConstruction>().size()) << original;
  EXPECT_FALSE(newConstruction.standardsInformation() == construction.standardsInformation());
  EXPECT_EQ(2u,original.getModelObjects<StandardsInformationConstruction>().size()) << original;
  // resource not cloned
  EXPECT_EQ(1u,newConstruction.numLayers());
  EXPECT_TRUE(newConstruction.layers() == construction.layers());
  EXPECT_EQ(5u,original.numObjects()) << original;

  // clone into new model
  Model newModel;
  newConstruction = construction.clone(newModel).cast<Construction>();
  EXPECT_FALSE(newConstruction.model() == construction.model());
  EXPECT_EQ(3u,newModel.numObjects()) << newModel;
  EXPECT_EQ("Material 1",newConstruction.layers()[0].name().get());
  // clone again -- object and child added again, resource reused
  Construction anotherNewConstruction = construction.clone(newModel).cast<Construction>();
  EXPECT_FALSE(anotherNewConstruction == newConstruction);
  EXPECT_EQ(5u,newModel.numObjects()) << newModel;
  EXPECT_EQ("Material 1",anotherNewConstruction.layers()[0].name().get());
  // change resource data
  newConstruction.layers()[0].setName("Material with Changed Data");
  // clone again -- all added again
  anotherNewConstruction = construction.clone(newModel).cast<Construction>();
  EXPECT_EQ(8u,newModel.numObjects()) << newModel;
  EXPECT_EQ("Material with Changed Data",newConstruction.layers()[0].name().get());
  EXPECT_EQ("Material 1",anotherNewConstruction.layers()[0].name().get());
}
Ejemplo n.º 4
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];
  }

}