static TreeToken fromMM(Node *mm) { TreeToken token; token.tree_size = 1; Value *lhs = mm->inputs()[0]; Value *rhs = mm->inputs()[1]; token.lhs_sizes = as_array(lhs->type()->expect<TensorType>()->sizes()); token.rhs_sizes = as_array(rhs->type()->expect<TensorType>()->sizes()); token.node = mm; token.is_root = true; return token; }
bool ReaderMapping::get(const char* key, std::string& value, std::string defaultValue) const { value = defaultValue; auto const sx = get_item(key); if (!sx) { return false; } else { assert_array_size_eq(*m_doc, *sx, 2); auto const& item = sx->as_array(); if (item[1].is_string()) { value = item[1].as_string(); return true; } else if (item[1].is_array() && item[1].as_array().size() == 2 && item[1].as_array()[0].is_symbol() && item[1].as_array()[0].as_string() == "_" && item[1].as_array()[1].is_string()) { if (translations_enabled) { value = _(item[1].as_array()[1].as_string()); } else { value = item[1].as_array()[1].as_string(); } return true; } else { raise_exception(*m_doc, item[1], "expected string"); } } }
void free() { if( data_ == nullptr ){ return; } switch( type_ ) { default: break; case object_type: delete as_object(); break; case array_type: delete as_array(); break; case string_type: delete as_string(); break; case int_type: delete as_int(); break; case number_type: delete as_number(); break; case bool_type: delete as_bool(); break; } }
TEST(ArrayBuilder, WithAllInMultipleTimes) { cpp_redis::builders::array_builder builder; std::string buffer = "4\r\n+simple_string\r"; builder << buffer; buffer += "\n-error\r\n:42\r\n"; builder << buffer; buffer += "$5\r\nhello\r\n"; builder << buffer; EXPECT_EQ(true, builder.reply_ready()); EXPECT_EQ("", buffer); auto reply = builder.get_reply(); EXPECT_TRUE(reply.is_array()); auto array = reply.as_array(); EXPECT_EQ(4U, array.size()); auto row_1 = array[0]; EXPECT_TRUE(row_1.is_simple_string()); EXPECT_EQ("simple_string", row_1.as_string()); auto row_2 = array[1]; EXPECT_TRUE(row_2.is_error()); EXPECT_EQ("error", row_2.as_string()); auto row_3 = array[2]; EXPECT_TRUE(row_3.is_integer()); EXPECT_EQ(42, row_3.as_integer()); auto row_4 = array[3]; EXPECT_TRUE(row_4.is_bulk_string()); EXPECT_EQ("hello", row_4.as_string()); }
std::vector<std::string> mastermind_t::data::create_elliptics_remotes(const std::string &name , const kora::dynamic_t &raw_value) { (void) name; std::vector<std::string> result; const auto &raw_value_array = raw_value.as_array(); for (auto p_it = raw_value_array.begin(), p_end = raw_value_array.end(); p_it != p_end; ++p_it) { const auto &tuple = p_it->as_array(); const auto &name = tuple[0].to<std::string>(); const auto &port = tuple[1].to<int>(); const auto &family = tuple[2].to<int>(); std::ostringstream oss; oss << name << ':' << port << ':' << family; result.emplace_back(oss.str()); } if (result.empty()) { throw std::runtime_error("elliptics-remotes list is empty"); } return result; }
std::map<std::string, groups_t> mastermind_t::data::create_cache_groups(const std::string &name , const kora::dynamic_t &raw_value) { (void) name; std::map<std::string, groups_t> result; const auto &raw_value_array = raw_value.as_array(); for (auto p_it = raw_value_array.begin(), p_end = raw_value_array.end(); p_it != p_end; ++p_it) { const auto &pair = p_it->as_array(); const auto &name = pair[0].to<std::string>(); const auto &raw_groups = pair[1].as_array(); groups_t groups; for (auto it = raw_groups.begin(), end = raw_groups.end(); it != end; ++it) { groups.emplace_back(it->to<group_t>()); } result.insert(std::make_pair(name, groups)); } if (result.empty()) { throw std::runtime_error("cache-groups list is empty"); } return result; }
void JSON::convertToArray() { if (m_type != e_array) { JSON arr = as_array(); (*this) = arr; } }
std::vector<attributes_e> get_attributes_below( dice_e threshold ) const { std::vector<attributes_e> result; for( std::size_t i = 0; i < 5; ++i ) { if( as_array()[i] < threshold ) { result.push_back( static_cast<attributes_e>( i ) ); } } return result; }
X X::from_json(JSON::Value const& v) { X result; auto& o = as_object(as_array(v)[0]); result.var1 = as_string(o["var1"]); result.var2 = as_double(o["var2"]); return result; }
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; }
concurrency::task<std::shared_ptr<std::vector<api::TrackInfo>>> AudioService::getCurrentPlaylistAsync() { auto file = co_await concurrency::create_task(Windows::Storage::ApplicationData::Current->LocalFolder->CreateFileAsync(L"current_playlist.json", Windows::Storage::CreationCollisionOption::OpenIfExists)); auto text = co_await concurrency::create_task(Windows::Storage::FileIO::ReadTextAsync(file)); auto result = std::make_shared<std::vector<api::TrackInfo>>(); if (text->Length() > 0) { tools::strings::WindowsWIStream stream(text); auto jsonVal = web::json::value::parse(stream); for (auto&& item : jsonVal.as_array()) { result->push_back(api::TrackInfo(item)); } } return result; }
TEST(ArrayBuilder, EmptyArray) { cpp_redis::builders::array_builder builder; std::string buffer = "0\r\n"; builder << buffer; EXPECT_EQ(true, builder.reply_ready()); EXPECT_EQ("", buffer); auto reply = builder.get_reply(); EXPECT_TRUE(reply.is_array()); auto array = reply.as_array(); EXPECT_EQ(0U, array.size()); }
void exec( ) throw( general_error ) { size_t arr_len; ssc_number_t *p_poabeam = as_array( "poa_beam", &arr_len ); ssc_number_t *p_poaskydiff = as_array( "poa_skydiff", &arr_len ); ssc_number_t *p_poagnddiff = as_array( "poa_gnddiff", &arr_len ); ssc_number_t *p_tdry = as_array( "tdry", &arr_len ); ssc_number_t *p_wspd = as_array( "wspd", &arr_len ); ssc_number_t *p_wdir = as_array( "wdir", &arr_len ); ssc_number_t *p_inc = as_array( "incidence", &arr_len ); ssc_number_t *p_zen = as_array( "sun_zen", &arr_len ); ssc_number_t *p_stilt = as_array( "surf_tilt", &arr_len ); double site_elevation = as_double("elev"); cec6par_module_t mod; mod.Area = as_double("area"); mod.Vmp = as_double("Vmp"); mod.Imp = as_double("Imp"); mod.Voc = as_double("Voc"); mod.Isc = as_double("Isc"); mod.alpha_isc = as_double("alpha_isc"); mod.beta_voc = as_double("beta_voc"); mod.a = as_double("a"); mod.Il = as_double("Il"); mod.Io = as_double("Io"); mod.Rs = as_double("Rs"); mod.Rsh = as_double("Rsh"); mod.Adj = as_double("Adj"); noct_celltemp_t tc; tc.Tnoct = as_double("tnoct"); int standoff = as_integer("standoff"); tc.standoff_tnoct_adj = 0; switch(standoff) { case 2: tc.standoff_tnoct_adj = 2; break; // between 2.5 and 3.5 inches case 3: tc.standoff_tnoct_adj = 6; break; // between 1.5 and 2.5 inches case 4: tc.standoff_tnoct_adj = 11; break; // between 0.5 and 1.5 inches case 5: tc.standoff_tnoct_adj = 18; break; // less than 0.5 inches // note: all others, standoff_tnoct_adj = 0; } int height = as_integer("height"); tc.ffv_wind = 0.51; if ( height == 1 ) tc.ffv_wind = 0.61; ssc_number_t *opvoltage = 0; if ( is_assigned("opvoltage") ) { size_t opvlen = 0; opvoltage = as_array( "opvoltage", &opvlen ); if ( opvlen != arr_len ) throw general_error("operating voltage array must be same length as input vectors"); } ssc_number_t *p_tcell = allocate("tcell", arr_len); ssc_number_t *p_volt = allocate("dc_voltage", arr_len); ssc_number_t *p_amp = allocate("dc_current", arr_len); ssc_number_t *p_eff = allocate("eff", arr_len); ssc_number_t *p_dc = allocate("dc", arr_len); for (size_t i = 0; i < arr_len; i++ ) { pvinput_t in; in.Ibeam = (double) p_poabeam[i]; in.Idiff = (double) p_poaskydiff[i]; in.Ignd = (double) p_poagnddiff[i]; in.Tdry = (double) p_tdry[i]; in.Wspd = (double) p_wspd[i]; in.Wdir = (double) p_wdir[i]; in.Zenith = (double) p_zen[i]; in.IncAng = (double) p_inc[i]; in.Elev = site_elevation; in.Tilt = (double) p_stilt[i]; pvoutput_t out; double opv = -1; // by default, calculate MPPT if ( opvoltage != 0 ) opv = opvoltage[i]; double tcell = in.Tdry; if (! tc( in, mod, opv, tcell ) ) throw general_error("error calculating cell temperature", (float)i); if (! mod( in, tcell, opv, out ) ) throw general_error( "error calculating module power and temperature with given parameters", (float) i); p_tcell[i] = (ssc_number_t)out.CellTemp; p_volt[i] = (ssc_number_t)out.Voltage; p_amp[i] = (ssc_number_t)out.Current; p_eff[i] = (ssc_number_t)out.Efficiency; p_dc[i] = (ssc_number_t)out.Power; } }
dice_e get( attributes_e a ) const { return as_array()[static_cast<std::size_t>( a )]; }
attributes_bag( attributes_e attrib, dice_e d ) : attributes_bag() { as_array()[static_cast<std::size_t>( attrib )] = d; }
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))); }