示例#1
0
  void NullJob::startImpl(const std::shared_ptr<ProcessCreator> &)
  {
    LOG(Info, "Null starting");

    {
      QMutexLocker l(&m_mutex);
    }

    emitStatusChanged(AdvancedStatus(AdvancedStatusEnum::Starting));

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

    openstudio::path outpath;
    try {
      outpath = outdir(true);
      boost::filesystem::create_directories(outpath);
      setErrors(JobErrors(ruleset::OSResultValue::Success, std::vector<std::pair<runmanager::ErrorType, std::string> >() ));
    } catch (const std::exception &e) {
      LOG(Error, "NullJob error starting job: " << e.what() << ". Job path is: " 
          << toString(outpath));
      std::vector<std::pair<runmanager::ErrorType, std::string> > err;
      err.push_back(std::make_pair(runmanager::ErrorType::Error, e.what()));
      setErrors(JobErrors(ruleset::OSResultValue::Fail, err));
    }

  }
  void ParallelEnergyPlusSplitJob::startImpl(const std::shared_ptr<ProcessCreator> &)
  {
    openstudio::path outpath = outdir();
    QWriteLocker l(&m_mutex);
    if (!m_input)
    {
      m_input = inputFile();
      resetFiles(m_files, m_input);
    }

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

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

    emitStatusChanged(AdvancedStatus(AdvancedStatusEnum::Starting));

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

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

      FileInfo inputfile = inputFile();
      openstudio::path input = inputfile.fullPath;
      LOG(Debug, "Splitting inputfile: " << toString(input) << " into " << m_numSplits << " parts");
      std::vector<openstudio::path> outfilepaths = generateFileNames(outpath, m_numSplits);

      ParallelEnergyPlus p(input, m_numSplits, m_offset);

      for (int i = 0; i < m_numSplits; ++i)
      {
        p.writePartition(i, outfilepaths[i]);
        emitOutputFileChanged(RunManager_Util::dirFile(outfilepaths[i]));
      }


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

    setErrors(errors);
  }
示例#3
0
  void LocalProcess::processFinished(int t_exitCode, QProcess::ExitStatus t_exitStatus)
  {
    m_fileCheckTimer.stop();

    directoryChanged(openstudio::toQString(m_outdir));
    emitStatusChanged(AdvancedStatus(AdvancedStatusEnum::Finishing));

    if (!stopped())
    {
      handleOutput(m_process.readAllStandardOutput(), false);
      handleOutput(m_process.readAllStandardError(), true);
    }

    QCoreApplication::processEvents();
    directoryChanged(openstudio::toQString(m_outdir));

    emit finished(t_exitCode, t_exitStatus);
    emitStatusChanged(AdvancedStatus(AdvancedStatusEnum::Idle));
  }
示例#4
0
  void LocalProcess::processStarted()
  {
    // Send stdin input meant for process
    emitStatusChanged(AdvancedStatus(AdvancedStatusEnum::Processing));
    emit started();
    directoryChanged(openstudio::toQString(m_outdir));

    // If there is stdin to write and the process has not already finished by the time we process
    // this signal...
    if (!m_stdin.empty() && m_process.state() != QProcess::Running)
    {
      // write the stdin
      m_process.write(m_stdin.c_str(), m_stdin.size());
    }
  }
示例#5
0
  void LocalProcess::processZombied(QProcess::ProcessError /*t_e*/)
  {
    m_fileCheckTimer.stop();

    LOG(Info, "Process appears to be zombied"); 

    // but this isn't necessarily an error because it's probably due to miscaught signals.
    //emit error(t_e);

    QCoreApplication::processEvents();
    directoryChanged(openstudio::toQString(m_outdir));

    emit finished(0, QProcess::NormalExit);
    emitStatusChanged(AdvancedStatus(AdvancedStatusEnum::Idle));

  }
  void EnergyPlusPreProcessJob::startImpl(const boost::shared_ptr<ProcessCreator> &)
  {
    openstudio::path outpath = outdir();

    QWriteLocker l(&m_mutex);

    JobErrors errors;
    errors.result = ruleset::OSResultValue::Success;

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

    LOG(Info, "EnergyPlusPreProcess 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(outdir(true));

      bool needssqlobj = false;
      bool needsmonthlyoutput = false;


      {
        boost::optional<openstudio::Workspace> ws = openstudio::Workspace::load(m_idf->fullPath);

        if (!ws){
          LOG_AND_THROW("Unable to load idf into workspace");
        }

        std::vector<openstudio::WorkspaceObject> sqliteobjs = ws->getObjectsByType(IddObjectType::Output_SQLite);

        if (sqliteobjs.empty())
        {
          //          ws->addObject(IdfObject(IddObjectType::Output_SQLite));
          needssqlobj = true;
          //          sqliteobjs = ws->getObjectsByType(IddObjectType::Output_SQLite);
        }

        if (ws->getObjectsByName("Building Energy Performance - Natural Gas").empty()
            || ws->getObjectsByName("Building Energy Performance - Electricity").empty()
            || ws->getObjectsByName("Building Energy Performance - District Heating").empty()
            || ws->getObjectsByName("Building Energy Performance - District Cooling").empty()
           )
        {
          needsmonthlyoutput = true;
        }
      }

      if (needssqlobj || needsmonthlyoutput)
      {
        openstudio::path outfile = outdir(true)/openstudio::toPath("out.idf");

        if (boost::filesystem::exists(outfile))
        {
          try {
            boost::filesystem::remove(outfile);
          } catch (const boost::filesystem::basic_filesystem_error<openstudio::path> &e) {
            LOG(Error, "Error removing existing out.idf file: " + std::string(e.what()) + " continuing with run, if copy_file errors, the process will fail");
          }
        }

        boost::filesystem::copy_file(m_idf->fullPath, outfile, boost::filesystem::copy_option::overwrite_if_exists);
        std::ofstream ofs(openstudio::toString(outfile).c_str(), std::ios::app);

        if (needssqlobj)
        {
          ofs << "Output:SQLite," << std::endl;
          ofs << "  SimpleAndTabular;         ! Option Type" << std::endl;
        }

        if (needsmonthlyoutput)
        {
          //energy consumption

          ofs << "Output:Table:Monthly," << std::endl;
          ofs << "  Building Energy Performance - Electricity,  !- Name" << std::endl;
          ofs << "    2,                       !- Digits After Decimal" << std::endl;
          ofs << "    InteriorLights:Electricity,  !- Variable or Meter 1 Name" << std::endl;
          ofs << "    SumOrAverage,            !- Aggregation Type for Variable or Meter 1" << std::endl;
          ofs << "    ExteriorLights:Electricity,  !- Variable or Meter 2 Name" << std::endl;
          ofs << "    SumOrAverage,            !- Aggregation Type for Variable or Meter 2" << std::endl;
          ofs << "    InteriorEquipment:Electricity,  !- Variable or Meter 3 Name" << std::endl;
          ofs << "    SumOrAverage,            !- Aggregation Type for Variable or Meter 3" << std::endl;
          ofs << "    ExteriorEquipment:Electricity,  !- Variable or Meter 4 Name" << std::endl;
          ofs << "    SumOrAverage,            !- Aggregation Type for Variable or Meter 4" << std::endl;
          ofs << "    Fans:Electricity,        !- Variable or Meter 5 Name" << std::endl;
          ofs << "    SumOrAverage,            !- Aggregation Type for Variable or Meter 5" << std::endl;
          ofs << "    Pumps:Electricity,       !- Variable or Meter 6 Name" << std::endl;
          ofs << "    SumOrAverage,            !- Aggregation Type for Variable or Meter 6" << std::endl;
          ofs << "    Heating:Electricity,     !- Variable or Meter 7 Name" << std::endl;
          ofs << "    SumOrAverage,            !- Aggregation Type for Variable or Meter 7" << std::endl;
          ofs << "    Cooling:Electricity,     !- Variable or Meter 8 Name" << std::endl;
          ofs << "    SumOrAverage,            !- Aggregation Type for Variable or Meter 8" << std::endl;
          ofs << "    HeatRejection:Electricity,  !- Variable or Meter 9 Name" << std::endl;
          ofs << "    SumOrAverage,            !- Aggregation Type for Variable or Meter 9" << std::endl;
          ofs << "    Humidifier:Electricity,  !- Variable or Meter 10 Name" << std::endl;
          ofs << "    SumOrAverage,            !- Aggregation Type for Variable or Meter 10" << std::endl;
          ofs << "    HeatRecovery:Electricity,!- Variable or Meter 11 Name" << std::endl;
          ofs << "    SumOrAverage,            !- Aggregation Type for Variable or Meter 11" << std::endl;
          ofs << "    WaterSystems:Electricity,!- Variable or Meter 12 Name" << std::endl;
          ofs << "    SumOrAverage,            !- Aggregation Type for Variable or Meter 12" << std::endl;
          ofs << "    Cogeneration:Electricity,!- Variable or Meter 13 Name" << std::endl;
          ofs << "    SumOrAverage,            !- Aggregation Type for Variable or Meter 13" << std::endl;
          ofs << "    Refrigeration:Electricity,!- Variable or Meter 14 Name" << std::endl;
          ofs << "    SumOrAverage;            !- Aggregation Type for Variable or Meter 14" << std::endl;

          ofs << "Output:Table:Monthly," << std::endl;
          ofs << "  Building Energy Performance - Natural Gas,  !- Name" << std::endl;
          ofs << "    2,                       !- Digits After Decimal" << std::endl;
          ofs << "    InteriorEquipment:Gas,   !- Variable or Meter 1 Name" << std::endl;
          ofs << "    SumOrAverage,            !- Aggregation Type for Variable or Meter 1" << std::endl;
          ofs << "    ExteriorEquipment:Gas,   !- Variable or Meter 2 Name" << std::endl;
          ofs << "    SumOrAverage,            !- Aggregation Type for Variable or Meter 2" << std::endl;
          ofs << "    Heating:Gas,             !- Variable or Meter 3 Name" << std::endl;
          ofs << "    SumOrAverage,            !- Aggregation Type for Variable or Meter 3" << std::endl;
          ofs << "    Cooling:Gas,             !- Variable or Meter 4 Name" << std::endl;
          ofs << "    SumOrAverage,            !- Aggregation Type for Variable or Meter 4" << std::endl;
          ofs << "    WaterSystems:Gas,        !- Variable or Meter 5 Name" << std::endl;
          ofs << "    SumOrAverage,            !- Aggregation Type for Variable or Meter 5" << std::endl;
          ofs << "    Cogeneration:Gas,        !- Variable or Meter 6 Name" << std::endl;
          ofs << "    SumOrAverage;            !- Aggregation Type for Variable or Meter 6" << std::endl;

          ofs << "Output:Table:Monthly," << std::endl;
          ofs << "  Building Energy Performance - District Heating,  !- Name" << std::endl;
          ofs << "    2,                       !- Digits After Decimal" << std::endl;
          ofs << "    InteriorLights:DistrictHeating,  !- Variable or Meter 1 Name" << std::endl;
          ofs << "    SumOrAverage,            !- Aggregation Type for Variable or Meter 1" << std::endl;
          ofs << "    ExteriorLights:DistrictHeating,  !- Variable or Meter 2 Name" << std::endl;
          ofs << "    SumOrAverage,            !- Aggregation Type for Variable or Meter 2" << std::endl;
          ofs << "    InteriorEquipment:DistrictHeating,  !- Variable or Meter 3 Name" << std::endl;
          ofs << "    SumOrAverage,            !- Aggregation Type for Variable or Meter 3" << std::endl;
          ofs << "    ExteriorEquipment:DistrictHeating,  !- Variable or Meter 4 Name" << std::endl;
          ofs << "    SumOrAverage,            !- Aggregation Type for Variable or Meter 4" << std::endl;
          ofs << "    Fans:DistrictHeating,        !- Variable or Meter 5 Name" << std::endl;
          ofs << "    SumOrAverage,            !- Aggregation Type for Variable or Meter 5" << std::endl;
          ofs << "    Pumps:DistrictHeating,       !- Variable or Meter 6 Name" << std::endl;
          ofs << "    SumOrAverage,            !- Aggregation Type for Variable or Meter 6" << std::endl;
          ofs << "    Heating:DistrictHeating,     !- Variable or Meter 7 Name" << std::endl;
          ofs << "    SumOrAverage,            !- Aggregation Type for Variable or Meter 7" << std::endl;
          ofs << "    Cooling:DistrictHeating,     !- Variable or Meter 8 Name" << std::endl;
          ofs << "    SumOrAverage,            !- Aggregation Type for Variable or Meter 8" << std::endl;
          ofs << "    HeatRejection:DistrictHeating,  !- Variable or Meter 9 Name" << std::endl;
          ofs << "    SumOrAverage,            !- Aggregation Type for Variable or Meter 9" << std::endl;
          ofs << "    Humidifier:DistrictHeating,  !- Variable or Meter 10 Name" << std::endl;
          ofs << "    SumOrAverage,            !- Aggregation Type for Variable or Meter 10" << std::endl;
          ofs << "    HeatRecovery:DistrictHeating,!- Variable or Meter 11 Name" << std::endl;
          ofs << "    SumOrAverage,            !- Aggregation Type for Variable or Meter 11" << std::endl;
          ofs << "    WaterSystems:DistrictHeating,!- Variable or Meter 12 Name" << std::endl;
          ofs << "    SumOrAverage,            !- Aggregation Type for Variable or Meter 12" << std::endl;
          ofs << "    Cogeneration:DistrictHeating,!- Variable or Meter 13 Name" << std::endl;
          ofs << "    SumOrAverage;            !- Aggregation Type for Variable or Meter 13" << std::endl;

          ofs << "Output:Table:Monthly," << std::endl;
          ofs << "  Building Energy Performance - District Cooling,  !- Name" << std::endl;
          ofs << "    2,                       !- Digits After Decimal" << std::endl;
          ofs << "    InteriorLights:DistrictCooling,  !- Variable or Meter 1 Name" << std::endl;
          ofs << "    SumOrAverage,            !- Aggregation Type for Variable or Meter 1" << std::endl;
          ofs << "    ExteriorLights:DistrictCooling,  !- Variable or Meter 2 Name" << std::endl;
          ofs << "    SumOrAverage,            !- Aggregation Type for Variable or Meter 2" << std::endl;
          ofs << "    InteriorEquipment:DistrictCooling,  !- Variable or Meter 3 Name" << std::endl;
          ofs << "    SumOrAverage,            !- Aggregation Type for Variable or Meter 3" << std::endl;
          ofs << "    ExteriorEquipment:DistrictCooling,  !- Variable or Meter 4 Name" << std::endl;
          ofs << "    SumOrAverage,            !- Aggregation Type for Variable or Meter 4" << std::endl;
          ofs << "    Fans:DistrictCooling,        !- Variable or Meter 5 Name" << std::endl;
          ofs << "    SumOrAverage,            !- Aggregation Type for Variable or Meter 5" << std::endl;
          ofs << "    Pumps:DistrictCooling,       !- Variable or Meter 6 Name" << std::endl;
          ofs << "    SumOrAverage,            !- Aggregation Type for Variable or Meter 6" << std::endl;
          ofs << "    Heating:DistrictCooling,     !- Variable or Meter 7 Name" << std::endl;
          ofs << "    SumOrAverage,            !- Aggregation Type for Variable or Meter 7" << std::endl;
          ofs << "    Cooling:DistrictCooling,     !- Variable or Meter 8 Name" << std::endl;
          ofs << "    SumOrAverage,            !- Aggregation Type for Variable or Meter 8" << std::endl;
          ofs << "    HeatRejection:DistrictCooling,  !- Variable or Meter 9 Name" << std::endl;
          ofs << "    SumOrAverage,            !- Aggregation Type for Variable or Meter 9" << std::endl;
          ofs << "    Humidifier:DistrictCooling,  !- Variable or Meter 10 Name" << std::endl;
          ofs << "    SumOrAverage,            !- Aggregation Type for Variable or Meter 10" << std::endl;
          ofs << "    HeatRecovery:DistrictCooling,!- Variable or Meter 11 Name" << std::endl;
          ofs << "    SumOrAverage,            !- Aggregation Type for Variable or Meter 11" << std::endl;
          ofs << "    WaterSystems:DistrictCooling,!- Variable or Meter 12 Name" << std::endl;
          ofs << "    SumOrAverage,            !- Aggregation Type for Variable or Meter 12" << std::endl;
          ofs << "    Cogeneration:DistrictCooling,!- Variable or Meter 13 Name" << std::endl;
          ofs << "    SumOrAverage;            !- Aggregation Type for Variable or Meter 13" << std::endl;

          //energy demand

          ofs << "Output:Table:Monthly," << std::endl;
          ofs << "  Building Energy Performance - Electricity Peak Demand,  !- Name" << std::endl;
          ofs << "    2,                       !- Digits After Decimal" << std::endl;
          ofs << "    Electricity:Facility,  !- Variable or Meter 1 Name" << std::endl;
          ofs << "    Maximum,            !- Aggregation Type for Variable or Meter 1" << std::endl;
          ofs << "    InteriorLights:Electricity,  !- Variable or Meter 1 Name" << std::endl;
          ofs << "    ValueWhenMaximumOrMinimum,            !- Aggregation Type for Variable or Meter 1" << std::endl;
          ofs << "    ExteriorLights:Electricity,  !- Variable or Meter 2 Name" << std::endl;
          ofs << "    ValueWhenMaximumOrMinimum,            !- Aggregation Type for Variable or Meter 2" << std::endl;
          ofs << "    InteriorEquipment:Electricity,  !- Variable or Meter 3 Name" << std::endl;
          ofs << "    ValueWhenMaximumOrMinimum,            !- Aggregation Type for Variable or Meter 3" << std::endl;
          ofs << "    ExteriorEquipment:Electricity,  !- Variable or Meter 4 Name" << std::endl;
          ofs << "    ValueWhenMaximumOrMinimum,            !- Aggregation Type for Variable or Meter 4" << std::endl;
          ofs << "    Fans:Electricity,        !- Variable or Meter 5 Name" << std::endl;
          ofs << "    ValueWhenMaximumOrMinimum,            !- Aggregation Type for Variable or Meter 5" << std::endl;
          ofs << "    Pumps:Electricity,       !- Variable or Meter 6 Name" << std::endl;
          ofs << "    ValueWhenMaximumOrMinimum,            !- Aggregation Type for Variable or Meter 6" << std::endl;
          ofs << "    Heating:Electricity,     !- Variable or Meter 7 Name" << std::endl;
          ofs << "    ValueWhenMaximumOrMinimum,            !- Aggregation Type for Variable or Meter 7" << std::endl;
          ofs << "    Cooling:Electricity,     !- Variable or Meter 8 Name" << std::endl;
          ofs << "    ValueWhenMaximumOrMinimum,            !- Aggregation Type for Variable or Meter 8" << std::endl;
          ofs << "    HeatRejection:Electricity,  !- Variable or Meter 9 Name" << std::endl;
          ofs << "    ValueWhenMaximumOrMinimum,            !- Aggregation Type for Variable or Meter 9" << std::endl;
          ofs << "    Humidifier:Electricity,  !- Variable or Meter 10 Name" << std::endl;
          ofs << "    ValueWhenMaximumOrMinimum,            !- Aggregation Type for Variable or Meter 10" << std::endl;
          ofs << "    HeatRecovery:Electricity,!- Variable or Meter 11 Name" << std::endl;
          ofs << "    ValueWhenMaximumOrMinimum,            !- Aggregation Type for Variable or Meter 11" << std::endl;
          ofs << "    WaterSystems:Electricity,!- Variable or Meter 12 Name" << std::endl;
          ofs << "    ValueWhenMaximumOrMinimum,            !- Aggregation Type for Variable or Meter 12" << std::endl;
          ofs << "    Cogeneration:Electricity,!- Variable or Meter 13 Name" << std::endl;
          ofs << "    ValueWhenMaximumOrMinimum;            !- Aggregation Type for Variable or Meter 13" << std::endl;

          ofs << "Output:Table:Monthly," << std::endl;
          ofs << "  Building Energy Performance - Natural Gas Peak Demand,  !- Name" << std::endl;
          ofs << "    2,                       !- Digits After Decimal" << std::endl;
          ofs << "    Gas:Facility,  !- Variable or Meter 1 Name" << std::endl;
          ofs << "    Maximum,            !- Aggregation Type for Variable or Meter 1" << std::endl;
          ofs << "    InteriorEquipment:Gas,   !- Variable or Meter 1 Name" << std::endl;
          ofs << "    ValueWhenMaximumOrMinimum,            !- Aggregation Type for Variable or Meter 1" << std::endl;
          ofs << "    ExteriorEquipment:Gas,   !- Variable or Meter 2 Name" << std::endl;
          ofs << "    ValueWhenMaximumOrMinimum,            !- Aggregation Type for Variable or Meter 2" << std::endl;
          ofs << "    Heating:Gas,             !- Variable or Meter 3 Name" << std::endl;
          ofs << "    ValueWhenMaximumOrMinimum,            !- Aggregation Type for Variable or Meter 3" << std::endl;
          ofs << "    Cooling:Gas,             !- Variable or Meter 4 Name" << std::endl;
          ofs << "    ValueWhenMaximumOrMinimum,            !- Aggregation Type for Variable or Meter 4" << std::endl;
          ofs << "    WaterSystems:Gas,        !- Variable or Meter 5 Name" << std::endl;
          ofs << "    ValueWhenMaximumOrMinimum,            !- Aggregation Type for Variable or Meter 5" << std::endl;
          ofs << "    Cogeneration:Gas,        !- Variable or Meter 6 Name" << std::endl;
          ofs << "    ValueWhenMaximumOrMinimum;            !- Aggregation Type for Variable or Meter 6" << std::endl;

          ofs << "Output:Table:Monthly," << std::endl;
          ofs << "  Building Energy Performance - District Heating Peak Demand,  !- Name" << std::endl;
          ofs << "    2,                       !- Digits After Decimal" << std::endl;
          ofs << "    DistrictHeating:Facility,  !- Variable or Meter 1 Name" << std::endl;
          ofs << "    Maximum,            !- Aggregation Type for Variable or Meter 1" << std::endl;
          ofs << "    InteriorLights:DistrictHeating,  !- Variable or Meter 1 Name" << std::endl;
          ofs << "    ValueWhenMaximumOrMinimum,            !- Aggregation Type for Variable or Meter 1" << std::endl;
          ofs << "    ExteriorLights:DistrictHeating,  !- Variable or Meter 2 Name" << std::endl;
          ofs << "    ValueWhenMaximumOrMinimum,            !- Aggregation Type for Variable or Meter 2" << std::endl;
          ofs << "    InteriorEquipment:DistrictHeating,  !- Variable or Meter 3 Name" << std::endl;
          ofs << "    ValueWhenMaximumOrMinimum,            !- Aggregation Type for Variable or Meter 3" << std::endl;
          ofs << "    ExteriorEquipment:DistrictHeating,  !- Variable or Meter 4 Name" << std::endl;
          ofs << "    ValueWhenMaximumOrMinimum,            !- Aggregation Type for Variable or Meter 4" << std::endl;
          ofs << "    Fans:DistrictHeating,        !- Variable or Meter 5 Name" << std::endl;
          ofs << "    ValueWhenMaximumOrMinimum,            !- Aggregation Type for Variable or Meter 5" << std::endl;
          ofs << "    Pumps:DistrictHeating,       !- Variable or Meter 6 Name" << std::endl;
          ofs << "    ValueWhenMaximumOrMinimum,            !- Aggregation Type for Variable or Meter 6" << std::endl;
          ofs << "    Heating:DistrictHeating,     !- Variable or Meter 7 Name" << std::endl;
          ofs << "    ValueWhenMaximumOrMinimum,            !- Aggregation Type for Variable or Meter 7" << std::endl;
          ofs << "    Cooling:DistrictHeating,     !- Variable or Meter 8 Name" << std::endl;
          ofs << "    ValueWhenMaximumOrMinimum,            !- Aggregation Type for Variable or Meter 8" << std::endl;
          ofs << "    HeatRejection:DistrictHeating,  !- Variable or Meter 9 Name" << std::endl;
          ofs << "    ValueWhenMaximumOrMinimum,            !- Aggregation Type for Variable or Meter 9" << std::endl;
          ofs << "    Humidifier:DistrictHeating,  !- Variable or Meter 10 Name" << std::endl;
          ofs << "    ValueWhenMaximumOrMinimum,            !- Aggregation Type for Variable or Meter 10" << std::endl;
          ofs << "    HeatRecovery:DistrictHeating,!- Variable or Meter 11 Name" << std::endl;
          ofs << "    ValueWhenMaximumOrMinimum,            !- Aggregation Type for Variable or Meter 11" << std::endl;
          ofs << "    WaterSystems:DistrictHeating,!- Variable or Meter 12 Name" << std::endl;
          ofs << "    ValueWhenMaximumOrMinimum,            !- Aggregation Type for Variable or Meter 12" << std::endl;
          ofs << "    Cogeneration:DistrictHeating,!- Variable or Meter 13 Name" << std::endl;
          ofs << "    ValueWhenMaximumOrMinimum;            !- Aggregation Type for Variable or Meter 13" << std::endl;

          ofs << "Output:Table:Monthly," << std::endl;
          ofs << "  Building Energy Performance - District Cooling Peak Demand,  !- Name" << std::endl;
          ofs << "    2,                       !- Digits After Decimal" << std::endl;
          ofs << "    DistrictCooling:Facility,  !- Variable or Meter 1 Name" << std::endl;
          ofs << "    Maximum,            !- Aggregation Type for Variable or Meter 1" << std::endl;
          ofs << "    InteriorLights:DistrictCooling,  !- Variable or Meter 1 Name" << std::endl;
          ofs << "    ValueWhenMaximumOrMinimum,            !- Aggregation Type for Variable or Meter 1" << std::endl;
          ofs << "    ExteriorLights:DistrictCooling,  !- Variable or Meter 2 Name" << std::endl;
          ofs << "    ValueWhenMaximumOrMinimum,            !- Aggregation Type for Variable or Meter 2" << std::endl;
          ofs << "    InteriorEquipment:DistrictCooling,  !- Variable or Meter 3 Name" << std::endl;
          ofs << "    ValueWhenMaximumOrMinimum,            !- Aggregation Type for Variable or Meter 3" << std::endl;
          ofs << "    ExteriorEquipment:DistrictCooling,  !- Variable or Meter 4 Name" << std::endl;
          ofs << "    ValueWhenMaximumOrMinimum,            !- Aggregation Type for Variable or Meter 4" << std::endl;
          ofs << "    Fans:DistrictCooling,        !- Variable or Meter 5 Name" << std::endl;
          ofs << "    ValueWhenMaximumOrMinimum,            !- Aggregation Type for Variable or Meter 5" << std::endl;
          ofs << "    Pumps:DistrictCooling,       !- Variable or Meter 6 Name" << std::endl;
          ofs << "    ValueWhenMaximumOrMinimum,            !- Aggregation Type for Variable or Meter 6" << std::endl;
          ofs << "    Heating:DistrictCooling,     !- Variable or Meter 7 Name" << std::endl;
          ofs << "    ValueWhenMaximumOrMinimum,            !- Aggregation Type for Variable or Meter 7" << std::endl;
          ofs << "    Cooling:DistrictCooling,     !- Variable or Meter 8 Name" << std::endl;
          ofs << "    ValueWhenMaximumOrMinimum,            !- Aggregation Type for Variable or Meter 8" << std::endl;
          ofs << "    HeatRejection:DistrictCooling,  !- Variable or Meter 9 Name" << std::endl;
          ofs << "    ValueWhenMaximumOrMinimum,            !- Aggregation Type for Variable or Meter 9" << std::endl;
          ofs << "    Humidifier:DistrictCooling,  !- Variable or Meter 10 Name" << std::endl;
          ofs << "    ValueWhenMaximumOrMinimum,            !- Aggregation Type for Variable or Meter 10" << std::endl;
          ofs << "    HeatRecovery:DistrictCooling,!- Variable or Meter 11 Name" << std::endl;
          ofs << "    ValueWhenMaximumOrMinimum,            !- Aggregation Type for Variable or Meter 11" << std::endl;
          ofs << "    WaterSystems:DistrictCooling,!- Variable or Meter 12 Name" << std::endl;
          ofs << "    ValueWhenMaximumOrMinimum,            !- Aggregation Type for Variable or Meter 12" << std::endl;
          ofs << "    Cogeneration:DistrictCooling,!- Variable or Meter 13 Name" << std::endl;
          ofs << "    ValueWhenMaximumOrMinimum;            !- Aggregation Type for Variable or Meter 13" << std::endl;

        }

        //timestep-level utility demand by fuel type to calculate demand
        ofs << "    Output:Meter,Electricity:Facility,Timestep; !- [J]" << std::endl;
        ofs << "    Output:Meter,Gas:Facility,Timestep; !- [J]" << std::endl;
        ofs << "    Output:Meter,DistrictCooling:Facility,Timestep; !- [J]" << std::endl;
        ofs << "    Output:Meter,DistrictHeating:Facility,Timestep; !- [J]" << std::endl;


        ofs.flush();
        ofs.close();

      }



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

    emitOutputFileChanged(RunManager_Util::dirFile(outpath / openstudio::toPath("out.idf")));
    setErrors(errors);
  }
示例#7
0
  void ModelToRadJob::startImpl(const boost::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);
      
      // capture translator errors and warnings?
      //ft.errors();
      //ft.warnings();
      
      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);
      }

      l.relock();

      m_outputfiles = outfileinfos;

      /// Do work here - and be sure to set output files too
    } 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);
  }
示例#8
0
  void IdfToModelJob::startImpl(const std::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);
  }
  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);

      // 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);
      }

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

      // 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);
      }

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

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

      attribute = facility.endUsesAttribute();
      if (attribute){
        attributes.push_back(*attribute);
      }

      attribute = facility.calibrationResultAttribute();
      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;
        
        boost::optional<double> value = timeDependentValuation->energyTimeDependentValuation();
        if (value){
          attribute = Attribute("energyTimeDependentValuation", *value, "J");
          attribute->setDisplayName("Energy Time Dependent Valuation");
          attributes.push_back(*attribute);
        }

        value = timeDependentValuation->costTimeDependentValuation();
        if (value){
          attribute = Attribute("costTimeDependentValuation", *value, "$");
          attribute->setDisplayName("Cost Time Dependent Valuation");
          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);
  }
  void ModelToRadPreProcessJob::startImpl(const std::shared_ptr<ProcessCreator> &)
  {
    openstudio::path outpath = outdir(true);

    QWriteLocker l(&m_mutex);

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

    LOG(Info, "ModelToRadPreProcess starting, loading model file: " << toString(m_osm->fullPath));
    openstudio::model::OptionalModel model = openstudio::model::Model::load(m_osm->fullPath);

    if (!model)
    {
      errors.result = ruleset::OSResultValue::Fail;
      errors.addError(ErrorType::Error, "Unable to load model file");
    }
          
    LOG(Info, "ModelToRadPreProcess 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);

      openstudio::path path = outpath / openstudio::toPath("out.osm");
  
      openstudio::model::Model outmodel; 
      outmodel.getUniqueModelObject<openstudio::model::Building>(); // implicitly create building object
      outmodel.getUniqueModelObject<openstudio::model::Timestep>(); // implicitly create timestep object
      outmodel.getUniqueModelObject<openstudio::model::RunPeriod>(); // implicitly create runperiod object
  
      if (model->getOptionalUniqueModelObject<openstudio::model::WeatherFile>())
      {
        outmodel.addObject(model->getUniqueModelObject<openstudio::model::WeatherFile>());
      }

      std::map<std::string, openstudio::model::ThermalZone> thermalZones;

      std::vector<openstudio::model::Space> spaces = model->getConcreteModelObjects<openstudio::model::Space>();
      for (auto & space : spaces)
      {
        space.hardApplyConstructions();
        space.hardApplySpaceType(true);
        space.hardApplySpaceLoadSchedules();

        // make all surfaces with surface boundary condition adiabatic
        std::vector<openstudio::model::Surface> surfaces = space.surfaces();
        for (auto & surf_it : surfaces){
          boost::optional<openstudio::model::Surface> adjacentSurface = surf_it.adjacentSurface();
          if (adjacentSurface){

            // make sure to hard apply constructions in other space before messing with surface in other space
            boost::optional<openstudio::model::Space> adjacentSpace = adjacentSurface->space();
            if (adjacentSpace){
              adjacentSpace->hardApplyConstructions();
            }

            // resets both surfaces
            surf_it.resetAdjacentSurface();

            // set both to adiabatic
            surf_it.setOutsideBoundaryCondition("Adiabatic");
            adjacentSurface->setOutsideBoundaryCondition("Adiabatic");

            // remove interior windows
            for (openstudio::model::SubSurface subSurface : surf_it.subSurfaces()){
              subSurface.remove();
            }
            for (openstudio::model::SubSurface subSurface : adjacentSurface->subSurfaces()){
              subSurface.remove();
            }
          }
        }

        openstudio::model::Space new_space = space.clone(outmodel).optionalCast<openstudio::model::Space>().get();

        boost::optional<openstudio::model::ThermalZone> thermalZone = space.thermalZone();

        if (thermalZone && thermalZone->name())
        {
          if (thermalZones.find(*thermalZone->name()) == thermalZones.end())
          {
            openstudio::model::ThermalZone newThermalZone(outmodel);
            newThermalZone.setName(*thermalZone->name());
            newThermalZone.setUseIdealAirLoads(true);
            thermalZones.insert(std::make_pair(*thermalZone->name(), newThermalZone));
          }

          auto itr = thermalZones.find(*thermalZone->name());
          OS_ASSERT(itr != thermalZones.end()); // We just added it above if we needed it
          new_space.setThermalZone(itr->second);
        } else if (thermalZone && !thermalZone->name()) {
          errors.addError(ErrorType::Warning, "Space discovered in un-named thermalZone, not translating");
        }
      }
 
      std::vector<openstudio::model::ShadingSurfaceGroup> shadingsurfacegroups = outmodel.getConcreteModelObjects<openstudio::model::ShadingSurfaceGroup>(); 
      for (auto & shadingSurfaceGroup : shadingsurfacegroups)
      {
        shadingSurfaceGroup.remove();
      }
  
      std::vector<openstudio::model::SpaceItem> spaceitems = outmodel.getModelObjects<openstudio::model::SpaceItem>(); 
      for (auto & spaceItem : spaceitems)
      {
        if (spaceItem.optionalCast<openstudio::model::People>()){
          // keep people
        }else if (spaceItem.optionalCast<openstudio::model::Lights>()){
          // keep lights
        }else if (spaceItem.optionalCast<openstudio::model::Luminaire>()){
          // keep luminaires
        }else{
          spaceItem.remove();
        }
      }

      std::vector<openstudio::model::OutputVariable> outputVariables = outmodel.getConcreteModelObjects<openstudio::model::OutputVariable>();
      for (auto & outputVariable : outputVariables)
      {
        outputVariable.remove();
      }

      openstudio::model::OutputVariable outputVariable("Site Exterior Horizontal Sky Illuminance", outmodel);
      outputVariable.setReportingFrequency("Hourly");

      outputVariable = openstudio::model::OutputVariable("Site Exterior Beam Normal Illuminance", outmodel);
      outputVariable.setReportingFrequency("Hourly");

      outputVariable = openstudio::model::OutputVariable("Site Solar Altitude Angle", outmodel);
      outputVariable.setReportingFrequency("Hourly");

      outputVariable = openstudio::model::OutputVariable("Site Solar Azimuth Angle", outmodel);
      outputVariable.setReportingFrequency("Hourly");

      outputVariable = openstudio::model::OutputVariable("Site Sky Diffuse Solar Radiation Luminous Efficacy", outmodel);
      outputVariable.setReportingFrequency("Hourly");

      outputVariable = openstudio::model::OutputVariable("Site Beam Solar Radiation Luminous Efficacy", outmodel);
      outputVariable.setReportingFrequency("Hourly");

      outputVariable = openstudio::model::OutputVariable("Zone People Occupant Count", outmodel);
      outputVariable.setReportingFrequency("Hourly");

      outputVariable = openstudio::model::OutputVariable("Zone Lights Electric Power", outmodel);
      outputVariable.setReportingFrequency("Hourly");

      // only report weather periods
      openstudio::model::SimulationControl simulation_control = outmodel.getUniqueModelObject<openstudio::model::SimulationControl>();
      simulation_control.setRunSimulationforSizingPeriods(false);
      simulation_control.setRunSimulationforWeatherFileRunPeriods(true);
      simulation_control.setSolarDistribution("MinimalShadowing");

      outmodel.save(path, true);

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

    // Change this to whatever output files you generate
    emitOutputFileChanged(RunManager_Util::dirFile(outpath / openstudio::toPath("out.osm")));
    setErrors(errors);
  }
  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);
  }
示例#12
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);
  }