Пример #1
0
//
//	This code has been debugged but requires changes to other portions of the
//	code to enable. Specifically, the cgiHandler.cpp.
//
int MprCmd::makeStdio()
{
	int		fds[2], i;

	resetFiles();

	for (i = 0; i < MPR_CMD_MAX_FD; i++) {
		if (pipe(fds) < 0) {
			mprError(MPR_L, MPR_LOG, "Can't create stdio pipes. Err %d",
				mprGetOsError());
			mprAssert(0);
			return -1;
		}
		if (i == MPR_CMD_OUT) {
			files.clientFd[i] = fds[0];			// read fd
			files.fd[i] = fds[1];				// write fd
		} else {
			files.clientFd[i] = fds[1];			// write fd
			files.fd[i] = fds[0];				// read fd
		}
		mprLog(7, log, "makeStdio: pipe handles[%d] read %d, write %d\n",
			i, fds[0], fds[1]);
	}

	return 0;
}
Пример #2
0
  ModelToRadJob::ModelToRadJob(const UUID &t_uuid,
          const Tools &tools,
          const JobParams &params,
          const Files &files,
      const JobState &t_restoreData)
    : Job_Impl(t_uuid, JobType::ModelToRad, tools, params, files, t_restoreData)
  {
    try {
      m_model = files.getLastByExtension("osm");
      resetFiles(m_files, m_model);
    } catch (const std::runtime_error &) {
    }

    m_description = buildDescription("osm");
  }
  ModelToRadPreProcessJob::ModelToRadPreProcessJob(const UUID &t_uuid,
          const Tools &tools,
          const JobParams &params,
          const Files &files,
      const JobState &t_restoreData)
    : Job_Impl(t_uuid, JobType::ModelToRadPreProcess, tools, params, files, t_restoreData)
  {
    try {
      m_osm = files.getLastByExtension("osm");
      resetFiles(m_files, m_osm);
    } catch (const std::exception &) {
    }

    m_description = buildDescription("osm");
  }
  EnergyPlusPreProcessJob::EnergyPlusPreProcessJob(const UUID &t_uuid,
      const Tools &tools,
      const JobParams &params,
      const Files &files,
      const JobState &t_restoreData)
    : Job_Impl(t_uuid, JobType::EnergyPlusPreProcess, tools, params, files, t_restoreData)
  {
    try {
      m_idf = files.getLastByExtension("idf");
      resetFiles(m_files, m_idf);
    } catch (const std::runtime_error &) {
    }

    m_description = buildDescription("idf");
  }
  OpenStudioPostProcessJob::OpenStudioPostProcessJob(const UUID &t_uuid,
          const Tools &tools,
          const JobParams &params,
          const Files &files,
      const JobState &t_restoreData)
    : Job_Impl(t_uuid, JobType::OpenStudioPostProcess, tools, params, files, t_restoreData)
  {
    try {
      m_sql = files.getLastByFilename("eplusout.sql");
      resetFiles(m_files, m_sql);
    } catch (const std::runtime_error &) {
    }

    // what should this be?
    m_description = buildDescription("sql");
  }
  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);
  }
  ParallelEnergyPlusSplitJob::ParallelEnergyPlusSplitJob(const UUID &t_uuid,
          const Tools &tools,
          const JobParams &params,
          const Files &files,
      const JobState &t_restoreData)
    : Job_Impl(t_uuid, JobType::ParallelEnergyPlusSplit, tools, params, files, t_restoreData),
      m_numSplits(boost::lexical_cast<int>(params.get("numsplits").children.at(0).value)),
      m_offset(boost::lexical_cast<int>(params.get("offset").children.at(0).value))
  {
    try {
      m_input = files.getLastByExtension("idf");
      resetFiles(m_files, m_input);
    } catch (const std::runtime_error &) {
    }

    m_description = buildDescription("idf");
  }
Пример #8
0
MprCmd::~MprCmd()
{
    mprLog(8, log, "~MprCmd: process %d\n", process);

    //
    //	Must do remove first
    //
    mprGetMpr()->cmdService->removeCmd(this);

    reset();
    resetFiles();

#if BLD_FEATURE_LOG
    delete log;
#endif
#if BLD_FEATURE_MULTITHREAD
    delete mutex;
#if VXWORKS
    delete startCond;
    delete exitCond;
#endif
#endif
}
Пример #9
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);
  }
Пример #10
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);
  }
Пример #11
0
 void IdfToModelJob::basePathChanged()
 {
   m_idf.reset();
   resetFiles(m_files);
 }
 void OpenStudioPostProcessJob::basePathChanged() 
 {
   m_sql.reset();
   m_osm.reset();
   resetFiles(m_files);
 }
Пример #13
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);
  }
Пример #14
0
 void ModelInModelOutJob::basePathChanged()
 {
   m_model.reset();
   resetFiles(m_files);
 }
  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);
  }
Пример #16
0
  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);
  }
 void EnergyPlusPreProcessJob::basePathChanged()
 {
   m_idf.reset();
   resetFiles(m_files);
 }
 void ParallelEnergyPlusSplitJob::basePathChanged()
 {
   m_input.reset();
   resetFiles(m_files);
 }
Пример #19
0
 void EnergyPlusPostProcessJob::basePathChanged()
 {
   m_sql.reset();
   resetFiles(m_files);
 }
Пример #20
0
  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);
  }
  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);
  }
  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 ModelToRadPreProcessJob::basePathChanged()
 {
   m_osm.reset();
   resetFiles(m_files);
 }
Пример #24
0
//
//	This code has been debugged but requires changes to other portions of the
//	code to enable. Specifically the cgiHandler.cpp
//
int MprCmd::makeStdio()
{
	SECURITY_ATTRIBUTES	clientAtt, serverAtt, *att;
	HANDLE				fileHandle;
	char				pipeBuf[MPR_MAX_FNAME];
	int					openMode, pipeMode, i, pipeFd, fileFd;
	static int			tempSeed = 0;

	resetFiles();

	//
	//	The difference is server fds are not inherited by the child
	//
	memset(&clientAtt, 0, sizeof(clientAtt));
	clientAtt.nLength = sizeof(SECURITY_ATTRIBUTES);
	clientAtt.bInheritHandle = TRUE;

	memset(&serverAtt, 0, sizeof(serverAtt));
	serverAtt.nLength = sizeof(SECURITY_ATTRIBUTES);
	serverAtt.bInheritHandle = FALSE;

	for (i = 0; i < MPR_CMD_MAX_FD; i++) {

		mprSprintf(pipeBuf, sizeof(pipeBuf), "\\\\.\\pipe\\mpr_%d_%d", 
			getpid(), tempSeed++);

		if (i == MPR_CMD_IN) {
			openMode = PIPE_ACCESS_OUTBOUND;
				/* | FILE_FLAG_OVERLAPPED; */
			pipeMode = 0;
		} else {
			openMode = PIPE_ACCESS_INBOUND;
			pipeMode = 0;
		}
		att = &clientAtt;

		//
		//	Create named pipe and read handle
		//
		fileHandle = CreateNamedPipe(pipeBuf, openMode, pipeMode, 1, 0, 
			65536, 1, att);
		pipeFd = (int) _open_osfhandle((long) fileHandle, 0);

		//
		//	Create write handle
		//
		att = &serverAtt;
		if (i == MPR_CMD_IN) {
			fileHandle = CreateFile(pipeBuf, GENERIC_READ, 0, att,
				OPEN_EXISTING, 0, 0);
		} else {
			fileHandle = CreateFile(pipeBuf, GENERIC_WRITE, 0, att,
				OPEN_EXISTING, 0, 0);
		}
		fileFd = (int) _open_osfhandle((long) fileHandle, 0);

		if (pipeFd < 0 || fileFd < 0) {
			mprError(MPR_L, MPR_LOG, "Can't create stdio pipes. Err %d",
				mprGetOsError());
			mprAssert(0);
			return -1;
		}
		files.fd[i] = fileFd;
		files.clientFd[i] = pipeFd;
	}
	flags |= MPR_CMD_STDIO_MADE;
	return 0;
}