Exemple #1
0
  boost::optional<openstudio::model::ModelObject> ReverseTranslator::translateHoliday(const QDomElement& element, const QDomDocument& doc, openstudio::model::Model& model)
  {
		//<Name>Thanksgiving Day</Name>
		//<SpecMthd>Fourth</SpecMthd>
		//<DayOfWeek>Thursday</DayOfWeek>
		//<Month>November</Month>

		//<Name>Christmas Day</Name>
		//<SpecMthd>Date</SpecMthd>
		//<Month>December</Month>
		//<Day>25</Day>

    boost::optional<openstudio::model::ModelObject> result;

    QDomElement nameElement = element.firstChildElement("Name");
    QDomElement specificationMethodElement = element.firstChildElement("SpecMthd");
    OS_ASSERT(!nameElement.isNull());
    OS_ASSERT(!specificationMethodElement.isNull());

    if (specificationMethodElement.text() == "Date"){
      QDomElement monthElement = element.firstChildElement("Month");
      QDomElement dayElement = element.firstChildElement("Day");
      OS_ASSERT(!monthElement.isNull());
      OS_ASSERT(!dayElement.isNull());

      MonthOfYear monthOfYear(toString(monthElement.text()));
      unsigned day = dayElement.text().toUInt();

      result = model::RunPeriodControlSpecialDays(monthOfYear, day, model);
      result->setName(escapeName(nameElement.text()));

    }else{
      QDomElement dayOfWeekElement = element.firstChildElement("DayOfWeek");
      QDomElement monthElement = element.firstChildElement("Month");
      OS_ASSERT(!dayOfWeekElement.isNull());
      OS_ASSERT(!monthElement.isNull());

      // fifth is treated equivalently to last
      std::string specificationMethod = toString(specificationMethodElement.text());
      if (specificationMethod == "Last"){
        specificationMethod = "Fifth";
      }

      NthDayOfWeekInMonth nth(specificationMethod);
      DayOfWeek dayOfWeek(toString(dayOfWeekElement.text()));
      MonthOfYear monthOfYear(toString(monthElement.text()));

      result = model::RunPeriodControlSpecialDays(nth, dayOfWeek, monthOfYear, model);
      result->setName(escapeName(nameElement.text()));
    }

    return result;
  }
Exemple #2
0
  boost::optional<openstudio::model::ModelObject> ReverseTranslator::translateSchedule(const QDomElement& element, const QDomDocument& doc, openstudio::model::Model& model)
  {
    QDomElement nameElement = element.firstChildElement("Name");
    QDomElement typeElement = element.firstChildElement("Type");

    OS_ASSERT(!nameElement.isNull());
    std::string name = escapeName(nameElement.text());

    model::ScheduleYear scheduleYear(model);
    scheduleYear.setName(name);

    OS_ASSERT(!typeElement.isNull());
    std::string type = escapeName(typeElement.text());
    boost::optional<model::ScheduleTypeLimits> scheduleTypeLimits = model.getModelObjectByName<model::ScheduleTypeLimits>(type);
    if (scheduleTypeLimits){
      scheduleYear.setScheduleTypeLimits(*scheduleTypeLimits);
    }

    QDomNodeList endMonthElements = element.elementsByTagName("EndMonth");
    QDomNodeList endDayElements = element.elementsByTagName("EndDay");
    QDomNodeList schWeekRefElements = element.elementsByTagName("SchWeekRef");

    OS_ASSERT(endMonthElements.count() == endDayElements.count());
    OS_ASSERT(endMonthElements.count() == schWeekRefElements.count());
    
    for (int i = 0; i < endMonthElements.count(); i++){
      QDomElement endMonthElement = endMonthElements.at(i).toElement();
      QDomElement endDayElement = endDayElements.at(i).toElement();
      QDomElement schWeekRefElement = schWeekRefElements.at(i).toElement();

      boost::optional<model::ScheduleWeek> scheduleWeek = model.getModelObjectByName<model::ScheduleWeek>(escapeName(schWeekRefElement.text()));
      if (scheduleWeek){

        boost::optional<model::YearDescription> yearDescription = model.getOptionalUniqueModelObject<model::YearDescription>();
        if (yearDescription){
          MonthOfYear monthOfYear(endMonthElement.text().toUInt());
          unsigned dayOfMonth = endDayElement.text().toUInt();
          Date untilDate(monthOfYear, dayOfMonth, yearDescription->assumedYear());
          scheduleYear.addScheduleWeek(untilDate, *scheduleWeek);
        }else{
          MonthOfYear monthOfYear(endMonthElement.text().toUInt());
          unsigned dayOfMonth = endDayElement.text().toUInt();
          Date untilDate(monthOfYear, dayOfMonth);
          scheduleYear.addScheduleWeek(untilDate, *scheduleWeek);
        }
      }
    }

    return scheduleYear;
  }
  boost::optional<openstudio::model::ModelObject> ReverseTranslator::translateConstruction(const QDomElement& element, const QDomNodeList& layerElements, const QDomDocument& doc, openstudio::model::Model& model)
  {
    // Krishnan, this constructor should only be used for unique objects like Building and Site
    //openstudio::model::Construction construction = model.getUniqueModelObject<openstudio::model::Construction>();

    openstudio::model::Construction construction(model);
    QString constructionId = element.attribute("id");
    m_idToObjectMap.insert(std::make_pair(constructionId, construction));

    QString constructionName = element.firstChildElement("Name").toElement().text();
    construction.setName(escapeName(constructionId, constructionName));
        
    QDomNodeList layerIdList = element.elementsByTagName("LayerId");

    if (layerIdList.isEmpty()){
      return construction;
    }

    QString layerId = layerIdList.at(0).toElement().attribute("layerIdRef");

    std::vector<openstudio::model::Material> materials;
    for (int i = 0; i < layerElements.count(); i++){
      QDomElement layerElement = layerElements.at(i).toElement();
      if (layerId == layerElement.attribute("id")){
        QDomNodeList materialIdElements = layerElement.elementsByTagName("MaterialId");
        for (int j = 0; j < materialIdElements.count(); j++){
          QString materialId = materialIdElements.at(j).toElement().attribute("materialIdRef");
          auto materialIt = m_idToObjectMap.find(materialId);
          if (materialIt != m_idToObjectMap.end()){
            boost::optional<openstudio::model::Material> material = materialIt->second.optionalCast<openstudio::model::Material>();
            OS_ASSERT(material); // Krishnan, what type of error handling do you want?
            materials.push_back(*material);
          }
        }
        break;
      }
    }

    // now assign all layers to real material, does gbXML have same layer order convention as E+?
    for (unsigned i = 0; i < materials.size(); ++i){
      bool test = false;
          
      if (materials[i].optionalCast<openstudio::model::OpaqueMaterial>()){
        test = construction.insertLayer(i, materials[i].cast<openstudio::model::OpaqueMaterial>());
      }else if (materials[i].optionalCast<openstudio::model::FenestrationMaterial>()){
        test = construction.insertLayer(i, materials[i].cast<openstudio::model::FenestrationMaterial>());
      }else if (materials[i].optionalCast<openstudio::model::ModelPartitionMaterial>()){
        test = construction.setLayer(materials[i].cast<openstudio::model::ModelPartitionMaterial>());
      }
          
      OS_ASSERT(test); // Krishnan, what type of error handling do you want?
    }

    return construction;
  }
  boost::optional<openstudio::model::ModelObject> ReverseTranslator::translateWindowType(const QDomElement& element, const QDomDocument& doc, openstudio::model::Model& model)
  {  
    openstudio::model::Construction construction(model);
    QString windowTypeId = element.attribute("id");
    m_idToObjectMap.insert(std::make_pair(windowTypeId, construction));

    QString windowTypeName = element.firstChildElement("Name").toElement().text();
    construction.setName(escapeName(windowTypeId, windowTypeName));

    boost::optional<double> uValue;
    boost::optional<double> shgc;
    boost::optional<double> tVis;

    QDomNodeList uValueElements = element.elementsByTagName("U-value");
    for (int i = 0; i < uValueElements.count(); i++){
      QDomElement uValueElement = uValueElements.at(i).toElement();
      if (uValueElement.attribute("unit") == "WPerSquareMeterK"){
        uValue = uValueElement.text().toDouble();
        break;
      }
    }
        
    QDomNodeList shgcElements = element.elementsByTagName("SolarHeatGainCoeff");
    for (int i = 0; i < shgcElements.count(); i++){
      QDomElement shgcElement = shgcElements.at(i).toElement();
      if (shgcElement.attribute("unit") == "Fraction"){
        shgc = shgcElement.text().toDouble();
        break;
      }
    }
        
    QDomNodeList transmittanceElements = element.elementsByTagName("Transmittance");
    for (int i = 0; i < transmittanceElements.count(); i++){
      QDomElement transmittanceElement = transmittanceElements.at(i).toElement();
      if (transmittanceElement.attribute("type") == "Visible"){
        tVis = transmittanceElement.text().toDouble();
        break;
      }
    }

    if (uValue && shgc && tVis){
      model::SimpleGlazing glazing(model);
      glazing.setUFactor(*uValue);
      glazing.setSolarHeatGainCoefficient(*shgc);
      glazing.setVisibleTransmittance(*tVis);

      std::vector<model::Material> layers;
      layers.push_back(glazing);
      construction.setLayers(layers);
    }
    
    return construction;
  }
  boost::optional<QDomElement> ForwardTranslator::translateLayer(const openstudio::model::Material& material, QDomDocument& doc)
  {
    boost::optional<QDomElement> result;

    result = doc.createElement("Layer");

    std::string materialName = material.name().get();
    std::string layerName = materialName + " Layer";

    // id
    result->setAttribute("id", escapeName(layerName));

    // name
    QDomElement nameElement = doc.createElement("Name");
    result->appendChild(nameElement);
    nameElement.appendChild(doc.createTextNode(QString::fromStdString(layerName)));

    // name
    QDomElement materialIdElement = doc.createElement("MaterialId");
    result->appendChild(materialIdElement);
    materialIdElement.setAttribute("materialIdRef", escapeName(materialName));

    return result;
  }
boost::optional<openstudio::model::ModelObject> ReverseTranslator::translateScheduleDay(const QDomElement& element, const QDomDocument& doc, openstudio::model::Model& model)
{
    QString id = element.attribute("id");
    QString type = element.attribute("type");

    openstudio::model::ScheduleDay result(model);
    result.setName(escapeName(id));

    openstudio::model::ScheduleTypeLimits scheduleTypeLimits = getScheduleTypeLimits(type.toStdString(), model);
    result.setScheduleTypeLimits(scheduleTypeLimits);

    QDomNodeList valueElements = element.elementsByTagName("ScheduleValue");
    openstudio::Time dt(1.0/((double) valueElements.size()));

    for (int i = 0; i < valueElements.count(); i++) {
        double value = valueElements.at(i).toElement().text().toDouble();
        result.addValue( dt*(i+1) , value);
    }

    return result;
}
boost::optional<openstudio::model::ModelObject> ReverseTranslator::translateScheduleWeek(const QDomElement& element, const QDomDocument& doc, openstudio::model::Model& model)
{
    QString id = element.attribute("id");
    QString type = element.attribute("type");

    openstudio::model::ScheduleWeek result(model);
    result.setName(escapeName(id));

    // don't need to translate type

    QDomNodeList dayElements = element.elementsByTagName("Day");
    for (int i = 0; i < dayElements.count(); i++) {

        QString dayType = dayElements.at(i).toElement().attribute("dayType");
        QString dayScheduleIdRef = dayElements.at(i).toElement().attribute("dayScheduleIdRef");

        // this can be made more efficient using QXPath in QXmlPatterns later
        QDomNodeList dayScheduleElements = doc.documentElement().elementsByTagName("DaySchedule");
        for (int i = 0; i < dayScheduleElements.count(); i++) {
            QDomElement dayScheduleElement = dayScheduleElements.at(i).toElement();
            QString thisId = dayScheduleElement.attribute("id");
            if (thisId == dayScheduleIdRef) {

                boost::optional<openstudio::model::ModelObject> modelObject = translateScheduleDay(dayScheduleElement, doc, model);
                if (modelObject) {

                    boost::optional<openstudio::model::ScheduleDay> scheduleDay = modelObject->cast<openstudio::model::ScheduleDay>();
                    if (scheduleDay) {

                        if (dayType == "Weekday") {
                            result.setWeekdaySchedule(*scheduleDay);
                        } else if (dayType == "Weekend") {
                            result.setWeekendSchedule(*scheduleDay);
                        } else if (dayType == "Holiday") {
                            result.setHolidaySchedule(*scheduleDay);
                        } else if (dayType == "WeekendOrHoliday") {
                            result.setWeekendSchedule(*scheduleDay);
                            result.setHolidaySchedule(*scheduleDay);
                        } else if (dayType == "HeatingDesignDay") {
                            result.setWinterDesignDaySchedule(*scheduleDay);
                        } else if (dayType == "CoolingDesignDay") {
                            result.setSummerDesignDaySchedule(*scheduleDay);
                        } else if (dayType == "Sun") {
                            result.setSundaySchedule(*scheduleDay);
                        } else if (dayType == "Mon") {
                            result.setMondaySchedule(*scheduleDay);
                        } else if (dayType == "Tue") {
                            result.setTuesdaySchedule(*scheduleDay);
                        } else if (dayType == "Wed") {
                            result.setWednesdaySchedule(*scheduleDay);
                        } else if (dayType == "Thu") {
                            result.setThursdaySchedule(*scheduleDay);
                        } else if (dayType == "Fri") {
                            result.setFridaySchedule(*scheduleDay);
                        } else if (dayType == "Sat") {
                            result.setSaturdaySchedule(*scheduleDay);
                        } else {
                            // dayType can be "All"
                            result.setAllSchedules(*scheduleDay);
                        }
                    }
                }

                break;
            }
        }
    }

    return result;
}
boost::optional<openstudio::model::ModelObject> ReverseTranslator::translateSchedule(const QDomElement& element, const QDomDocument& doc, openstudio::model::Model& model)
{
    QString id = element.attribute("id");
    QString type = element.attribute("type");
    QString name = element.elementsByTagName("Name").at(0).toElement().text();

    openstudio::model::ScheduleYear result(model);
    result.setName(escapeName(id));

    openstudio::model::ScheduleTypeLimits scheduleTypeLimits = getScheduleTypeLimits(type.toStdString(), model);
    result.setScheduleTypeLimits(scheduleTypeLimits);

    openstudio::model::YearDescription yd = model.getUniqueModelObject<openstudio::model::YearDescription>();

    QDomNodeList scheduleYearElements = element.elementsByTagName("YearSchedule");
    for (int i = 0; i < scheduleYearElements.count(); i++) {
        QDomElement scheduleYearElement = scheduleYearElements.at(i).toElement();

        QString beginDateString = scheduleYearElement.elementsByTagName("BeginDate").at(0).toElement().text();
        QStringList beginDateParts = beginDateString.split('-'); // 2011-01-01
        OS_ASSERT(beginDateParts.size() == 3);
        yd.setCalendarYear(beginDateParts.at(0).toInt());
        openstudio::Date beginDate = yd.makeDate(beginDateParts.at(1).toInt(), beginDateParts.at(2).toInt());

        // handle case if schedule does not start on 1/1
        if ((i == 0) && (beginDate != yd.makeDate(1,1))) {
            OS_ASSERT(false);
        }

        QString endDateString = scheduleYearElement.elementsByTagName("EndDate").at(0).toElement().text();
        QStringList endDateParts = endDateString.split('-'); // 2011-12-31
        OS_ASSERT(endDateParts.size() == 3);
        OS_ASSERT(yd.calendarYear());
        OS_ASSERT(yd.calendarYear().get() == endDateParts.at(0).toInt());
        openstudio::Date endDate = yd.makeDate(endDateParts.at(1).toInt(), endDateParts.at(2).toInt());

        QString weekScheduleId = element.elementsByTagName("WeekScheduleId").at(0).toElement().attribute("weekScheduleIdRef");

        // this can be made more efficient using QXPath in QXmlPatterns later
        QDomNodeList scheduleWeekElements = doc.documentElement().elementsByTagName("WeekSchedule");
        for (int i = 0; i < scheduleWeekElements.count(); i++) {
            QDomElement scheduleWeekElement = scheduleWeekElements.at(i).toElement();
            QString thisId = scheduleWeekElement.attribute("id");
            if (thisId == weekScheduleId) {

                boost::optional<openstudio::model::ModelObject> modelObject = translateScheduleWeek(scheduleWeekElement, doc, model);
                if (modelObject) {

                    boost::optional<openstudio::model::ScheduleWeek> scheduleWeek = modelObject->cast<openstudio::model::ScheduleWeek>();
                    if (scheduleWeek) {
                        result.addScheduleWeek(endDate, *scheduleWeek);
                    }
                }

                break;
            }
        }
    }

    return result;
}
Exemple #9
0
  boost::optional<openstudio::model::ModelObject> ReverseTranslator::translateSchedule(const QDomElement& element, const QDomDocument& doc, openstudio::model::Model& model)
  {
    QDomElement nameElement = element.firstChildElement("Name");
    QDomElement typeElement = element.firstChildElement("Type");

    std::string name;
    if (nameElement.isNull()){
      LOG(Error, "Sch element 'Name' is empty.")
    } else{
      name = escapeName(nameElement.text());
    }

    if (typeElement.isNull()){
      LOG(Error, "Sch element 'Type' is empty for Sch named '" << name << "'.  ScheduleYear will not be created");
      return boost::none;
    }
    std::string type = escapeName(typeElement.text());

    QDomNodeList endMonthElements = element.elementsByTagName("EndMonth");
    QDomNodeList endDayElements = element.elementsByTagName("EndDay");
    QDomNodeList schWeekRefElements = element.elementsByTagName("SchWeekRef");

    if (endMonthElements.count() != endDayElements.count()){
      LOG(Error, "Number of 'EndMonth' elements not equal to number of 'EndDay' elements for Sch named '" << name << "'.  ScheduleYear will not be created");
      return boost::none;
    }

    if (endMonthElements.count() != schWeekRefElements.count()){
      LOG(Error, "Number of 'EndMonth' elements not equal to number of 'SchWeekRef' elements for Sch named '" << name << "'.  ScheduleYear will not be created");
      return boost::none;
    }

    model::ScheduleYear scheduleYear(model);
    scheduleYear.setName(name);
    
    boost::optional<model::ScheduleTypeLimits> scheduleTypeLimits = model.getModelObjectByName<model::ScheduleTypeLimits>(type);
    if (scheduleTypeLimits){
      scheduleYear.setScheduleTypeLimits(*scheduleTypeLimits);
    }

    for (int i = 0; i < endMonthElements.count(); i++){
      QDomElement endMonthElement = endMonthElements.at(i).toElement();
      QDomElement endDayElement = endDayElements.at(i).toElement();
      QDomElement schWeekRefElement = schWeekRefElements.at(i).toElement();

      boost::optional<model::ScheduleWeek> scheduleWeek = model.getModelObjectByName<model::ScheduleWeek>(escapeName(schWeekRefElement.text()));
      if (scheduleWeek){

        boost::optional<model::YearDescription> yearDescription = model.getOptionalUniqueModelObject<model::YearDescription>();
        if (yearDescription){
          MonthOfYear monthOfYear(endMonthElement.text().toUInt());
          unsigned dayOfMonth = endDayElement.text().toUInt();
          Date untilDate(monthOfYear, dayOfMonth, yearDescription->assumedYear());
          scheduleYear.addScheduleWeek(untilDate, *scheduleWeek);
        }else{
          MonthOfYear monthOfYear(endMonthElement.text().toUInt());
          unsigned dayOfMonth = endDayElement.text().toUInt();
          Date untilDate(monthOfYear, dayOfMonth);
          scheduleYear.addScheduleWeek(untilDate, *scheduleWeek);
        }
      }
    }

    return scheduleYear;
  }
Exemple #10
0
  boost::optional<openstudio::model::ModelObject> ReverseTranslator::translateScheduleWeek(const QDomElement& element, const QDomDocument& doc, openstudio::model::Model& model)
  {
    QDomElement nameElement = element.firstChildElement("Name");
    QDomElement typeElement = element.firstChildElement("Type");
    QDomElement schDaySunRefElement = element.firstChildElement("SchDaySunRef");
    QDomElement schDayMonRefElement = element.firstChildElement("SchDayMonRef");
    QDomElement schDayTueRefElement = element.firstChildElement("SchDayTueRef");
    QDomElement schDayWedRefElement = element.firstChildElement("SchDayWedRef");
    QDomElement schDayThuRefElement = element.firstChildElement("SchDayThuRef");
    QDomElement schDayFriRefElement = element.firstChildElement("SchDayFriRef");
    QDomElement schDaySatRefElement = element.firstChildElement("SchDaySatRef");
    QDomElement schDayHolRefElement = element.firstChildElement("SchDayHolRef");
    QDomElement schDayClgDDRefElement = element.firstChildElement("SchDayClgDDRef");
    QDomElement schDayHtgDDRefElement = element.firstChildElement("SchDayHtgDDRef");

    OS_ASSERT(!nameElement.isNull());
    std::string name = escapeName(nameElement.text());

    model::ScheduleWeek scheduleWeek(model);
    scheduleWeek.setName(name);

    OS_ASSERT(!typeElement.isNull());
    std::string type = escapeName(typeElement.text());
    boost::optional<model::ScheduleTypeLimits> scheduleTypeLimits = model.getModelObjectByName<model::ScheduleTypeLimits>(type);
    if (scheduleTypeLimits){
      //scheduleWeek.setScheduleTypeLimits(*scheduleTypeLimits);
    }

    if (!schDaySunRefElement.isNull()){
      boost::optional<model::ScheduleDay> scheduleDay = model.getModelObjectByName<model::ScheduleDay>(escapeName(schDaySunRefElement.text()));
      if (scheduleDay){
        scheduleWeek.setSundaySchedule(*scheduleDay);
      }else{
        LOG(Error, "No Sunday schedule found for week schedule '" << name << "'");
      }
    }

    if (!schDayMonRefElement.isNull()){
      boost::optional<model::ScheduleDay> scheduleDay = model.getModelObjectByName<model::ScheduleDay>(escapeName(schDayMonRefElement.text()));
      if (scheduleDay){
        scheduleWeek.setMondaySchedule(*scheduleDay);
      }else{
        LOG(Error, "No Monday schedule found for week schedule '" << name << "'");
      }
    }

    if (!schDayTueRefElement.isNull()){
      boost::optional<model::ScheduleDay> scheduleDay = model.getModelObjectByName<model::ScheduleDay>(escapeName(schDayTueRefElement.text()));
      if (scheduleDay){
        scheduleWeek.setTuesdaySchedule(*scheduleDay);
      }else{
        LOG(Error, "No Tuesday schedule found for week schedule '" << name << "'");
      }
    }

    if (!schDayWedRefElement.isNull()){
      boost::optional<model::ScheduleDay> scheduleDay = model.getModelObjectByName<model::ScheduleDay>(escapeName(schDayWedRefElement.text()));
      if (scheduleDay){
        scheduleWeek.setWednesdaySchedule(*scheduleDay);
      }else{
        LOG(Error, "No Wednesday schedule found for week schedule '" << name << "'");
      }
    }

    if (!schDayThuRefElement.isNull()){
      boost::optional<model::ScheduleDay> scheduleDay = model.getModelObjectByName<model::ScheduleDay>(escapeName(schDayThuRefElement.text()));
      if (scheduleDay){
        scheduleWeek.setThursdaySchedule(*scheduleDay);
      }else{
        LOG(Error, "No Thursday schedule found for week schedule '" << name << "'");
      }
    }

    if (!schDayFriRefElement.isNull()){
      boost::optional<model::ScheduleDay> scheduleDay = model.getModelObjectByName<model::ScheduleDay>(escapeName(schDayFriRefElement.text()));
      if (scheduleDay){
        scheduleWeek.setFridaySchedule(*scheduleDay);
      }else{
        LOG(Error, "No Friday schedule found for week schedule '" << name << "'");
      }
    }

    if (!schDaySatRefElement.isNull()){
      boost::optional<model::ScheduleDay> scheduleDay = model.getModelObjectByName<model::ScheduleDay>(escapeName(schDaySatRefElement.text()));
      if (scheduleDay){
        scheduleWeek.setSaturdaySchedule(*scheduleDay);
      }else{
        LOG(Error, "No Saturday schedule found for week schedule '" << name << "'");
      }
    }
   
    if (!schDayHolRefElement.isNull()){
      boost::optional<model::ScheduleDay> scheduleDay = model.getModelObjectByName<model::ScheduleDay>(escapeName(schDayHolRefElement.text()));
      if (scheduleDay){
        scheduleWeek.setHolidaySchedule(*scheduleDay);
        scheduleWeek.setCustomDay1Schedule(*scheduleDay);
        scheduleWeek.setCustomDay2Schedule(*scheduleDay);
      }else{
        LOG(Error, "No Holiday schedule found for week schedule '" << name << "'");
      }
    }

    if (!schDayClgDDRefElement.isNull()){
      boost::optional<model::ScheduleDay> scheduleDay = model.getModelObjectByName<model::ScheduleDay>(escapeName(schDayClgDDRefElement.text()));
      if (scheduleDay){
        scheduleWeek.setSummerDesignDaySchedule(*scheduleDay);
      }else{
        LOG(Error, "No Summer Design Day schedule found for week schedule '" << name << "'");
      }
    }

    if (!schDayHtgDDRefElement.isNull()){
      boost::optional<model::ScheduleDay> scheduleDay = model.getModelObjectByName<model::ScheduleDay>(escapeName(schDayHtgDDRefElement.text()));
      if (scheduleDay){
        scheduleWeek.setWinterDesignDaySchedule(*scheduleDay);
      }else{
        LOG(Error, "No Winter Design Day schedule found for week schedule '" << name << "'");
      }
    }

    return scheduleWeek;
  }
Exemple #11
0
  boost::optional<openstudio::model::ModelObject> ReverseTranslator::translateScheduleDay(const QDomElement& element, const QDomDocument& doc, openstudio::model::Model& model)
  {
    QDomElement nameElement = element.firstChildElement("Name");
    QDomElement typeElement = element.firstChildElement("Type");

    OS_ASSERT(!nameElement.isNull());
    std::string name = escapeName(nameElement.text());

    model::ScheduleDay scheduleDay(model);
    scheduleDay.setName(name);

    OS_ASSERT(!typeElement.isNull());
    std::string type = escapeName(typeElement.text());
    boost::optional<model::ScheduleTypeLimits> scheduleTypeLimits = model.getModelObjectByName<model::ScheduleTypeLimits>(type);
    bool isTemperature = false;
    if (type == "Temperature"){
      isTemperature = true;
    }

    if (!scheduleTypeLimits){
      if (type == "Fraction"){
        scheduleTypeLimits = model::ScheduleTypeLimits(model);
        scheduleTypeLimits->setName("Fraction");
        scheduleTypeLimits->setLowerLimitValue(0);
        scheduleTypeLimits->setUpperLimitValue(1);
        scheduleTypeLimits->setNumericType("Continuous");
        scheduleTypeLimits->setUnitType("Dimensionless");
      }else if (type == "Temperature"){
        scheduleTypeLimits = model::ScheduleTypeLimits(model);
        scheduleTypeLimits->setName("Temperature");
        scheduleTypeLimits->setUnitType("Temperature");
      }else if (type == "OnOff"){
        scheduleTypeLimits = model::ScheduleTypeLimits(model);
        scheduleTypeLimits->setName("OnOff");
        scheduleTypeLimits->setLowerLimitValue(0);
        scheduleTypeLimits->setUpperLimitValue(1);
        scheduleTypeLimits->setNumericType("Discrete");
        scheduleTypeLimits->setUnitType("Availability");
      }else{
        LOG(Error, "Unknown schedule type '" << type << "'");
      }
    }
    if (scheduleTypeLimits){
      scheduleDay.setScheduleTypeLimits(*scheduleTypeLimits);
    }

    QDomNodeList hrElements = element.elementsByTagName("Hr");
    OS_ASSERT(hrElements.count() == 24);
    for (int i = 0; i < hrElements.count(); i++){
      QDomElement hrElement = hrElements.at(i).toElement();
      double value = hrElement.text().toDouble();

      if (isTemperature){
        value = (value-32.0)/1.8; // deg F to deg C
      }

      scheduleDay.addValue(openstudio::Time(0, i+1, 0, 0), value);
    }

    return scheduleDay;
  }
  boost::optional<QDomElement> ForwardTranslator::translateMaterial(const openstudio::model::Material& material, QDomDocument& doc)
  {
    boost::optional<QDomElement> result;

    result = doc.createElement("Material");

    std::string name = material.name().get();

    // id
    result->setAttribute("id", escapeName(name));

    // name
    QDomElement nameElement = doc.createElement("Name");
    result->appendChild(nameElement);
    nameElement.appendChild(doc.createTextNode(QString::fromStdString(name)));

    boost::optional<double> thermalReflectance;
    boost::optional<double> solarReflectance;
    boost::optional<double> visibleReflectance;
    boost::optional<std::string> roughness;
    boost::optional<double> thickness;
    boost::optional<double> conductivity;
    boost::optional<double> resistance;
    boost::optional<double> density;
    boost::optional<double> specificHeat;
    boost::optional<double> thermalAbsorptance;
    boost::optional<double> solarAbsorptance;
    boost::optional<double> visibleAbsorptance;

    if (material.optionalCast<openstudio::model::StandardOpaqueMaterial>()){
      openstudio::model::StandardOpaqueMaterial som = material.cast<openstudio::model::StandardOpaqueMaterial>();
      thermalReflectance = som.thermalReflectance();
      solarReflectance = som.solarReflectance();
      visibleReflectance = som.visibleReflectance();
      roughness = som.roughness();
      thickness = som.thickness();
      conductivity = som.conductivity();
      density = som.density();
      specificHeat = som.specificHeat(); 
      thermalAbsorptance = som.thermalAbsorptance();
      solarAbsorptance = som.solarAbsorptance();
      visibleAbsorptance = som.visibleAbsorptance();
    }else if (material.optionalCast<openstudio::model::MasslessOpaqueMaterial>()){
      openstudio::model::MasslessOpaqueMaterial mom = material.cast<openstudio::model::MasslessOpaqueMaterial>();
      roughness = mom.roughness();
      resistance = mom.thermalResistance();
      thermalAbsorptance = mom.thermalAbsorptance();
      solarAbsorptance = mom.solarAbsorptance();
      visibleAbsorptance = mom.visibleAbsorptance();
    }else if (material.optionalCast<openstudio::model::AirGap>()){
      openstudio::model::AirGap gap = material.cast<openstudio::model::AirGap>();
      resistance = gap.thermalResistance();
    }

    if (thermalReflectance){
      QDomElement element = doc.createElement("Reflectance");
      result->appendChild(element);
      element.appendChild(doc.createTextNode(QString::number(*thermalReflectance)));
      element.setAttribute("unit", "Fraction");
      element.setAttribute("type", "ExtIR");
      element.setAttribute("surfaceType", "Both");

      element = doc.createElement("Reflectance");
      result->appendChild(element);
      element.appendChild(doc.createTextNode(QString::number(*thermalReflectance)));
      element.setAttribute("unit", "Fraction");
      element.setAttribute("type", "IntIR");
      element.setAttribute("surfaceType", "Both");
    }

    if (solarReflectance){
      QDomElement element = doc.createElement("Reflectance");
      result->appendChild(element);
      element.appendChild(doc.createTextNode(QString::number(*solarReflectance)));
      element.setAttribute("unit", "Fraction");
      element.setAttribute("type", "ExtSolar");
      element.setAttribute("surfaceType", "Both");

      element = doc.createElement("Reflectance");
      result->appendChild(element);
      element.appendChild(doc.createTextNode(QString::number(*solarReflectance)));
      element.setAttribute("unit", "Fraction");
      element.setAttribute("type", "IntSolar");
      element.setAttribute("surfaceType", "Both");
    }

    if (visibleReflectance){
      QDomElement element = doc.createElement("Reflectance");
      result->appendChild(element);
      element.appendChild(doc.createTextNode(QString::number(*visibleReflectance)));
      element.setAttribute("unit", "Fraction");
      element.setAttribute("type", "ExtVisible");
      element.setAttribute("surfaceType", "Both");

      element = doc.createElement("Reflectance");
      result->appendChild(element);
      element.appendChild(doc.createTextNode(QString::number(*visibleReflectance)));
      element.setAttribute("unit", "Fraction");
      element.setAttribute("type", "IntVisible");
      element.setAttribute("surfaceType", "Both");
    }

    if (roughness){
      QDomElement element = doc.createElement("Roughness");
      result->appendChild(element);
      element.setAttribute("value", QString::fromStdString(*roughness));
    }

    if (thickness){
      QDomElement element = doc.createElement("Thickness");
      result->appendChild(element);
      element.appendChild(doc.createTextNode(QString::number(*thickness)));
      element.setAttribute("unit", "Meters");
    }
    
    if (conductivity){
      QDomElement element = doc.createElement("Conductivity");
      result->appendChild(element);
      element.appendChild(doc.createTextNode(QString::number(*conductivity)));
      element.setAttribute("unit", "WPerMeterK");
    }

    if (resistance){
      QDomElement element = doc.createElement("R-value");
      result->appendChild(element);
      element.appendChild(doc.createTextNode(QString::number(*resistance)));
      element.setAttribute("unit", "SquareMeterKPerW");
    }
    
    if (density){
      QDomElement element = doc.createElement("Density");
      result->appendChild(element);
      element.appendChild(doc.createTextNode(QString::number(*density)));
      element.setAttribute("unit", "KgPerCubicM");
    }

    if (specificHeat){
      QDomElement element = doc.createElement("SpecificHeat");
      result->appendChild(element);
      element.appendChild(doc.createTextNode(QString::number(*specificHeat)));
      element.setAttribute("unit", "JPerKgK");
    }

    if (thermalAbsorptance){
      QDomElement element = doc.createElement("Absorptance");
      result->appendChild(element);
      element.appendChild(doc.createTextNode(QString::number(*thermalAbsorptance)));
      element.setAttribute("unit", "Fraction");
      element.setAttribute("type", "ExtIR");

      element = doc.createElement("Absorptance");
      result->appendChild(element);
      element.appendChild(doc.createTextNode(QString::number(*thermalAbsorptance)));
      element.setAttribute("unit", "Fraction");
      element.setAttribute("type", "IntIR");
    }

    if (solarAbsorptance){
      QDomElement element = doc.createElement("Absorptance");
      result->appendChild(element);
      element.appendChild(doc.createTextNode(QString::number(*solarAbsorptance)));
      element.setAttribute("unit", "Fraction");
      element.setAttribute("type", "ExtSolar");
      element = doc.createElement("Absorptance");
      result->appendChild(element);
      element.appendChild(doc.createTextNode(QString::number(*solarAbsorptance)));
      element.setAttribute("unit", "Fraction");
      element.setAttribute("type", "IntSolar");
    }

    if (visibleAbsorptance){
      QDomElement element = doc.createElement("Absorptance");
      result->appendChild(element);
      element.appendChild(doc.createTextNode(QString::number(*visibleAbsorptance)));
      element.setAttribute("unit", "Fraction");
      element.setAttribute("type", "ExtVisible");
      element = doc.createElement("Absorptance");
      result->appendChild(element);
      element.appendChild(doc.createTextNode(QString::number(*visibleAbsorptance)));
      element.setAttribute("unit", "Fraction");
      element.setAttribute("type", "IntVisible");
    }
    return result;
  }
  boost::optional<QDomElement> ForwardTranslator::translateConstructionBase(const openstudio::model::ConstructionBase& constructionBase, QDomDocument& doc)
  {
    boost::optional<QDomElement> result;

    bool isOpaque = constructionBase.isOpaque();

    if (isOpaque){
      result = doc.createElement("Construction");
      m_translatedObjects[constructionBase.handle()] = *result;
    } else{
      result = doc.createElement("WindowType");
      m_translatedObjects[constructionBase.handle()] = *result;
    }

    std::string name = constructionBase.name().get();

    // id
    result->setAttribute("id", escapeName(name));

    // name
    QDomElement nameElement = doc.createElement("Name");
    result->appendChild(nameElement);
    nameElement.appendChild(doc.createTextNode(QString::fromStdString(name)));
    
    if (isOpaque){
      if (constructionBase.optionalCast<model::LayeredConstruction>()){
        for (const auto& layer : constructionBase.cast<model::LayeredConstruction>().layers()){
          QDomElement layerIdElement = doc.createElement("LayerId");
          result->appendChild(layerIdElement);
          layerIdElement.setAttribute("layerIdRef", escapeName(layer.name().get() + " Layer"));

          m_materials.insert(layer);
        }
      }
    } else{
      boost::optional<double> visibleTransmittance;
      boost::optional<double> uFactor;
      boost::optional<double> solarHeatGainCoefficient;

      if (constructionBase.optionalCast<model::LayeredConstruction>()){
        std::vector<model::Material> layers = constructionBase.cast<model::LayeredConstruction>().layers();
        if (layers.size() == 1u){
          if (layers[0].optionalCast<model::SimpleGlazing>()){
            model::SimpleGlazing glazing = layers[0].cast<model::SimpleGlazing>();
            visibleTransmittance = glazing.visibleTransmittance();
            uFactor = glazing.uFactor();
            solarHeatGainCoefficient = glazing.solarHeatGainCoefficient();
          }
        }
      }

      if (!visibleTransmittance){
        visibleTransmittance = constructionBase.visibleTransmittance();
      }
      if (!uFactor){
        uFactor = constructionBase.uFactor();
      }
      //if (!solarHeatGainCoefficient){
      //  solarHeatGainCoefficient = constructionBase.solarHeatGainCoefficient();
      //}


      if (visibleTransmittance){
        QDomElement element = doc.createElement("Transmittance");
        result->appendChild(element);
        element.appendChild(doc.createTextNode(QString::number(*visibleTransmittance)));
        element.setAttribute("unit", "Fraction");
        element.setAttribute("type", "Visible");
        element.setAttribute("surfaceType", "Both");
      }

      if (uFactor){
        QDomElement element = doc.createElement("U-value");
        result->appendChild(element);
        element.appendChild(doc.createTextNode(QString::number(*uFactor)));
        element.setAttribute("unit", "WPerSquareMeterK");
      }

      if (solarHeatGainCoefficient){
        QDomElement element = doc.createElement("SolarHeatGainCoeff");
        result->appendChild(element);
        element.appendChild(doc.createTextNode(QString::number(*solarHeatGainCoefficient)));
        element.setAttribute("unit", "Fraction");
      }
    }
    return result;
  }
  boost::optional<openstudio::model::ModelObject> ReverseTranslator::translateMaterial(const QDomElement& element, const QDomDocument& doc, openstudio::model::Model& model)
  {
    boost::optional<openstudio::model::ModelObject> result;

    QDomNodeList rvalueElements = element.elementsByTagName("R-value");
    QDomNodeList densityElements = element.elementsByTagName("Density");
    QDomNodeList conductivityElements = element.elementsByTagName("Conductivity");
    QDomNodeList thicknessElements = element.elementsByTagName("Thickness");
    QDomNodeList specificHeatElements = element.elementsByTagName("SpecificHeat");
    QDomNodeList roughnessElements = element.elementsByTagName("Roughness");

    if (!(densityElements.isEmpty() || conductivityElements.isEmpty() || thicknessElements.isEmpty() || specificHeatElements.isEmpty())){

      double density = densityElements.at(0).toElement().text().toDouble();
      double conductivity = conductivityElements.at(0).toElement().text().toDouble();
      double thickness = thicknessElements.at(0).toElement().text().toDouble();
      double specificHeat = specificHeatElements.at(0).toElement().text().toDouble();

      std::string roughness = "MediumRough";
      if (!roughnessElements.isEmpty()){
        roughness = roughnessElements.at(0).toElement().text().toStdString();
      }

      openstudio::model::StandardOpaqueMaterial material(model);
      result = material;
        
      QString id = element.attribute("id");
      m_idToObjectMap.insert(std::make_pair(id, material));

      QString name = element.firstChildElement("Name").toElement().text();
      material.setName(escapeName(id, name));
        
      material.setDensity(density);
      material.setThermalConductivity(conductivity);
      material.setThickness(thickness);
      material.setSpecificHeat(specificHeat);
      material.setRoughness(roughness);

    } else if (!rvalueElements.isEmpty())  //Material no mass that has only R-value
    {
      // Krishnan, this constructor should only be used for unique objects like Building and Site
      //openstudio::model::MasslessOpaqueMaterial material = model.getUniqueModelObject<openstudio::model::MasslessOpaqueMaterial>();

      double rvalue = rvalueElements.at(0).toElement().text().toDouble();

      // the idd specifies a minimum value of .001 for rvalue
      rvalue = std::max(rvalue, .001);

      openstudio::model::MasslessOpaqueMaterial material(model);
      result = material;

      QString id = element.attribute("id");
      m_idToObjectMap.insert(std::make_pair(id, material));

      QString name = element.firstChildElement("Name").toElement().text(); 
      material.setName(escapeName(id, name));

      material.setThermalResistance(rvalue);

    } else { 
        
        // make a stub material
      openstudio::model::MasslessOpaqueMaterial material(model);
      result = material;

      QString id = element.attribute("id");
      m_idToObjectMap.insert(std::make_pair(id, material));

      QString name = element.firstChildElement("Name").toElement().text();
      material.setName(escapeName(id, name));

      LOG(Warn, "Creating stub material '" << name.toStdString() << "'");

      material.setThermalResistance(.001);
    }

    return result;
  }