void EnergyPlusPostProcessJob::startImpl(const boost::shared_ptr<ProcessCreator> &)
  {
    openstudio::path outpath = outdir();
    QWriteLocker l(&m_mutex);

    JobErrors errors;
    errors.result = ruleset::OSResultValue::Success;
    
    try {
      m_sql = sqlFile();
      resetFiles(m_files, m_sql);
    } catch (const std::exception &e) {
      std::vector<std::pair<ErrorType, std::string> > err;
      err.push_back(std::make_pair(ErrorType::Error, e.what()));
      errors = JobErrors(ruleset::OSResultValue::Fail, err);
    }

    if (m_sql)
    {
      LOG(Info, "EnergyPlusPostProcess starting, filename: " << toString(m_sql->fullPath));
    }

    LOG(Info, "EnergyPlusPostProcess starting, outdir: " << toString(outpath));

    l.unlock();

    emitStatusChanged(AdvancedStatus(AdvancedStatusEnum::Starting));

    emitStarted();
    emitStatusChanged(AdvancedStatus(AdvancedStatusEnum::Processing));

    if (errors.result == ruleset::OSResultValue::Fail)
    {
      setErrors(errors);
      return;
    }

    SqlFile sqlFile(m_sql->fullPath);


    try {
      boost::filesystem::create_directories(outpath);

      std::vector<Attribute> attributes = PostProcessReporting::go(sqlFile);

      if (attributes.empty())
      {
        LOG(Warn, "No attributes loaded for report");
      }

      Attribute report("Report", attributes);
      bool result = report.saveToXml(outpath / openstudio::toPath("report.xml"));
      if (!result){
        LOG_AND_THROW("Failed to write report.xml");
      }

    } catch (const std::exception &e) {
      LOG(Error, "Error with EnergyPlusPostProcessJob: " + std::string(e.what()));
      errors.addError(ErrorType::Error, "Error with EnergyPlusPostProcessJob: " + std::string(e.what()));
      errors.result = ruleset::OSResultValue::Fail;
    }

    // Change this to whatever output files you generate
    emitOutputFileChanged(RunManager_Util::dirFile(outpath / openstudio::toPath("report.xml")));
    setErrors(errors);
  }
Exemplo n.º 2
0
  void ModelToRadJob::startImpl(const std::shared_ptr<ProcessCreator> &)
  {
    openstudio::path outpath = outdir();
    QWriteLocker l(&m_mutex);
    JobErrors errors;
    errors.result = ruleset::OSResultValue::Success;
    
    try {
      if (!m_model)
      {
        m_model = modelFile();
      }
      if (!m_sql)
      {
        m_sql = sqlFile();
      }

      resetFiles(m_files, m_model);
    } catch (const std::runtime_error &e) {
      errors.result = ruleset::OSResultValue::Fail;
      errors.addError(ErrorType::Error, e.what());
    }

    if (!m_sql || !m_model)
    {
      errors.result = ruleset::OSResultValue::Fail;
      errors.addError(ErrorType::Error, "Unable to find required model or sql file");
    }

    LOG(Info, "ModelToRad starting, filename: " << toString(m_model->fullPath));
    LOG(Info, "ModelToRad starting, outdir: " << toString(outpath));

    l.unlock();

    emitStatusChanged(AdvancedStatus(AdvancedStatusEnum::Starting));

    emitStarted();
    emitStatusChanged(AdvancedStatus(AdvancedStatusEnum::Processing));

    if (errors.result == ruleset::OSResultValue::Fail)
    {
      setErrors(errors);
      return;
    }


    try {
      boost::filesystem::create_directories(outpath);

      //
      // setup
      //
      LOG(Debug, "Working Directory: " + openstudio::toString(outpath));

      // get model
      boost::optional<openstudio::IdfFile> idf = openstudio::IdfFile::load(m_model->fullPath);
      openstudio::model::Model model = openstudio::model::Model(idf.get());

      // load the sql file
      openstudio::SqlFile sqlFile(m_sql->fullPath);

      if (!sqlFile.connectionOpen())
      {
        LOG(Error, "SqlFile connection is not open");
        errors.result = ruleset::OSResultValue::Fail;
        errors.addError(ErrorType::Error, "SqlFile collection is not open");
        setErrors(errors);
        return;
      }

      // set the sql file
      model.setSqlFile(sqlFile);
      if (!model.sqlFile())
      {
        LOG(Error, "SqlFile is not set on model");
        errors.result = ruleset::OSResultValue::Fail;
        errors.addError(ErrorType::Error, "SqlFile is not set on model");
        setErrors(errors);
        return;
      }

      openstudio::radiance::ForwardTranslator ft;
      std::vector<openstudio::path> outfiles = ft.translateModel(outpath, model);
      
      Files outfileinfos;

      for (std::vector<openstudio::path>::const_iterator itr = outfiles.begin();
          itr != outfiles.end();
          ++itr)
      {
        FileInfo fi = RunManager_Util::dirFile(*itr);
        LOG(Info, "Output file generated: " << openstudio::toString(fi.fullPath));
        emitOutputFileChanged(fi);
        outfileinfos.append(fi);
      }

      // capture translator errors and warnings
      std::vector<openstudio::LogMessage> logwarnings = ft.warnings();
      std::vector<openstudio::LogMessage> logerrors = ft.errors();

      for (std::vector<openstudio::LogMessage>::const_iterator itr = logwarnings.begin();
          itr != logwarnings.end();
          ++itr)
      {
        errors.addError(ErrorType::Warning, itr->logMessage());
      }

      for (std::vector<openstudio::LogMessage>::const_iterator itr = logerrors.begin();
          itr != logerrors.end();
          ++itr)
      {
        errors.addError(ErrorType::Error, itr->logMessage());
      }

      if (!errors.errors().empty())
      {
        errors.result = ruleset::OSResultValue::Fail;
      }
      setErrors(errors);

      l.relock();
      m_outputfiles = outfileinfos;

    } catch (const std::runtime_error &e) {
      errors.addError(ErrorType::Error, "Error with conversion (runtime_error): " + std::string(e.what()));
      errors.result = ruleset::OSResultValue::Fail;
    }
    catch (const std::exception &e) {
      errors.addError(ErrorType::Error, "Error with conversion: " + std::string(e.what()));
      errors.result = ruleset::OSResultValue::Fail;
    }

    setErrors(errors);
  }
  void OpenStudioPostProcessJob::startImpl(const std::shared_ptr<ProcessCreator> &)
  {
    QWriteLocker l(&m_mutex);

    JobErrors errors;
    errors.result = ruleset::OSResultValue::Success;
    
    try {
      m_sql = sqlFile();
      m_osm = osmFile();
      resetFiles(m_files, m_sql, m_osm);
    } catch (const std::exception &e) {
      JobErrors error;
      error.result = ruleset::OSResultValue::Fail;
      error.addError(ErrorType::Error, e.what());
      errors = error;
    }


    if (m_sql)
    {
      LOG(Info, "OpenStudioPostProcess starting, filename: " << toString(m_sql->fullPath));
    }

    LOG(Info, "OpenStudioPostProcess starting, outdir: " << toString(outdir()));

    l.unlock();

    emitStatusChanged(AdvancedStatus(AdvancedStatusEnum::Starting));

    emitStarted();
    emitStatusChanged(AdvancedStatus(AdvancedStatusEnum::Processing));

    if (errors.result == ruleset::OSResultValue::Fail)
    {
      setErrors(errors);
      return;
    }

    try {
      SqlFile sqlFile(m_sql->fullPath);

      boost::optional<openstudio::model::Model> model = model::Model::load(m_osm->fullPath);

      if (!model)
      {
        throw std::runtime_error("Unable to load model file from " + openstudio::toString(m_osm->fullPath));
      }

      model->setSqlFile(sqlFile);

      boost::filesystem::create_directories(outdir(true));

      std::vector<Attribute> attributes = PostProcessReporting::go(sqlFile,"OpenStudioPostProcess");

      // ETH@20140219 - Not great to add an object here either, but needed for
      // Facility, and Building is really the same case. (If get this far with 
      // simulation, no harm in accessing data through Building, which has 
      // smart defaults for all fields.)
      model::Building building = model->getUniqueModelObject<model::Building>();
      LOG(Debug,"Extracting attributes from model::Building.");
      boost::optional<Attribute> attribute;
      
      boost::optional<double> value = building.floorArea();
      if (value){
        attribute = Attribute("floorArea", *value, "m^2");
        attribute->setDisplayName("Floor Area");
        attributes.push_back(*attribute);
        attributes.back().setSource("OpenStudioPostProcess");
      }

      value = building.conditionedFloorArea();
      if (value){
        attribute = Attribute("conditionedFloorArea", *value, "m^2");
        attribute->setDisplayName("Conditioned Floor Area");
        attributes.push_back(*attribute);
        attributes.back().setSource("OpenStudioPostProcess");
      }

      // ETH@20140218 - Not great to add an object here, but otherwise, do not get 
      // calibration results table in PAT.
      model::Facility facility = model->getUniqueModelObject<model::Facility>();
      LOG(Debug,"Extracting attributes from model::Facility.");     

      value = facility.economicsCapitalCost();
      if (value){
        attribute = Attribute("economicsCapitalCost", *value, "$");
        attribute->setDisplayName("Capital Cost");
        attributes.push_back(*attribute);
        attributes.back().setSource("OpenStudioPostProcess");
      }

      value = facility.economicsTLCC();
      if (value){
        attribute = Attribute("economicsTLCC", *value, "$");
        attribute->setDisplayName("Total Life Cycle Cost");
        attributes.push_back(*attribute);
        attributes.back().setSource("OpenStudioPostProcess");
      }

      value = facility.annualWaterTotalCost();
      if (value){
        attribute = Attribute("annualWaterTotalCost", *value, "$");
        attribute->setDisplayName("Annual Water Total Cost");
        attributes.push_back(*attribute);
        attributes.back().setSource("OpenStudioPostProcess");
      }

      attribute = facility.endUsesAttribute();
      if (attribute){
        attributes.push_back(*attribute);
        attributes.back().setSource("OpenStudioPostProcess");
      }

      attribute = facility.calibrationResultAttribute();
      if (attribute){
        attributes.push_back(*attribute);
        attributes.back().setSource("OpenStudioPostProcess");
      }

      if (attributes.empty())
      {
        LOG(Warn, "No attributes loaded for report");
      }

      Attribute report("Report", attributes);
      bool result = report.saveToXml(outdir() / openstudio::toPath("report.xml"));
      if (!result){
        LOG_AND_THROW("Failed to write report.xml");
      }

    } catch (const std::exception &e) {
      LOG(Error, "Error with OpenStudioPostProcessJob: " + std::string(e.what()));
      errors.addError(ErrorType::Error, "Error with OpenStudioPostProcessJob: " + std::string(e.what()));
      errors.result = ruleset::OSResultValue::Fail;
    }

    // Change this to whatever output files you generate
    emitOutputFileChanged(RunManager_Util::dirFile(outdir() / openstudio::toPath("report.xml")));
    setErrors(errors);
  }
Exemplo n.º 4
0
  void IdfToModelJob::startImpl(const boost::shared_ptr<ProcessCreator> &)
  {
    openstudio::path outpath = outdir(true);

    QWriteLocker l(&m_mutex);
    if (!m_idf)
    {
      m_idf = idfFile();
      resetFiles(m_files, m_idf);
    }

    LOG(Info, "IdfToModel starting, filename: " << toString(m_idf->fullPath));
    LOG(Info, "IdfToModel starting, outdir: " << toString(outpath));

    JobErrors errors;
    errors.result = ruleset::OSResultValue::Success;
    l.unlock();

    emitStatusChanged(AdvancedStatus(AdvancedStatusEnum::Starting));

    emitStarted();
    emitStatusChanged(AdvancedStatus(AdvancedStatusEnum::Processing));

    openstudio::energyplus::ReverseTranslator rt;

    try {
      boost::filesystem::create_directories(outpath);

      LOG(Debug, "Loading input file: " + toString(m_idf->fullPath));

      boost::optional<openstudio::model::Model> model;
      boost::optional<openstudio::Workspace> workspace = openstudio::Workspace::load(m_idf->fullPath);
      if (workspace){
        model = rt.translateWorkspace(*workspace);
      }

      OS_ASSERT(model);

      openstudio::path outfile = outpath / openstudio::toPath("out.osm");

      LOG(Debug, "Saving to path: " + toString(outfile));
      model->save(outfile, true);
      emitOutputFileChanged(RunManager_Util::dirFile(outfile));

    } catch (const std::exception &e) {
      LOG(Error, std::string("Error with IdfToModel translation: ") + e.what());
      errors.addError(ErrorType::Error, "Error with conversion: " + std::string(e.what()));
      errors.result = ruleset::OSResultValue::Fail;
    }

    std::vector<openstudio::LogMessage> logwarnings = rt.warnings();
    std::vector<openstudio::LogMessage> logerrors = rt.errors();

    for (std::vector<openstudio::LogMessage>::const_iterator itr = logwarnings.begin();
        itr != logwarnings.end();
        ++itr)
    {
      errors.addError(ErrorType::Warning, itr->logMessage());
    }

    for (std::vector<openstudio::LogMessage>::const_iterator itr = logerrors.begin();
        itr != logerrors.end();
        ++itr)
    {
      errors.addError(ErrorType::Error, itr->logMessage());
    }

    setErrors(errors);
  }
Exemplo n.º 5
0
  void ModelInModelOutJob::startImpl(const std::shared_ptr<ProcessCreator> &)
  {
    openstudio::path outpath = outdir(true);

    QWriteLocker l(&m_mutex);
    if (!m_model)
    {
      m_model = modelFile();
      resetFiles(m_files, m_model);
    }

    std::vector<std::shared_ptr<ModelInModelOutJob> > mergedJobs = m_mergedJobs;
    boost::optional<FileInfo> model = m_model;

    LOG(Info, "ModelInModelOut starting, filename: " << toString(m_model->fullPath));
    LOG(Info, "ModelInModelOut starting, outdir: " << toString(outpath));
    LOG(Info, "ModelInModelOut starting, num merged jobs: " << m_mergedJobs.size());

    m_lastrun = QDateTime::currentDateTime();
    JobErrors errors;
    errors.result = ruleset::OSResultValue::Success;
    l.unlock();

    emitStatusChanged(AdvancedStatus(AdvancedStatusEnum::Starting));

    emitStarted();
    emitStatusChanged(AdvancedStatus(AdvancedStatusEnum::Processing));

    try {
      boost::filesystem::create_directories(outpath);

      model::OptionalModel m = model::Model::load(model->fullPath);

      if (!m)
      {
        errors.addError(ErrorType::Error, "Unable to load model: " + toString(model->fullPath));
        errors.result = ruleset::OSResultValue::Fail;
      } else {
        LOG(Info, "ModelInModelOut executing primary job");
        model::Model outmodel = modelToModelRun(*m);

        for (const auto & mergedJob : mergedJobs)
        {
          LOG(Info, "ModelInModelOut executing merged job");
          outmodel = mergedJob->modelToModelRun(outmodel);
        }

        openstudio::path outFile = outpath / toPath("out.osm");
        if (!outmodel.save(outFile,true))
        {
          errors.addError(ErrorType::Error, "Error while writing final output file");
          errors.result = ruleset::OSResultValue::Fail;
        }
      }
    } catch (const std::exception &e) {
      errors.addError(ErrorType::Error, "Error with processing: " + std::string(e.what()));
      errors.result = ruleset::OSResultValue::Fail;
    }

    emitOutputFileChanged(RunManager_Util::dirFile(outpath / openstudio::toPath("out.osm")));
    setErrors(errors);
  }
  void OpenStudioPostProcessJob::startImpl(const boost::shared_ptr<ProcessCreator> &)
  {
    QWriteLocker l(&m_mutex);

    JobErrors errors;
    errors.result = ruleset::OSResultValue::Success;
    
    try {
      m_sql = sqlFile();
      m_osm = osmFile();
      resetFiles(m_files, m_sql, m_osm);
    } catch (const std::exception &e) {
      JobErrors error;
      error.result = ruleset::OSResultValue::Fail;
      error.addError(ErrorType::Error, e.what());
      errors = error;
    }


    if (m_sql)
    {
      LOG(Info, "OpenStudioPostProcess starting, filename: " << toString(m_sql->fullPath));
    }

    LOG(Info, "OpenStudioPostProcess starting, outdir: " << toString(outdir()));

    l.unlock();

    emitStatusChanged(AdvancedStatus(AdvancedStatusEnum::Starting));

    emitStarted();
    emitStatusChanged(AdvancedStatus(AdvancedStatusEnum::Processing));

    if (errors.result == ruleset::OSResultValue::Fail)
    {
      setErrors(errors);
      return;
    }

    try {
      SqlFile sqlFile(m_sql->fullPath);

      boost::optional<openstudio::model::Model> model = model::Model::load(m_osm->fullPath);

      if (!model)
      {
        throw std::runtime_error("Unable to load model file from " + openstudio::toString(m_osm->fullPath));
      }

      model->setSqlFile(sqlFile);

      boost::filesystem::create_directories(outdir(true));

      std::vector<Attribute> attributes = PostProcessReporting::go(sqlFile);

      boost::optional<model::Building> building = model->getOptionalUniqueModelObject<model::Building>();
      if (building)
      {
        LOG(Debug,"Extracting attributes from model::Building.");
        boost::optional<Attribute> attribute = building->getAttribute("floorArea");
        if (attribute){
          attribute->setDisplayName("Floor Area");
          attribute->setUnits("m^2");
          attributes.push_back(*attribute);
        }

        attribute = building->getAttribute("conditionedFloorArea");
        if (attribute){
          attribute->setDisplayName("Conditioned Floor Area");
          attribute->setUnits("m^2");
          attributes.push_back(*attribute);
        }
      }

      boost::optional<model::Facility> facility = model->getOptionalUniqueModelObject<model::Facility>();
      if (facility){
        LOG(Debug,"Extracting attributes from model::Facility.");      
        boost::optional<Attribute> attribute = facility->getAttribute("economicsCapitalCost");
        if (attribute){
          attribute->setDisplayName("Capital Cost");
          attribute->setUnits("$");
          attributes.push_back(*attribute);
        }

        attribute = facility->getAttribute("economicsTLCC");
        if (attribute){
          attribute->setDisplayName("Total Life Cycle Cost");
          attribute->setUnits("$");
          attributes.push_back(*attribute);
        }
        attribute = facility->getAttribute("annualWaterTotalCost");
        if (attribute){
          attribute->setDisplayName("Annual Water Total Cost");
          attribute->setUnits("$");
          attributes.push_back(*attribute);
        }

        attribute = facility->getAttribute("endUsesAttribute");
        if (attribute){
          attributes.push_back(*attribute);
        }
      }

      boost::optional<model::TimeDependentValuation> timeDependentValuation = model->getOptionalUniqueModelObject<model::TimeDependentValuation>();
      if (timeDependentValuation){
        LOG(Debug,"Extracting attributes from model::TimeDependentValuation.");      
        boost::optional<Attribute> attribute = timeDependentValuation->getAttribute("energyTimeDependentValuation");
        if (attribute){
          attribute->setDisplayName("Energy Time Dependent Valuation");
          attribute->setUnits("J");
          attributes.push_back(*attribute);
        }
        attribute = timeDependentValuation->getAttribute("costTimeDependentValuation");
        if (attribute){
          attribute->setDisplayName("Cost Time Dependent Valuation");
          attribute->setUnits("$");
          attributes.push_back(*attribute);
        }
      }

      if (attributes.empty())
      {
        LOG(Warn, "No attributes loaded for report");
      }

      Attribute report("Report", attributes);
      bool result = report.saveToXml(outdir() / openstudio::toPath("report.xml"));
      if (!result){
        LOG_AND_THROW("Failed to write report.xml");
      }

    } catch (const std::exception &e) {
      LOG(Error, "Error with OpenStudioPostProcessJob: " + std::string(e.what()));
      errors.addError(ErrorType::Error, "Error with OpenStudioPostProcessJob: " + std::string(e.what()));
      errors.result = ruleset::OSResultValue::Fail;
    }

    // Change this to whatever output files you generate
    emitOutputFileChanged(RunManager_Util::dirFile(outdir() / openstudio::toPath("report.xml")));
    setErrors(errors);
  }