当前位置: 首页>>代码示例>>C++>>正文


C++ OptionalQuantity类代码示例

本文整理汇总了C++中OptionalQuantity的典型用法代码示例。如果您正苦于以下问题:C++ OptionalQuantity类的具体用法?C++ OptionalQuantity怎么用?C++ OptionalQuantity使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了OptionalQuantity类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: TEST_F

TEST_F(UnitsFixture,IddUnits_DefaultValue) {
  IdfObject idfObject(IddObjectType::OS_Building);
  // IdfObject::getQuantity(unsigned index, bool returnDefault=false, bool returnIP=false) const;

  // this field is empty but has a default value of 3 m
  EXPECT_TRUE(idfObject.getQuantity(OS_BuildingFields::NominalFloortoFloorHeight, false).empty());

  OSOptionalQuantity siQ = idfObject.getQuantity(OS_BuildingFields::NominalFloortoFloorHeight, true, false);
  ASSERT_FALSE(siQ.empty());
  OptionalUnit mUnit = createUnit("m");
  ASSERT_TRUE(mUnit);
  EXPECT_EQ(*mUnit, siQ.get().units());
  EXPECT_EQ(3.0, siQ.get().value());

  OSOptionalQuantity ipQ = idfObject.getQuantity(OS_BuildingFields::NominalFloortoFloorHeight, true, true);
  ASSERT_FALSE(ipQ.empty());
  OptionalUnit ftUnit = createUnit("ft");
  ASSERT_TRUE(ftUnit);
  EXPECT_EQ(*ftUnit, ipQ.get().units());
  EXPECT_NE(3.0, ipQ.get().value());
  
  OptionalQuantity q = QuantityConverter::instance().convert(ipQ.get(), *mUnit);
  ASSERT_TRUE(q);
  EXPECT_DOUBLE_EQ(3.0, q->value());
}
开发者ID:ChengXinDL,项目名称:OpenStudio,代码行数:25,代码来源:IddUnits_GTest.cpp

示例2: working

boost::optional<Quantity> QuantityConverterSingleton::convert(const Quantity &original,
                                                              const Unit& targetUnits) const
{
  Quantity working(original);
  OptionalQuantity candidate;

  // See if nothing to be done. (Check for equality of system and base units + exponents.)
  if ((working.system() == targetUnits.system()) && (working.units() == targetUnits))
  {
    // Assume targetUnits has desired scale.
    working.setScale(targetUnits.scale().exponent);
    return working;
  }

  // All conversions go through SI
  if (working.system() != UnitSystem::SI) {
    candidate = m_convertToSI(working);
    if (!candidate) {
      return boost::none;
    }
    working = *candidate;
  }

  // Retain pretty string
  OptionalQuantity result = m_convertToTargetFromSI(working,targetUnits);
  if (result && 
      result->prettyUnitsString(false).empty() && 
      !targetUnits.prettyString(false).empty()) 
  {
    result->setPrettyUnitsString(targetUnits.prettyString(false));
  }

  return result;
}
开发者ID:CUEBoxer,项目名称:OpenStudio,代码行数:34,代码来源:QuantityConverter.cpp

示例3: TEST_F

TEST_F(UnitsFixture,QuantityConverter_PowerDensity) {
    Quantity siLpd(10.0,createSIPowerDensity());
    Unit ipPowerDensity = createUnit("W/ft^2").get();
    OptionalQuantity ipLpd = convert(siLpd,ipPowerDensity);
    Quantity siArea(1.0,pow(createSILength(),2));
    OptionalQuantity ipArea = convert(siArea,UnitSystem(UnitSystem::IP));
    ASSERT_TRUE(ipLpd);
    ASSERT_TRUE(ipArea);
    EXPECT_NEAR(10.0/ipArea->value(),ipLpd->value(),tol);
    EXPECT_EQ("W/ft^2",ipLpd->prettyUnitsString());
}
开发者ID:urbanengr,项目名称:OpenStudio,代码行数:11,代码来源:QuantityConverter_GTest.cpp

示例4: convert

OSQuantityVector convert(const OSQuantityVector& original, const Unit& targetUnits) {
  OSQuantityVector result;
  Quantity testQuantity(0.0,original.units());
  OptionalQuantity offset = convert(testQuantity,targetUnits);
  if (!offset) {
    return result;
  }
  testQuantity.setValue(1.0);
  OptionalQuantity factorPlusOffset = convert(testQuantity,targetUnits);
  OS_ASSERT(factorPlusOffset);
  OS_ASSERT(offset->units() == factorPlusOffset->units());
  result = OSQuantityVector(offset->units(),original.values());
  result = result * (factorPlusOffset->value() - offset->value()) + offset.get();
  return result;
}
开发者ID:CUEBoxer,项目名称:OpenStudio,代码行数:15,代码来源:QuantityConverter.cpp

示例5: TEST_F

TEST_F(IdfFixture, IdfObject_GetQuantity)
{
    std::string text = "Building,                !- Building \n\
                      Building,                !- Name \n\
                      30.,                     !- North Axis {deg} \n\
                      City,                    !- Terrain \n\
                      0.04,                    !- Loads Convergence Tolerance Value \n\
                      0.4,                     !- Temperature Convergence Tolerance Value {deltaC} \n\
                      FullExterior,            !- Solar Distribution \n\
                      25;                      !- Maximum Number of Warmup Days";

  // make an idf object
  OptionalIdfObject oObj = IdfObject::load(text);
  ASSERT_TRUE(oObj);

  // Test get.
  OSOptionalQuantity ooq = oObj->getQuantity (4);
  ASSERT_TRUE(ooq.isSet());
  Quantity q = ooq.get();
  EXPECT_TRUE(q.value() == 0.4);
  EXPECT_TRUE(q.system() == UnitSystem::SI);
  EXPECT_TRUE(q.standardUnitsString() == "K");

  // Test set.
  OptionalQuantity oq = convert(q,UnitSystem(UnitSystem::IP));
  ASSERT_TRUE(oq);
  EXPECT_TRUE(oq->system() == UnitSystem::IP);
  EXPECT_DOUBLE_EQ(0.72,oq->value());
  oq->setValue(1.5);

  EXPECT_TRUE(oObj->setQuantity(4, *oq));
  ooq = oObj->getQuantity(4);
  ASSERT_TRUE(ooq.isSet());
  q = ooq.get();
  EXPECT_DOUBLE_EQ(0.83333333333333333,q.value());
  EXPECT_TRUE(q.system() == UnitSystem::SI);
  EXPECT_TRUE(q.standardUnitsString() == "K");
}
开发者ID:ChengXinDL,项目名称:OpenStudio,代码行数:38,代码来源:IdfObject_GTest.cpp

示例6: result

double SchedulesTabController::defaultStartingValue(const model::ScheduleDay& scheduleDay) {
  double result(0.3);
  if (model::OptionalScheduleTypeLimits typeLimits = scheduleDay.scheduleTypeLimits()) {
    OptionalUnit siU = model::ScheduleTypeLimits::units(typeLimits->unitType(),false);
    if (siU) {
      std::string unitType = typeLimits->unitType();
      boost::to_lower(unitType);
      char firstLetter = unitType[0];
      OptionalQuantity siQ;
      switch (firstLetter) {
      case 'a' :
        { 
          if (unitType == "activitylevel") {          
            siQ = Quantity(100.0,*siU);
          }
          else if (unitType == "angle") {
            siQ = Quantity(0.0,*siU);
          }
          else if (unitType == "availability") {
            siQ = Quantity(1.0,*siU);
          }
          break;
        }
      case 'c' :
        {
          if (unitType == "capacity") {
            siQ = Quantity(100.0,*siU);
          }
          else if (unitType == "clothinginsulation") {
            siQ = Quantity(0.5,*siU);
          }
          else if (unitType == "controlmode") {
            siQ = Quantity(0.0,*siU);
          }
          else if (unitType == "convectioncoefficient") {
            siQ = Quantity(10.0,*siU);
          }
          break;
        }
      case 'd' :
        {
          if (unitType == "deltatemperature") {
            siQ = Quantity(3.0,*siU);
          }
          break;
        }
      case 'm' :
        {
          if (unitType == "massflowrate") {
            siQ = Quantity(1.0,*siU);
          }
          break;
        }
      case 'p' :
        {
          if (unitType == "percent") {
            siQ = Quantity(50.0,*siU);
          }
          else if (unitType == "power") {
            siQ = Quantity(100.0,*siU);
          }
          else if (unitType == "precipitationrate") {
            siQ = Quantity(0.01,*siU);
          }
          else if (unitType == "pressure") {
            siQ = Quantity(100.0,*siU);
          }
          break;
        }
      case 'r' :
        {
          siQ = Quantity(1500.0,*siU);
          break;
        }
      case 's' :
        {
          if (unitType == "solarenergy") {
            siQ = Quantity(1000.0,*siU);
          }
          break;
        }
      case 't' :
        {
          if (unitType == "temperature") {
            siQ = Quantity(23.5,*siU);
          }
          break;
        }
      case 'v' :
        {
          if (unitType == "velocity") {
            siQ = Quantity(1.0,*siU);
          }
          if (unitType == "volumetricflowrate") {
            siQ = Quantity(1.0E-4,*siU);
          }
          break;
        }
      default :
        break;
//.........这里部分代码省略.........
开发者ID:pepsi7959,项目名称:OpenStudio,代码行数:101,代码来源:SchedulesTabController.cpp

示例7: TEST_F

TEST_F(ModelFixture, PlanarSurface_FilmResistanceConversions)
{
  Quantity q;
  OptionalQuantity qc;

  q = createQuantity(0.61,"ft^2*R*h/Btu").get();
  qc = QuantityConverter::instance().convert(q,UnitSystem(UnitSystem::SI));
  ASSERT_TRUE(qc);
  EXPECT_EQ("s^3*K/kg",qc->standardUnitsString());
  EXPECT_NEAR(qc->value(),PlanarSurface::filmResistance(FilmResistanceType::StillAir_HorizontalSurface_HeatFlowsUpward),1.0E-8);

  q = createQuantity(0.62,"ft^2*R*h/Btu").get();
  qc = QuantityConverter::instance().convert(q,UnitSystem(UnitSystem::SI));
  ASSERT_TRUE(qc);
  EXPECT_EQ("s^3*K/kg",qc->standardUnitsString());
  EXPECT_NEAR(qc->value(),PlanarSurface::filmResistance(FilmResistanceType::StillAir_45DegreeSurface_HeatFlowsUpward),1.0E-8);

  q = createQuantity(0.68,"ft^2*R*h/Btu").get();
  qc = QuantityConverter::instance().convert(q,UnitSystem(UnitSystem::SI));
  ASSERT_TRUE(qc);
  EXPECT_EQ("s^3*K/kg",qc->standardUnitsString());
  EXPECT_NEAR(qc->value(),PlanarSurface::filmResistance(FilmResistanceType::StillAir_VerticalSurface),1.0E-8);

  q = createQuantity(0.76,"ft^2*R*h/Btu").get();
  qc = QuantityConverter::instance().convert(q,UnitSystem(UnitSystem::SI));
  ASSERT_TRUE(qc);
  EXPECT_EQ("s^3*K/kg",qc->standardUnitsString());
  EXPECT_NEAR(qc->value(),PlanarSurface::filmResistance(FilmResistanceType::StillAir_45DegreeSurface_HeatFlowsDownward),1.0E-8);

  q = createQuantity(0.92,"ft^2*R*h/Btu").get();
  qc = QuantityConverter::instance().convert(q,UnitSystem(UnitSystem::SI));
  ASSERT_TRUE(qc);
  EXPECT_EQ("s^3*K/kg",qc->standardUnitsString());
  EXPECT_NEAR(qc->value(),PlanarSurface::filmResistance(FilmResistanceType::StillAir_HorizontalSurface_HeatFlowsDownward),1.0E-8);

  q = createQuantity(0.17,"ft^2*R*h/Btu").get();
  qc = QuantityConverter::instance().convert(q,UnitSystem(UnitSystem::SI));
  ASSERT_TRUE(qc);
  EXPECT_EQ("s^3*K/kg",qc->standardUnitsString());
  EXPECT_NEAR(qc->value(),PlanarSurface::filmResistance(FilmResistanceType::MovingAir_15mph),1.0E-8);

  q = createQuantity(0.25,"ft^2*R*h/Btu").get();
  qc = QuantityConverter::instance().convert(q,UnitSystem(UnitSystem::SI));
  ASSERT_TRUE(qc);
  EXPECT_EQ("s^3*K/kg",qc->standardUnitsString());
  EXPECT_NEAR(qc->value(),PlanarSurface::filmResistance(FilmResistanceType::MovingAir_7p5mph),1.0E-8);
}
开发者ID:NREL,项目名称:OpenStudio,代码行数:47,代码来源:PlanarSurface_GTest.cpp

示例8: TEST_F

TEST_F(IddFixture,IddFactory_Units) {
    std::vector<boost::regex> unsupported;
    unsupported.push_back(boost::regex("\\$"));
    unsupported.push_back(boost::regex("eV"));
    unsupported.push_back(boost::regex("hh:mm"));
    unsupported.push_back(boost::regex("percent"));
    unsupported.push_back(boost::regex("ppm"));

    IddObjectVector objects = IddFactory::instance().getObjects(IddFileType(IddFileType::WholeFactory));
    StringSet goodUnits;
    StringSet badUnits;
    for (const IddObject& object : objects) {
        IddFieldVector fields = object.nonextensibleFields();
        IddFieldVector temp = object.extensibleGroup();
        fields.insert(fields.end(),temp.begin(),temp.end());
        for (const IddField& field : fields) {
            OptionalString iddUnits = field.properties().units;
            OptionalUnit siUnit;
            if (iddUnits) {

                // check if already tested units
                if (goodUnits.find(*iddUnits) != goodUnits.end()) {
                    continue;
                }
                if (badUnits.find(*iddUnits) != badUnits.end()) {
                    continue;
                }

                // screen for unsupported units
                for (const boost::regex& re : unsupported) {
                    if (boost::regex_search(*iddUnits,re)) {
                        iddUnits = boost::none;
                        break;
                    }
                }
                if (!iddUnits) {
                    continue;
                }

                siUnit = field.getUnits(false);
                EXPECT_TRUE(siUnit || field.unitsBasedOnOtherField()) << object.name() << " field: " << field.name();
                if (siUnit) {
                    // could just return junk unit. if not junk, quantity will be convertible
                    // to UnitSystem::SI.
                    Quantity q(1.0,*siUnit);
                    OptionalQuantity testQ = convert(q,UnitSystem(UnitSystem::SI));
                    EXPECT_TRUE(testQ) << "Unable to convert unit '" << *iddUnits << "' to SI for field '"
                                       << field.name() << "' in IddObject '" << object.name() << "'.";
                    if (testQ) {
                        goodUnits.insert(*iddUnits);
                        EXPECT_TRUE(testQ->system() == UnitSystem::SI);
                    } else {
                        badUnits.insert(*iddUnits);
                        LOG(Debug,"Unable to convert unit '" << *iddUnits << "' to SI for field '"
                            << field.name() << "' in IddObject '" << object.name() << "'.");
                    }
                }
                else if (field.unitsBasedOnOtherField()) {
                    goodUnits.insert(*iddUnits);
                    continue;
                }
                else {
                    badUnits.insert(*iddUnits);
                    LOG(Debug,"Unable to instantiate unit '" << *iddUnits << "' for field '"
                        << field.name() << "' in IddObject '" << object.name() << "'.");
                    continue;
                }
                OptionalUnit ipUnit = field.getUnits(true);
                EXPECT_TRUE(ipUnit);
                if (ipUnit) {
                    // could just return junk unit. if not junk, quantity will be convertable
                    // to *siUnit or UnitSystem::SI.
                    Quantity q(1.0,*ipUnit);
                    OptionalQuantity testQ;
                    if (siUnit) {
                        testQ = convert(q,*siUnit);
                    }
                    else {
                        testQ = convert(q,UnitSystem(UnitSystem::SI));
                    }
                    EXPECT_TRUE(testQ);
                    if (testQ) {
                        goodUnits.insert(*iddUnits);
                    }
                    else {
                        badUnits.insert(ipUnit->standardString());
                        LOG(Debug,"Unable to convert unit " << *ipUnit << " to IDD/SI units " << *siUnit
                            << " for field '" << field.name() << "' in IddObject '" << object.name() << "'.");
                    }
                }
                else {
                    badUnits.insert(*iddUnits);
                    LOG(Debug,"Unable to instantiate ipUnit for field " << field.name() << " in IddObject "
                        << object.name() << ", which has units " << *siUnit << ".");
                }
            }
        }
    }
    LOG(Info,"IddUnitStrings not handled properly by the Factories and Converter:");
    for (const std::string& str : badUnits) {
//.........这里部分代码省略.........
开发者ID:BIMDataHub,项目名称:OpenStudio-IFC-Importer,代码行数:101,代码来源:IddFactory_GTest.cpp


注:本文中的OptionalQuantity类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。