Skip to content

Commit

Permalink
Merge pull request #8715 from LipingWang/RoomAirInternalGains
Browse files Browse the repository at this point in the history
Update the function of GetInternalGainDeviceIndex
  • Loading branch information
Myoldmopar authored May 25, 2021
2 parents 0adfd25 + 13f623c commit 1713dbf
Show file tree
Hide file tree
Showing 4 changed files with 194 additions and 33 deletions.
32 changes: 12 additions & 20 deletions src/EnergyPlus/InternalHeatGains.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8038,12 +8038,10 @@ namespace InternalHeatGains {
}
}

void GetInternalGainDeviceIndex(EnergyPlusData &state,
int const ZoneNum, // zone index pointer for which zone to sum gains for
int const IntGainTypeOfNum, // zone internal gain type number
std::string const &IntGainName, // Internal gain name
int &DeviceIndex, // Device index
bool &ErrorFound)
int GetInternalGainDeviceIndex(EnergyPlusData &state,
int const ZoneNum, // zone index pointer for which zone to sum gains for
int const IntGainTypeOfNum, // zone internal gain type number
std::string_view const &IntGainName) // Internal gain name
{

// SUBROUTINE INFORMATION:
Expand All @@ -8054,31 +8052,25 @@ namespace InternalHeatGains {

// PURPOSE OF THIS SUBROUTINE:
// utility to retrieve index pointer to a specific internal gain
// the subroutine returns the index of matched internal gain device or -1 if no match found.

// SUBROUTINE LOCAL VARIABLE DECLARATIONS:
bool Found;
int DeviceNum;

Found = false;

int DeviceIndex;
if (state.dataHeatBal->ZoneIntGain(ZoneNum).NumberOfDevices == 0) {
DeviceIndex = -1;
ErrorFound = true;
return;
return DeviceIndex;
}

for (DeviceNum = 1; DeviceNum <= state.dataHeatBal->ZoneIntGain(ZoneNum).NumberOfDevices; ++DeviceNum) {
if (UtilityRoutines::SameString(state.dataHeatBal->ZoneIntGain(ZoneNum).Device(DeviceNum).CompObjectName, IntGainName)) {
if (state.dataHeatBal->ZoneIntGain(ZoneNum).Device(DeviceNum).CompTypeOfNum != IntGainTypeOfNum) {
ErrorFound = true;
} else {
ErrorFound = false;
}
Found = true;
if ((UtilityRoutines::SameString(state.dataHeatBal->ZoneIntGain(ZoneNum).Device(DeviceNum).CompObjectName, IntGainName.data())) &&
(state.dataHeatBal->ZoneIntGain(ZoneNum).Device(DeviceNum).CompTypeOfNum == IntGainTypeOfNum)) {
DeviceIndex = DeviceNum;
break;
} else {
DeviceIndex = -1;
}
}
return DeviceIndex;
}

void SumInternalConvectionGainsByIndices(
Expand Down
10 changes: 4 additions & 6 deletions src/EnergyPlus/InternalHeatGains.hh
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,10 @@ namespace InternalHeatGains {
const Array1D_int &GainTypeARR, // variable length 1-d array of integer valued gain types
Real64 &SumConvGainRate);

void GetInternalGainDeviceIndex(EnergyPlusData &state,
int const ZoneNum, // zone index pointer for which zone to sum gains for
int const IntGainTypeOfNum, // zone internal gain type number
std::string const &IntGainName, // Internal gain name
int &DeviceIndex, // Device index
bool &ErrorFound);
int GetInternalGainDeviceIndex(EnergyPlusData &state,
int const ZoneNum, // zone index pointer for which zone to sum gains for
int const IntGainTypeOfNum, // zone internal gain type number
std::string_view const &IntGainName); // Internal gain name

void SumInternalConvectionGainsByIndices(
EnergyPlusData &state,
Expand Down
13 changes: 6 additions & 7 deletions src/EnergyPlus/RoomAirModelManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1381,7 +1381,7 @@ namespace RoomAirModelManager {
int TotNumOfRAFNNodeSurfLists;
int TotNumOfRAFNNodeGainsLists;
int TotNumOfRAFNNodeHVACLists;
bool IntGainError;
int IntGainIndex;
int RAFNNodeNum;
bool foundList;
int NumSurfsThisNode;
Expand Down Expand Up @@ -1694,15 +1694,14 @@ namespace RoomAirModelManager {
state.dataIPShortCut->cAlphaArgs(gainsLoop * 2 + 1);

// verify type and name and get pointer to device in internal gains structure array
IntGainError = false;
GetInternalGainDeviceIndex(
IntGainIndex = GetInternalGainDeviceIndex(
state,
ZoneNum,
state.dataRoomAirMod->RoomAirflowNetworkZoneInfo(ZoneNum).Node(RAFNNodeNum).IntGain(gainsLoop).TypeOfNum,
state.dataRoomAirMod->RoomAirflowNetworkZoneInfo(ZoneNum).Node(RAFNNodeNum).IntGain(gainsLoop).Name,
state.dataRoomAirMod->RoomAirflowNetworkZoneInfo(ZoneNum).Node(RAFNNodeNum).IntGainsDeviceIndices(gainsLoop),
IntGainError);
if (IntGainError) {
state.dataRoomAirMod->RoomAirflowNetworkZoneInfo(ZoneNum).Node(RAFNNodeNum).IntGain(gainsLoop).Name);
state.dataRoomAirMod->RoomAirflowNetworkZoneInfo(ZoneNum).Node(RAFNNodeNum).IntGainsDeviceIndices(gainsLoop) =
IntGainIndex;
if (IntGainIndex < 0) {
ShowSevereError(state,
"GetRoomAirflowNetworkData: Invalid " + state.dataIPShortCut->cAlphaFieldNames(gainsLoop * 2 + 1) +
" = " + state.dataIPShortCut->cAlphaArgs(gainsLoop * 2 + 1));
Expand Down
172 changes: 172 additions & 0 deletions tst/EnergyPlus/unit/RoomAirflowNetwork.unit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,13 @@
#include <EnergyPlus/DataSizing.hh>
#include <EnergyPlus/DataSurfaces.hh>
#include <EnergyPlus/DataZoneEquipment.hh>
#include <EnergyPlus/HeatBalanceManager.hh>
#include <EnergyPlus/InternalHeatGains.hh>
#include <EnergyPlus/Psychrometrics.hh>
#include <EnergyPlus/RoomAirModelAirflowNetwork.hh>
#include <EnergyPlus/RoomAirModelManager.hh>
#include <EnergyPlus/ScheduleManager.hh>
#include <EnergyPlus/SurfaceGeometry.hh>

using namespace EnergyPlus;
using namespace DataEnvironment;
Expand Down Expand Up @@ -358,3 +363,170 @@ TEST_F(RoomAirflowNetworkTest, RAFNTest)
EXPECT_NEAR(24.397538, state->dataLoopNodes->Node(2).Temp, 0.00001);
EXPECT_NEAR(0.0024802305, state->dataLoopNodes->Node(2).HumRat, 0.000001);
}
TEST_F(EnergyPlusFixture, RoomAirInternalGains_InternalHeatGains_Check)
{
// different names between internal gain objects and room air objects for internal gains result in fatal error from GetInternalGainDeviceIndex.
bool ErrorsFound(false);
std::string const idf_objects = delimited_string({

"Zone,living_unit1;",

"BuildingSurface:Detailed,",
" unit1, !- Name",
" Wall, !- Surface Type",
" PARTITION, !- Construction Name",
" living_unit1, !- Zone Name",
" Outdoors, !- Outside Boundary Condition",
" , !- Outside Boundary Condition Object",
" SunExposed, !- Sun Exposure",
" WindExposed, !- Wind Exposure",
" 0.5000000, !- View Factor to Ground",
" 4, !- Number of Vertices",
" 0,0,3.048000, !- X,Y,Z ==> Vertex 1 {m}",
" 0,0,0, !- X,Y,Z ==> Vertex 2 {m}",
" 6.096000,0,0, !- X,Y,Z ==> Vertex 3 {m}",
" 6.096000,0,3.048000; !- X,Y,Z ==> Vertex 4 {m}",

"Construction,",
" PARTITION, !- Name",
" GYP BOARD; !- Outside Layer",

"Material,",
" GYP BOARD, !- Name",
" Smooth, !- Roughness",
" 1.9050000E-02, !- Thickness {m}",
" 0.7264224, !- Conductivity {W/m-K}",
" 1601.846, !- Density {kg/m3}",
" 836.8000, !- Specific Heat {J/kg-K}",
" 0.9000000, !- Thermal Absorptance",
" 0.9200000, !- Solar Absorptance",
" 0.9200000; !- Visible Absorptance",

"Schedule:Constant,sch_act,,120.0;",
"Schedule:Constant,sch,,1.0;",
"People,",
" people_unit1, !- Name",
" living_unit1, !- Zone or ZoneList Name",
" sch, !- Number of People Schedule Name",
" People, !- Number of People Calculation Method",
" 3, !- Number of People",
" , !- People per Zone Floor Area {person / m2}",
" , !- Zone Floor Area per Person {m2 / person}",
" 0, !- Fraction Radiant",
" autocalculate, !- Sensible Heat Fraction",
" sch_act, !- Activity Level Schedule Name",
" ; !- Carbon Dioxide Generation Rate {m3 / s - W}",

"Lights,",
" Living Hardwired Lighting1, !- Name",
" living_unit1, !- Zone or ZoneList Name",
" sch, !- Schedule Name",
" LightingLevel, !- Design Level Calculation Method",
" 1000, !- Lighting Level {W}",
" , !- Watts per Zone Floor Area {W / m2}",
" , !- Watts per Person {W / person}",
" 0, !- Return Air Fraction",
" 0.6, !- Fraction Radiant",
" 0.2, !- Fraction Visible",
" 0; !- Fraction Replaceable",
" ElectricEquipment,",
" Electric Equipment 1, !- Name",
" living_unit1, !- Zone or ZoneList Name",
" sch, !- Schedule Name",
" EquipmentLevel, !- Design Level Calculation Method",
" 150.0, !- Design Level {W}",
" , !- Watts per Zone Floor Area {W/m2}",
" , !- Watts per Person {W/person}",
" 0.0000, !- Fraction Latent",
" 0.5000, !- Fraction Radiant",
" 0.0000; !- Fraction Lost",

"RoomAirModelType,",
" RoomAirWithAirflowNetwork, !- Name",
" living_unit1, !- Zone Name",
" AirflowNetwork, !- Room - Air Modeling Type",
" DIRECT; !- Air Temperature Coupling Strategy",

"RoomAir:Node:AirflowNetwork,",
" Node1, !- Name",
" living_unit1, !- Zone Name",
" 1, !- Fraction of Zone Air Volume",
" unit1_List, !- RoomAir : Node : AirflowNetwork : AdjacentSurfaceList Name",
" Node1_Gain, !- RoomAir : Node : AirflowNetwork : InternalGains Name",
" Node1_HVAC; !- RoomAir:Node:AirflowNetwork:HVACEquipment Name",

"RoomAir:Node:AirflowNetwork:AdjacentSurfaceList,",
" unit1_List, !- Name",
" unit1; !- Surface 1 Name",

"RoomAir:Node:AirflowNetwork:InternalGains,",
" Node1_Gain, !- Name",
" People, !- Internal Gain Object 1 Type",
" living_unit1 People, !- Internal Gain Object 1 Name",
" 1, !- Fraction of Gains to Node 1",
" Lights, !- Internal Gain Object 2 Type",
" living_unit1 Lights, !- Internal Gain Object 2 Name",
" 1, !- Fraction of Gains to Node 2",
" ElectricEquipment, !- Internal Gain Object 3 Type",
" living_unit1 Equip, !- Internal Gain Object 3 Name",
" 1; !- Fraction of Gains to Node 3",

"RoomAirSettings:AirflowNetwork,",
" living_unit1, !- Name",
" living_unit1, !- Zone Name",
" Node1, !- Control Point RoomAirflowNetwork : Node Name",
" Node1; !- RoomAirflowNetwork : Node Name 1",

});

ASSERT_TRUE(process_idf(idf_objects));
EXPECT_FALSE(has_err_output());

ErrorsFound = false;
state->dataGlobal->NumOfTimeStepInHour = 1;
state->dataGlobal->MinutesPerTimeStep = 60;
ScheduleManager::ProcessScheduleInput(*state);

HeatBalanceManager::GetZoneData(*state, ErrorsFound);
EXPECT_FALSE(ErrorsFound);

ErrorsFound = false;
HeatBalanceManager::GetMaterialData(*state, ErrorsFound);
EXPECT_FALSE(ErrorsFound);

ErrorsFound = false;
HeatBalanceManager::GetConstructData(*state, ErrorsFound);
EXPECT_FALSE(ErrorsFound);

ErrorsFound = false;
state->dataSurfaceGeometry->CosZoneRelNorth.allocate(1);
state->dataSurfaceGeometry->SinZoneRelNorth.allocate(1);
state->dataSurfaceGeometry->CosZoneRelNorth(1) = std::cos(-state->dataHeatBal->Zone(1).RelNorth * DataGlobalConstants::DegToRadians);
state->dataSurfaceGeometry->SinZoneRelNorth(1) = std::sin(-state->dataHeatBal->Zone(1).RelNorth * DataGlobalConstants::DegToRadians);
state->dataSurfaceGeometry->CosBldgRelNorth = 1.0;
state->dataSurfaceGeometry->SinBldgRelNorth = 0.0;
SurfaceGeometry::GetSurfaceData(*state, ErrorsFound);
EXPECT_FALSE(ErrorsFound);

HeatBalanceManager::AllocateHeatBalArrays(*state);
InternalHeatGains::GetInternalHeatGainsInput(*state);

ErrorsFound = false;
state->dataRoomAirMod->AirModel.allocate(1);
state->dataRoomAirMod->AirModel(1).AirModelType = DataRoomAirModel::RoomAirModel::AirflowNetwork;
RoomAirModelManager::GetRoomAirflowNetworkData(*state, ErrorsFound);
EXPECT_TRUE(ErrorsFound);

std::string const error_string =
delimited_string({" ** Severe ** GetRoomAirflowNetworkData: Invalid Internal Gain Object Name = LIVING_UNIT1 PEOPLE",
" ** ~~~ ** Entered in RoomAir:Node:AirflowNetwork:InternalGains = NODE1_GAIN",
" ** ~~~ ** Internal gain did not match correctly",
" ** Severe ** GetRoomAirflowNetworkData: Invalid Internal Gain Object Name = LIVING_UNIT1 LIGHTS",
" ** ~~~ ** Entered in RoomAir:Node:AirflowNetwork:InternalGains = NODE1_GAIN",
" ** ~~~ ** Internal gain did not match correctly",
" ** Severe ** GetRoomAirflowNetworkData: Invalid Internal Gain Object Name = LIVING_UNIT1 EQUIP",
" ** ~~~ ** Entered in RoomAir:Node:AirflowNetwork:InternalGains = NODE1_GAIN",
" ** ~~~ ** Internal gain did not match correctly"});

EXPECT_TRUE(compare_err_stream(error_string, true));
}

10 comments on commit 1713dbf

@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.15-clang-11.0.0: OK (2362 of 2362 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.

develop (Myoldmopar) - x86_64-Linux-Ubuntu-18.04-gcc-7.5: OK (2382 of 2382 tests passed, 0 test warnings)

Build Badge Test Badge

@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 (2332 of 2333 tests passed, 0 test warnings)

Failures:\n

EnergyPlusFixture Test Summary

  • Passed: 1141
  • Failed: 1

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.

develop (Myoldmopar) - x86_64-Linux-Ubuntu-18.04-gcc-7.5-UnitTestsCoverage-Debug: OK (1638 of 1638 tests passed, 0 test warnings)

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

develop (Myoldmopar) - x86_64-Linux-Ubuntu-18.04-gcc-7.5-IntegrationCoverage-Debug: OK (726 of 726 tests passed, 0 test warnings)

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

Issue8735-AFN-Bad-allocation-error (Myoldmopar) - x86_64-MacOS-10.15-clang-11.0.0: OK (3083 of 3084 tests passed, 0 test warnings)

Failures:\n

EnergyPlusFixture Test Summary

  • Passed: 1142
  • Failed: 1

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.

Issue8735-AFN-Bad-allocation-error (Myoldmopar) - x86_64-Linux-Ubuntu-18.04-gcc-7.5: OK (3123 of 3124 tests passed, 0 test warnings)

Failures:\n

FileSystem Test Summary

  • Passed: 6
  • Failed: 1

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.

Issue8735-AFN-Bad-allocation-error (Myoldmopar) - x86_64-Linux-Ubuntu-18.04-gcc-7.5-UnitTestsCoverage-Debug: OK (1638 of 1638 tests passed, 0 test warnings)

Build Badge Test Badge Coverage Badge

@nrel-bot
Copy link

Choose a reason for hiding this comment

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

Issue8735-AFN-Bad-allocation-error (Myoldmopar) - Win64-Windows-10-VisualStudio-16: OK (2333 of 2333 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.

Issue8735-AFN-Bad-allocation-error (Myoldmopar) - x86_64-Linux-Ubuntu-18.04-gcc-7.5-IntegrationCoverage-Debug: OK (726 of 726 tests passed, 0 test warnings)

Build Badge Test Badge Coverage Badge

Please sign in to comment.