Skip to content

Commit

Permalink
Add a Unit test for NREL#10524
Browse files Browse the repository at this point in the history
  • Loading branch information
jmarrec committed May 30, 2024
1 parent 1b333b5 commit 34a9291
Showing 1 changed file with 78 additions and 6 deletions.
84 changes: 78 additions & 6 deletions tst/EnergyPlus/unit/SetPointManager.unit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
#include <EnergyPlus/DataLoopNode.hh>
#include <EnergyPlus/DataZoneEnergyDemands.hh>
#include <EnergyPlus/DataZoneEquipment.hh>
#include <EnergyPlus/FluidProperties.hh>
#include <EnergyPlus/HeatBalanceManager.hh>
#include <EnergyPlus/MixedAir.hh>
#include <EnergyPlus/NodeInputManager.hh>
Expand Down Expand Up @@ -173,9 +174,81 @@ TEST_F(EnergyPlusFixture, SetPointManager_DefineReturnWaterChWSetPointManager)
state->dataPlnt->PlantLoop.deallocate();
}

TEST_F(EnergyPlusFixture, SetPointManager_DefineReturnWaterHWSetPointManager)
TEST_F(EnergyPlusFixture, SetPointManager_DefineReturnWaterChWSetPointManager_FluidIndex)
{

std::string const idf_objects = delimited_string({
"FluidProperties:GlycolConcentration,",
" EthyleneGlycol40Percent, !- Name",
" EthyleneGlycol, !- Glycol Type",
" , !- User Defined Glycol Name",
" 0.4; !- Glycol Concentration",
});

ASSERT_TRUE(process_idf(idf_objects));

EXPECT_EQ(2, state->dataFluidProps->NumOfGlycols);
const auto &thisGlycol = state->dataFluidProps->GlycolData(2);
EXPECT_EQ("ETHYLENEGLYCOL40PERCENT", thisGlycol.Name);
EXPECT_EQ("ETHYLENEGLYCOL", thisGlycol.GlycolName);

// Set up the required plant loop data
state->dataPlnt->TotNumLoops = 1;
state->dataPlnt->PlantLoop.allocate(1);
state->dataPlnt->PlantLoop(1).FluidIndex = 2;

state->dataPlnt->PlantLoop(1).LoopSide(DataPlant::LoopSideLocation::Supply).NodeNumIn = 1; // Supply inlet, return
state->dataPlnt->PlantLoop(1).LoopSide(DataPlant::LoopSideLocation::Supply).NodeNumOut = 2; // Supply outlet, supply
state->dataPlnt->PlantLoop(1).LoopSide(DataPlant::LoopSideLocation::Demand).Branch.allocate(1);
state->dataPlnt->PlantLoop(1).LoopSide(DataPlant::LoopSideLocation::Demand).Branch(1).Comp.allocate(1);
state->dataPlnt->PlantLoop(1).LoopSide(DataPlant::LoopSideLocation::Supply).Branch.allocate(1);
state->dataPlnt->PlantLoop(1).LoopSide(DataPlant::LoopSideLocation::Supply).Branch(1).Comp.allocate(1);
state->dataPlnt->PlantLoop(1).LoopSide(DataPlant::LoopSideLocation::Demand).Branch(1).Comp(1).NodeNumIn = 0;
state->dataPlnt->PlantLoop(1).LoopSide(DataPlant::LoopSideLocation::Demand).Branch(1).Comp(1).NodeNumOut = 0;
state->dataPlnt->PlantLoop(1).LoopSide(DataPlant::LoopSideLocation::Supply).Branch(1).Comp(1).NodeNumIn = 1;
state->dataPlnt->PlantLoop(1).LoopSide(DataPlant::LoopSideLocation::Supply).Branch(1).Comp(1).NodeNumOut = 2;

// Set up the required node data
state->dataLoopNodes->Node.allocate(2);
state->dataLoopNodes->Node(2).MassFlowRate = 1.0;

// Set up a cooling setpoint manager
SetPointManager::DefineReturnWaterChWSetPointManager mySPM;
mySPM.returnNodeIndex = 1;
mySPM.supplyNodeIndex = 2;
mySPM.plantLoopIndex = 0;
mySPM.minimumChilledWaterSetpoint = 7;
mySPM.maximumChilledWaterSetpoint = 10;
mySPM.returnTemperatureConstantTarget = 12;

// test 1: normal, in range
state->dataLoopNodes->Node(1).Temp = 11;
state->dataLoopNodes->Node(2).Temp = 7;
mySPM.calculate(*state, state->dataLoopNodes->Node(1), state->dataLoopNodes->Node(2));
// on the first pass through it should detect the plant loop it manages
EXPECT_EQ(1, mySPM.plantLoopIndex);
// with a delta T of 4, and a target return of 12, it should produce 8
EXPECT_EQ(8, mySPM.currentSupplySetPt);

compare_err_stream("");

// Avg temp will be < 0, and before fix it throws this error
// ** Warning ** GetSpecificHeatGlycol: Temperature is out of range (too low) for fluid [WATER] specific heat supplied values **
// ** ~~~ ** ..Called From:ReturnWaterChWSetPointManager::calculate,Temperature=[-1.00], supplied data range=[0.00,125.00]
// ** ~~~ ** Environment=, at Simulation time= 00:00 - 00:00
state->dataLoopNodes->Node(1).Temp = 1;
state->dataLoopNodes->Node(2).Temp = -3;
// Calling it a second time, ensure #10524 is fixed
mySPM.calculate(*state, state->dataLoopNodes->Node(1), state->dataLoopNodes->Node(2));
// on the first pass through it should detect the plant loop it manages
EXPECT_EQ(1, mySPM.plantLoopIndex);
// with a delta T of 4, and a target return of 12, it should produce 8
EXPECT_EQ(8, mySPM.currentSupplySetPt);
compare_err_stream("");
}

TEST_F(EnergyPlusFixture, SetPointManager_DefineReturnWaterHWSetPointManager)
{
// Set up the required plant loop data
state->dataPlnt->TotNumLoops = 1;
state->dataPlnt->PlantLoop.allocate(1);
Expand Down Expand Up @@ -428,7 +501,6 @@ TEST_F(EnergyPlusFixture, SetPointManager_DefineCondEntSetPointManager)

TEST_F(EnergyPlusFixture, SetPointManager_setupSetPointAndFlags)
{

Real64 totEnergy = 0.0;
Real64 totEnergyPrevious = 0.0;
Real64 condenserWaterSetPoint = 0.0;
Expand Down Expand Up @@ -517,7 +589,8 @@ TEST_F(EnergyPlusFixture, SetPointManager_setupSetPointAndFlags)
EXPECT_FALSE(statusRunSubOptimalCondenserEnteringTemp);
EXPECT_TRUE(statusRunFinalOptimalCondenserEnteringTemp);

// and finally, the sixth pass through when it is set to run final; totEnergy doesn't matter when that flag is true, and the sp shouldn't change
// and finally, the sixth pass through when it is set to run final; totEnergy doesn't matter when that flag is true, and the sp shouldn't
// change
thisSPM.setupSetPointAndFlags(totEnergy,
totEnergyPrevious,
condenserWaterSetPoint,
Expand Down Expand Up @@ -832,7 +905,6 @@ TEST_F(EnergyPlusFixture, SetPointManager_CalcSetPointLinInt)

TEST_F(EnergyPlusFixture, DefineMixedAirSetPointManager)
{

// Set up the required node data
state->dataLoopNodes->Node.allocate(5);
state->dataLoopNodes->Node(1).MassFlowRate = 1.0;
Expand Down Expand Up @@ -884,7 +956,6 @@ TEST_F(EnergyPlusFixture, DefineMixedAirSetPointManager)

TEST_F(EnergyPlusFixture, MixedAirSetPointManager_SameRefAndSPNodeName)
{

std::string const idf_objects = delimited_string({
"SetpointManager:MixedAir,",
" Mixed Air Temp, !- Name",
Expand Down Expand Up @@ -1499,7 +1570,8 @@ TEST_F(EnergyPlusFixture, SingZoneCoolHeatSetPtMgrZoneInletNodeTest)
" ** Fatal ** InitSetPointManagers: Errors found in getting SetPointManager input.",
" ...Summary of Errors that led to program termination:",
" ..... Reference severe error count=2",
" ..... Last severe error=SetpointManager:SingleZone:Cooling=\"COOLING SUPPLY AIR TEMP MANAGER 1\", The zone inlet node of ZNF1 INLET NODE",
" ..... Last severe error=SetpointManager:SingleZone:Cooling=\"COOLING SUPPLY AIR TEMP MANAGER 1\", The zone inlet node of ZNF1 INLET "
"NODE",
});

EXPECT_TRUE(compare_err_stream(error_string, true));
Expand Down

0 comments on commit 34a9291

Please sign in to comment.