TEST_F(ModelFixture,MasslessOpaqueMaterial_VisibleAbsorptance_Quantity) {
  Model model;
  // TODO: Check constructor.
  MasslessOpaqueMaterial masslessOpaqueMaterial(model);

  Unit units = masslessOpaqueMaterial.getVisibleAbsorptance(true).units(); // Get IP units.

  // Bounds: 0.0 <= value <= 1.0

  double value(1.0);
  Quantity testQ(value,units);
  EXPECT_TRUE(masslessOpaqueMaterial.setVisibleAbsorptance(testQ));
  Quantity q = masslessOpaqueMaterial.getVisibleAbsorptance(true);
  EXPECT_NEAR(value,q.value(),1.0E-8);
  EXPECT_EQ(units.standardString(),q.units().standardString());
}
Beispiel #2
0
OSQuantityVector::OSQuantityVector(const std::vector<Quantity>& values)
  : m_units(), m_values(values.size(),0.0)
{
  if (!values.empty()) {
    m_units = values[0].units();
  }
  const Scale& myScale = scale();
  for (unsigned i = 0, n = size(); i < n; ++i) {
    if (!(values[i].units() == m_units)) {
      LOG_AND_THROW("Quantity " << values[i] << " has units inconsistent with the first "
                    << "Quantity in vector values, " << values[0] << ".");
    }
    if (values[i].scale() != myScale) {
      Quantity working = values[i];
      working.setScale(myScale.exponent);
      m_values[i] = working.value();
    }
    else {
      m_values[i] = values[i].value();
    }
  }
}
Beispiel #3
0
  QVariant toVariant(const OSArgument& argument) {
    QVariantMap argumentData;

    argumentData["uuid"] = toQString(removeBraces(argument.uuid()));
    argumentData["version_uuid"] = toQString(removeBraces(argument.versionUUID()));
    argumentData["name"] = toQString(argument.name());
    if (!argument.displayName().empty()) {
      argumentData["display_name"] = toQString(argument.displayName());
    }
    if (argument.description() && !argument.description()->empty()) {
      argumentData["description"] = toQString(argument.description().get());
    }
    OSArgumentType type = argument.type();
    if (argument.units() && !argument.units()->empty()) {
      argumentData["units"] = toQString(argument.units().get());
    }
    argumentData["type"] = toQString(type.valueName());
    argumentData["required"] = argument.required();
    argumentData["model_dependent"] = argument.modelDependent();
    if (argument.hasValue()) {
      if (type == OSArgumentType::Quantity) {
        Quantity value = argument.valueAsQuantity();
        argumentData["value"] = value.value();
        argumentData["value_units"] = toQString(value.units().standardString());
      }
      else {
        // use QVariant directly
        argumentData["value"] = argument.valueAsQVariant();
      }
    }
    if (argument.hasDefaultValue()) {
      if (type == OSArgumentType::Quantity) {
        Quantity defaultValue = argument.defaultValueAsQuantity();
        argumentData["default_value"] = defaultValue.value();
        argumentData["default_value_units"] = toQString(defaultValue.units().standardString());
      }
      else {
        // use QVariant directly
        argumentData["default_value"] = argument.defaultValueAsQVariant();
      }
    }
    argumentData["domain_type"] = toQString(argument.domainType().valueName());
    if (argument.hasDomain()) {
      QVariantList domainList;
      int index(0);
      for (const QVariant& dval : argument.domainAsQVariant()) {
        QVariantMap domainValueMap;
        domainValueMap["domain_value_index"] = index;
        if (type == OSArgumentType::Quantity) {
          Quantity q = dval.value<openstudio::Quantity>();
          domainValueMap["value"] = q.value();
          domainValueMap["units"] = toQString(q.units().standardString());
        }
        else {
          domainValueMap["value"] = dval;
        }
        domainList.push_back(domainValueMap);
        ++index;
      }
      argumentData["domain"] = domainList;
    }
    if (type == OSArgumentType::Choice) {
      QVariantList choicesList;
      StringVector displayNames = argument.choiceValueDisplayNames();
      int index(0), displayNamesN(displayNames.size());
      for (const std::string& choice : argument.choiceValues()) {
        QVariantMap choiceMap;
        choiceMap["choice_index"] = index;
        choiceMap["value"] = toQString(choice);
        if (index < displayNamesN) {
          choiceMap["display_name"] = toQString(displayNames[index]);
        }
        choicesList.push_back(choiceMap);
        ++index;
      }
      argumentData["choices"] = QVariant(choicesList);
    }
    if (type == OSArgumentType::Path) {
      argumentData["is_read"] = argument.isRead();
      argumentData["extension"] = toQString(argument.extension());
    }

    return QVariant(argumentData);
  }
TEST_F(UnitsFixture,Quantity_ArithmeticOperators)
{
  LOG(Debug,"Quantity_ArithmeticOperators");

  Quantity q1;
  Quantity q2(1.0);

  Unit u3;
  u3.setBaseUnitExponent("ft",1);
  Quantity q3(34.2,u3);

  // addition
  Quantity q4 = q1 + q2;
  q4 += q4;
  testNumbersEqual(2.0,q4.value());
  testStreamOutput("2",q4);
  ASSERT_THROW(q3 + q1,Exception);

  // subtraction;
  ASSERT_THROW(q3 - q1,Exception);
  Quantity len(3.5,u3);
  len -= q3;
  testNumbersEqual(-30.7,len.value());
  testStreamOutput("-30.7 ft",len,1);

  // multiplication
  q3 *= q4;
  testNumbersEqual(68.4,q3.value());
  testStreamOutput("68.4 ft",q3,1);

  Unit u5;
  u5.setBaseUnitExponent("s",-2);
  u5.setBaseUnitExponent("ft",1);
  Quantity q5(0.5,u5);
  Quantity q6 = q5 * q3;
  testNumbersEqual(34.2,q6.value());
  testStreamOutput("34.2 ft^2/s^2",q6,1);

  // division
  len = Quantity(1.1,u3);
  Quantity a = q6/len;
  testNumbersEqual(31.0909090909,a.value());
  EXPECT_EQ("ft/s^2",a.standardUnitsString());

  // pow
  a.pow(6);
  EXPECT_EQ("ft^6/s^12",a.standardUnitsString());
  Quantity b = openstudio::pow(a,1,3);
  EXPECT_EQ("ft^2/s^4",b.standardUnitsString());
  testNumbersEqual(966.644628099,b.value());
  a = b;

  // multiplication and division with double
  a *= 1.21;
  testNumbersEqual(1169.64,a.value());
  b = a/2;
  testNumbersEqual(584.82,b.value());
  EXPECT_EQ("ft^2/s^4",b.standardUnitsString());
  EXPECT_EQ("",b.prettyUnitsString());

  Quantity c = 32.0/b;
  EXPECT_EQ("s^4/ft^2",c.standardUnitsString());
  testNumbersEqual(0.054717690913,c.value());

  // Operations on Quantities with units of temperature
  LOG(Debug,"Quantity_FahrenheitUnit_Arithmetic");

  FahrenheitUnit fu1(1, 0, "");
  Quantity T1(60.0,fu1);
  FahrenheitUnit fu2(1);
  Quantity T2(74.0,fu2);
  Quantity TT1 = pow(T1,2);
  Quantity TT2 = pow(T2,2);

  EXPECT_TRUE(TT1.isAbsolute());
  EXPECT_TRUE(TT2.isAbsolute());

  Quantity q;

  // -, unary
  q = -T1;
  testStreamOutput("-60 F",q);
  q.setAsRelative();
  q = -q;
  testStreamOutput("60 F",q);
  EXPECT_FALSE(q.isAbsolute());

  // +, good units, bad units, absolute + relative = absolute
  q = T1 + T2;
  EXPECT_TRUE(q.isAbsolute());
  testStreamOutput("134 F",q,0);
  EXPECT_THROW(T1 + TT1,Exception);
  q.setAsRelative();
  q += T1;
  EXPECT_TRUE(q.isAbsolute());

  // -, binary, good units, bad units, absolute -> relative when exp == 1, ow same as +
  q = T2 - T1;
  testStreamOutput("14 F",q,0);
  EXPECT_FALSE(q.isAbsolute());
  EXPECT_THROW(q - TT2,Exception);
  q -= T1;
  EXPECT_TRUE(q.isAbsolute());
  testStreamOutput("-46 F",q,0);
  q = TT2 - TT1;
  EXPECT_TRUE(q.isAbsolute());

  // *, absolute*relative = absolute
  Quantity deltaT = T2 - T1;
  q = deltaT * TT1;
  EXPECT_TRUE(q.isAbsolute());
  testNumbersEqual(14.0*3600.0,q.value());
  q = TT1 * deltaT;
  EXPECT_TRUE(q.isAbsolute());
  testNumbersEqual(14.0*3600.0,q.value());
  EXPECT_EQ("F^3",q.standardUnitsString());

  // /, absolute/relative = absolute and vice-versa
  q = TT1/deltaT;
  EXPECT_TRUE(q.isAbsolute());
  q = deltaT/TT2;
  EXPECT_TRUE(q.isAbsolute());
  testNumbersEqual(14.0/TT2.value(),q.value());
  EXPECT_EQ("1/F",q.standardUnitsString());

  // * w/ double, retains absolute v. relative of quantity
  q = T1 * 3.0;
  EXPECT_TRUE(q.isAbsolute());
  testStreamOutput("180 F",q,0);
  q = 2.0 * deltaT;
  EXPECT_FALSE(q.isAbsolute());
  testNumbersEqual(28.0,q.value());

  // / w/ double, retains absolute v. relative of quantity
  q = 20.0/T1;
  EXPECT_TRUE(q.isAbsolute());
  testStreamOutput("0.333 1/F",q,3);
  q = deltaT/2.0;
  EXPECT_FALSE(q.isAbsolute());
  testStreamOutput("7 F",q,0);

}
Beispiel #5
0
bool OSRunner::validateUserArguments(const std::vector<OSArgument>& script_arguments,
                                     const std::map<std::string, OSArgument>& user_arguments)
{
    bool result(true);
    std::stringstream ss;
    AttributeVector argumentValueAttributes;
    for (const OSArgument& script_argument : script_arguments) {
        auto it = user_arguments.find(script_argument.name());
        if (it == user_arguments.end()) {
            // script_argument is not in user_arguments
            // this is only okay for purely optional arguments
            if (script_argument.required() || script_argument.hasDefaultValue()) {
                ss << "Argument " << script_argument.name() << " is required or has a default value, ";
                ss << "but is not in user_arguments.";
                registerError(ss.str());
                ss.str("");
                result = false;
            }
        }
        else {
            // script_argument is in user_arguments
            OSArgument user_argument = it->second;

            // check that names still match
            if (user_argument.name() != script_argument.name()) {
                ss << "User argument name '" << user_argument.name() << "' does not match map key ";
                ss << script_argument.name() << ".";
                registerWarning(ss.str());
                ss.str("");
            }

            // check that types still match
            if (user_argument.type() != script_argument.type()) {
                ss << "User argument type " << user_argument.type().valueName() << " does not match ";
                ss << "script argument type " << script_argument.type().valueName() << ".";
                registerError(ss.str());
                ss.str("");
                result = false;
            }

            //  check that we have values
            if ((script_argument.required()) &&
                    !(user_argument.hasValue() || user_argument.hasDefaultValue()))
            {
                ss << "Script argument '" << script_argument.name() << "' is required, ";
                ss << "but the user argument does not have a value or default value set.";
                registerError(ss.str());
                ss.str("");
                result = false;
            }

            // check for default value mismatch
            if (script_argument.hasDefaultValue() && !user_argument.hasDefaultValue()) {
                ss << "Script argument '" << script_argument.name() << "' has a default value, but the ";
                ss << "user-supplied version does not.";
                registerWarning(ss.str());
                ss.str("");
            }
            if (!script_argument.hasDefaultValue() && user_argument.hasDefaultValue()) {
                ss << "Script argument '" << script_argument.name() << "' does not have a default value, ";
                ss << "but the user-supplied version does.";
                registerWarning(ss.str());
                ss.str("");
            }
            if (script_argument.hasDefaultValue() && user_argument.hasDefaultValue() &&
                    (user_argument.type() == script_argument.type()))
            {
                ss << "The default value of script argument " << std::endl << script_argument << std::endl;
                ss << "does not match that of the corresponding user argument " << std::endl << user_argument << ".";
                switch (script_argument.type().value()) {
                case OSArgumentType::Boolean :
                    if (user_argument.defaultValueAsBool() != script_argument.defaultValueAsBool()) {
                        registerWarning(ss.str());
                    }
                    break;
                case OSArgumentType::Double :
                    if (user_argument.defaultValueAsDouble() != script_argument.defaultValueAsDouble()) {
                        registerWarning(ss.str());
                    }
                    break;
                case OSArgumentType::Quantity :
                    if (user_argument.defaultValueAsQuantity() != script_argument.defaultValueAsQuantity()) {
                        registerWarning(ss.str());
                    }
                    break;
                case OSArgumentType::Integer :
                    if (user_argument.defaultValueAsInteger() != script_argument.defaultValueAsInteger()) {
                        registerWarning(ss.str());
                    }
                    break;
                case OSArgumentType::String :
                case OSArgumentType::Choice :
                case OSArgumentType::Path :
                    if (user_argument.defaultValueAsString() != script_argument.defaultValueAsString()) {
                        registerWarning(ss.str());
                    }
                    break;
                default :
                    OS_ASSERT(false);
                }
                ss.str("");
            }

            // check for domain mismatch
            if (script_argument.hasDomain() && !user_argument.hasDomain()) {
                ss << "Script argument '" << script_argument.name() << "' has a specified domain, but the ";
                ss << "user-supplied version does not.";
                registerWarning(ss.str());
                ss.str("");
            }
            if (!script_argument.hasDomain() && user_argument.hasDomain()) {
                ss << "Script argument '" << script_argument.name() << "' does not have a specified domain, ";
                ss << "but the user-supplied version does.";
                registerWarning(ss.str());
                ss.str("");
            }
            if (script_argument.hasDomain() && user_argument.hasDomain() &&
                    (user_argument.type() == script_argument.type()))
            {
                ss << "The domain of script argument " << std::endl << script_argument << std::endl;
                ss << "does not match that of the corresponding user argument " << std::endl << user_argument << ".";
                switch (script_argument.type().value()) {
                case OSArgumentType::Boolean:
                    // DLM: should bool's even have domains?
                    if (user_argument.domainAsBool() != script_argument.domainAsBool()) {
                        registerWarning(ss.str());
                    }
                    break;
                case OSArgumentType::Double:
                    if (user_argument.domainAsDouble() != script_argument.domainAsDouble()) {
                        registerWarning(ss.str());
                    }
                    break;
                case OSArgumentType::Quantity:
                    // DLM: deprecated forget about getting this to compile
                    //if (user_argument.domainAsQuantity() != script_argument.domainAsQuantity()) {
                    //  registerWarning(ss.str());
                    //}
                    break;
                case OSArgumentType::Integer:
                    if (user_argument.domainAsInteger() != script_argument.domainAsInteger()) {
                        registerWarning(ss.str());
                    }
                    break;
                case OSArgumentType::String:
                case OSArgumentType::Choice:
                case OSArgumentType::Path:
                    if (user_argument.domainAsString() != script_argument.domainAsString()) {
                        registerWarning(ss.str());
                    }
                    break;
                default:
                    OS_ASSERT(false);
                }
                ss.str("");
            }

            // success, set the values
            if (result) {
                Quantity q;
                switch(user_argument.type().value()) {
                case OSArgumentType::Boolean :
                    if (user_argument.hasValue()) {
                        argumentValueAttributes.push_back(Attribute(user_argument.name(),user_argument.valueAsBool()));
                    } else if (user_argument.hasDefaultValue()) {
                        argumentValueAttributes.push_back(Attribute(user_argument.name(),user_argument.defaultValueAsBool()));
                    }
                    break;
                case OSArgumentType::Double :
                    if (user_argument.hasValue()) {
                        argumentValueAttributes.push_back(Attribute(user_argument.name(),user_argument.valueAsDouble()));
                    } else if (user_argument.hasDefaultValue()) {
                        argumentValueAttributes.push_back(Attribute(user_argument.name(),user_argument.defaultValueAsDouble()));
                    }
                    break;
                case OSArgumentType::Quantity :
                    if (user_argument.hasValue()) {
                        q = user_argument.valueAsQuantity();
                    } else if (user_argument.hasDefaultValue()) {
                        q = user_argument.defaultValueAsQuantity();
                    }
                    argumentValueAttributes.push_back(Attribute(user_argument.name(),q.value(),q.units().print()));
                    break;
                case OSArgumentType::Integer :
                    if (user_argument.hasValue()) {
                        argumentValueAttributes.push_back(Attribute(user_argument.name(),user_argument.valueAsInteger()));
                    } else if (user_argument.hasDefaultValue()) {
                        argumentValueAttributes.push_back(Attribute(user_argument.name(),user_argument.defaultValueAsInteger()));
                    }
                    break;
                case OSArgumentType::String :
                case OSArgumentType::Choice :
                case OSArgumentType::Path :
                    if (user_argument.hasValue()) {
                        argumentValueAttributes.push_back(Attribute(user_argument.name(),user_argument.valueAsString()));
                    } else if (user_argument.hasDefaultValue()) {
                        argumentValueAttributes.push_back(Attribute(user_argument.name(),user_argument.defaultValueAsString()));
                    }
                    break;
                default:
                    OS_ASSERT(false);
                }
            }
        }
    }

    if (result) {
        for (Attribute& attribute : argumentValueAttributes) {
            registerAttribute(attribute);
        }
    }

    return result;
}
Beispiel #6
0
Quantity::Quantity(const Quantity &q)
  : m_value(q.value()), m_units(q.units())
{}
 double FFactorGroundFloorConstruction_Impl::fFactor() const {
   Quantity q = getFFactor(false);
   return q.value();
 }
 double FFactorGroundFloorConstruction_Impl::perimeterExposed() const {
   Quantity q = getPerimeterExposed(false);
   return q.value();
 }