Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CppCheck ZoneContaminantPredictorCorrector #10706

Merged
merged 9 commits into from
Sep 11, 2024
Merged
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
6 changes: 3 additions & 3 deletions src/EnergyPlus/WindowModel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ namespace Window {

// PURPOSE OF THIS SUBROUTINE:
// Reads input and creates instance of WindowModel object
int NumNums;
int NumAlphas;
int IOStat;

auto aModel = std::make_unique<CWindowModel>(); // (AUTO_OK)
int numCurrModels = state.dataInputProcessing->inputProcessor->getNumObjectsFound(state, objectName);
if (numCurrModels > 0) {
int NumNums;
int NumAlphas;
int IOStat;
state.dataInputProcessing->inputProcessor->getObjectItem(
state, objectName, 1, state.dataIPShortCut->cAlphaArgs, NumAlphas, state.dataIPShortCut->rNumericArgs, NumNums, IOStat);
// Please consider using getEnumValue pattern here.
Expand Down
24 changes: 10 additions & 14 deletions src/EnergyPlus/ZoneAirLoopEquipmentManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -217,28 +217,25 @@ namespace ZoneAirLoopEquipmentManager {
static std::string const CurrentModuleObject("ZoneHVAC:AirDistributionUnit"); // Object type for getting and error messages

// SUBROUTINE LOCAL VARIABLE DECLARATIONS:
int AirDistUnitNum;
int AirDistCompUnitNum;
int NumAlphas;
int NumNums;
int IOStat;
bool ErrorsFound(false); // If errors detected in input
bool IsNotOK; // Flag to verify name
Array1D_string AlphArray(5);
Array1D<Real64> NumArray(2);
Array1D_string cAlphaFields(5); // Alpha field names
Array1D_string cNumericFields(2); // Numeric field names
Array1D_bool lAlphaBlanks(5); // Logical array, alpha field input BLANK = .TRUE.
Array1D_bool lNumericBlanks(2); // Logical array, numeric field input BLANK = .TRUE.
bool DualDuctRecircIsUsed; // local temporary for deciding if recirc side used by dual duct terminal

int NumAirDistUnits = state.dataInputProcessing->inputProcessor->getNumObjectsFound(state, CurrentModuleObject);

state.dataDefineEquipment->AirDistUnit.allocate(NumAirDistUnits);

if (NumAirDistUnits > 0) {
int NumAlphas;
int NumNums;
int IOStat;
bool IsNotOK; // Flag to verify name

for (AirDistUnitNum = 1; AirDistUnitNum <= NumAirDistUnits; ++AirDistUnitNum) {
for (int AirDistUnitNum = 1; AirDistUnitNum <= NumAirDistUnits; ++AirDistUnitNum) {
auto &airDistUnit = state.dataDefineEquipment->AirDistUnit(AirDistUnitNum);
state.dataInputProcessing->inputProcessor->getObjectItem(state,
CurrentModuleObject,
Expand Down Expand Up @@ -267,7 +264,7 @@ namespace ZoneAirLoopEquipmentManager {
ObjectIsParent);
airDistUnit.InletNodeNum = 0;
airDistUnit.NumComponents = 1;
AirDistCompUnitNum = 1;
int AirDistCompUnitNum = 1;
// Load the air Distribution Unit Equip and Name
airDistUnit.EquipType(AirDistCompUnitNum) = AlphArray(3);
airDistUnit.EquipName(AirDistCompUnitNum) = AlphArray(4);
Expand Down Expand Up @@ -387,6 +384,7 @@ namespace ZoneAirLoopEquipmentManager {
airDistUnit.EquipName(AirDistCompUnitNum),
"UNDEFINED",
AlphArray(2));
bool DualDuctRecircIsUsed; // local temporary for deciding if recirc side used by dual duct terminal
GetDualDuctOutdoorAirRecircUse(
state, airDistUnit.EquipType(AirDistCompUnitNum), airDistUnit.EquipName(AirDistCompUnitNum), DualDuctRecircIsUsed);
if (DualDuctRecircIsUsed) {
Expand All @@ -409,7 +407,7 @@ namespace ZoneAirLoopEquipmentManager {
}

} // End of Air Dist Do Loop
for (AirDistUnitNum = 1; AirDistUnitNum <= (int)state.dataDefineEquipment->AirDistUnit.size(); ++AirDistUnitNum) {
for (int AirDistUnitNum = 1; AirDistUnitNum <= (int)state.dataDefineEquipment->AirDistUnit.size(); ++AirDistUnitNum) {
auto &airDistUnit = state.dataDefineEquipment->AirDistUnit(AirDistUnitNum);
SetupOutputVariable(state,
"Zone Air Terminal Sensible Heating Energy",
Expand Down Expand Up @@ -557,8 +555,6 @@ namespace ZoneAirLoopEquipmentManager {

bool ProvideSysOutput;
int AirDistCompNum;
int InNodeNum; // air distribution unit inlet node
int OutNodeNum; // air distribution unit outlet node
int AirLoopNum(0); // index of air loop
Real64 MassFlowRateMaxAvail; // max avail mass flow rate excluding leaks [kg/s]
Real64 MassFlowRateMinAvail; // min avail mass flow rate excluding leaks [kg/s]
Expand All @@ -574,8 +570,8 @@ namespace ZoneAirLoopEquipmentManager {
NonAirSysOutput = 0.0;

auto &airDistUnit = state.dataDefineEquipment->AirDistUnit(AirDistUnitNum);
InNodeNum = airDistUnit.InletNodeNum;
OutNodeNum = airDistUnit.OutletNodeNum;
int InNodeNum = airDistUnit.InletNodeNum;
int OutNodeNum = airDistUnit.OutletNodeNum;
MassFlowRateMaxAvail = 0.0;
MassFlowRateMinAvail = 0.0;
// check for no plenum
Expand Down
34 changes: 16 additions & 18 deletions src/EnergyPlus/ZoneContaminantPredictorCorrector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1504,7 +1504,6 @@ void InitZoneContSetPoints(EnergyPlusData &state)
Real64 Pi; // Pressue at zone i
Real64 Pj; // Pressue at zone j
Real64 Sch; // Schedule value
bool ErrorsFound(false);

if (state.dataContaminantBalance->Contaminant.CO2Simulation) {
state.dataContaminantBalance->OutdoorCO2 =
Expand Down Expand Up @@ -1707,6 +1706,7 @@ void InitZoneContSetPoints(EnergyPlusData &state)
}

if (allocated(state.dataZoneEquip->ZoneEquipConfig) && state.dataZoneContaminantPredictorCorrector->MyConfigOneTimeFlag) {
bool ErrorsFound = false;
for (int ContZoneNum = 1; ContZoneNum <= (int)state.dataContaminantBalance->ContaminantControlledZone.size(); ++ContZoneNum) {
int ZoneNum = state.dataContaminantBalance->ContaminantControlledZone(ContZoneNum).ActualZoneNum;
for (int zoneInNode = 1; zoneInNode <= state.dataZoneEquip->ZoneEquipConfig(ZoneNum).NumInletNodes; ++zoneInNode) {
Expand Down Expand Up @@ -1817,13 +1817,13 @@ void InitZoneContSetPoints(EnergyPlusData &state)

// From decay model
for (auto &con : state.dataContaminantBalance->ZoneContamGenericDecay) {
int Sch = ScheduleManager::GetCurrentScheduleValue(state, con.GCEmiRateSchedPtr);
if (Sch == 0.0 || state.dataGlobal->BeginEnvrnFlag || state.dataGlobal->WarmupFlag) {
int intSch = ScheduleManager::GetCurrentScheduleValue(state, con.GCEmiRateSchedPtr);
if (intSch == 0.0 || state.dataGlobal->BeginEnvrnFlag || state.dataGlobal->WarmupFlag) {
Copy link
Contributor Author

@rraustad rraustad Sep 1, 2024

Choose a reason for hiding this comment

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

So here, Sch shadows an outer REAL variable. So what was the intent? I think it was to convert a Real64 0 - 1 to either 0 or 1 given the text in the idd. Instead of changing this to read the schedule into a real I chose to int that data just like it was done before. It does seem like this was the intent, except that the idd says if it's 1 it will be set to 0 and here if it's 0 it's set to 0.

[src/EnergyPlus/ZoneContaminantPredictorCorrector.cc:1820]:(style),[shadowVariable],Local variable 'Sch' shadows outer variable

ZoneContaminantSourceAndSink:Generic:DecaySource,
  A3 , \field Schedule Name
       \required-field
       \type object-list
       \object-list ScheduleNames
       \note Value in this schedule should be a fraction (generally 0.0 - 1.0) applied to the
       \note Initial Emission Rate. When the value is equal to 1.0, the time will be reset to
       \note zero.

con.GCTime = 0.0;
} else {
con.GCTime += state.dataGlobal->TimeStepZoneSec;
}
GCGain = con.GCInitEmiRate * Sch * std::exp(-con.GCTime / con.GCDelayTime);
GCGain = con.GCInitEmiRate * intSch * std::exp(-con.GCTime / con.GCDelayTime);
con.GCGenRate = GCGain;
}

Expand Down Expand Up @@ -2051,7 +2051,6 @@ void PredictZoneContaminants(EnergyPlusData &state,
// Calculate the coefficients for the 3rd Order derivative for final
// zone CO2. The A, B, C coefficients are analogous to the CO2 balance.
// Assume that the system will have flow
auto &thisZoneHB = state.dataZoneTempPredictorCorrector->zoneHeatBalance(ZoneNum);
if (state.afn->multizone_always_simulated ||
(state.afn->simulation_control.type == AirflowNetwork::ControlType::MultizoneWithDistributionOnlyDuringFanOperation &&
state.afn->AirflowNetworkFanActivated)) {
Expand Down Expand Up @@ -2165,7 +2164,6 @@ void PredictZoneContaminants(EnergyPlusData &state,
// Calculate the coefficients for the 3rd Order derivative for final
// zone GC. The A, B, C coefficients are analogous to the GC balance.
// Assume that the system will have flow
auto &thisZoneHB = state.dataZoneTempPredictorCorrector->zoneHeatBalance(ZoneNum);
if (state.afn->multizone_always_simulated ||
(state.afn->simulation_control.type == AirflowNetwork::ControlType::MultizoneWithDistributionOnlyDuringFanOperation &&
state.afn->AirflowNetworkFanActivated)) {
Expand Down Expand Up @@ -2334,12 +2332,12 @@ void RevertZoneTimestepHistories(EnergyPlusData &state)
}

void InverseModelCO2(EnergyPlusData &state,
int const ZoneNum, // Zone number
Real64 &CO2Gain, // Zone total CO2 gain
Real64 &CO2GainExceptPeople, // ZOne total CO2 gain from sources except for people
Real64 &ZoneMassFlowRate, // Zone air mass flow rate
Real64 &CO2MassFlowRate, // Zone air CO2 mass flow rate
Real64 &RhoAir // Air density
int const ZoneNum, // Zone number
Real64 const CO2Gain, // Zone total CO2 gain
Real64 const CO2GainExceptPeople, // ZOne total CO2 gain from sources except for people
Real64 const ZoneMassFlowRate, // Zone air mass flow rate
Real64 const CO2MassFlowRate, // Zone air CO2 mass flow rate
Real64 const RhoAir // Air density
Copy link
Contributor Author

Choose a reason for hiding this comment

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

[src/EnergyPlus/ZoneContaminantPredictorCorrector.cc:2338]:(style),[constParameter],Parameter 'CO2Gain' can be declared as reference to const
[src/EnergyPlus/ZoneContaminantPredictorCorrector.cc:2339]:(style),[constParameter],Parameter 'CO2GainExceptPeople' can be declared as reference to const
[src/EnergyPlus/ZoneContaminantPredictorCorrector.cc:2340]:(style),[constParameter],Parameter 'ZoneMassFlowRate' can be declared as reference to const
[src/EnergyPlus/ZoneContaminantPredictorCorrector.cc:2341]:(style),[constParameter],Parameter 'CO2MassFlowRate' can be declared as reference to const
[src/EnergyPlus/ZoneContaminantPredictorCorrector.cc:2342]:(style),[constParameter],Parameter 'RhoAir' can be declared as reference to const

)
{
// SUBROUTINE INFORMATION:
Expand All @@ -2363,7 +2361,7 @@ void InverseModelCO2(EnergyPlusData &state,
state.dataEnvrn->DayOfYear <= state.dataHybridModel->HybridModelZone(ZoneNum).HybridEndDayOfYear) {
state.dataContaminantBalance->ZoneAirCO2(ZoneNum) = state.dataHeatBal->Zone(ZoneNum).ZoneMeasuredCO2Concentration;

auto &thisZoneHB = state.dataZoneTempPredictorCorrector->zoneHeatBalance(ZoneNum);
auto const &thisZoneHB = state.dataZoneTempPredictorCorrector->zoneHeatBalance(ZoneNum);
if (state.dataHybridModel->HybridModelZone(ZoneNum).InfiltrationCalc_C && state.dataHVACGlobal->UseZoneTimeStepHistory) {
static constexpr std::string_view RoutineNameInfiltration("CalcAirFlowSimple:Infiltration");
// Conditionally calculate the CO2-dependent and CO2-independent terms.
Expand Down Expand Up @@ -2575,7 +2573,7 @@ void CorrectZoneContaminants(EnergyPlusData &state,

// Calculate moisture flow rate into each zone
for (int NodeNum = 1; NodeNum <= state.dataZoneEquip->ZoneEquipConfig(ZoneNum).NumInletNodes; ++NodeNum) {
auto &node = state.dataLoopNodes->Node(state.dataZoneEquip->ZoneEquipConfig(ZoneNum).InletNode(NodeNum));
auto const &node = state.dataLoopNodes->Node(state.dataZoneEquip->ZoneEquipConfig(ZoneNum).InletNode(NodeNum));
if (state.dataContaminantBalance->Contaminant.CO2Simulation) {
CO2MassFlowRate += (node.MassFlowRate * node.CO2) / ZoneMult;
}
Expand All @@ -2588,7 +2586,7 @@ void CorrectZoneContaminants(EnergyPlusData &state,
// Do the calculations for the plenum zone
} else if (ZoneRetPlenumAirFlag) {
for (int NodeNum = 1; NodeNum <= state.dataZonePlenum->ZoneRetPlenCond(ZoneRetPlenumNum).NumInletNodes; ++NodeNum) {
auto &node = state.dataLoopNodes->Node(state.dataZonePlenum->ZoneRetPlenCond(ZoneRetPlenumNum).InletNode(NodeNum));
auto const &node = state.dataLoopNodes->Node(state.dataZonePlenum->ZoneRetPlenCond(ZoneRetPlenumNum).InletNode(NodeNum));
if (state.dataContaminantBalance->Contaminant.CO2Simulation) {
CO2MassFlowRate += (node.MassFlowRate * node.CO2) / ZoneMult;
}
Expand All @@ -2602,7 +2600,7 @@ void CorrectZoneContaminants(EnergyPlusData &state,
int ADUNum = state.dataZonePlenum->ZoneRetPlenCond(ZoneRetPlenumNum).ADUIndex(ADUListIndex);
if (state.dataDefineEquipment->AirDistUnit(ADUNum).UpStreamLeak) {
auto &airDistUnit = state.dataDefineEquipment->AirDistUnit(ADUNum);
auto &node = state.dataLoopNodes->Node(airDistUnit.InletNodeNum);
auto const &node = state.dataLoopNodes->Node(airDistUnit.InletNodeNum);
if (state.dataContaminantBalance->Contaminant.CO2Simulation) {
CO2MassFlowRate += (airDistUnit.MassFlowRateUpStrLk * node.CO2) / ZoneMult;
}
Expand All @@ -2613,7 +2611,7 @@ void CorrectZoneContaminants(EnergyPlusData &state,
}
if (state.dataDefineEquipment->AirDistUnit(ADUNum).DownStreamLeak) {
auto &airDistUnit = state.dataDefineEquipment->AirDistUnit(ADUNum);
auto &node = state.dataLoopNodes->Node(airDistUnit.OutletNodeNum);
auto const &node = state.dataLoopNodes->Node(airDistUnit.OutletNodeNum);
if (state.dataContaminantBalance->Contaminant.CO2Simulation) {
CO2MassFlowRate += (airDistUnit.MassFlowRateDnStrLk * node.CO2) / ZoneMult;
}
Expand All @@ -2625,7 +2623,7 @@ void CorrectZoneContaminants(EnergyPlusData &state,
}

} else if (ZoneSupPlenumAirFlag) {
auto &node = state.dataLoopNodes->Node(state.dataZonePlenum->ZoneSupPlenCond(ZoneSupPlenumNum).InletNode);
auto const &node = state.dataLoopNodes->Node(state.dataZonePlenum->ZoneSupPlenCond(ZoneSupPlenumNum).InletNode);
if (state.dataContaminantBalance->Contaminant.CO2Simulation) {
CO2MassFlowRate += (node.MassFlowRate * node.CO2) / ZoneMult;
}
Expand Down
12 changes: 6 additions & 6 deletions src/EnergyPlus/ZoneContaminantPredictorCorrector.hh
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ namespace ZoneContaminantPredictorCorrector {
void RevertZoneTimestepHistories(EnergyPlusData &state);

void InverseModelCO2(EnergyPlusData &state,
int ZoneNum, // Zone number
Real64 &CO2Gain, // Zone total CO2 gain
Real64 &CO2GainExceptPeople, // ZOne total CO2 gain from sources except for people
Real64 &ZoneMassFlowRate, // Zone air mass flow rate
Real64 &CO2MassFlowRate, // Zone air CO2 mass flow rate
Real64 &RhoAir // Air density
int ZoneNum, // Zone number
Real64 CO2Gain, // Zone total CO2 gain
Real64 CO2GainExceptPeople, // ZOne total CO2 gain from sources except for people
Real64 ZoneMassFlowRate, // Zone air mass flow rate
Real64 CO2MassFlowRate, // Zone air CO2 mass flow rate
Real64 RhoAir // Air density
);

void CorrectZoneContaminants(EnergyPlusData &state,
Expand Down
5 changes: 1 addition & 4 deletions src/EnergyPlus/ZoneDehumidifier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,6 @@ namespace ZoneDehumidifier {
Real64 AirMassFlowRate; // Air mass flow rate through this dehumidifier (kg/s)
Real64 Cp; // Heat capacity of inlet air (J/kg-C)
int AirInletNodeNum(0); // Node number for the inlet air to the dehumidifier
int AirOutletNodeNum(0); // Node number for the outlet air from the dehumidifier

SensibleOutput = 0.0;
LatentOutput = 0.0;
Expand All @@ -763,7 +762,6 @@ namespace ZoneDehumidifier {
ElectricPowerOnCycle = 0.0;

AirInletNodeNum = state.dataZoneDehumidifier->ZoneDehumid(ZoneDehumNum).AirInletNodeNum;
AirOutletNodeNum = state.dataZoneDehumidifier->ZoneDehumid(ZoneDehumNum).AirOutletNodeNum;

InletAirTemp = state.dataLoopNodes->Node(AirInletNodeNum).Temp;
InletAirHumRat = state.dataLoopNodes->Node(AirInletNodeNum).HumRat;
Expand Down Expand Up @@ -1105,7 +1103,6 @@ namespace ZoneDehumidifier {
Real64 RhoWater; // Density of condensate (water) being removed (kg/m3)
Real64 InletAirTemp; // Dry-bulb temperature of air entering the dehumidifier (C)
Real64 OutletAirTemp; // Dry-bulb temperature of air leaving the dehumidifier (C)
int AirInletNodeNum; // Node number corresponding to the air entering dehumidifier

state.dataZoneDehumidifier->ZoneDehumid(DehumidNum).SensHeatingEnergy =
state.dataZoneDehumidifier->ZoneDehumid(DehumidNum).SensHeatingRate * TimeStepSysSec;
Expand All @@ -1121,7 +1118,7 @@ namespace ZoneDehumidifier {
// Calculate and report condensation rate (how much water extracted from the air stream)
// Volumetric flow of water in m3/s for water system interactions

AirInletNodeNum = state.dataZoneDehumidifier->ZoneDehumid(DehumidNum).AirInletNodeNum;
int AirInletNodeNum = state.dataZoneDehumidifier->ZoneDehumid(DehumidNum).AirInletNodeNum;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

[src/EnergyPlus/ZoneDehumidifier.cc:1108]:(style),[variableScope],The scope of the variable 'AirInletNodeNum' can be reduced.
[src/EnergyPlus/ZoneDehumidifier.cc:766]:(style),[unreadVariable],Variable 'AirOutletNodeNum' is assigned a value that is never used.

InletAirTemp = state.dataLoopNodes->Node(AirInletNodeNum).Temp;
OutletAirTemp = max((InletAirTemp - 11.0), 1.0); // Assume coil outlet air is 11C (20F) lower than inlet air temp
RhoWater = RhoH2O(OutletAirTemp); // Density of water, minimum temp = 1.0 C
Expand Down