Skip to content

Commit

Permalink
Merge pull request #10668 from NREL/CppCheck-FluidProperties
Browse files Browse the repository at this point in the history
CppCheck FluidProperties through HVACUnitaryBypassVAV
  • Loading branch information
Myoldmopar committed Aug 20, 2024
2 parents 9f0fc00 + 266dfa2 commit f274ccb
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 47 deletions.
58 changes: 29 additions & 29 deletions src/EnergyPlus/FluidProperties.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ namespace FluidProperties {
continue;
}

auto &supTempArray = FluidTemps(supTempArrayNum);
auto const &supTempArray = FluidTemps(supTempArrayNum);
refrig->NumSupTempPoints = supTempArray.NumOfTemps;
refrig->SupTemps.allocate(refrig->NumSupTempPoints);
refrig->SupTemps = supTempArray.Temps;
Expand Down Expand Up @@ -1441,7 +1441,7 @@ namespace FluidProperties {

if (!glycolRaw->CpTempArrayName.empty()) {
int cpTempArrayNum = Util::FindItemInList(glycolRaw->CpTempArrayName, FluidTemps);
auto &cpTempArray = FluidTemps(cpTempArrayNum);
auto const &cpTempArray = FluidTemps(cpTempArrayNum);
glycolRaw->NumCpTempPoints = cpTempArray.NumOfTemps;
glycolRaw->CpTemps.allocate(glycolRaw->NumCpTempPoints);
glycolRaw->CpTemps = cpTempArray.Temps;
Expand All @@ -1452,7 +1452,7 @@ namespace FluidProperties {

if (!glycolRaw->RhoTempArrayName.empty()) {
int rhoTempArrayNum = Util::FindItemInList(glycolRaw->RhoTempArrayName, FluidTemps);
auto &rhoTempArray = FluidTemps(rhoTempArrayNum);
auto const &rhoTempArray = FluidTemps(rhoTempArrayNum);
glycolRaw->NumRhoTempPoints = rhoTempArray.NumOfTemps;
glycolRaw->RhoTemps.allocate(glycolRaw->NumRhoTempPoints);
glycolRaw->RhoTemps = rhoTempArray.Temps;
Expand All @@ -1463,7 +1463,7 @@ namespace FluidProperties {

if (!glycolRaw->CondTempArrayName.empty()) {
int condTempArrayNum = Util::FindItemInList(glycolRaw->CondTempArrayName, FluidTemps);
auto &condTempArray = FluidTemps(condTempArrayNum);
auto const &condTempArray = FluidTemps(condTempArrayNum);
glycolRaw->NumCondTempPoints = condTempArray.NumOfTemps;
glycolRaw->CondTemps.allocate(glycolRaw->NumCondTempPoints);
glycolRaw->CondTemps = condTempArray.Temps;
Expand All @@ -1474,7 +1474,7 @@ namespace FluidProperties {

if (!glycolRaw->ViscTempArrayName.empty()) {
int viscTempArrayNum = Util::FindItemInList(glycolRaw->ViscTempArrayName, FluidTemps);
auto &viscTempArray = FluidTemps(viscTempArrayNum);
auto const &viscTempArray = FluidTemps(viscTempArrayNum);
glycolRaw->NumViscTempPoints = viscTempArray.NumOfTemps;
glycolRaw->ViscTemps.allocate(glycolRaw->NumViscTempPoints);
glycolRaw->ViscTemps = viscTempArray.Temps;
Expand Down Expand Up @@ -1936,7 +1936,7 @@ namespace FluidProperties {
// Most properties requested (e.g., Specific Heat) must be > 0 but the tables may
// be set up for symmetry and not be limited to just valid values.

auto &df = state.dataFluidProps;
auto const &df = state.dataFluidProps;

for (auto *glycol : df->glycols) {
if (glycol->CpDataPresent) {
Expand Down Expand Up @@ -2039,7 +2039,7 @@ namespace FluidProperties {
// for the refrigerant properties.
// Most properties requested (e.g., Specific Heat) must be > 0 but the tables may
// be set up for symmetry and not be limited to just valid values.
auto &df = state.dataFluidProps;
auto const &df = state.dataFluidProps;

for (auto *refrig : df->refrigs) {
for (int IndexNum = 1; IndexNum <= refrig->NumPsPoints; ++IndexNum) {
Expand Down Expand Up @@ -2181,7 +2181,7 @@ namespace FluidProperties {
Real64 Temperature; // Temperature to drive values
Real64 ReturnValue; // Values returned from glycol functions

auto &df = state.dataFluidProps;
auto const &df = state.dataFluidProps;

for (auto *glycol : df->glycols) {

Expand Down Expand Up @@ -2423,7 +2423,7 @@ namespace FluidProperties {
Real64 Temperature; // Temperature to drive values
Real64 ReturnValue; // Values returned from refrigerant functions

auto &df = state.dataFluidProps;
auto const &df = state.dataFluidProps;

for (auto *refrig : df->refrigs) {
// Lay out the basic values:
Expand Down Expand Up @@ -2759,8 +2759,6 @@ namespace FluidProperties {

int LoTempIndex = FindArrayIndex(Temperature, this->PsTemps, this->PsLowTempIndex, this->PsHighTempIndex);

auto &df = state.dataFluidProps;

// check for out of data bounds problems
if (LoTempIndex == 0) {
ReturnValue = this->PsValues(this->PsLowTempIndex);
Expand All @@ -2778,6 +2776,8 @@ namespace FluidProperties {

if (!state.dataGlobal->WarmupFlag && ErrorFlag) {
++this->errors[(int)RefrigError::SatTemp].count;
auto &df = state.dataFluidProps;

// send warning
if (this->errors[(int)RefrigError::SatTemp].count <= df->RefrigErrorLimitTest) {
ShowSevereMessage(
Expand Down Expand Up @@ -2851,8 +2851,6 @@ namespace FluidProperties {
// FUNCTION LOCAL VARIABLE DECLARATIONS:
bool ErrorFlag = false; // error flag for current call

auto &df = state.dataFluidProps;

// get the array indices
int LoPresIndex = FindArrayIndex(Pressure, this->PsValues, this->PsLowPresIndex, this->PsHighPresIndex);

Expand All @@ -2873,6 +2871,8 @@ namespace FluidProperties {

if (!state.dataGlobal->WarmupFlag && ErrorFlag) {
++this->errors[(int)RefrigError::SatPress].count;
auto &df = state.dataFluidProps;

// send warning
if (this->errors[(int)RefrigError::SatPress].count <= df->RefrigErrorLimitTest) {
ShowSevereMessage(state,
Expand Down Expand Up @@ -2995,8 +2995,6 @@ namespace FluidProperties {
// FUNCTION PARAMETER DEFINITIONS:
static constexpr std::string_view routineName = "RefrigProps::getSatDensity";

auto &df = state.dataFluidProps;

if ((Quality < 0.0) || (Quality > 1.0)) {
ShowSevereError(state, fmt::format("{}Refrigerant \"{}\", invalid quality, called from {}", routineName, this->Name, CalledFrom));
ShowContinueError(state, format("Saturated density quality must be between 0 and 1, entered value=[{:.4R}].", Quality));
Expand Down Expand Up @@ -3045,6 +3043,8 @@ namespace FluidProperties {

if (!state.dataGlobal->WarmupFlag && ErrorFlag) {
++this->errors[(int)RefrigError::SatTempDensity].count;
auto &df = state.dataFluidProps;

// send warning
if (this->errors[(int)RefrigError::SatTempDensity].count <= df->RefrigErrorLimitTest) {
ShowSevereMessage(
Expand Down Expand Up @@ -3403,8 +3403,6 @@ namespace FluidProperties {
// the enthalpy calculated from the pressure found
static constexpr std::string_view routineName = "RefrigProps::getSupHeatPressure";

auto &df = state.dataFluidProps;

// SUBROUTINE LOCAL VARIABLE DECLARATIONS:
Real64 EnthalpyCheck; // recalculates enthalpy based on calculated pressure
Real64 EnthalpyHigh; // Enthalpy value at interpolated pressure and high temperature
Expand Down Expand Up @@ -3542,6 +3540,8 @@ namespace FluidProperties {
}

if (ErrCount > 0 && !state.dataGlobal->WarmupFlag) {
auto &df = state.dataFluidProps;

// send near saturation warning if flagged
this->errors[(int)RefrigError::SatSupPress].count += CurSatErrCount;
// send warning
Expand Down Expand Up @@ -4593,7 +4593,7 @@ namespace FluidProperties {

int GetGlycolRawNum(EnergyPlusData &state, std::string_view const glycolRawName) // carries in substance name
{
auto &df = state.dataFluidProps;
auto const &df = state.dataFluidProps;

auto found = std::find_if(df->glycolsRaw.begin(), df->glycolsRaw.end(), [glycolRawName](GlycolRawProps const *glycolRaw) {
return glycolRaw->Name == glycolRawName;
Expand Down Expand Up @@ -4779,8 +4779,6 @@ namespace FluidProperties {
// Return value
Real64 ReturnValue;

auto &df = state.dataFluidProps;

// error counters and dummy string
bool ErrorFlag(false); // error flag for current call

Expand Down Expand Up @@ -4811,6 +4809,8 @@ namespace FluidProperties {
}

if (ErrorFlag && (CalledFrom != "ReportAndTestRefrigerants")) {
auto &df = state.dataFluidProps;

++df->TempRangeErrCountGetInterpolatedSatProp;
// send warning
if (df->TempRangeErrCountGetInterpolatedSatProp <= df->RefrigErrorLimitTest) {
Expand All @@ -4832,7 +4832,7 @@ namespace FluidProperties {

//*****************************************************************************

bool CheckFluidPropertyName(EnergyPlusData &state,
bool CheckFluidPropertyName(EnergyPlusData const &state,
std::string const &name) // Name from input(?) to be checked against valid FluidPropertyNames
{

Expand All @@ -4842,7 +4842,7 @@ namespace FluidProperties {

// PURPOSE OF THIS FUNCTION:
// This function checks on an input fluid property to make sure it is valid.
auto &df = state.dataFluidProps;
auto const &df = state.dataFluidProps;

auto foundRefrig = std::find_if(df->refrigs.begin(), df->refrigs.end(), [name](RefrigProps const *refrig) { return refrig->Name == name; });
if (foundRefrig != df->refrigs.end()) return true;
Expand All @@ -4867,7 +4867,7 @@ namespace FluidProperties {
bool NeedOrphanMessage = true;
int NumUnusedRefrig = 0;

auto &df = state.dataFluidProps;
auto const &df = state.dataFluidProps;

for (auto const *refrig : df->refrigs) {
if (refrig->used) continue;
Expand Down Expand Up @@ -4913,18 +4913,18 @@ namespace FluidProperties {
void GetFluidDensityTemperatureLimits(EnergyPlusData &state, int const FluidIndex, Real64 &MinTempLimit, Real64 &MaxTempLimit)
{
if (FluidIndex > 0) {
auto &df = state.dataFluidProps;
MinTempLimit = df->glycols(FluidIndex)->RhoLowTempValue;
MaxTempLimit = df->glycols(FluidIndex)->RhoHighTempValue;
auto const &df = state.dataFluidProps->glycols(FluidIndex);
MinTempLimit = df->RhoLowTempValue;
MaxTempLimit = df->RhoHighTempValue;
}
}

void GetFluidSpecificHeatTemperatureLimits(EnergyPlusData &state, int const FluidIndex, Real64 &MinTempLimit, Real64 &MaxTempLimit)
{
if (FluidIndex > 0) {
auto &df = state.dataFluidProps;
MinTempLimit = df->glycols(FluidIndex)->CpLowTempValue;
MaxTempLimit = df->glycols(FluidIndex)->CpHighTempValue;
auto const &df = state.dataFluidProps->glycols(FluidIndex);
MinTempLimit = df->CpLowTempValue;
MaxTempLimit = df->CpHighTempValue;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/EnergyPlus/FluidProperties.hh
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ namespace FluidProperties {
int UpperBound // Valid values upper bound (set by calling program)
);

bool CheckFluidPropertyName(EnergyPlusData &state,
bool CheckFluidPropertyName(EnergyPlusData const &state,
std::string const &NameToCheck); // Name from input(?) to be checked against valid FluidPropertyNames

void ReportOrphanFluids(EnergyPlusData &state);
Expand Down
8 changes: 1 addition & 7 deletions src/EnergyPlus/Furnaces.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2768,8 +2768,6 @@ namespace Furnaces {
// Get fan data
FanName = Alphas(7);

errFlag = false;

thisFurnace.fanType = static_cast<HVAC::FanType>(getEnumValue(HVAC::fanTypeNamesUC, Alphas(6)));

if (thisFurnace.fanType == HVAC::FanType::OnOff || thisFurnace.fanType == HVAC::FanType::Constant) {
Expand Down Expand Up @@ -4739,11 +4737,7 @@ namespace Furnaces {

if (!state.dataGlobal->DoingSizing && state.dataFurnaces->MySecondOneTimeFlag(FurnaceNum)) {
// sizing all done. check fan air flow rates
errFlag = false;
thisFurnace.ActualFanVolFlowRate = state.dataFans->fans(thisFurnace.FanIndex)->maxAirFlowRate;
if (errFlag) {
ShowContinueError(state, format("...occurs in {} ={}", HVAC::unitarySysTypeNames[(int)thisFurnace.type], thisFurnace.Name));
}
if (thisFurnace.ActualFanVolFlowRate != DataSizing::AutoSize) {
if (thisFurnace.DesignFanVolFlowRate > thisFurnace.ActualFanVolFlowRate) {
ShowWarningError(state,
Expand Down Expand Up @@ -5001,11 +4995,11 @@ namespace Furnaces {
thisFurnace.CoolingSpeedRatio = thisFurnace.MaxCoolAirVolFlow / thisFurnace.ActualFanVolFlowRate;
thisFurnace.NoHeatCoolSpeedRatio = thisFurnace.MaxNoCoolHeatAirVolFlow / thisFurnace.ActualFanVolFlowRate;
}
std::string FanName; // used in warning messages
if (dynamic_cast<Fans::FanComponent *>(state.dataFans->fans(thisFurnace.FanIndex))->powerRatioAtSpeedRatioCurveNum > 0) {
if (thisFurnace.ActualFanVolFlowRate == thisFurnace.MaxHeatAirVolFlow &&
thisFurnace.ActualFanVolFlowRate == thisFurnace.MaxCoolAirVolFlow &&
thisFurnace.ActualFanVolFlowRate == thisFurnace.MaxNoCoolHeatAirVolFlow) {
std::string FanName = state.dataFans->fans(thisFurnace.FanIndex)->Name;
ShowWarningError(state, format("{} \"{}\"", HVAC::unitarySysTypeNames[(int)thisFurnace.type], thisFurnace.Name));
ShowContinueError(state,
format("...For fan type and name = {} \"{}\"", HVAC::fanTypeNames[(int)thisFurnace.fanType], FanName));
Expand Down
2 changes: 1 addition & 1 deletion src/EnergyPlus/HVACInterfaceManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void UpdateHVACInterface(EnergyPlusData &state,
Real64 totDemandSideMaxAvail = 0.0;
for (int demIn = 1; demIn <= state.dataAirLoop->AirToZoneNodeInfo(AirLoopNum).NumSupplyNodes; ++demIn) {
int demInNode = state.dataAirLoop->AirToZoneNodeInfo(AirLoopNum).ZoneEquipSupplyNodeNum(demIn);
auto &node = state.dataLoopNodes->Node(demInNode);
auto const &node = state.dataLoopNodes->Node(demInNode);
totDemandSideMassFlow += node.MassFlowRate;
totDemandSideMinAvail += node.MassFlowRateMinAvail;
totDemandSideMaxAvail += node.MassFlowRateMaxAvail;
Expand Down
2 changes: 1 addition & 1 deletion src/EnergyPlus/HVACManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2051,7 +2051,7 @@ void ResolveLockoutFlags(EnergyPlusData &state, bool &SimAir) // TRUE means air
}
}

void ResetHVACControl(EnergyPlusData &state)
void ResetHVACControl(EnergyPlusData const &state)
{

// SUBROUTINE INFORMATION:
Expand Down
2 changes: 1 addition & 1 deletion src/EnergyPlus/HVACManager.hh
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ namespace HVACManager {

void ResolveLockoutFlags(EnergyPlusData &state, bool &SimAir); // TRUE means air loops must be (re)simulated

void ResetHVACControl(EnergyPlusData &state);
void ResetHVACControl(EnergyPlusData const &state);

void ResetNodeData(EnergyPlusData &state);

Expand Down
4 changes: 0 additions & 4 deletions src/EnergyPlus/HVACStandAloneERV.cc
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,6 @@ void GetStandAloneERV(EnergyPlusData &state)
GlobalNames::IntraObjUniquenessCheck(
state, Alphas(4), CurrentModuleObject, cAlphaFields(4), state.dataHVACStandAloneERV->SupplyAirFanUniqueNames, ErrorsFound);

errFlag = false;

if ((standAloneERV.SupplyAirFanIndex = Fans::GetFanIndex(state, standAloneERV.SupplyAirFanName)) == 0) {
ShowSevereItemNotFound(state, eoh, cAlphaFields(4), standAloneERV.SupplyAirFanName);
ErrorsFound = true;
Expand All @@ -297,7 +295,6 @@ void GetStandAloneERV(EnergyPlusData &state)
standAloneERV.ExhaustAirFanName = Alphas(5);
GlobalNames::IntraObjUniquenessCheck(
state, Alphas(5), CurrentModuleObject, cAlphaFields(5), state.dataHVACStandAloneERV->ExhaustAirFanUniqueNames, ErrorsFound);
errFlag = false;

if ((standAloneERV.ExhaustAirFanIndex = Fans::GetFanIndex(state, standAloneERV.ExhaustAirFanName)) == 0) {
ShowSevereItemNotFound(state, eoh, cAlphaFields(5), standAloneERV.ExhaustAirFanName);
Expand Down Expand Up @@ -1695,7 +1692,6 @@ int getEqIndex(EnergyPlusData &state, std::string_view CompName)
for (int StandAloneERVNum = 1; StandAloneERVNum <= state.dataHVACStandAloneERV->NumStandAloneERVs; StandAloneERVNum++) {
if (Util::SameString(CompName, state.dataHVACStandAloneERV->StandAloneERV(StandAloneERVNum).Name)) {
return StandAloneERVNum;
break;
}
}
return 0;
Expand Down
5 changes: 2 additions & 3 deletions src/EnergyPlus/HVACUnitaryBypassVAV.cc
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,6 @@ namespace HVACUnitaryBypassVAV {
bool ErrorsFound(false); // Set to true if errors in input, fatal at end of routine
bool DXErrorsFound(false); // Set to true if errors in get coil input
Array1D_int OANodeNums(4); // Node numbers of OA mixer (OA, EA, RA, MA)
std::string HXDXCoolCoilName; // Name of DX cooling coil used with Heat Exchanger Assisted Cooling Coil
bool DXCoilErrFlag; // used in warning messages

Array1D_string Alphas(20, "");
Expand Down Expand Up @@ -754,7 +753,7 @@ namespace HVACUnitaryBypassVAV {
ShowContinueError(state, format("...occurs in {} \"{}\"", thisCBVAV.UnitType, thisCBVAV.Name));
ErrorsFound = true;
} else {
auto &newCoil = state.dataCoilCooingDX->coilCoolingDXs[thisCBVAV.DXCoolCoilIndexNum];
auto const &newCoil = state.dataCoilCooingDX->coilCoolingDXs[thisCBVAV.DXCoolCoilIndexNum];
thisCBVAV.DXCoilInletNode = newCoil.evapInletNodeIndex;
thisCBVAV.DXCoilOutletNode = newCoil.evapOutletNodeIndex;
thisCBVAV.CondenserNodeNum = newCoil.condInletNodeIndex;
Expand Down Expand Up @@ -2444,7 +2443,7 @@ namespace HVACUnitaryBypassVAV {
}
// now find the speed ratio for the found speednum
auto f = [&state, CBVAVNum, SpeedNum, DesOutTemp](Real64 const SpeedRatio) {
auto &thisCBVAV = state.dataHVACUnitaryBypassVAV->CBVAV(CBVAVNum);
auto const &thisCBVAV = state.dataHVACUnitaryBypassVAV->CBVAV(CBVAVNum);
// FUNCTION LOCAL VARIABLE DECLARATIONS:
Real64 OutletAirTemp; // outlet air temperature [C]
Real64 QZnReqCycling = 0.001;
Expand Down

5 comments on commit f274ccb

@nrel-bot
Copy link

Choose a reason for hiding this comment

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

develop (Myoldmopar) - Win64-Windows-10-VisualStudio-16: OK (2871 of 2871 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.

develop (Myoldmopar) - x86_64-MacOS-10.18-clang-15.0.0: OK (2872 of 2872 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.

develop (Myoldmopar) - x86_64-Linux-Ubuntu-22.04-gcc-11.4: OK (2893 of 2893 tests passed, 0 test warnings)

Build Badge Test 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.

develop (Myoldmopar) - x86_64-Linux-Ubuntu-22.04-gcc-11.4-UnitTestsCoverage-Debug: OK (2077 of 2077 tests passed, 0 test warnings)

Build Badge Test Badge Coverage 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.

develop (Myoldmopar) - x86_64-Linux-Ubuntu-22.04-gcc-11.4-IntegrationCoverage-Debug: OK (797 of 797 tests passed, 0 test warnings)

Build Badge Test Badge Coverage Badge

Please sign in to comment.