void FllImporter::processOutputVariable(const std::string& block, Engine* engine) const {
     std::istringstream reader(block);
     std::string line;
     FL_unique_ptr<OutputVariable> outputVariable(new OutputVariable);
     while (std::getline(reader, line)) {
         std::pair<std::string, std::string> keyValue = parseKeyValue(line, ':');
         if ("OutputVariable" == keyValue.first) {
             outputVariable->setName(Op::validName(keyValue.second));
         } else if ("enabled" == keyValue.first) {
             outputVariable->setEnabled(parseBoolean(keyValue.second));
         } else if ("range" == keyValue.first) {
             std::pair<scalar, scalar> range = parseRange(keyValue.second);
             outputVariable->setRange(range.first, range.second);
         } else if ("default" == keyValue.first) {
             outputVariable->setDefaultValue(Op::toScalar(keyValue.second));
         } else if ("lock-previous" == keyValue.first or "lock-valid" == keyValue.first) {
             outputVariable->setLockPreviousValue(parseBoolean(keyValue.second));
         } else if ("lock-range" == keyValue.first) {
             outputVariable->setLockValueInRange(parseBoolean(keyValue.second));
         } else if ("defuzzifier" == keyValue.first) {
             outputVariable->setDefuzzifier(parseDefuzzifier(keyValue.second));
         } else if ("aggregation" == keyValue.first) {
             outputVariable->fuzzyOutput()->setAggregation(parseSNorm(keyValue.second));
         } else if ("accumulation" == keyValue.first) {
             outputVariable->fuzzyOutput()->setAggregation(parseSNorm(keyValue.second));
             FL_LOG("[warning] obsolete usage of identifier <accumulation: SNorm> in OutputVariable");
             FL_LOG("[information] from version 6.0, the identifier <aggregation: SNorm> should be used");
             FL_LOG("[backward compatibility] assumed "
                     "<aggregation: " << keyValue.second << "> "
                     "instead of <accumulation: " << keyValue.second << ">");
         } else if ("term" == keyValue.first) {
             outputVariable->addTerm(parseTerm(keyValue.second, engine));
         } else {
             throw Exception("[import error] key <" + keyValue.first + "> not "
                     "recognized in pair <" + keyValue.first + ":" + keyValue.second + ">", FL_AT);
         }
     }
     engine->addOutputVariable(outputVariable.release());
 }
OptionalModelObject ReverseTranslator::translateOutputVariable( const WorkspaceObject & workspaceObject )
{

  OptionalString s = workspaceObject.getString(Output_VariableFields::VariableName);
  if(!s){
    return boost::none;
  }

  openstudio::model::OutputVariable outputVariable( *s,  m_model );

  s = workspaceObject.getString(Output_VariableFields::KeyValue);
  if(s){
    outputVariable.setKeyValue(*s);
  }

  s = workspaceObject.getString(Output_VariableFields::VariableName);
  if(s){
    outputVariable.setVariableName(*s);
  }

  s = workspaceObject.getString(Output_VariableFields::ReportingFrequency);
  if(s){
    outputVariable.setReportingFrequency(*s);
  }

  OptionalWorkspaceObject target = workspaceObject.getTarget(Output_VariableFields::ScheduleName);
  if (target){
    OptionalModelObject modelObject = translateAndMapWorkspaceObject( *target );
    if (modelObject){
      OptionalSchedule schedule = modelObject->optionalCast<Schedule>();
      if (schedule){
        outputVariable.setSchedule(*schedule);
      }
    }
  }

  return outputVariable;
}
Example #3
0
  void VariableListItem::onOffClicked(bool t_on)
  {
    LOG(Debug, "onOffClicked " << t_on);
    m_combobox->setEnabled(t_on);

    if (t_on)
    {
      if (!m_variable)
      {
        openstudio::model::OutputVariable outputVariable(m_name, m_model);
        outputVariable.setReportingFrequency("Hourly");
        outputVariable.setKeyValue(m_keyValue);
        m_variable = outputVariable;
        m_combobox->bind(*m_variable, "reportingFrequency");
      }
    } else {
      if (m_variable)
      {
        m_combobox->unbind();
        m_variable->remove();
        m_variable = boost::none;
      }
    }
  }
  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);
  }