diff --git a/src/EnergyPlus/OutputProcessor.cc b/src/EnergyPlus/OutputProcessor.cc index ab559898b1e..819feeed40d 100644 --- a/src/EnergyPlus/OutputProcessor.cc +++ b/src/EnergyPlus/OutputProcessor.cc @@ -4102,8 +4102,8 @@ int GetMeterIndex(EnergyPlusData const &state, std::string const &name) // DATE WRITTEN August 2002 // PURPOSE OF THIS FUNCTION: - // This function returns a index to the meter "number" (aka assigned report number) - // for the meter name. If none active for this run, a zero is returned. This is used later to + // This function returns an index to the meter "number" (aka assigned report number) + // for the meter name. If none is active for this run, -1 is returned. This is used later to // obtain a meter "value". auto const &op = state.dataOutputProcessor; diff --git a/src/EnergyPlus/api/datatransfer.cc b/src/EnergyPlus/api/datatransfer.cc index 17fc64eb0ca..d70fd7b483d 100644 --- a/src/EnergyPlus/api/datatransfer.cc +++ b/src/EnergyPlus/api/datatransfer.cc @@ -386,12 +386,7 @@ int getMeterHandle(EnergyPlusState state, const char *meterName) { auto *thisState = static_cast(state); std::string const meterNameUC = EnergyPlus::Util::makeUPPER(meterName); - const int i = EnergyPlus::GetMeterIndex(*thisState, meterNameUC); - if (i == 0) { - // inside E+, zero is meaningful, but through the API, I want to use negative one as a signal of a bad lookup - return -1; - } - return i; + return EnergyPlus::GetMeterIndex(*thisState, meterNameUC); } Real64 getMeterValue(EnergyPlusState state, int handle) diff --git a/tst/EnergyPlus/unit/OutputProcessor.unit.cc b/tst/EnergyPlus/unit/OutputProcessor.unit.cc index 6466380f1a4..901dce2d7f8 100644 --- a/tst/EnergyPlus/unit/OutputProcessor.unit.cc +++ b/tst/EnergyPlus/unit/OutputProcessor.unit.cc @@ -47,6 +47,8 @@ // EnergyPlus::OutputProcessor Unit Tests +#include + // Google Test Headers #include @@ -67,6 +69,7 @@ #include #include #include +#include #include #include @@ -5313,6 +5316,11 @@ namespace OutputProcessor { EXPECT_EQ(1, op->EndUseCategory(2).NumSubcategories); EXPECT_EQ("General", op->EndUseCategory(2).SubcategoryName(1)); + auto const zeroMeter = std::find_if(op->meterMap.begin(), op->meterMap.end(), [](auto const &meterEntry) { return meterEntry.second == 0; }); + ASSERT_NE(op->meterMap.end(), zeroMeter); + EXPECT_EQ(0, getMeterHandle(state, zeroMeter->first.c_str())); + EXPECT_EQ(GetMeterIndex(*state, "ELECTRICITY:FACILITY"), getMeterHandle(state, "Electricity:Facility")); + int found = GetMeterIndex(*state, "COOLING:ELECTRICITY"); EXPECT_NE(-1, found); EXPECT_EQ((int)Constant::eResource::Electricity, (int)op->meters[found]->resource);