void tcKernel::set_unit_value_ssc_array(int id, const char *tcs_name, const char *ssc_name) { size_t len; ssc_number_t * p = as_array(ssc_name, &len); double *pt = new double[len]; for (size_t i = 0; i<len; i++) pt[i] = (double)p[i]; set_unit_value(id, tcs_name, pt, (int)len); delete[] pt; return; }
void tcKernel::set_unit_value_ssc_matrix(int id, const char *tcs_name, const char *ssc_name) { size_t nr, nc; ssc_number_t *p = as_matrix(ssc_name, &nr, &nc); double *pt = new double[nr*nc]; for (size_t i = 0; i<nr*nc; i++) pt[i] = (double)p[i]; set_unit_value(id, tcs_name, pt, (int)nr, (int)nc); delete[] pt; return; }
void tcKernel::set_unit_value_ssc_matrix_transpose(int id, const char *tcs_name, const char *ssc_name) { size_t nr, nc; ssc_number_t *p = as_matrix(ssc_name, &nr, &nc); double *pt = new double[nr*nc]; size_t i = 0; for (size_t c = 0; c< nc; c++) for (size_t r = 0; r < nr; r++) pt[i++] = (double)p[r*nc + c]; set_unit_value(id, tcs_name, pt, (int)nc, (int)nr); delete[] pt; return; }
void Slider::_input_event(InputEvent p_event) { if (p_event.type==InputEvent::MOUSE_BUTTON) { InputEventMouseButton &mb = p_event.mouse_button; if (mb.button_index==BUTTON_LEFT) { if (mb.pressed) { grab.pos=orientation==VERTICAL?mb.y:mb.x; double max = orientation==VERTICAL ? get_size().height : get_size().width ; if (orientation==VERTICAL) set_unit_value( 1 - ((double)grab.pos / max) ); else set_unit_value((double)grab.pos / max); grab.active=true; grab.uvalue=get_unit_value(); } else { grab.active=false; } } else if (mb.pressed && mb.button_index==BUTTON_WHEEL_UP) { set_val( get_val() + get_step()); } else if (mb.pressed && mb.button_index==BUTTON_WHEEL_DOWN) { set_val( get_val() - get_step()); } } else if (p_event.type==InputEvent::MOUSE_MOTION) { if (grab.active) { Size2i size = get_size(); Ref<Texture> grabber = get_icon("grabber"); float motion = (orientation==VERTICAL?p_event.mouse_motion.y:p_event.mouse_motion.x) - grab.pos; if (orientation==VERTICAL) motion=-motion; float areasize = orientation==VERTICAL?size.height - grabber->get_size().height:size.width - grabber->get_size().width; if (areasize<=0) return; float umotion = motion / float(areasize); set_unit_value( grab.uvalue + umotion ); } } else { if (p_event.is_action("ui_left") && p_event.is_pressed()) { if (orientation!=HORIZONTAL) return; set_val( get_val() - (custom_step>=0?custom_step:get_step()) ); accept_event(); } else if (p_event.is_action("ui_right") && p_event.is_pressed()) { if (orientation!=HORIZONTAL) return; set_val( get_val() + (custom_step>=0?custom_step:get_step()) ); accept_event(); } else if (p_event.is_action("ui_up") && p_event.is_pressed()) { if (orientation!=VERTICAL) return; set_val( get_val() + (custom_step>=0?custom_step:get_step()) ); accept_event(); } else if (p_event.is_action("ui_down") && p_event.is_pressed()) { if (orientation!=VERTICAL) return; set_val( get_val() - (custom_step>=0?custom_step:get_step()) ); accept_event(); } else if (p_event.type==InputEvent::KEY) { const InputEventKey &k=p_event.key; if (!k.pressed) return; switch (k.scancode) { case KEY_HOME: { set_val( get_min() ); accept_event(); } break; case KEY_END: { set_val( get_max() ); accept_event(); } break; } ; } } }
void tcKernel::set_unit_value_ssc_double(int id, const char *tcs_name, const char *ssc_name) { set_unit_value(id, tcs_name, as_double(ssc_name)); }
void tcKernel::set_unit_value_ssc_double( int id, const char *name, double x ) { set_unit_value( id, name, x ); }
void tcKernel::set_unit_value_ssc_double( int id, const char *name ) { set_unit_value( id, name, as_double(name) ); }
void tcKernel::set_unit_value_ssc_string(int id, const char *tcs_name, const char *ssc_name) { set_unit_value(id, tcs_name, as_string(ssc_name)); }
void tcKernel::set_unit_value_ssc_string(int id, const char *name) { set_unit_value(id, name, as_string(name)); }
void ScrollBar::_input_event(InputEvent p_event) { switch(p_event.type) { case InputEvent::MOUSE_BUTTON: { const InputEventMouseButton &b=p_event.mouse_button; accept_event(); if (b.button_index==5 && b.pressed) { if (orientation==VERTICAL) set_val( get_val() + get_page() / 4.0 ); else set_val( get_val() + get_page() / 4.0 ); accept_event(); } if (b.button_index==4 && b.pressed) { if (orientation==HORIZONTAL) set_val( get_val() - get_page() / 4.0 ); else set_val( get_val() - get_page() / 4.0 ); accept_event(); } if (b.button_index!=1) return; if (b.pressed) { double ofs = orientation==VERTICAL ? b.y : b.x ; Ref<Texture> decr = get_icon("decrement"); Ref<Texture> incr = get_icon("increment"); double decr_size = orientation==VERTICAL ? decr->get_height() : decr->get_width(); double incr_size = orientation==VERTICAL ? incr->get_height() : incr->get_width(); double grabber_ofs = get_grabber_offset(); double grabber_size = get_grabber_size(); double total = orientation==VERTICAL ? get_size().height : get_size().width; if (ofs < decr_size ) { set_val( get_val() - (custom_step>=0?custom_step:get_step()) ); break; } if (ofs > total-incr_size ) { set_val( get_val() + (custom_step>=0?custom_step:get_step()) ); break; } ofs-=decr_size; if ( ofs < grabber_ofs ) { set_val( get_val() - get_page() ); break; } ofs-=grabber_ofs; if (ofs < grabber_size ) { drag.active=true; drag.pos_at_click=grabber_ofs+ofs; drag.value_at_click=get_unit_value(); update(); } else { set_val( get_val() + get_page() ); } } else { drag.active=false; update(); } } break; case InputEvent::MOUSE_MOTION: { const InputEventMouseMotion &m=p_event.mouse_motion; accept_event(); if (drag.active) { double ofs = orientation==VERTICAL ? m.y : m.x ; Ref<Texture> decr = get_icon("decrement"); double decr_size = orientation==VERTICAL ? decr->get_height() : decr->get_width(); ofs-=decr_size; double diff = (ofs-drag.pos_at_click) / get_area_size(); set_unit_value( drag.value_at_click + diff ); } else { double ofs = orientation==VERTICAL ? m.y : m.x ; Ref<Texture> decr = get_icon("decrement"); Ref<Texture> incr = get_icon("increment"); double decr_size = orientation==VERTICAL ? decr->get_height() : decr->get_width(); double incr_size = orientation==VERTICAL ? incr->get_height() : incr->get_width(); double total = orientation==VERTICAL ? get_size().height : get_size().width; HiliteStatus new_hilite; if (ofs < decr_size ) { new_hilite=HILITE_DECR; } else if (ofs > total-incr_size ) { new_hilite=HILITE_INCR; } else { new_hilite=HILITE_RANGE; } if (new_hilite!=hilite) { hilite=new_hilite; update(); } } } break; case InputEvent::KEY: { const InputEventKey &k=p_event.key; if (!k.pressed) return; switch (k.scancode) { case KEY_LEFT: { if (orientation!=HORIZONTAL) return; set_val( get_val() - (custom_step>=0?custom_step:get_step()) ); } break; case KEY_RIGHT: { if (orientation!=HORIZONTAL) return; set_val( get_val() + (custom_step>=0?custom_step:get_step()) ); } break; case KEY_UP: { if (orientation!=VERTICAL) return; set_val( get_val() - (custom_step>=0?custom_step:get_step()) ); } break; case KEY_DOWN: { if (orientation!=VERTICAL) return; set_val( get_val() + (custom_step>=0?custom_step:get_step()) ); } break; case KEY_HOME: { set_val( get_min() ); } break; case KEY_END: { set_val( get_max() ); } break; } break; } } }
void exec( ) throw( general_error ) { //if ( 0 >= load_library("typelib") ) throw exec_error( "tcsgeneric_solar", util::format("could not load the tcs type library.") ); //bool debug_mode = (__DEBUG__ == 1); // When compiled in VS debug mode, this will use the trnsys weather file; otherwise, it will attempt to open the file with name that was passed in // type260_genericsolar uses 'poa_beam' from the weather reader, which is not available from a "trnsys_weatherreader", so this must be set to false bool debug_mode = false; //Add weather file reader unit int weather = 0; if(debug_mode) weather = add_unit("trnsys_weatherreader", "TRNSYS weather reader"); else weather = add_unit("weatherreader", "TCS weather reader"); // Add time-of-use reader int tou = add_unit("tou_translator", "Time of Use Translator"); //Add Physical Solar Field Model int type260_genericsolar = add_unit( "sam_mw_gen_type260", "Generic solar model" ); if(debug_mode) { set_unit_value( weather, "file_name", "C:/svn_NREL/main/ssc/tcsdata/typelib/TRNSYS_weather_outputs/tucson_trnsys_weather.out" ); set_unit_value( weather, "i_hour", "TIME" ); set_unit_value( weather, "i_month", "month" ); set_unit_value( weather, "i_day", "day" ); set_unit_value( weather, "i_global", "GlobalHorizontal" ); set_unit_value( weather, "i_beam", "DNI" ); set_unit_value( weather, "i_diff", "DiffuseHorizontal" ); set_unit_value( weather, "i_tdry", "T_dry" ); set_unit_value( weather, "i_twet", "T_wet" ); set_unit_value( weather, "i_tdew", "T_dew" ); set_unit_value( weather, "i_wspd", "WindSpeed" ); set_unit_value( weather, "i_wdir", "WindDir" ); set_unit_value( weather, "i_rhum", "RelHum" ); set_unit_value( weather, "i_pres", "AtmPres" ); set_unit_value( weather, "i_snow", "SnowCover" ); set_unit_value( weather, "i_albedo", "GroundAlbedo" ); set_unit_value( weather, "i_poa", "POA" ); set_unit_value( weather, "i_solazi", "Azimuth" ); set_unit_value( weather, "i_solzen", "Zenith" ); set_unit_value( weather, "i_lat", "Latitude" ); set_unit_value( weather, "i_lon", "Longitude" ); set_unit_value( weather, "i_shift", "Shift" ); } else { //Set weatherreader parameters set_unit_value_ssc_string( weather, "file_name" ); set_unit_value_ssc_double( weather, "track_mode" ); //, 1 ); set_unit_value_ssc_double( weather, "tilt" ); //, 0 ); set_unit_value_ssc_double( weather, "azimuth" ); //, 0 ); } set_unit_value_ssc_matrix(tou, "weekday_schedule"); // tou values from control will be between 1 and 9 set_unit_value_ssc_matrix(tou, "weekend_schedule"); //Set parameters set_unit_value_ssc_double(type260_genericsolar, "latitude" ); //, 35); set_unit_value_ssc_double(type260_genericsolar, "longitude" ); //, -117); set_unit_value_ssc_double(type260_genericsolar, "istableunsorted"); set_unit_value_ssc_matrix(type260_genericsolar, "OpticalTable" ); //, opt_data); //set_unit_value_ssc_matrix(type260_genericsolar, "OpticalTableUns" ); set_unit_value_ssc_double(type260_genericsolar, "timezone" ); //, -8); set_unit_value_ssc_double(type260_genericsolar, "theta_stow" ); //, 170); set_unit_value_ssc_double(type260_genericsolar, "theta_dep" ); //, 10); set_unit_value_ssc_double(type260_genericsolar, "interp_arr" ); //, 1); set_unit_value_ssc_double(type260_genericsolar, "rad_type" ); //, 1); set_unit_value_ssc_double(type260_genericsolar, "solarm" ); //, solarm); set_unit_value_ssc_double(type260_genericsolar, "T_sfdes" ); //, T_sfdes); set_unit_value_ssc_double(type260_genericsolar, "irr_des" ); //, irr_des); set_unit_value_ssc_double(type260_genericsolar, "eta_opt_soil" ); //, eta_opt_soil); set_unit_value_ssc_double(type260_genericsolar, "eta_opt_gen" ); //, eta_opt_gen); set_unit_value_ssc_double(type260_genericsolar, "f_sfhl_ref" ); //, f_sfhl_ref); set_unit_value_ssc_array(type260_genericsolar, "sfhlQ_coefs" ); //, [1,-0.1,0,0]); set_unit_value_ssc_array(type260_genericsolar, "sfhlT_coefs" ); //, [1,0.005,0,0]); set_unit_value_ssc_array(type260_genericsolar, "sfhlV_coefs" ); //, [1,0.01,0,0]); set_unit_value_ssc_double(type260_genericsolar, "qsf_des" ); //, q_sf); set_unit_value_ssc_double(type260_genericsolar, "w_des" ); //, w_gr_des); set_unit_value_ssc_double(type260_genericsolar, "eta_des" ); //, eta_cycle_des); set_unit_value_ssc_double(type260_genericsolar, "f_wmax" ); //, 1.05); set_unit_value_ssc_double(type260_genericsolar, "f_wmin" ); //, 0.25); set_unit_value_ssc_double(type260_genericsolar, "f_startup" ); //, 0.2); set_unit_value_ssc_double(type260_genericsolar, "eta_lhv" ); //, 0.9); set_unit_value_ssc_array(type260_genericsolar, "etaQ_coefs" ); //, [0.9,0.1,0,0,0]); set_unit_value_ssc_array(type260_genericsolar, "etaT_coefs" ); //, [1,-0.002,0,0,0]); set_unit_value_ssc_double(type260_genericsolar, "T_pcdes" ); //, 21); set_unit_value_ssc_double(type260_genericsolar, "PC_T_corr" ); //, 1); set_unit_value_ssc_double(type260_genericsolar, "f_Wpar_fixed" ); //, f_Wpar_fixed); set_unit_value_ssc_double(type260_genericsolar, "f_Wpar_prod" ); //, f_Wpar_prod); set_unit_value_ssc_array(type260_genericsolar, "Wpar_prodQ_coefs" ); //, [1,0,0,0]); set_unit_value_ssc_array(type260_genericsolar, "Wpar_prodT_coefs" ); //, [1,0,0,0]); set_unit_value_ssc_array(type260_genericsolar, "Wpar_prodD_coefs" ); //, [1,0,0,0]); set_unit_value_ssc_double(type260_genericsolar, "hrs_tes" ); //, hrs_tes); set_unit_value_ssc_double(type260_genericsolar, "f_charge" ); //, 0.98); set_unit_value_ssc_double(type260_genericsolar, "f_disch" ); //, 0.98); set_unit_value_ssc_double(type260_genericsolar, "f_etes_0" ); //, 0.1); set_unit_value_ssc_double(type260_genericsolar, "f_teshl_ref" ); //, 0.35); set_unit_value_ssc_array(type260_genericsolar, "teshlX_coefs" ); //, [1,0,0,0]); set_unit_value_ssc_array(type260_genericsolar, "teshlT_coefs" ); //, [1,0,0,0]); set_unit_value_ssc_double(type260_genericsolar, "ntod" ); //, 9); set_unit_value_ssc_array(type260_genericsolar, "disws" ); //, [0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1]); set_unit_value_ssc_array(type260_genericsolar, "diswos" ); //, [0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1]); set_unit_value_ssc_array(type260_genericsolar, "qdisp" ); //, [1,1,1,1,1,1,1,1,1]); set_unit_value_ssc_array(type260_genericsolar, "fdisp" ); //, [0,0,0,0,0,0,0,0,0]); set_unit_value_ssc_matrix(type260_genericsolar, "exergy_table" ); set_unit_value_ssc_double(type260_genericsolar, "storage_config"); //Direct storage=0,Indirect storage=1 //Set the initial values set_unit_value_ssc_double(type260_genericsolar, "ibn" ); //, 0.); //Beam-normal (DNI) irradiation set_unit_value_ssc_double(type260_genericsolar, "ibh" ); //, 0.); // Beam-horizontal irradiation set_unit_value_ssc_double(type260_genericsolar, "itoth" ); //, 0.); // Total horizontal irradiation set_unit_value_ssc_double(type260_genericsolar, "tdb" ); //, 15.); // Ambient dry-bulb temperature set_unit_value_ssc_double(type260_genericsolar, "twb" ); //, 10.); // Ambient wet-bulb temperature set_unit_value_ssc_double(type260_genericsolar, "vwind" ); //, 1.); // Wind velocity // Connect the units bool bConnected = connect(weather, "beam", type260_genericsolar, "ibn"); bConnected &= connect(weather, "global", type260_genericsolar, "itoth"); bConnected &= connect(weather, "poa_beam", type260_genericsolar, "ibh"); bConnected &= connect(weather, "tdry", type260_genericsolar, "tdb"); bConnected &= connect(weather, "twet", type260_genericsolar, "twb"); bConnected &= connect(weather, "wspd", type260_genericsolar, "vwind"); //location bConnected &= connect(weather, "lat", type260_genericsolar, "latitude"); bConnected &= connect(weather, "lon", type260_genericsolar, "longitude"); bConnected &= connect(weather, "tz", type260_genericsolar, "timezone"); bConnected &= connect(tou, "tou_value", type260_genericsolar, "TOUPeriod"); // Example for changing an input variable name in the SSC interface // set_unit_value( u3, "m_dot_htf", as_double("m_dot_htf_init") ); // check if all connections worked if ( !bConnected ) throw exec_error( "tcsgeneric_solar", util::format("there was a problem connecting outputs of one unit to inputs of another for the simulation.") ); size_t hours = 8760; //Load the solar field adjustment factors sf_adjustment_factors sf_haf(this); if (!sf_haf.setup()) throw exec_error("tcsgeneric_solar", "failed to setup sf adjustment factors: " + sf_haf.error()); //allocate array to pass to tcs ssc_number_t *sf_adjust = allocate("sf_adjust", hours); for( size_t i=0; i<hours; i++) sf_adjust[i] = sf_haf(i); set_unit_value_ssc_array(type260_genericsolar, "sf_adjust"); // Run simulation if (0 > simulate(3600.0, hours*3600.0, 3600.0) ) throw exec_error( "tcsgeneric_solar", util::format("there was a problem simulating in tcsgeneric_solar.") ); // get the outputs if (!set_all_output_arrays() ) throw exec_error( "tcsgeneric_solar", util::format("there was a problem returning the results from the simulation.") ); // annual accumulations size_t count = 0; ssc_number_t *enet = as_array("enet", &count); if (!enet || count != 8760) throw exec_error("tcsgeneric_solar", "Failed to retrieve hourly net energy"); adjustment_factors haf(this, "adjust"); if (!haf.setup()) throw exec_error("tcsgeneric_solar", "failed to setup adjustment factors: " + haf.error()); ssc_number_t *hourly = allocate("gen", count); for (size_t i = 0; i < count; i++) { hourly[i] = enet[i] * 1000 * haf(i); // convert from MWh to kWh } accumulate_annual("gen", "annual_energy"); accumulate_annual("w_gr", "annual_w_gr",1000); // convert from MWh to kWh accumulate_annual("q_sf", "annual_q_sf"); accumulate_annual("q_to_pb", "annual_q_to_pb"); accumulate_annual("q_to_tes", "annual_q_to_tes"); accumulate_annual("q_from_tes", "annual_q_from_tes"); accumulate_annual("q_hl_sf", "annual_q_hl_sf"); accumulate_annual("q_hl_tes", "annual_q_hl_tes"); accumulate_annual("q_dump_tot", "annual_q_dump_tot"); accumulate_annual("q_startup", "annual_q_startup"); double fuel_MWht = accumulate_annual("q_fossil", "annual_q_fossil"); // monthly accumulations accumulate_monthly("gen", "monthly_energy"); accumulate_monthly("w_gr", "monthly_w_gr",1000); // convert from MWh to kWh accumulate_monthly("q_sf", "monthly_q_sf"); accumulate_monthly("q_to_pb", "monthly_q_to_pb"); accumulate_monthly("q_to_tes", "monthly_q_to_tes"); accumulate_monthly("q_from_tes", "monthly_q_from_tes"); accumulate_monthly("q_hl_sf", "monthly_q_hl_sf"); accumulate_monthly("q_hl_tes", "monthly_q_hl_tes"); accumulate_monthly("q_dump_tot", "monthly_q_dump_tot"); accumulate_monthly("q_startup", "monthly_q_startup"); accumulate_monthly("q_fossil", "monthly_q_fossil"); ssc_number_t ae = as_number("annual_energy"); ssc_number_t pg = as_number("annual_w_gr"); ssc_number_t convfactor = (pg != 0) ? 100 * ae / pg : 0; assign("conversion_factor", convfactor); // metric outputs moved to technology double kWhperkW = 0.0; double nameplate = as_double("system_capacity"); double annual_energy = 0.0; for (int i = 0; i < 8760; i++) annual_energy += hourly[i]; if (nameplate > 0) kWhperkW = annual_energy / nameplate; assign("capacity_factor", var_data((ssc_number_t)(kWhperkW / 87.6))); assign("kwh_per_kw", var_data((ssc_number_t)kWhperkW)); assign("system_heat_rate", (ssc_number_t)3.413); // samsim tcsgeneric_solar assign("annual_fuel_usage", var_data((ssc_number_t)(fuel_MWht * 1000.0))); }