Skip to content

Commit

Permalink
Merge branch 'develop' into 89911514-Allow-OtherSideCoefficients-in-AFN
Browse files Browse the repository at this point in the history
Conflicts:
	src/EnergyPlus/AirflowNetworkBalanceManager.cc
	tst/EnergyPlus/unit/CMakeLists.txt
  • Loading branch information
lgu1234 committed Mar 11, 2015
2 parents 77d1bdb + 6dd7037 commit 23232c6
Show file tree
Hide file tree
Showing 9 changed files with 267 additions and 32 deletions.
22 changes: 14 additions & 8 deletions src/EnergyPlus/AirflowNetworkSolver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,14 @@ namespace AirflowNetworkSolver {
if ( LIST >= 1 ) {
gio::write( Unit21, Format_901 ) << "Flow: " << i << n << M << AirflowNetworkLinkSimu( i ).DP << AFLOW( i ) << AFLOW2( i );
}
SUMAF( n ) = SUMAF( n ) - AFLOW( i ) - AFLOW2( i );
SUMAF( M ) += AFLOW( i ) + AFLOW2( i );
if ( AirflowNetworkCompData( AirflowNetworkLinkageData( i ).CompNum ).CompTypeNum == CompTypeNum_HOP ) {
SUMAF( n ) = SUMAF( n ) - AFLOW( i );
SUMAF( M ) += AFLOW( i );
}
else {
SUMAF( n ) = SUMAF( n ) - AFLOW( i ) - AFLOW2( i );
SUMAF( M ) += AFLOW( i ) + AFLOW2( i );
}
}
for ( n = 1; n <= NetworkNumOfNodes; ++n ) {
if ( LIST >= 1 ) gio::write( Unit21, Format_903 ) << "Room: " << n << PZ( n ) << SUMAF( n ) << TZ( n );
Expand All @@ -539,9 +545,12 @@ namespace AirflowNetworkSolver {
AirflowNetworkLinkSimu( i ).FLOW2 = -AFLOW( i );
}
if ( AirflowNetworkCompData( AirflowNetworkLinkageData( i ).CompNum ).CompTypeNum == CompTypeNum_HOP ) {
if ( AFLOW2( i ) != 0.0 ) {
if ( AFLOW( i ) > 0.0 ) {
AirflowNetworkLinkSimu( i ).FLOW = AFLOW( i ) + AFLOW2( i );
AirflowNetworkLinkSimu( i ).FLOW2 = AFLOW2( i );
} else {
AirflowNetworkLinkSimu( i ).FLOW = AFLOW2( i );
AirflowNetworkLinkSimu( i ).FLOW2 = -AFLOW( i ) + AFLOW2( i );
}
}
if ( AirflowNetworkLinkageData( i ).DetOpenNum > 0 ) {
Expand Down Expand Up @@ -920,9 +929,6 @@ namespace AirflowNetworkSolver {
if ( AirflowNetworkCompData( j ).CompTypeNum == CompTypeNum_DOP ) {
AFLOW2( i ) = F( 2 );
}
if ( AirflowNetworkCompData( j ).CompTypeNum == CompTypeNum_HOP ) {
AFLOW2( i ) = F( 2 );
}
if ( LIST >= 3 ) gio::write( Unit21, Format_901 ) << " NRi:" << i << n << M << AirflowNetworkLinkSimu( i ).DP << F( 1 ) << DF( 1 );
FLAG = 1;
if ( AirflowNetworkNodeData( n ).NodeTypeNum == 0 ) {
Expand Down Expand Up @@ -3162,7 +3168,7 @@ Label999: ;
DH = 4.0 * ( Width * Height ) / 2.0 / ( Width + Height ) * Fact;

// Check which zone is higher

NF = 1;
if ( Fact == 0.0 ) {
GenericCrack( coef, expn, LFLAG, PDROP, n, M, F, DF, NF );
return;
Expand Down Expand Up @@ -3222,7 +3228,7 @@ Label999: ;
DF( 1 ) = dp1fma12 - dp1fma21;
F( 2 ) = 0.0;
if ( fma12 != 0.0 && fma21 != 0.0 ) {
F( 2 ) = fma21;
F( 2 ) = BuoFlow;
}
DF( 2 ) = 0.0;

Expand Down
2 changes: 1 addition & 1 deletion src/EnergyPlus/EvaporativeCoolers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2327,7 +2327,7 @@ namespace EvaporativeCoolers {
} else {
FlowRatio = 1.0;
}
if ( AirMassFlowSec >= 0.0 ) {
if ( AirMassFlowSec > 0.0 ) {
RhoAirSec = PsyRhoAirFnPbTdbW( OutBaroPress, EDBTSec, EHumRatSec );
RhoAirSys = PsyRhoAirFnPbTdbW( OutBaroPress, EvapCond( EvapCoolNum ).InletTemp, EvapCond( EvapCoolNum ).InletHumRat );
if ( DryOrWetOperatingMode == DryModulated || DryOrWetOperatingMode == DryFull ) {
Expand Down
101 changes: 80 additions & 21 deletions src/EnergyPlus/ManageElectricPower.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1528,7 +1528,7 @@ namespace ManageElectricPower {
SetupOutputVariable( "Transformer Load Loss Energy [J]", Transformer( TransfNum ).LoadLossEnergy, "System", "Sum", Transformer( TransfNum ).Name );
SetupOutputVariable( "Transformer Thermal Loss Rate [W]", Transformer( TransfNum ).ThermalLossRate, "System", "Average", Transformer( TransfNum ).Name );
SetupOutputVariable( "Transformer Thermal Loss Energy [J]", Transformer( TransfNum ).ThermalLossEnergy, "System", "Sum", Transformer( TransfNum ).Name );
SetupOutputVariable( "Transformer Distribution Electric Loss Energy [J]", Transformer( TransfNum ).ElecUseUtility, "System", "Sum", Transformer( TransfNum ).Name, _, "Electricity", _, _, "System" );
SetupOutputVariable( "Transformer Distribution Electric Loss Energy [J]", Transformer( TransfNum ).ElecUseUtility, "System", "Sum", Transformer( TransfNum ).Name, _, "Electricity", "ExteriorEquipment", "Transformer", "System" );
SetupOutputVariable( "Transformer Cogeneration Electric Loss Energy [J]", Transformer( TransfNum ).ElecProducedCoGen, "System", "Sum", Transformer( TransfNum ).Name, _, "ElectricityProduced", "COGENERATION", _, "System" );

if ( Transformer( TransfNum ).ZoneNum > 0 ) {
Expand Down Expand Up @@ -3029,26 +3029,9 @@ namespace ManageElectricPower {

Pw = tmpPdraw / Numbattery;
q0 = ElecStorage( ElecStorNum ).LastTimeStepAvailable + ElecStorage( ElecStorNum ).LastTimeStepBound;
I0 = 10.0; // Initial assumption
T0 = qmax / I0; // Initial Assumption
qmaxf = qmax * k * c * T0 / ( 1.0 - std::exp( -k * T0 ) + c * ( k * T0 - 1.0 + std::exp( -k * T0 ) ) ); //Initial calculation of a function qmax(I)
Xf = ( qmax - q0 ) / qmaxf;
Ef = E0c + CurveValue( ElecStorage( ElecStorNum ).DischargeCurveNum, Xf ); //E0d+Ac*Xf+Cc*X/(Dc-Xf)
Volt = Ef - I0 * InternalR;
Inew = Pw / Volt;
Tnew = qmaxf / Inew;
error = 1.0;

while ( error > 0.0001 ) { //Iteration process to get converged current(I)
I0 = Inew;
T0 = Tnew;
qmaxf = qmax * k * c * T0 / ( 1.0 - std::exp( -k * T0 ) + c * ( k * T0 - 1.0 + std::exp( -k * T0 ) ) );
Xf = ( qmax - q0 ) / qmaxf;
Ef = E0c + CurveValue( ElecStorage( ElecStorNum ).DischargeCurveNum, Xf ); //E0c+Ad*Xf+Cd*X/(Dd-Xf)
Volt = Ef - I0 * InternalR;
Inew = Pw / Volt;
Tnew = qmaxf / Inew;
error = std::abs( Inew - I0 );
bool ok = determineCurrentForBatteryDischarge( I0, T0, Volt, Pw, q0, ElecStorage( ElecStorNum ).DischargeCurveNum, k, c, qmax, E0c, InternalR );
if ( !ok ){
ShowFatalError( "ElectricLoadCenter:Storage:Battery named=\"" + ElecStorage( ElecStorNum ).Name + "\". Battery discharge current could not be estimated due to iteration limit reached. " );
}

dividend = k * ElecStorage( ElecStorNum ).LastTimeStepAvailable * std::exp( -k * TimeStepSys ) + q0 * k * c * ( 1.0 - std::exp( -k * TimeStepSys ) );
Expand Down Expand Up @@ -3192,6 +3175,82 @@ namespace ManageElectricPower {

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

bool
determineCurrentForBatteryDischarge(
Real64& curI0,
Real64& curT0,
Real64& curVolt,
Real64 const Pw,
Real64 const q0,
int const CurveNum,
Real64 const k,
Real64 const c,
Real64 const qmax,
Real64 const E0c,
Real64 const InternalR )
{
// FUNCTION INFORMATION:
// AUTHOR B. Griffith
// DATE WRITTEN June-August 2008
// MODIFIED BG May 2009, added EMS
// BN (FSEC) Feb 2010 (pass out two storage values)
// Y. KyungTae & W. Wang July-August, 2011 Added a battery model
// RE-ENGINEERED Jason Glazer, GARD Analytics, February 2015, refactor charge calculation into a function

// PURPOSE OF THIS FUNCTION:
// Calculate the current for battery discharge in a separate function so that it could be called from the unit tests

// METHODOLOGY EMPLOYED:
// na

// REFERENCES:
// na

// Using/Aliasing
using CurveManager::CurveValue;

// Locals
// FUNCTION ARGUMENT DEFINITIONS:

// INTERFACE BLOCK SPECIFICATIONS:
// na

// DERIVED TYPE DEFINITIONS:
// na

// FUNCTION LOCAL VARIABLE DECLARATIONS:
curI0 = 10.0; // Initial assumption
curT0 = qmax / curI0; // Initial Assumption
Real64 qmaxf = qmax * k * c * curT0 / ( 1.0 - std::exp( -k * curT0 ) + c * ( k * curT0 - 1.0 + std::exp( -k * curT0 ) ) ); //Initial calculation of a function qmax(I)
Real64 Xf = ( qmax - q0 ) / qmaxf;
Real64 Ef = E0c + CurveValue( CurveNum, Xf ); //E0d+Ac*Xf+Cc*X/(Dc-Xf)
curVolt = Ef - curI0 * InternalR;
Real64 Inew = Pw / curVolt;
Real64 Tnew = qmaxf / Inew;
Real64 error = 1.0;
int countForIteration = 0;
bool exceedIterationLimit = false;

while ( error > 0.0001 ) { //Iteration process to get converged current(I)
curI0 = Inew;
curT0 = Tnew;
qmaxf = qmax * k * c * curT0 / ( 1.0 - std::exp( -k * curT0 ) + c * ( k * curT0 - 1.0 + std::exp( -k * curT0 ) ) );
Xf = ( qmax - q0 ) / qmaxf;
Ef = E0c + CurveValue( CurveNum, Xf ); //E0c+Ad*Xf+Cd*X/(Dd-Xf)
curVolt = Ef - curI0 * InternalR;
Inew = Pw / curVolt;
Tnew = qmaxf / Inew;
error = std::abs( Inew - curI0 );
countForIteration++;
if ( countForIteration > 1000 ){
exceedIterationLimit = true;
break;
}
}
return (!exceedIterationLimit);
}


void
FigureElectricalStorageZoneGains()
{
Expand Down
15 changes: 15 additions & 0 deletions src/EnergyPlus/ManageElectricPower.hh
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,21 @@ namespace ManageElectricPower {

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

bool
determineCurrentForBatteryDischarge(
Real64& curI0,
Real64& curT0,
Real64& curVolt,
Real64 const Pw,
Real64 const q0,
int const CurveNum,
Real64 const k,
Real64 const c,
Real64 const qmax,
Real64 const E0c,
Real64 const InternalR
);

void
FigureElectricalStorageZoneGains();

Expand Down
12 changes: 12 additions & 0 deletions src/EnergyPlus/OutputReportTabular.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7208,6 +7208,18 @@ namespace OutputReportTabular {
}
tableBody( 16, iResource ) = RealToStr( useVal( 15, iResource ), 2 );
}
// add warning message if end use values do not add up to total
Real64 curTotal = 0.0;
for ( iResource = 1; iResource <= 6; ++iResource ) {
curTotal = 0.0;
for ( int jUse = 1; jUse <= 14; ++jUse ) {
curTotal += useVal( jUse, iResource );
}
if ( abs( curTotal - collapsedTotal( iResource ) ) > ( collapsedTotal( iResource ) * 0.001 )) {
ShowWarningError( "In the Annual Building Utility Performance Summary Report the total row does not match the sum of the column for: " + columnHead( 1 ) );
}
}

//complete the LEED end use table using the same values
// for certain rows in the LEED table the subcategories are necessary so first compute those values
leedFansParkFromFan = 0.0;
Expand Down
5 changes: 4 additions & 1 deletion src/ExpandObjects/epfilter.f90
Original file line number Diff line number Diff line change
Expand Up @@ -3481,13 +3481,16 @@ REAL FUNCTION StringToReal(stringIn)

IF (LEN_TRIM(stringIn) .GE. 1) THEN
IF (VERIFY(TRIM(stringIn),'-0123456789.E+') .EQ. 0) THEN
READ(stringIn,*) StringToReal
READ(stringIn,*,ERR=2222) StringToReal
ELSE
StringToReal = 0
END IF
ELSE
StringToReal = 0
END IF
RETURN

2222 StringToReal = 0
END FUNCTION

!----------------------------------------------------------------------------------
Expand Down
87 changes: 87 additions & 0 deletions tst/EnergyPlus/unit/AirflowNetworkSolver.unit.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// EnergyPlus::AirflowNetworkSolver unit tests

// Google test headers
#include <gtest/gtest.h>

// C++ Headers
//#include <cassert>
//#include <cmath>
//#include <string>

// ObjexxFCL Headers
//#include <ObjexxFCL/FArray.functions.hh>
//#include <ObjexxFCL/Fmath.hh>
//#include <ObjexxFCL/gio.hh>

// EnergyPlus Headers
#include <DataAirflowNetwork.hh>
#include <AirflowNetworkBalanceManager.hh>
#include <AirflowNetworkSolver.hh>

using namespace EnergyPlus;
using namespace AirflowNetworkBalanceManager;
using namespace DataAirflowNetwork;
using namespace AirflowNetworkSolver;

TEST( AirflowNetworkSolverTest, HorizontalOpening )
{

int i = 1;
int j = 1;
int CurveNum;
int n;
int m;
int NF;
FArray1D< Real64 > F;
FArray1D< Real64 > DF;

n = 1;
m = 2;


AirflowNetworkCompData.allocate( j );
AirflowNetworkCompData( j ).TypeNum = 1;
MultizoneSurfaceData.allocate( i );
MultizoneSurfaceData( i ).Width = 10.0;
MultizoneSurfaceData( i ).Height = 5.0;
MultizoneSurfaceData( i ).OpenFactor = 1.0;

RHOZ.allocate( 2 );
RHOZ( 1 ) = 1.2;
RHOZ( 2 ) = 1.18;

MultizoneCompHorOpeningData.allocate( 1 );
MultizoneCompHorOpeningData( 1 ).FlowCoef = 0.1;
MultizoneCompHorOpeningData( 1 ).FlowExpo = 0.5;
MultizoneCompHorOpeningData( 1 ).Slope = 90.0;
MultizoneCompHorOpeningData( 1 ).DischCoeff = 0.2;

F.allocate( 2 );
DF.allocate( 2 );

AirflowNetworkLinkageData.allocate( i );
AirflowNetworkLinkageData( i ).NodeHeights( 1 ) = 4.0;
AirflowNetworkLinkageData( i ).NodeHeights( 2 ) = 2.0;

AFEHOP( 1, 1, 0.05, 1, 1, 2, F, DF, NF );
EXPECT_NEAR( 3.47863, F( 1 ), 0.00001 );
EXPECT_NEAR( 34.7863, DF( 1 ), 0.0001 );
EXPECT_NEAR( 2.96657, F( 2 ), 0.00001 );
EXPECT_EQ( 0.0, DF( 2 ) );

AFEHOP( 1, 1, -0.05, 1, 1, 2, F, DF, NF );
EXPECT_NEAR( -3.42065, F( 1 ), 0.00001 );
EXPECT_NEAR( 34.20649, DF( 1 ), 0.0001 );
EXPECT_NEAR( 2.96657, F( 2 ), 0.00001 );
EXPECT_EQ( 0.0, DF( 2 ) );

AirflowNetworkLinkageData.deallocate();
DF.deallocate();
F.deallocate();
RHOZ.deallocate();
MultizoneCompHorOpeningData.deallocate();
MultizoneSurfaceData.deallocate();
AirflowNetworkCompData.deallocate();
}


4 changes: 3 additions & 1 deletion tst/EnergyPlus/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/src/EnergyPlus )
set( test_src
AdvancedAFN.unit.cc
AirflowNetworkBalanceManager.unit.cc
AirflowNetworkSolver.unit.cc
DataPlant.unit.cc
DataZoneEquipment.unit.cc
DXCoils.unit.cc
Expand All @@ -12,8 +13,9 @@ set( test_src
FluidCoolers.unit.cc
GroundHeatExchangers.unit.cc
HeatBalanceManager.unit.cc
HVACStandaloneERV.unit.cc
Humidifiers.unit.cc
HVACStandaloneERV.unit.cc
ManageElectricPower.unit.cc
MixedAir.unit.cc
PurchasedAirManager.unit.cc
OutputProcessor.unit.cc
Expand Down
Loading

7 comments on commit 23232c6

@nrel-bot
Copy link

Choose a reason for hiding this comment

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

89911514-Allow-OtherSideCoefficients-in-AFN (lgu1234) - x86_64-Linux-Ubuntu-14.04-gcc-4.8: OK (1656 of 1656 tests passed)

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.

89911514-Allow-OtherSideCoefficients-in-AFN (lgu1234) - x86_64-Linux-Ubuntu-14.04-cppcheck-1.61: OK (0 of 0 tests passed)

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

89911514-Allow-OtherSideCoefficients-in-AFN (lgu1234) - i386-Windows-7-VisualStudio-12: OK (1656 of 1656 tests passed)

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.

89911514-Allow-OtherSideCoefficients-in-AFN (lgu1234) - x86_64-Linux-Ubuntu-14.04-gcc-4.8-UnitTestsCoverage-Debug: OK (640 of 640 tests passed)

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.

89911514-Allow-OtherSideCoefficients-in-AFN (lgu1234) - x86_64-MacOS-10.9-clang: OK (1650 of 1650 tests passed)

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.

89911514-Allow-OtherSideCoefficients-in-AFN (lgu1234) - x86_64-Linux-Ubuntu-14.04-gcc-4.8-IntegrationCoverage-Debug: OK (1149 of 1149 tests passed)

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.

89911514-Allow-OtherSideCoefficients-in-AFN (lgu1234) - Win64-Windows-7-VisualStudio-12: OK (1656 of 1656 tests passed)

Build Badge Test Badge

Please sign in to comment.