Skip to content

Commit

Permalink
Fix string diffs, final cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
amirroth committed Nov 5, 2023
1 parent 6e1406a commit 35a398f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 103 deletions.
82 changes: 1 addition & 81 deletions src/EnergyPlus/DataGlobalConstants.hh
Original file line number Diff line number Diff line change
Expand Up @@ -151,27 +151,7 @@ namespace Constant {
Num
};

enum class ePollutant
{
Invalid = -1,
SO2,
NOx,
N2O,
PM,
PM2_5,
PM10,
CO,
CO2,
CH4,
NH3,
NMVOC,
Hg,
Pb,
NuclearHigh,
NuclearLow,
Num
};


constexpr std::array<eFuel, static_cast<int>(eResource::Num)> eResource2eFuel = {eFuel::Electricity,
eFuel::NaturalGas,
eFuel::Gasoline,
Expand Down Expand Up @@ -237,32 +217,6 @@ namespace Constant {
eResource::Water,
eResource::None};

constexpr std::array<ePollutant, static_cast<int>(eResource::Num)> eResource2ePollutant = {
ePollutant::Invalid, ePollutant::Invalid, ePollutant::Invalid, ePollutant::Invalid, ePollutant::Invalid, ePollutant::Invalid,
ePollutant::Invalid, ePollutant::Invalid, ePollutant::Invalid, ePollutant::Invalid, ePollutant::Invalid, ePollutant::Invalid,
ePollutant::Invalid, ePollutant::Invalid, ePollutant::Invalid, ePollutant::Invalid, ePollutant::Invalid, ePollutant::Invalid,
ePollutant::Invalid, ePollutant::Invalid, ePollutant::Invalid, ePollutant::Invalid, ePollutant::Invalid, ePollutant::Invalid,
ePollutant::Invalid, ePollutant::Invalid, ePollutant::Invalid, ePollutant::Invalid, ePollutant::Invalid, ePollutant::Invalid,
ePollutant::Invalid, ePollutant::Invalid, ePollutant::Invalid, ePollutant::SO2, ePollutant::NOx, ePollutant::N2O,
ePollutant::PM, ePollutant::PM2_5, ePollutant::PM10, ePollutant::CO, ePollutant::CO2, ePollutant::CH4,
ePollutant::NH3, ePollutant::NMVOC, ePollutant::Hg, ePollutant::Pb, ePollutant::NuclearHigh, ePollutant::NuclearLow};

constexpr std::array<eResource, static_cast<int>(ePollutant::Num)> ePollutant2eResource = {eResource::SO2,
eResource::NOx,
eResource::N2O,
eResource::PM,
eResource::PM2_5,
eResource::PM10,
eResource::CO,
eResource::CO2,
eResource::CH4,
eResource::NH3,
eResource::NMVOC,
eResource::Hg,
eResource::Pb,
eResource::NuclearHigh,
eResource::NuclearLow};

static constexpr std::array<std::string_view, static_cast<int>(eResource::Num)> eResourceNamesUC = {"ELECTRICITY",
"NATURALGAS",
"GASOLINE",
Expand Down Expand Up @@ -395,40 +349,6 @@ namespace Constant {
eResourceNames[static_cast<int>(eFuel2eResource[static_cast<int>(eFuel::Water)])],
eResourceNames[static_cast<int>(eFuel2eResource[static_cast<int>(eFuel::None)])]};

static constexpr std::array<std::string_view, static_cast<int>(ePollutant::Num)> ePollutantNamesUC = {
eResourceNamesUC[static_cast<int>(ePollutant2eResource[static_cast<int>(ePollutant::SO2)])],
eResourceNamesUC[static_cast<int>(ePollutant2eResource[static_cast<int>(ePollutant::NOx)])],
eResourceNamesUC[static_cast<int>(ePollutant2eResource[static_cast<int>(ePollutant::N2O)])],
eResourceNamesUC[static_cast<int>(ePollutant2eResource[static_cast<int>(ePollutant::PM)])],
eResourceNamesUC[static_cast<int>(ePollutant2eResource[static_cast<int>(ePollutant::PM2_5)])],
eResourceNamesUC[static_cast<int>(ePollutant2eResource[static_cast<int>(ePollutant::PM10)])],
eResourceNamesUC[static_cast<int>(ePollutant2eResource[static_cast<int>(ePollutant::CO)])],
eResourceNamesUC[static_cast<int>(ePollutant2eResource[static_cast<int>(ePollutant::CO2)])],
eResourceNamesUC[static_cast<int>(ePollutant2eResource[static_cast<int>(ePollutant::CH4)])],
eResourceNamesUC[static_cast<int>(ePollutant2eResource[static_cast<int>(ePollutant::NH3)])],
eResourceNamesUC[static_cast<int>(ePollutant2eResource[static_cast<int>(ePollutant::NMVOC)])],
eResourceNamesUC[static_cast<int>(ePollutant2eResource[static_cast<int>(ePollutant::Hg)])],
eResourceNamesUC[static_cast<int>(ePollutant2eResource[static_cast<int>(ePollutant::Pb)])],
eResourceNamesUC[static_cast<int>(ePollutant2eResource[static_cast<int>(ePollutant::NuclearHigh)])],
eResourceNamesUC[static_cast<int>(ePollutant2eResource[static_cast<int>(ePollutant::NuclearLow)])]};

static constexpr std::array<std::string_view, static_cast<int>(ePollutant::Num)> ePollutantNames = {
eResourceNames[static_cast<int>(ePollutant2eResource[static_cast<int>(ePollutant::SO2)])],
eResourceNames[static_cast<int>(ePollutant2eResource[static_cast<int>(ePollutant::NOx)])],
eResourceNames[static_cast<int>(ePollutant2eResource[static_cast<int>(ePollutant::N2O)])],
eResourceNames[static_cast<int>(ePollutant2eResource[static_cast<int>(ePollutant::PM)])],
eResourceNames[static_cast<int>(ePollutant2eResource[static_cast<int>(ePollutant::PM2_5)])],
eResourceNames[static_cast<int>(ePollutant2eResource[static_cast<int>(ePollutant::PM10)])],
eResourceNames[static_cast<int>(ePollutant2eResource[static_cast<int>(ePollutant::CO)])],
eResourceNames[static_cast<int>(ePollutant2eResource[static_cast<int>(ePollutant::CO2)])],
eResourceNames[static_cast<int>(ePollutant2eResource[static_cast<int>(ePollutant::CH4)])],
eResourceNames[static_cast<int>(ePollutant2eResource[static_cast<int>(ePollutant::NH3)])],
eResourceNames[static_cast<int>(ePollutant2eResource[static_cast<int>(ePollutant::NMVOC)])],
eResourceNames[static_cast<int>(ePollutant2eResource[static_cast<int>(ePollutant::Hg)])],
eResourceNames[static_cast<int>(ePollutant2eResource[static_cast<int>(ePollutant::Pb)])],
eResourceNames[static_cast<int>(ePollutant2eResource[static_cast<int>(ePollutant::NuclearHigh)])],
eResourceNames[static_cast<int>(ePollutant2eResource[static_cast<int>(ePollutant::NuclearLow)])]};

enum class CallIndicator
{
Invalid = -1,
Expand Down
24 changes: 12 additions & 12 deletions src/EnergyPlus/PollutionModule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ void GetPollutionFactorInput(EnergyPlusData &state)
}
}

for (int iPollutant = 0; iPollutant < (int)Pollutant2::Num; ++iPollutant) {
for (int iPollutant = 0; iPollutant < (int)Pollutant::Num; ++iPollutant) {
pollCoeff.pollutantCoeffs[iPollutant] = ipsc->rNumericArgs(iPollutant+2);
if (!ipsc->lAlphaFieldBlanks(iPollutant+3)) {

Expand Down Expand Up @@ -458,17 +458,17 @@ void SetupPollutionMeterReporting(EnergyPlusData &state)
{},
"");

for (int iPollutant2 = 0; iPollutant2 < (int)Pollutant2::Num; ++iPollutant2) {
for (int iPollutant = 0; iPollutant < (int)Pollutant::Num; ++iPollutant) {
SetupOutputVariable(state,
format("Environmental Impact {} {}",
Constant::eFuelNames[(int)fuel], poll2outVarStrs[iPollutant2]),
poll2Units[iPollutant2],
pollComp.pollutantVals[iPollutant2],
Constant::eFuelNames[(int)fuel], poll2outVarStrs[iPollutant]),
poll2Units[iPollutant],
pollComp.pollutantVals[iPollutant],
OutputProcessor::SOVTimeStepType::System,
OutputProcessor::SOVStoreType::Summed,
"Site",
{},
poll2Names[iPollutant2],
poll2Names[iPollutant],
format("{}Emissions", Constant::eFuelNames[(int)fuel]),
{},
"");
Expand Down Expand Up @@ -564,7 +564,7 @@ void CheckPollutionMeterReporting(EnergyPlusData &state)
ShowWarningError(
state, "GetPollutionFactorInput: Requested reporting for Carbon Equivalent Pollution, but insufficient information is entered.");
ShowContinueError(
state, "(Both \"FuelFactors\" and \"EnvironmentalImpactFactors\" must be entered or the displayed carbon pollution will all be zero.)");
state, "Both \"FuelFactors\" and \"EnvironmentalImpactFactors\" must be entered or the displayed carbon pollution will all be zero.");
}
}
}
Expand All @@ -590,7 +590,7 @@ void CalcPollution(EnergyPlusData &state)
// For each pollution/fuel type, Schedule values are allowed. Thus, calculations are bundled.
auto &pm = state.dataPollution;

for (int iPoll = 0; iPoll < (int)Pollutant2::Num; ++iPoll) {
for (int iPoll = 0; iPoll < (int)Pollutant::Num; ++iPoll) {
pm->pollutantVals[iPoll] = 0.0;

for (int iPollFuel = 0; iPollFuel < (int)PollFuel::Num; ++iPollFuel) {
Expand All @@ -603,7 +603,7 @@ void CalcPollution(EnergyPlusData &state)
Real64 pollutantVal = pollCoeff.pollutantCoeffs[iPoll];

// Why are these two the exceptions?
if (iPoll != (int)Pollutant2::Water && iPoll != (int)Pollutant2::NuclearLow) pollutantVal *= 0.001;
if (iPoll != (int)Pollutant::Water && iPoll != (int)Pollutant::NuclearLow) pollutantVal *= 0.001;

if (pollCoeff.pollutantSchedNums[iPoll] != 0) {
pollutantVal *= ScheduleManager::GetCurrentScheduleValue(state, pollCoeff.pollutantSchedNums[iPoll]);
Expand All @@ -616,9 +616,9 @@ void CalcPollution(EnergyPlusData &state)
} // for (iPollFactor)
} // for (iPoll)

pm->TotCarbonEquivFromN2O = pm->pollutantVals[(int)Pollutant2::N2O] * pm->CarbonEquivN2O;
pm->TotCarbonEquivFromCH4 = pm->pollutantVals[(int)Pollutant2::CH4] * pm->CarbonEquivCH4;
pm->TotCarbonEquivFromCO2 = pm->pollutantVals[(int)Pollutant2::CO2] * pm->CarbonEquivCO2;
pm->TotCarbonEquivFromN2O = pm->pollutantVals[(int)Pollutant::N2O] * pm->CarbonEquivN2O;
pm->TotCarbonEquivFromCH4 = pm->pollutantVals[(int)Pollutant::CH4] * pm->CarbonEquivCH4;
pm->TotCarbonEquivFromCO2 = pm->pollutantVals[(int)Pollutant::CO2] * pm->CarbonEquivCO2;

auto const &pollCoeffElec = pm->pollCoeffs[(int)PollFuel::Electricity];
auto &pollCompElec = pm->pollComps[(int)PollFuelComponent::Electricity];
Expand Down
18 changes: 8 additions & 10 deletions src/EnergyPlus/PollutionModule.hh
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ namespace EnergyPlus {

namespace Pollution {

// This is very similar to ePollutant in DataGlobalConstants, but
// also includes water. Water is a pollutant? Really?
enum class Pollutant2
enum class Pollutant
{
Invalid = -1,
CO2,
Expand All @@ -85,10 +83,10 @@ namespace Pollution {
Num
};

constexpr std::array<std::string_view, (int)Pollutant2::Num> poll2Names = {
constexpr std::array<std::string_view, (int)Pollutant::Num> poll2Names = {
"CO2", "CO", "CH4", "NOx", "N2O", "SO2", "PM", "PM10", "PM2.5", "NH3", "NMVOC", "Hg", "Pb", "WaterEnvironmentalFactors", "Nuclear High", "Nuclear Low"};

constexpr std::array<OutputProcessor::Unit, (int)Pollutant2::Num> poll2Units = {
constexpr std::array<OutputProcessor::Unit, (int)Pollutant::Num> poll2Units = {
OutputProcessor::Unit::kg, // CO2
OutputProcessor::Unit::kg, // CO
OutputProcessor::Unit::kg, // CH4
Expand All @@ -107,7 +105,7 @@ namespace Pollution {
OutputProcessor::Unit::m3, // NuclearLow
};

constexpr std::array<std::string_view, (int)Pollutant2::Num> poll2outVarStrs = {
constexpr std::array<std::string_view, (int)Pollutant::Num> poll2outVarStrs = {
"CO2 Emissions Mass", // CO2
"CO Emissions Mass", // CO
"CH4 Emissions Mass", // CH4
Expand Down Expand Up @@ -286,16 +284,16 @@ namespace Pollution {
struct ComponentProps
{
Real64 sourceVal = 0.0;
std::array<Real64, (int)Pollutant2::Num> pollutantVals = {0.0};
std::array<Real64, (int)Pollutant::Num> pollutantVals = {0.0};
};

struct CoefficientProps
{
bool used = false;
Real64 sourceCoeff = 0.0;
std::array<Real64, (int)Pollutant2::Num> pollutantCoeffs = {0.0};
std::array<Real64, (int)Pollutant::Num> pollutantCoeffs = {0.0};
int sourceSchedNum = 0;
std::array<int, (int)Pollutant2::Num> pollutantSchedNums = {0};
std::array<int, (int)Pollutant::Num> pollutantSchedNums = {0};
};

void CalculatePollution(EnergyPlusData &state);
Expand Down Expand Up @@ -343,7 +341,7 @@ struct PollutionData : BaseGlobalStruct
std::array<Real64, (int)Pollution::PollFacilityMeter::Num> facilityMeterVals = {0.0};
std::array<Real64, (int)Pollution::PollFuelComponent::Num> facilityMeterFuelComponentVals = {0.0};

std::array<Real64, (int)Pollution::Pollutant2::Num> pollutantVals = {0.0};
std::array<Real64, (int)Pollution::Pollutant::Num> pollutantVals = {0.0};

std::vector<Pollution::PollFuel> pollFuelFactorList;

Expand Down

5 comments on commit 35a398f

@nrel-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pollution1 (amirroth) - Win64-Windows-10-VisualStudio-16: OK (2753 of 2753 tests passed, 0 test warnings)

Build Badge Test Badge

@nrel-bot-3
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pollution1 (amirroth) - x86_64-MacOS-10.17-clang-14.0.0: OK (3540 of 3540 tests passed, 0 test warnings)

Build Badge Test Badge

@nrel-bot-2b
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pollution1 (amirroth) - x86_64-Linux-Ubuntu-22.04-gcc-11.4: OK (3581 of 3581 tests passed, 0 test warnings)

Build Badge Test Badge

@nrel-bot-2c
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pollution1 (amirroth) - x86_64-Linux-Ubuntu-22.04-gcc-11.4-UnitTestsCoverage-Debug: OK (1966 of 1966 tests passed, 0 test warnings)

Build Badge Test Badge Coverage Badge

@nrel-bot-2
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pollution1 (amirroth) - x86_64-Linux-Ubuntu-22.04-gcc-11.4-IntegrationCoverage-Debug: OK (790 of 790 tests passed, 0 test warnings)

Build Badge Test Badge Coverage Badge

Please sign in to comment.