Skip to content

Commit

Permalink
Merge pull request #4754 from NREL/88621024-ElectricLoadCenterStorage…
Browse files Browse the repository at this point in the history
…Battery-Crash

88621024 electric load center storage battery crash
  • Loading branch information
jasondegraw committed Mar 11, 2015
2 parents 29b69b1 + bcc7daf commit 6dd7037
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 21 deletions.
99 changes: 79 additions & 20 deletions src/EnergyPlus/ManageElectricPower.cc
Original file line number Diff line number Diff line change
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
3 changes: 2 additions & 1 deletion tst/EnergyPlus/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,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
51 changes: 51 additions & 0 deletions tst/EnergyPlus/unit/ManageElectricPower.unit.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// EnergyPlus::ExteriorEnergyUse Unit Tests

// Google Test Headers
#include <gtest/gtest.h>

// EnergyPlus Headers
#include <EnergyPlus/ExteriorEnergyUse.hh>
#include <EnergyPlus/ManageElectricPower.hh>
#include <EnergyPlus/CurveManager.hh>

using namespace EnergyPlus;
using namespace EnergyPlus::ManageElectricPower;
using namespace EnergyPlus::CurveManager;
using namespace ObjexxFCL;
using namespace DataGlobals;

TEST( ManageElectricPowerTest, BatteryDischargeTest )
{

NumCurves = 1;
PerfCurve.allocate( NumCurves );
PerfCurve( 1 ).CurveType = CurveType_RectangularHyperbola1;
PerfCurve( 1 ).InterpolationType = EvaluateCurveToLimits;
PerfCurve( 1 ).Coeff1 = 0.0899;
PerfCurve( 1 ).Coeff2 = -98.24;
PerfCurve( 1 ).Coeff3 = -.0082;
int CurveNum1 = 1;
Real64 k = 0.5874;
Real64 c = 0.37;
Real64 qmax = 86.1;
Real64 E0c = 12.6;
Real64 InternalR = 0.054;

Real64 I0 = 0.159;
Real64 T0 = 537.9;
Real64 Volt = 12.59;
Real64 Pw = 2.0;
Real64 q0 = 60.2;

EXPECT_TRUE( determineCurrentForBatteryDischarge( I0, T0, Volt, Pw, q0, CurveNum1, k, c, qmax, E0c, InternalR ) );

I0 = -222.7;
T0 = -0.145;
Volt = 24.54;
Pw = 48000;
q0 = 0;

EXPECT_FALSE( determineCurrentForBatteryDischarge( I0, T0, Volt, Pw, q0, CurveNum1, k, c, qmax, E0c, InternalR ) );

PerfCurve.deallocate();
}

14 comments on commit 6dd7037

@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 (jasondegraw) - Win64-Windows-7-VisualStudio-12: OK (1148 of 1148 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.

develop (jasondegraw) - 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.

develop (jasondegraw) - x86_64-Linux-Ubuntu-14.04-gcc-4.8: OK (1148 of 1148 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.

develop (jasondegraw) - x86_64-MacOS-10.9-clang: OK (1145 of 1145 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.

develop (jasondegraw) - x86_64-Linux-Ubuntu-14.04-gcc-4.8-UnitTestsCoverage-Debug: OK (639 of 639 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.

develop (jasondegraw) - x86_64-Linux-Ubuntu-14.04-gcc-4.8-IntegrationCoverage-Debug: OK (1148 of 1148 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.

HVACWaterToAirMultiSpeedHP_-#4093 (jasondegraw) - i386-Windows-7-VisualStudio-12: OK (1148 of 1148 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.

90179052-SetupEMSActuatorMissingDuplicates (jasondegraw) - Win64-Windows-7-VisualStudio-12: OK (1148 of 1148 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.

90179052-SetupEMSActuatorMissingDuplicates (jasondegraw) - x86_64-MacOS-10.9-clang: OK (1145 of 1145 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.

90179052-SetupEMSActuatorMissingDuplicates (jasondegraw) - i386-Windows-7-VisualStudio-12: Tests Failed

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.

90179052-SetupEMSActuatorMissingDuplicates (jasondegraw) - x86_64-Linux-Ubuntu-14.04-gcc-4.8: Tests Failed

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.

90179052-SetupEMSActuatorMissingDuplicates (jasondegraw) - 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.

90179052-SetupEMSActuatorMissingDuplicates (jasondegraw) - x86_64-Linux-Ubuntu-14.04-gcc-4.8-UnitTestsCoverage-Debug: OK (639 of 639 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.

90179052-SetupEMSActuatorMissingDuplicates (jasondegraw) - x86_64-Linux-Ubuntu-14.04-gcc-4.8-IntegrationCoverage-Debug: OK (1148 of 1148 tests passed)

Build Badge Test Badge Coverage Badge

Please sign in to comment.