void enum_host_bus() { struct bus *host_bus; struct unit *pci_host_bridge; unsigned long unitcode; struct bus *pci_root_bus; struct unit *isa_bridge; struct bus *isa_bus; // Create host bus host_bus = add_bus(NULL, BUSTYPE_HOST, 0); unitcode = get_pci_hostbus_unitcode(); if (unitcode) { // Enumerate PCI buses pci_host_bridge = add_unit(host_bus, PCI_HOST_BRIDGE, unitcode, 0); pci_root_bus = add_bus(pci_host_bridge, BUSTYPE_PCI, 0); enum_pci_bus(pci_root_bus); } else { // Enumerate ISA bus using PnP isa_bridge = add_unit(host_bus, PCI_ISA_BRIDGE, 0, 0); isa_bus = add_bus(isa_bridge, BUSTYPE_ISA, 0); enum_isapnp(isa_bus); } }
void move_player(t_window *w, t_move t) { if ((t == LEFT && w->player_x < 2) || (t == RIGHT && w->player_x == WIDTH_MAP - 3)) return ; add_unit(w, w->player_x - (t * 2), PLAYER_Y, EMPTY); add_unit(w, w->player_x + (t * 2), PLAYER_Y, PLAYER); w->player_x += t; }
static int init_end(int **grid, t_unit **unit, int sizeX, int sizeY, int fd) { int i; char *str; char **tab; int tmp[4]; i = -1; while (++i < sizeX) if (grid[0][i] != 0 || grid[sizeY - 1][i] != 0) return (my_error(WF)); while ((str = get_next_line(fd)) != NULL) { if (str[0] != 0) { tab = parse(str, " \t"); free(str); if (tab == NULL) return (my_error(EM)); i = -1; while (tab[++i] != NULL && i < 4) tmp[i] = my_getnbr(tab[i]); free_tab(tab); while (i < 4) tmp[i++] = 0; if (add_unit(unit, tmp) == 1) return (my_error(EM)); } } close(fd); return (0); }
//--------- Begin of function UnitGroup::set_to_selected ---------// // // Add all selected units in unit_array into this group. // void UnitGroup::set_to_selected() { zap(); for( int i=unit_array.size() ; i>0 ; i-- ) { if( unit_array.is_deleted(i) ) continue; if( unit_array[i]->selected_flag ) add_unit(i); } }
void Species::deserialize(const Species::serial_type& serial) { std::vector<std::string> unit_serials; boost::split(unit_serials, serial, boost::is_any_of(".")); units_.clear(); for (std::vector<std::string>::const_iterator i(unit_serials.begin()); i != unit_serials.end(); ++i) { UnitSpecies usp; usp.deserialize(*i); add_unit(usp); } }
//--------- Begin of function UnitGroup::set ---------// // // Set UnitGroup with the given unit list. // void UnitGroup::set(short* unitRecnoArray, int unitCount) { zap(); for( int i=0 ; i<unitCount ; i++ ) { // ####### begin Gilbert 16/3 #######// if( !unit_array.is_deleted(unitRecnoArray[i]) ) { add_unit( unitRecnoArray[i] ); } // ####### end Gilbert 16/3 #######// } }
static int yp_int_to_txt( BIN_TXT_PARAMS, yp_style_t style) { int64_t data = 0, number = 0; char unit[2] = { '\0' }; memcpy(&data, bin, bin_len); number = le64toh(data); add_unit(&number, unit, style); int ret = snprintf(txt, *txt_len, "%"PRId64"%s", number, unit); if (ret <= 0 || ret >= *txt_len) { return KNOT_ERANGE; } *txt_len = ret; return KNOT_EOK; }
//打印标定表 ErrorStatus PrintCalibrationTable( SMPL_NAME_TypeDef2 ch ) { const uint8_t MIN_CALIRATION_SEGS = 2; //最小标定表项数 const uint8_t MAX_CALIRATION_SEGS = 11; const uint8_t MAX_CNT = 20; uint8_t i; uint8_t tab_num = 0; uint32_t force_value = 0,force_code = 0; char value_buff[MAX_CNT]; tTime t; ConfigPrinterDefaultSet(); tab_num = smpl_tab_num_get(ch); if ( (tab_num < MIN_CALIRATION_SEGS) || (tab_num > MAX_CALIRATION_SEGS) ) { PrintWordsAndLineFeed("检测点个数出错!"); return ERROR; } tab_num--; //去掉一个零点 switch ( ch ) { case SMPL_KY_NUM: PrintWordsAndLineFeed(" 抗压通道标定表"); break; case SMPL_KZ_NUM: PrintWordsAndLineFeed(" 抗折通道标定表"); break; default: PrintWordsAndLineFeed(" 通道错误!"); break; } PrintDottedLine(); //- - - - - time_cycle(); t = get_time(); PrintTime( &t ); PrintDottedLine(); for (i=1; i<=tab_num; ++i) //标定表数据 { PrintWordsAndLineFeed(pPrint_Title[i-1]); print("值:"); force_value = (uint32_t)smpl_tab_value_get(ch,i); if ( (ch==SMPL_KY_NUM) && ( UNIT_kN==ky_uint_get() )) { force_value /= 1000; } numtochar(7,force_value,value_buff); if ( (ch==SMPL_KY_NUM) && ( UNIT_kN==ky_uint_get() )) { add_unit(12,value_buff); } else { add_unit(11,value_buff); } PrintWordsAndLineFeed(value_buff); print("码:"); force_code = (uint32_t)smpl_tab_code_get(ch,i); numtochar(7,force_code,value_buff); PrintWordsAndLineFeed(value_buff); delay_ms(PRINT_DELAY); } PrintRowSpace(END_ROW_CNT); //防止被打印的数据卡在打印机内部 return SUCCESS; }
//打印试验报告 ErrorStatus PrintTestReport( SMPL_NAME_TypeDef2 ch, TEST_TYPE_TypeDef test_type, REPORT_TypeDef *report, TEST_INFO_TypeDef *test_info ) { tTime *t = NULL; char print_buff[20]; const uint8_t MAX_SHOW_BIT = 9; uint8_t i,tab_num; const uint8_t MAX_TEST_NUM = 12; const uint8_t BIT_FORCE_DOT = 2; float round_off = 0.0f; ConfigPrinterDefaultSet(); switch ( test_type ) { case NONE_TEST: PrintWordsAndLineFeed(" 无当前试验类型!"); return ERROR; case KYSNJS: PrintWordsAndLineFeed(" 水泥胶砂抗压试验报告"); break; case KYJZSJ: PrintWordsAndLineFeed(" 建筑砂浆抗压试验报告"); break; case KYHNT: PrintWordsAndLineFeed(" 混凝土抗压试验报告"); break; case KZHNT: PrintWordsAndLineFeed(" 混凝土抗折试验报告"); break; case KYQQZ: PrintWordsAndLineFeed(" 砌墙砖抗压试验报告"); break; case KYTY: PrintWordsAndLineFeed(" 通用抗压试验报告"); break; case KZSNJS: PrintWordsAndLineFeed(" 水泥胶砂抗折试验报告"); break; case KZYJSNJ: PrintWordsAndLineFeed(" 压浆水泥浆抗折试验报告"); break; case KZTY: PrintWordsAndLineFeed(" 通用抗折试验报告"); break; default: PrintWordsAndLineFeed(" 试验类型出错!"); return ERROR; } PrintDottedLine(); //- - - - - t = (tTime *)( &(test_info->time) ); PrintTime( t ); PrintDottedLine(); switch ( test_type ) { case NONE_TEST: break; case KYSNJS: print("标准:"); PrintWordsAndLineFeed(report->test_standard); print("编号:"); PrintWordsAndLineFeed(test_info->fname); print("品种:"); PrintWordsAndLineFeed(report->sample_type); print("强度:"); PrintWordsAndLineFeed(report->strength_grade); print("龄期:"); numtochar(MAX_SHOW_BIT,report->sample_age,print_buff); add_unit(13,print_buff); PrintWordsAndLineFeed(print_buff); print("规格:"); PrintWordsAndLineFeed(report->sample_spec); print("试件块数:"); numtochar(MAX_SHOW_BIT,report->sample_num,print_buff); PrintWordsAndLineFeed(print_buff); break; case KYJZSJ: print("标准:"); PrintWordsAndLineFeed(report->test_standard); print("编号:"); PrintWordsAndLineFeed(test_info->fname); print("品种:"); PrintWordsAndLineFeed(report->sample_type); print("龄期:"); numtochar(MAX_SHOW_BIT,report->sample_age,print_buff); add_unit(13,print_buff); PrintWordsAndLineFeed(print_buff); print("规格:"); chartochar(17,report->sample_spec,print_buff); add_unit(9,print_buff); PrintWordsAndLineFeed(print_buff); print("试件块数:"); numtochar(MAX_SHOW_BIT,report->sample_num,print_buff); PrintWordsAndLineFeed(print_buff); break; case KYHNT: case KZHNT: print("标准:"); PrintWordsAndLineFeed(report->test_standard); print("编号:"); PrintWordsAndLineFeed(test_info->fname); print("强度:"); PrintWordsAndLineFeed(report->strength_grade); print("龄期:"); numtochar(MAX_SHOW_BIT,report->sample_age,print_buff); add_unit(13,print_buff); PrintWordsAndLineFeed(print_buff); print("规格:"); //单位不能添加,有些是mm3,有些不是此单位 PrintWordsAndLineFeed(report->sample_spec); print("修正系数:"); floattochar(MAX_SHOW_BIT,2,report->correct_cof,print_buff); PrintWordsAndLineFeed(print_buff); print("试件块数:"); numtochar(MAX_SHOW_BIT,report->sample_num,print_buff); PrintWordsAndLineFeed(print_buff); break; case KYQQZ: print("标准:"); PrintWordsAndLineFeed(report->test_standard); print("编号:"); PrintWordsAndLineFeed(test_info->fname); print("品种:"); PrintWordsAndLineFeed(report->sample_type); print("长度:"); floattochar(MAX_SHOW_BIT,1,report->length,print_buff); add_unit(15,print_buff); PrintWordsAndLineFeed(print_buff); print("宽度:"); floattochar(MAX_SHOW_BIT,1,report->width,print_buff); add_unit(15,print_buff); PrintWordsAndLineFeed(print_buff); print("高度:"); floattochar(MAX_SHOW_BIT,1,report->high,print_buff); add_unit(15,print_buff); PrintWordsAndLineFeed(print_buff); print("试件块数:"); numtochar(MAX_SHOW_BIT,report->sample_num,print_buff); PrintWordsAndLineFeed(print_buff); break; case KYTY: PrintWordsAndLineFeed("暂且不支持通用抗压试验!"); return ERROR; case KZSNJS: case KZYJSNJ: print("标准:"); PrintWordsAndLineFeed(report->test_standard); print("编号:"); PrintWordsAndLineFeed(test_info->fname); print("品种:"); PrintWordsAndLineFeed(report->sample_type); print("强度:"); PrintWordsAndLineFeed(report->strength_grade); print("龄期:"); numtochar(MAX_SHOW_BIT,report->sample_age,print_buff); add_unit(13,print_buff); PrintWordsAndLineFeed(print_buff); print("边长:"); floattochar(MAX_SHOW_BIT,1,report->sample_length,print_buff); add_unit(15,print_buff); PrintWordsAndLineFeed(print_buff); print("跨距:"); floattochar(MAX_SHOW_BIT,1,report->sample_span,print_buff); add_unit(15,print_buff); PrintWordsAndLineFeed(print_buff); print("试件块数:"); numtochar(MAX_SHOW_BIT,report->sample_num,print_buff); PrintWordsAndLineFeed(print_buff); break; case KZTY: PrintWordsAndLineFeed("暂且不支持通用抗折试验!"); return ERROR; default: break; } print_enter(); PrintWordsAndLineFeed("结果数据:"); tab_num = report->sample_serial; if ( (tab_num<1) || (tab_num>MAX_TEST_NUM) ) { return ERROR; } for (i=0; i<tab_num; ++i) //加载力值、强度 { PrintWordsAndLineFeed(pPrint_Title[i]); print("力值:"); if ( (ch==SMPL_KY_NUM) && ( UNIT_kN==ky_uint_get() )) { report->force[i] /= 1000; } floattochar(MAX_SHOW_BIT,BIT_FORCE_DOT,report->force[i],print_buff); if ( (ch==SMPL_KY_NUM) && ( UNIT_kN==ky_uint_get() )) { add_unit(12,print_buff); } else { add_unit(11,print_buff); } PrintWordsAndLineFeed(print_buff); print("强度:"); rounding_off_4discard_6carry_5double(report->strength[i],ROUND_OFF_BIT,&round_off); floattochar(MAX_SHOW_BIT,ROUND_OFF_BIT,round_off,print_buff); add_unit(14,print_buff); PrintWordsAndLineFeed(print_buff); delay_ms(PRINT_DELAY); //必须加延时,否则数据发送太快导致丢失 } print_enter(); print("有效力值:"); if (report->force_valid[0] < MAX_DIRRER_VALUE) { PrintWordsAndLineFeed("无 效"); } else { if ( (ch==SMPL_KY_NUM) && ( UNIT_kN==ky_uint_get() )) { report->force_valid[0] /= 1000; } floattochar(MAX_SHOW_BIT,BIT_FORCE_DOT,report->force_valid[0],print_buff); if ( (ch==SMPL_KY_NUM) && ( UNIT_kN==ky_uint_get() )) { add_unit(12,print_buff); } else { add_unit(11,print_buff); } PrintWordsAndLineFeed(print_buff); } print("有效强度:"); if (report->strength_valid[0] < MAX_DIRRER_VALUE) { PrintWordsAndLineFeed("无 效"); } else { rounding_off_4discard_6carry_5double(report->strength_valid[0],ROUND_OFF_BIT,&round_off); floattochar(MAX_SHOW_BIT,ROUND_OFF_BIT,round_off,print_buff); add_unit(14,print_buff); PrintWordsAndLineFeed(print_buff); } PrintRowSpace(END_ROW_CNT); //防止被打印的数据卡在打印机内部 return SUCCESS; }
//打印校准、检定结果 ErrorStatus PrintForceCalibrationResultTable( SMPL_NAME_TypeDef2 ch ) { uint8_t i,j,index,point; uint8_t tab_num = 0; const uint8_t COLUMN_CNT = 4; const uint8_t MAX_FORCE_BIT = 9; const uint8_t MAX_CODE_BIT = 7; uint32_t buff_u = 0; float buff_f = 0.0f; char print_buff[20]; tTime t; ConfigPrinterDefaultSet(); if ( !cali_pcs.break_point ) { PrintWordsAndLineFeed("已打点个数出错!"); return ERROR; } switch ( GetForceCalibrationPage() ) { case force_calibration: switch ( ch ) { case SMPL_KY_NUM: PrintWordsAndLineFeed(" 抗压通道校准结果"); break; case SMPL_KZ_NUM: PrintWordsAndLineFeed(" 抗折通道校准结果"); break; default: PrintWordsAndLineFeed(" 通道错误!"); return ERROR; } break; case force_verification: switch ( ch ) { case SMPL_KY_NUM: PrintWordsAndLineFeed(" 抗压通道检定结果"); break; case SMPL_KZ_NUM: PrintWordsAndLineFeed(" 抗折通道检定结果"); break; default: PrintWordsAndLineFeed(" 通道错误!"); return ERROR; } break; default: return ERROR; } PrintDottedLine(); //- - - - - time_cycle(); t = get_time(); PrintTime( &t ); PrintDottedLine(); tab_num = cali_pcs.break_point; //回程个数也包含在内 for (i=0; i<tab_num; ++i) { PrintWordsAndLineFeed(pPrint_Title[i]); for (j=0; j<COLUMN_CNT; ++j) { index = j % COLUMN_CNT; switch ( index ) { case 0: //检测点 print("检测点:"); buff_u = (uint32_t)ustrtoul(pCal->data[i*COLUMN_CNT+0].buff,0,10); if ( (ch==SMPL_KY_NUM) && ( UNIT_kN==ky_uint_get() )) { buff_u /= 1000; } numtochar(MAX_FORCE_BIT,buff_u,print_buff); if ( (ch==SMPL_KY_NUM) && ( UNIT_kN==ky_uint_get() )) { add_unit(12,print_buff); } else { add_unit(11,print_buff); } break; case 1: //实测力值 print("力值: "); buff_f = str2float( pCal->data[i*COLUMN_CNT+1].buff ); if ( (ch==SMPL_KY_NUM) && ( UNIT_kN==ky_uint_get() )) { buff_f /= 1000; point = 3; } else { point = 2; } floattochar(MAX_FORCE_BIT,point,buff_f,print_buff); if ( (ch==SMPL_KY_NUM) && ( UNIT_kN==ky_uint_get() )) { add_unit(12,print_buff); } else { add_unit(11,print_buff); } break; case 2: //力码 print("力码: "); chartochar(MAX_CODE_BIT,pCal->data[i*COLUMN_CNT+2].buff,print_buff); break; case 3: //误差 print("误差: "); chartochar(MAX_CODE_BIT,pCal->data[i*COLUMN_CNT+3].buff,print_buff); add_unit(10,print_buff); break; } PrintWordsAndLineFeed(print_buff); delay_ms(PRINT_DELAY); //必须加延时,否则数据发送太快导致丢失 } } PrintRowSpace(END_ROW_CNT); //防止被打印的数据卡在打印机内部 return SUCCESS; }
getunit() { char no_new, bad_char; char olda, oldb; char dir, i; no_new = TRUE; bad_char = FALSE; movecur_hex(a, b); while(no_new) { olda = a; oldb = b; dir = readchar(); switch(dir) { case RIGHT: a--; b--; break; case UPRIGHT: a--; break; case DOWNRIGHT: b--; break; case LEFT: a++; b++; break; case UPLEFT: b++; break; case DOWNLEFT: a++; break; case UNDO: if ((i = occupied(a, b)) == 0 || unit[--i].status != OK) { bad_char = TRUE ; break ; } if (unit[i].type == CP) { cp_set = FALSE ; armor_points += unit[i].movement ; } else if (unit[i].type == INFANTRY) infantry_points += 1 ; else if (unit[i].type == HOWITZER) armor_points += 2 ; else if (unit[i].type == HVYTANK) armor_points += 1 ; else if (unit[i].type == MSLTANK) armor_points += 1 ; else if (unit[i].type == GEV) armor_points += 1 ; else broken("Internal error in init!") ; if (i < n_free) n_free = i ; unit[i].status = DESTROYED ; update_hex(a, b) ; no_new = FALSE ; break ; case CP: if(cp_set) { bad_char = TRUE; } else { add_unit(a, b, dir); no_new = FALSE; cp_set = TRUE; } break; case HVYTANK: case MSLTANK: case GEV: if(occupied(a, b) || blocked(a, b) || armor_points == 0) { bad_char = TRUE; break; } add_unit(a, b, dir); no_new = FALSE; armor_points--; break; case INFANTRY: dir = '3' ; case '3': case '2': case '1': dir = dir - '0' ; if(blocked(a, b) || infantry_points < dir) { bad_char = TRUE; break; } if ((i = occupied(a, b)) != 0) if (unit[--i].type != INFANTRY || infantry_on(a, b) + dir > 3) { bad_char = TRUE ; break ; } while (dir--) { add_unit(a, b, 'I'); infantry_points -= 1 ; } no_new = FALSE; break; case HOWITZER: if(occupied(a, b) || blocked(a, b) || armor_points <= 1) { bad_char = TRUE; break; } add_unit(a, b, dir); no_new = FALSE; armor_points -= 2; break; default: bad_char = TRUE; break; } if(off_obstructed(a, b) || bad_char) { putchar(BEEP) ; #ifdef __HELIOS fflush(stdout); #endif a = olda; b = oldb; bad_char = FALSE; } else { movecur_hex(a, b); } } }
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))); }