Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/EnergyPlus/OutputProcessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 1 addition & 6 deletions src/EnergyPlus/api/datatransfer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -386,12 +386,7 @@ int getMeterHandle(EnergyPlusState state, const char *meterName)
{
auto *thisState = static_cast<EnergyPlus::EnergyPlusData *>(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)
Expand Down
8 changes: 8 additions & 0 deletions tst/EnergyPlus/unit/OutputProcessor.unit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@

// EnergyPlus::OutputProcessor Unit Tests

#include <algorithm>

// Google Test Headers
#include <gtest/gtest.h>

Expand All @@ -67,6 +69,7 @@
#include <EnergyPlus/ScheduleManager.hh>
#include <EnergyPlus/SystemReports.hh>
#include <EnergyPlus/WeatherManager.hh>
#include <EnergyPlus/api/datatransfer.h>

#include <climits>
#include <map>
Expand Down Expand Up @@ -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);
Expand Down
Loading