Пример #1
0
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;
}
Пример #2
0
TEST_F(ModelFixture,People_Schedule_Quantities) {
  Model model;
  PeopleDefinition definition(model);
  definition.setNumberofPeople(Quantity(100.0,createSIPeople()));

  People people(definition);
  ScheduleRuleset activityLevelSchedule(model);
  EXPECT_TRUE(checkOrAssignScheduleTypeLimits("People","Activity Level",activityLevelSchedule));
  ScheduleDay defaultSchedule = activityLevelSchedule.defaultDaySchedule();
  defaultSchedule.addValue(Time(0,24,0,0),Quantity(150.0,createSIPower()/createSIPeople()));
  EXPECT_TRUE(people.setActivityLevelSchedule(activityLevelSchedule));
  OSQuantityVector ipValues = defaultSchedule.getValues(true);
  EXPECT_EQ("W/person",ipValues.units().prettyString());
  EXPECT_DOUBLE_EQ(150.0,ipValues.values()[0]);
}
Пример #3
0
Quantity dot(OSQuantityVector lVector, const OSQuantityVector& rVector) {
  Unit lUnits(lVector.units()), rUnits(rVector.units());
  OptionalTemperatureUnit ltu = lUnits.optionalCast<TemperatureUnit>();
  OptionalTemperatureUnit rtu = rUnits.optionalCast<TemperatureUnit>();
  Unit resultUnits;
  if (ltu && rtu) {
    resultUnits = ltu.get() * rtu.get();
  }
  else {
    resultUnits = lUnits * rUnits;
  }
  ScaleOpReturnType resultScale = lVector.scale() * rVector.scale();
  lVector *= resultScale.second;
  DoubleVector lValues(lVector.values()), rValues(rVector.values());
  double resultValue = dot(createVector(lValues),createVector(rValues));
  return Quantity(resultValue,resultUnits);
}
TEST_F(UnitsFixture,QuantityConverter_OSQuantityVector) {
    // basic conversion
    OSQuantityVector testVec(createIPEnergy(),2u,100.0);
    Quantity testQ(100.0,createIPEnergy());

    OSQuantityVector resultVec = convert(testVec,UnitSystem(UnitSystem::Wh));
    OptionalQuantity resultQ = convert(testQ,UnitSystem(UnitSystem::Wh));
    ASSERT_EQ(2u,resultVec.size());
    ASSERT_TRUE(resultQ);
    EXPECT_EQ(resultQ.get(),resultVec.getQuantity(0));
    EXPECT_EQ(resultQ.get(),resultVec.getQuantity(1));
    EXPECT_EQ(resultQ->system(),resultVec.system());

    resultVec = convert(testVec,resultQ->units());
    resultQ = convert(testQ,resultQ->units());
    ASSERT_EQ(2u,resultVec.size());
    ASSERT_TRUE(resultQ);
    EXPECT_EQ(resultQ.get(),resultVec.getQuantity(0));
    EXPECT_EQ(resultQ.get(),resultVec.getQuantity(1));
    EXPECT_EQ(resultQ->system(),resultVec.system());

    // temperature conversion
    testVec = OSQuantityVector(createCelsiusTemperature(),2u,20.0);
    testQ = Quantity(20.0,createCelsiusTemperature());
    resultVec = convert(testVec,UnitSystem(UnitSystem::Fahrenheit));
    resultQ = convert(testQ,UnitSystem(UnitSystem::Fahrenheit));
    ASSERT_EQ(2u,resultVec.size());
    ASSERT_TRUE(resultQ);
    EXPECT_EQ(resultQ.get().units(),resultVec.units());
    // not sure why these aren't quite getting the precision we would like
    EXPECT_NEAR(resultQ.get().value(),resultVec.getQuantity(0).value(),1.0E-12);
    EXPECT_NEAR(resultQ.get().value(),resultVec.getQuantity(1).value(),1.0E-12);
    EXPECT_EQ(resultQ->system(),resultVec.system());
    EXPECT_TRUE(resultVec.isAbsolute());
    EXPECT_TRUE(resultQ->isAbsolute());

    testVec.setAsRelative();
    testQ.setAsRelative();
    resultVec = convert(testVec,UnitSystem(UnitSystem::Fahrenheit));
    resultQ = convert(testQ,UnitSystem(UnitSystem::Fahrenheit));
    ASSERT_EQ(2u,resultVec.size());
    ASSERT_TRUE(resultQ);
    EXPECT_EQ(resultQ.get().units(),resultVec.units());
    // not sure why these aren't quite getting the precision we would like
    EXPECT_NEAR(resultQ.get().value(),resultVec.getQuantity(0).value(),1.0E-12);
    EXPECT_NEAR(resultQ.get().value(),resultVec.getQuantity(1).value(),1.0E-12);
    EXPECT_EQ(resultQ->system(),resultVec.system());
    EXPECT_TRUE(resultVec.isRelative());
    EXPECT_TRUE(resultQ->isRelative());
}
Пример #5
0
OSQuantityVector::OSQuantityVector(const OSQuantityVector& other)
  : m_units(other.units()), m_values(other.values())
{}
Пример #6
0
bool operator==(const OSQuantityVector& lVector,const OSQuantityVector& rVector) {
  return (&lVector == &rVector) || ((lVector.units() == rVector.units()) && (lVector.values() == rVector.values()));
}