Skip to content

Commit

Permalink
Merge pull request #1132 from NREL/sam_1684_consistent_tolerances
Browse files Browse the repository at this point in the history
Address confusion and consistency in powerflow variables
  • Loading branch information
brtietz authored Feb 22, 2024
2 parents 435a27f + 283376b commit 3041e7c
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
5 changes: 4 additions & 1 deletion shared/lib_battery_powerflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "lib_power_electronics.h"
#include "lib_shared_inverter.h"

// 0.005 W when applied to power. Some inverters have a night time loss of 0.01 W
double powerflow_tolerance = 0.000005;

BatteryPower::BatteryPower(double dtHour) :
dtHour(dtHour),
powerSystem(0),
Expand Down Expand Up @@ -102,7 +105,7 @@ BatteryPower::BatteryPower(double dtHour) :
depthOfDischargeMax(1),
currentChargeMax(0),
currentDischargeMax(0),
tolerance(0.001){}
tolerance(powerflow_tolerance){}

BatteryPower::BatteryPower(const BatteryPower& orig) {
sharedInverter = orig.sharedInverter;
Expand Down
3 changes: 3 additions & 0 deletions shared/lib_battery_powerflow.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ class SharedInverter;

struct BatteryPower;

// Allow for consistent power tolerances between the technology code and utility rate code
extern double powerflow_tolerance;

/**
* \class BatteryPowerFlow
*
Expand Down
6 changes: 5 additions & 1 deletion ssc/cmod_utilityrate5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1420,6 +1420,10 @@ class cm_utilityrate5 : public compute_module
dc_tou_sched[ii] = (ssc_number_t)rate.m_dc_tou_sched[ii];
load[ii] = -e_load_cy[ii];
e_tofromgrid[ii] = e_grid_cy[ii];

if (fabs(e_tofromgrid[ii]) < powerflow_tolerance) { // powerflow_tolerance is defined globally in shared/lib_battery_powerflow.h, set to 0.000005 (Watts or Watt-hrs)
e_tofromgrid[ii] = 0.0;
}
if (e_tofromgrid[ii] > 0)
{
year1_hourly_e_togrid[ii] = e_tofromgrid[ii];
Expand All @@ -1430,7 +1434,7 @@ class cm_utilityrate5 : public compute_module
year1_hourly_e_togrid[ii] = 0.0;
year1_hourly_e_fromgrid[ii] = -e_tofromgrid[ii];
}
p_tofromgrid[ii] = p_grid_cy[ii];
p_tofromgrid[ii] = fabs(p_grid_cy[ii]) > powerflow_tolerance ? p_grid_cy[ii] : 0.0;
salespurchases[ii] = revenue_w_sys[ii];
}
assign("year1_hourly_ec_tou_schedule", var_data(&ec_tou_sched[0], (int)m_num_rec_yearly));
Expand Down
2 changes: 1 addition & 1 deletion ssc/common_financial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3338,7 +3338,7 @@ var_info vtab_lcos_inputs[] = {
{ SSC_INPUT, SSC_MATRIX, "net_billing_credits_ym", "Net billing credit", "$", "", "Charges by Month", "", "", "COL_LABEL=MONTHS,FORMAT_SPEC=CURRENCY,GROUP=UR_AM" },

// fix for running financial compute modules tests
{ SSC_INOUT, SSC_ARRAY, "gen_purchases", "Electricity from grid", "kW", "", "System Output", "", "", "" },
{ SSC_INOUT, SSC_ARRAY, "gen_purchases", "Electricity from grid to system", "kW", "", "System Output", "", "", "" },
{ SSC_INPUT, SSC_ARRAY, "rate_escalation", "Annual electricity rate escalation", "%/year", "", "Electricity Rates", "", "", "" },


Expand Down
2 changes: 1 addition & 1 deletion test/ssc_test/cmod_battery_pvsamv1_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,7 @@ TEST_F(CMPvsamv1BatteryIntegration_cmod_pvsamv1, ResidentialACBatteryModelGridOu
ssc_number_t expectedEnergy = 8521.00;
ssc_number_t expectedBatteryChargeEnergy = 3290.77;
ssc_number_t expectedBatteryDischargeEnergy = 2974.91;
ssc_number_t expectedCritLoadUnmet = 485.18;
ssc_number_t expectedCritLoadUnmet = 488.14;

ssc_number_t peakKwCharge = -3.4;
ssc_number_t peakKwDischarge = 1.964;
Expand Down

0 comments on commit 3041e7c

Please sign in to comment.