本文整理汇总了C++中WorkspaceObject::numFields方法的典型用法代码示例。如果您正苦于以下问题:C++ WorkspaceObject::numFields方法的具体用法?C++ WorkspaceObject::numFields怎么用?C++ WorkspaceObject::numFields使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WorkspaceObject
的用法示例。
在下文中一共展示了WorkspaceObject::numFields方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: workspace
TEST_F(EnergyPlusFixture,ReverseTranslatorTest_TranslateScheduleCompact) {
openstudio::Workspace workspace(openstudio::StrictnessLevel::None,openstudio::IddFileType::EnergyPlus);
openstudio::IdfObject idfObject( openstudio::IddObjectType::Schedule_Compact );
idfObject.setString(1,"Fraction");
idfObject.setString(2,"Through: 12/31");
idfObject.setString(3,"For: Weekdays SummerDesignDay");
idfObject.setString(4,"Until: 08:00");
idfObject.setString(5,"0.0");
idfObject.setString(6,"Until: 18:00");
idfObject.setString(7,"1.0");
idfObject.setString(8,"Until: 24:00");
idfObject.setString(9,"0.0");
idfObject.setString(10,"For: Weekends WinterDesignDay");
idfObject.setString(11,"Until: 10:00");
idfObject.setString(12,"0.0");
idfObject.setString(13,"Until: 16:00");
idfObject.setString(14,"1.0");
idfObject.setString(15,"Until: 24:00");
idfObject.setString(16,"0.0");
idfObject.setString(17,"For: Holidays AllOtherDays");
idfObject.setString(18,"Until: 24:00");
idfObject.setString(19,"0.0");
WorkspaceObject epScheduleCompact = workspace.addObject(idfObject).get();
ReverseTranslator trans;
ASSERT_NO_THROW(trans.translateWorkspace(workspace));
Model model = trans.translateWorkspace(workspace);
ASSERT_EQ(static_cast<unsigned>(1), model.getModelObjects<openstudio::model::ScheduleCompact>().size());
openstudio::model::ScheduleCompact scheduleCompact = model.getModelObjects<openstudio::model::ScheduleCompact>()[0];
EXPECT_EQ(unsigned(20),epScheduleCompact.numFields());
EXPECT_EQ(unsigned(21),scheduleCompact.numFields()); // has handle field
ASSERT_EQ(epScheduleCompact.numFields() + 1u,scheduleCompact.numFields());
ASSERT_TRUE(epScheduleCompact.name());
ASSERT_TRUE(scheduleCompact.name());
EXPECT_EQ(epScheduleCompact.name().get(),scheduleCompact.name().get());
for( unsigned i = 1; i < epScheduleCompact.numFields(); i++ )
{
boost::optional<std::string> s1 = epScheduleCompact.getString(i);
boost::optional<std::string> s2 = scheduleCompact.getString(i+1);
ASSERT_TRUE(s1);
ASSERT_TRUE(s2);
EXPECT_EQ(s1.get(),s2.get());
}
}
示例2: scratch
TEST_F(IdfFixture, WorkspaceObject_FieldSettingWithHiddenPushes) {
Workspace scratch(StrictnessLevel::None,IddFileType::EnergyPlus); // Strictness level None
std::stringstream text;
text << "ZoneHVAC:HighTemperatureRadiant," << std::endl
<< " MyRadiantSystem," << std::endl
<< " MyHVACSchedule," << std::endl
<< " MyCoreZone," << std::endl
<< " HeatingDesignCapacity," << std::endl
<< " Autosize," << std::endl
<< " ," << std::endl
<< " ," << std::endl
<< " Electricity;";
OptionalIdfObject oObj = IdfObject::load(text.str());
ASSERT_TRUE(oObj);
IdfObject idfObject = *oObj;
OptionalWorkspaceObject w1 = scratch.addObject(idfObject);
ASSERT_TRUE(w1);
OptionalWorkspaceObject tObject = scratch.getObject(w1->handle ());
ASSERT_TRUE(tObject);
WorkspaceObject object = *tObject;
EXPECT_EQ(static_cast<unsigned>(8),object.numFields());
// create schedule object to point to from non-extensible field
text.str("");
text << "Schedule:Compact," << std::endl
<< " AlwaysOn," << std::endl
<< " ," << std::endl
<< " For: AllOtherDays," << std::endl
<< " Until: 24:00," << std::endl
<< " 1.0;";
oObj = IdfObject::load(text.str());
ASSERT_TRUE(oObj);
idfObject = *oObj;
ASSERT_TRUE(idfObject.iddObject().type() == IddObjectType::Schedule_Compact);
OptionalWorkspaceObject w2 = scratch.addObject(idfObject);
ASSERT_TRUE(w2);
EXPECT_TRUE(object.setPointer(14,w2->handle ()));
EXPECT_EQ(15u,object.numFields());
tObject = object.getTarget(14);
ASSERT_TRUE(tObject);
EXPECT_TRUE(tObject->handle() == w2->handle());
// hidden pushing for setting extensible string pointer
EXPECT_TRUE(object.setString(16,*(tObject->name()))); // should only work at strictness none
tObject = object.getTarget(16);
ASSERT_TRUE(tObject);
EXPECT_TRUE(tObject->handle() == w2->handle());
EXPECT_EQ(18u,object.numFields());
// hidden pushing for setting extensible double
EXPECT_TRUE(object.setDouble(19,0.5));
EXPECT_EQ(20u,object.numFields());
OptionalDouble dValue = object.getDouble(19);
ASSERT_TRUE(dValue);
EXPECT_NEAR(0.5,*dValue,tol);
// SHOULD NOT BE VALID
scratch = Workspace(StrictnessLevel::Draft, IddFileType::EnergyPlus); // Non-null data must be valid
text.str("");
text << "ZoneHVAC:HighTemperatureRadiant," << std::endl
<< " MyRadiantSystem," << std::endl
<< " MyHVACSchedule," << std::endl
<< " MyCoreZone," << std::endl
<< " HeatingDesignCapacity," << std::endl
<< " Autosize," << std::endl
<< " ," << std::endl
<< " ," << std::endl
<< " Electricity;";
oObj = IdfObject::load(text.str());
ASSERT_TRUE(oObj);
idfObject = *oObj;
w2 = scratch.addObject(idfObject);
ASSERT_TRUE(w2);
tObject = scratch.getObject(w2->handle());
ASSERT_TRUE(tObject);
object = *tObject;
// hidden pushing for setting nonextensible double
EXPECT_FALSE(object.setDouble(9,1.5));
EXPECT_EQ(8u,object.numFields());
EXPECT_TRUE(object.setDouble(9,0.6));
EXPECT_EQ(10u,object.numFields());
// hidden pushing for setting nonextensible string
EXPECT_FALSE(object.setString(12,"bad key"));
EXPECT_EQ(10u,object.numFields());
EXPECT_TRUE(object.setString(12,"MeanAirTemperature"));
EXPECT_EQ(13u,object.numFields());
// hidden pushing for setting nonextensible pointer
EXPECT_TRUE(object.setString(14,""));
EXPECT_EQ(15u,object.numFields());
// hidden pushing for setting extensible string pointer
EXPECT_FALSE(object.setString(16,"MySurface"));
EXPECT_EQ(15u,object.numFields());
EXPECT_TRUE(object.setString(16,""));
EXPECT_EQ(18u,object.numFields());
//.........这里部分代码省略.........
示例3: translateScheduleTypeLimits
OptionalModelObject ReverseTranslator::translateScheduleTypeLimits( const WorkspaceObject & workspaceObject )
{
if( workspaceObject.iddObject().type() != IddObjectType::ScheduleTypeLimits )
{
LOG(Error, "WorkspaceObject is not IddObjectType: ScheduleTypeLimits");
return boost::none;
}
openstudio::model::ScheduleTypeLimits scheduleTypeLimits( m_model );
OptionalString s = workspaceObject.name();
if (s) {
if ((workspaceObject.numFields() == 1u) &&
(istringEqual(*s,"Any Number") || istringEqual(*s,"Number")))
{
// Do not translate ScheduleTypeLimits called "Any Number" or "Number" and
// with no other fields specified. Instead, let ModelObjects assign more
// meaningful limits.
LOG(Info,"The energyplus::ReverseTranslator throws out all 'Any Number' ScheduleTypeLimits "
<< "to leave the OpenStudio model free to apply the appropriate units and limits.");
return boost::none;
}
scheduleTypeLimits.setName(*s);
}
OptionalDouble d = workspaceObject.getDouble(ScheduleTypeLimitsFields::LowerLimitValue);
if (d) {
scheduleTypeLimits.setLowerLimitValue(*d);
}
d = workspaceObject.getDouble(ScheduleTypeLimitsFields::UpperLimitValue);
if (d) {
scheduleTypeLimits.setUpperLimitValue(*d);
}
s = workspaceObject.getString(ScheduleTypeLimitsFields::NumericType);
if (s) {
scheduleTypeLimits.setNumericType(*s);
}
s = workspaceObject.getString(ScheduleTypeLimitsFields::UnitType);
if (s) {
scheduleTypeLimits.setUnitType(*s);
}
else {
bool test;
// Attempt to default based on name (many EnergyPlus files do not have this field filled out).
std::string name = scheduleTypeLimits.name().get();
if (boost::regex_search(name,boost::regex("[Tt][Ee][Mm][Pp]"))) {
if (boost::regex_search(name,boost::regex("[Dd][Ee][Ll][Tt][Aa]"))) {
test = scheduleTypeLimits.setUnitType("DeltaTemperature");
BOOST_ASSERT(test);
}
else {
test = scheduleTypeLimits.setUnitType("Temperature");
BOOST_ASSERT(test);
}
}
else if (boost::regex_search(name,boost::regex("[Oo][Nn]")) &&
boost::regex_search(name,boost::regex("[Oo][Ff][Ff]")))
{
test = scheduleTypeLimits.setUnitType("Availability");
BOOST_ASSERT(test);
}
else if (boost::regex_search(name,boost::regex("[Cc][Oo][Nn][Tt][Rr][Oo][Ll]"))) {
test = scheduleTypeLimits.setUnitType("ControlMode");
BOOST_ASSERT(test);
}
}
return scheduleTypeLimits;
}
示例4: object
TEST_F(ModelFixture, Construction_AddObjects) {
IdfFile idfFile; // OpenStudio Idd is default
// Can still use name references directly in IdfObjects. Will get turned into pointer/by handle
// references on import into Workspace.
IdfObject object(IddObjectType::OS_Construction);
object.setName("Exterior Wall");
unsigned index = OS_ConstructionFields::SurfaceRenderingName + 1;
object.setString(index,"M01 100mm brick"); ++index;
object.setString(index,"M15 200mm heavyweight concrete"); ++index;
object.setString(index,"I02 50mm insulation board"); ++index;
object.setString(index,"F04 Wall air space resistance"); ++index;
object.setString(index,"G01a 19mm gypsum board"); ++index;
idfFile.addObject(object);
object = IdfObject(IddObjectType::OS_Material);
object.setName("M01 100mm brick");
object.setString(OS_MaterialFields::Roughness,"MediumRough");
object.setDouble(OS_MaterialFields::Thickness,0.1016);
object.setDouble(OS_MaterialFields::Conductivity,0.89);
object.setDouble(OS_MaterialFields::Density,1920.0);
object.setDouble(OS_MaterialFields::SpecificHeat,790.0);
idfFile.addObject(object);
object = IdfObject(IddObjectType::OS_Material);
object.setName("M15 200mm heavyweight concrete");
object.setString(OS_MaterialFields::Roughness,"MediumRough");
object.setDouble(OS_MaterialFields::Thickness,0.2032);
object.setDouble(OS_MaterialFields::Conductivity,1.95);
object.setDouble(OS_MaterialFields::Density,2240.0);
object.setDouble(OS_MaterialFields::SpecificHeat,900.0);
idfFile.addObject(object);
object = IdfObject(IddObjectType::OS_Material);
object.setName("I02 50mm insulation board");
object.setString(OS_MaterialFields::Roughness,"MediumRough");
object.setDouble(OS_MaterialFields::Thickness,0.0508);
object.setDouble(OS_MaterialFields::Conductivity,0.03);
object.setDouble(OS_MaterialFields::Density,43.0);
object.setDouble(OS_MaterialFields::SpecificHeat,1210.0);
idfFile.addObject(object);
object = IdfObject(IddObjectType::OS_Material_AirGap);
object.setName("F04 Wall air space resistance");
object.setDouble(OS_Material_AirGapFields::ThermalResistance,0.15);
idfFile.addObject(object);
object = IdfObject(IddObjectType::OS_Material);
object.setName("G01a 19mm gypsum board");
object.setString(OS_MaterialFields::Roughness,"MediumSmooth");
object.setDouble(OS_MaterialFields::Thickness,0.019);
object.setDouble(OS_MaterialFields::Conductivity,0.16);
object.setDouble(OS_MaterialFields::Density,800.0);
object.setDouble(OS_MaterialFields::SpecificHeat,1090.0);
idfFile.addObject(object);
// first add to a workspace
Workspace workspace(StrictnessLevel::Draft, IddFileType::OpenStudio);
workspace.addObjects(idfFile.objects());
EXPECT_EQ(workspace.numObjects(), idfFile.numObjects());
ASSERT_EQ(1u, workspace.getObjectsByType(IddObjectType::OS_Construction).size());
WorkspaceObject workspaceObject = workspace.getObjectsByType(IddObjectType::OS_Construction)[0];
ASSERT_EQ(8u, workspaceObject.numFields());
for (int i = 3; i < 8; ++i){
EXPECT_FALSE(workspaceObject.isEmpty(i)) << "Index " << i << " is empty for:" << std::endl << workspaceObject;
}
// now add to a model
Model model;
model.addObjects(idfFile.objects());
EXPECT_EQ(model.numObjects(), idfFile.numObjects());
ASSERT_EQ(1u, model.getModelObjects<Construction>().size());
Construction construction = model.getModelObjects<Construction>()[0];
ASSERT_EQ(8u, construction.numFields());
for (int i = 3; i < 8; ++i){
EXPECT_FALSE(construction.isEmpty(i)) << "Index " << i << " is empty for:" << std::endl << construction;
}
ASSERT_EQ(5u, construction.layers().size());
std::vector<Material> layers = construction.layers();
for (int i = 0; i < 5; ++i){
EXPECT_TRUE(layers[i].name()) << "Layer " << i << " has no name:" << std::endl << layers[i];
}
}