/* This script writes data from a SAM PV Battery case to use as nputs to the SPECS Early Stage Decision Model Excel model. Written and tested in SAM 2020.11.29r2 for SPECS v2 Instructions: ------------ 1. Create a case or open the SAM file you plan to use to generate data for the SPECS model. It should be a PV Battery / Commercial case with Peak shaving one day look ahead dispatch. 2. Click Run (above) to generate a CSV file with data for the SPECS model. 3. Open the CSV file in Excel and the data from the CSV file to the appropriate sheet in the SPECS model workbook. */ // Functions /////////////////////////////////////////////////////////////////// // return inverter nominal efficiency as fraction function inv_eff() { inv_model = get('inverter_model'); if (inv_model == 0){ eff = get('inv_snl_eff_cec'); } elseif (inv_model == 1){ eff = get('inv_ds_eff'); } elseif (inv_model == 2){ eff = get('inv_pd_eff'); } elseif (inv_model == 3){ eff = get('inv_cec_cg_eff_cec'); } else { eff = 96; } return eff/100; } // truncate time series array to first year of data function truncate_time_series( arr ) { ts_per_year = #arr/get('analysis_period'); for ( i=0; i 0 ) { msg += '\n\nThe SPECS model requires the automated look ahead dispatch option (on the Battery Dispatch page). This case uses ' + options[dispatch] + '.'; } is_dc_connected = !get('batt_ac_or_dc'); if ( is_dc_connected ) // dc connected battery { p_dc_batt = get('batt_max_power'); p_ac = get('total_inverter_capacity'); if ( p_dc_batt > p_ac ) { msg += ('\n\nThe ' + sprintf('%.1f',p_dc_batt) + ' DC kW battery is DC-connected with a hybrid inverter capacity of ' + sprintf('%.1f',p_ac) + ' AC kW. You may want to check that the inverter is not limiting significant power from the battery or use a larger inverter by changing either the DC/AC ratio or number of inverters on the System Design page.'); } } if ( !is_dc_connected ) // ac connected battery { is_pv_charge = get( 'batt_dispatch_auto_can_charge' ); if ( is_pv_charge ) { msg += ('\n\nThe battery is AC-connected with with \"Battery can charge from system\" enabled. For AC-connected batteries, the controller proritizes meeting the load from the PV array over charging the battery. If the peak load is much higher than the PV array peak power output, the battery may never charge unless it is allowed to charge from the grid. Switch to a DC-connected battery on the Battery Ceel and System page if you want the PV array to charge the battery.'); } } return msg; } // Main //////////////////////////////////////////////////////////////////////// outln('Checking inputs.'); msg = check_inputs(); if ( msg != '' ) { ok = yesno( 'SAM case may be incorrectly configured!\n' + 'The SAM inputs for the \"' + active_case() + '\" case may not be configured properly to work with the SPECS model:' + msg + '\n\nContinue anyway?'); if ( !ok ) { exit; } } // Run a simulation to generate results outln( 'Running simulation.' ); msg = ''; sim_ok = simulate( msg, false ); if ( ! sim_ok ) { msgbox( 'SAM simulation failed!\nExiting script. Simulation message: \n\n' + msg ); exit; } // Write data outln( 'Getting data.' ); data_array = get_data(); // Write to CSV f_csv = cwd() + '/sam-inputs-for-specs.csv'; csv_ok = csvwrite( f_csv, data_array ); if ( ! csv_ok ) { msgbox( 'Failed to write SAM data to CSV!\nMake sure that CSV file is not open in another program.\n\n' + f_csv ); exit; } else { outln('Success! Data written to CSV: ' + f_csv); } outln( 'Done.' );