Ejemplo n.º 1
0
TEST_F(ModelFixture, ComponentWatcher_BadComponentDataFromWorkspace) {
  Workspace ws;
  OptionalWorkspaceObject owo = ws.addObject(IdfObject(IddObjectType::OS_ComponentData));
  ASSERT_TRUE(owo);
  // make component data ok except points to non-existent object
  WorkspaceObject cd = *owo;
  OptionalString oName = cd.name(); // should have been set by constructor
  ASSERT_TRUE(oName);
  EXPECT_FALSE(oName->empty());
  cd.setString(OS_ComponentDataFields::UUID,toString(createUUID()));
  cd.setString(OS_ComponentDataFields::VersionUUID,toString(createUUID()));
  StringVector values;
  values.push_back("My Material");
  IdfExtensibleGroup eg = cd.pushExtensibleGroup(values);
  EXPECT_TRUE(eg.empty()); // Cannot register a bad pointer.

  EXPECT_EQ(1u,ws.numObjects());
  Model model(ws);
  // expect ComponentWatcher creation to kick out ComponentData
  EXPECT_EQ(0u,model.numObjects());
}
Ejemplo n.º 2
0
Model ReverseTranslator::translateWorkspace(const Workspace & workspace, ProgressBar* progressBar )
{
  // check input
  if (workspace.iddFileType() != IddFileType::EnergyPlus){
    LOG(Error, "Cannot translate Workspace with IddFileType = '" << workspace.iddFileType().valueName() << "'");
    return Model();
  }

  m_model = Model();
  m_model.setFastNaming(true);

  m_workspace = workspace.clone();

  m_workspaceToModelMap.clear();

  m_untranslatedIdfObjects.clear();

  m_logSink.resetStringStream();

  // if multiple runperiod objects in idf, remove them all
  vector<WorkspaceObject> runPeriods = m_workspace.getObjectsByType(IddObjectType::RunPeriod);
  if (runPeriods.size() > 1){
    for(auto & runPeriod : runPeriods)
    {
      runPeriod.remove();
    }
  }

  // first thing to do is convert geometry system
  m_logSink.setChannelRegex(boost::regex("openstudio\\.energyplus\\.GeometryTranslator"));

  m_progressBar = progressBar;
  if (m_progressBar){
    m_progressBar->setMinimum(0);
    m_progressBar->setMaximum(workspace.numObjects());
  }

  LOG(Trace,"Calling geometry translator.");
  GeometryTranslator geometryTranslator(m_workspace);
  geometryTranslator.convert(CoordinateSystem::Relative, CoordinateSystem::Relative);

  m_logSink.setChannelRegex(boost::regex("openstudio\\.energyplus\\.ReverseTranslator"));

  // look for site object in workspace and translate if found
  LOG(Trace,"Translating Site:Location object.");
  vector<WorkspaceObject> site = m_workspace.getObjectsByType(IddObjectType::Site_Location);
  for(auto & elem : site)
  {
    translateAndMapWorkspaceObject(elem);
  }

  // look for simulation control object in workspace and translate if found
  LOG(Trace,"Translating SimulationControl object.");
  vector<WorkspaceObject> simulationControl = m_workspace.getObjectsByType(IddObjectType::SimulationControl);
  for(auto & elem : simulationControl)
  {
    translateAndMapWorkspaceObject(elem);
  }

  // loop over all of the air loops
  LOG(Trace,"Translating AirLoops.");
  vector<WorkspaceObject> airLoops = m_workspace.getObjectsByType(IddObjectType::AirLoopHVAC);
  for(auto it = airLoops.begin(),iend=airLoops.end();it!=iend;++it)
  {
    LOG(Trace,"Translating AirLoop '" << it->name().get() << "'.");
    translateAndMapWorkspaceObject( *it );
  }

  // Now loop over all objects to make sure nothing as missed.
  // In the future this might be removed.
  LOG(Trace,"Translating remaining objects.");
  vector<WorkspaceObject> all = m_workspace.objects();
  for(auto & elem : all)
  {
    translateAndMapWorkspaceObject( elem );
  }

  LOG(Trace,"Translation nominally complete.");
  m_model.setFastNaming(false);
  return m_model;
}