const Matrix& Bidirectional::getInitialTangent(void) { ks(0,0) = ks(1,1) = E; ks(0,1) = ks(1,0) = 0.0; return ks; }
const Matrix & ElasticSection2d::getInitialTangent(void) { ks(0,0) = E*A; ks(1,1) = E*I; return ks; }
const Matrix & ElasticSection2d::getInitialFlexibility(void) { ks(0,0) = 1.0/(E*A); ks(1,1) = 1.0/(E*I); return ks; }
void IBClient::updateAccountValue(const IBString &key, const IBString &val, const IBString ¤cy, const IBString &accountName) { receiveData("updateAccountValue", knk(4, kp((S)key.c_str()), kp((S)val.c_str()), ks((S)currency.c_str()), ks((S)accountName.c_str()) )); }
const Matrix & ElasticShearSection2d::getSectionFlexibility (void) { ks(0,0) = 1.0/(E*A); ks(1,1) = 1.0/(E*I); ks(2,2) = 1.0/(G*A*alpha); return ks; }
//! @brief Return the flexibility matrix. //! //! Gets the section flexibility matrix, \f$fsec\f$, to be the inverse //! of the result of invoking getTangent() on the UniaxialMaterial, then //! returns \f$fsec\f$. const XC::Matrix &XC::GenericSection1d::getSectionFlexibility(void) const { double tangent = theModel->getTangent(); if(tangent != 0.0) ks(0,0) = 1.0/tangent; else ks(0,0) = 1.0e12; return ks; }
void IBClient::accountSummary(int reqId, const IBString &account, const IBString &tag, const IBString &value, const IBString &curency) { receiveData("accountSummary", knk(5, ki(reqId), ks((S)account.c_str()), ks((S)tag.c_str()), kp((S)value.c_str()), ks((S)curency.c_str()))); }
const Matrix & ElasticShearSection2d::getInitialTangent(void) { ks(0,0) = E*A; ks(1,1) = E*I; ks(2,2) = G*A*alpha; return ks; }
const Matrix & ElasticSection3d::getInitialFlexibility (void) { ks(0,0) = 1.0/(E*A); ks(1,1) = 1.0/(E*Iz); ks(2,2) = 1.0/(E*Iy); ks(3,3) = 1.0/(G*J); return ks; }
const Matrix & ElasticSection3d::getInitialTangent(void) { ks(0,0) = E*A; ks(1,1) = E*Iz; ks(2,2) = E*Iy; ks(3,3) = G*J; return ks; }
// get contribution of fiber to section tangent stiffness Matrix & BiaxialFiber3d::getFiberTangentStiffContr(void) { // Use the section kinematic matrix to get the fiber // tangent stiffness matrix // ks = (as^as) * area * Et; Matrix value = theMaterial->getTangent(); value = value * area; double as1 = as[0]; double as2 = as[1]; double vas1 = as1*value(0,0); double vas2 = as2*value(1,1); double vas1as2 = vas1*as2; ks(0,0) = value(0,0); ks(0,1) = vas1; ks(0,2) = vas2; ks(1,0) = vas1; ks(1,1) = vas1*as1; ks(1,2) = vas1as2; ks(2,0) = vas2; ks(2,1) = vas1as2; ks(2,2) = vas2*as2; return ks; }
void IBClient::commissionReport( const CommissionReport& commissionReport) { auto dict = createDictionary(std::map<std::string, K> { { "commission", kf(commissionReport.commission) }, { "currency", ks((S)commissionReport.currency.c_str()) }, { "execId", ks((S)commissionReport.execId.c_str()) }, { "realizedPNL", kf(commissionReport.realizedPNL) }, { "yield", kf(commissionReport.yield) }, { "yieldRedemptionDate", kp((S)stringFormat("%i", commissionReport.yieldRedemptionDate).c_str()) } }); receiveData("commissionReport", dict); }
SColor BRDF(Vector& L, Vector& N, Vector& V) { float cos_in = L * N; if (cos_in > 0 && ks() != 0) { Vector R = N * (2.0 * cos_in) - L; float cos_refl_out = R * V; if (cos_refl_out > EPSILON) { SColor ref = ks() * (shine + 2) / M_PI / 2.0; return (ref * pow(cos_refl_out, shine)); } } return SColor(0); }
const Matrix& Isolator2spring::getInitialTangent(void) { // Intial tangent uses nominal properties of the isolator. ks(0,0) = k1; ks(1,1) = kvo; ks(0,1) = ks(1,0) = 0.0; ks(0,2) = ks(1,2) = ks(2,2) = ks(2,1) = ks(2,0) = 0.0; return ks; }
const Matrix& ElasticSection2d::getSectionTangentSensitivity(int gradIndex) { ks.Zero(); if (parameterID == 1) { // E ks(0,0) = A; ks(1,1) = I; } if (parameterID == 2) // A ks(0,0) = E; if (parameterID == 3) // I ks(1,1) = E; return ks; }
int main(int argc, char **argv) { try { unsigned int numKoules, numRuns; double maxTime, kouleVel; std::string plannerName, outputFile; po::options_description desc("Options"); desc.add_options() ("help", "show help message") ("plan", "solve the game of koules") ("benchmark", "benchmark the game of koules") ("numkoules", po::value<unsigned int>(&numKoules)->default_value(3), "start from <numkoules> koules") ("maxtime", po::value<double>(&maxTime)->default_value(10.), "time limit in seconds") ("output", po::value<std::string>(&outputFile), "output file name") ("numruns", po::value<unsigned int>(&numRuns)->default_value(10), "number of runs for each planner in benchmarking mode") ("planner", po::value<std::string>(&plannerName)->default_value("kpiece"), "planning algorithm to use (pdst, kpiece, rrt, or est)") ("velocity", po::value<double>(&kouleVel)->default_value(0.), "initial velocity of each koule") ; po::variables_map vm; po::store(po::parse_command_line(argc, argv, desc, po::command_line_style::unix_style ^ po::command_line_style::allow_short), vm); po::notify(vm); KoulesSetup ks(numKoules, plannerName, kouleVel); if (vm.count("help") || argc == 1) { std::cout << "Solve the games of Koules.\nSelect one of these two options:\n" << "\"--plan\", or \"--benchmark\"\n\n" << desc << "\n"; return 1; } if (outputFile.size() == 0) { std::string prefix(vm.count("plan") ? "koules_" : "koulesBenchmark_"); outputFile = boost::str(boost::format("%1%%2%_%3%_%4%.dat") % prefix % numKoules % plannerName % maxTime); } if (vm.count("plan")) plan(ks, maxTime, outputFile); else if (vm.count("benchmark")) benchmark(ks, ot::Benchmark::Request(maxTime, 10000.0, numRuns), plannerName, outputFile); } catch(std::exception& e) { std::cerr << "Error: " << e.what() << "\n"; return 1; } catch(...) { std::cerr << "Exception of unknown type!\n"; } return 0; }
void ObjFile::computeNewVerts() { std::vector<int> ks(newverts_.size(), 0); for (std::vector<Triangle>::const_iterator t = triangles_.begin(); t != triangles_.end(); ++t) { for (int i = 0; i < 3; ++i) { // all vertices are summed double newverts_[t->v[i]] = newverts_[t->v[i]] + vertices_[t->v[(i + 1) % 3]] + vertices_[t->v[(i + 2) % 3]]; ++ks[t->v[i]]; } } for (std::vector<Vec3f>::iterator nv = newverts_.begin(); nv != newverts_.end(); ++nv) { int num = ks[nv - newverts_.begin()]; float beta = 3.0f / (8.0f * (float)num); if (num == 3) beta = 3.0f / 16.0f; //float interm = (3.0/8.0 - 0.25 * cos ( 2 * M_PI / num )); //float beta = 1.0/num*(5.0/8.0 - interm*interm); *nv = (*nv * (0.5f * beta)) + vertices_[nv - newverts_.begin()] * (1 - beta*num); } }
void BufferDecryptor::generate_key(int cipher) { #ifdef HAVE_LIBCRYPTO const EVP_CIPHER *evp_cipher = cipher_by_id(cipher); const size_t key_size = EVP_CIPHER_key_length(evp_cipher); const size_t iv_size = EVP_CIPHER_iv_length(evp_cipher); unsigned char *key = (unsigned char *)malloc(key_size); unsigned char iv[iv_size]; if( ! EVP_BytesToKey(evp_cipher, EVP_sha256(), NULL, (const unsigned char *)key_.c_str(), key_.size(), 8, key, iv)) { free(key); #endif throw std::runtime_error("Failed to generate key"); #ifdef HAVE_LIBCRYPTO } std::string ks((const char *)key, key_size); free(key); keys_[cipher] = ks; #endif }
// get contribution of fiber to section tangent stiffness Matrix & BiaxialFiber2d::getFiberTangentStiffContr(void) { // Use the section kinematic matrix to get the fiber // tangent stiffness matrix // ks = (as^as) * area * Et; Matrix value = theMaterial->getTangent() * area; double value_as1 = value(0,0)*y; ks(0,0) = value(0,0); ks(0,1) = value_as1; ks(1,0) = value_as1; ks(1,1) = value_as1 * y; return ks; }
void DBout::proc_point(DBT *k, DBT *v, const DBinfo & info, int list) { // check for correct key size (do not parse DB info) if (k->size!=sizeof(uint64_t) && k->size!=sizeof(uint32_t) ) return; // convert DBT to strings std::string ks((char *)k->data, (char *)k->data+k->size); std::string vs((char *)v->data, (char *)v->data+v->size); // print values into a string (always \n in the end!) std::ostringstream str; if (time0.size() == 0) str << info.print_time(ks); // absolute timestamp else str << std::fixed << std::setprecision(9) << info.time_diff(ks, info.parse_time(time0)); // relative time str << " " << info.print_data(vs, col) << "\n"; // data std::string s = str.str(); // keep only first line (s always ends with \n - see above) if (list==1 && info.val==DATA_TEXT) s.resize(s.find('\n')+1); // do filtering if (pid>0){ write(fd1[1], s.data(), s.length()); char buf[256]; size_t n; std::string out; while ((n = read(fd2[0], buf, sizeof(buf)))>0){ out+=std::string(buf, buf+n); if (out.find('\n')!=std::string::npos) break; } print_point(out); } else{ print_point(s); } };
void write_tasks(transport::repository<>& repo, transport::step_mpi<>* model) { const double M_P = 1.0; const double m = 1E-5 * M_P; const double c = 0.0018; const double d = 0.022 * M_P; const double phi0 = 14.84 * M_P; const double phi_init = 16.5 * M_P; const double N_init = 0.0; const double N_pre = 6.0; const double N_max = 50.1; transport::parameters<> params(M_P, { m, c, d, phi0 }, model); transport::initial_conditions<> ics("step", params, { phi_init }, N_init, N_pre); transport::basic_range<> times(N_init, N_max, 100, transport::spacing::linear); transport::basic_range<> ks(exp(7.0), exp(11.5), 1000, transport::spacing::log_bottom); transport::basic_range<> alphas(0.0, 0.0, 0, transport::spacing::linear); transport::basic_range<> betas(1.0/3.0, 1.0/3.0, 0, transport::spacing::linear); // construct a threepf task transport::threepf_alphabeta_task<> tk3("step.threepf", ics, times, ks, alphas, betas); tk3.set_collect_initial_conditions(true).set_adaptive_ics_efolds(5.0); transport::zeta_threepf_task<> ztk3("step.threepf-zeta", tk3); repo.commit(ztk3); }
const Matrix& ElasticSection2d::getSectionFlexibilitySensitivity(int gradIndex) { ks.Zero(); if (parameterID == 1) { // E ks(0,0) = -1.0/(E*E*A); ks(1,1) = -1.0/(E*E*I); } if (parameterID == 2) // A ks(0,0) = -1.0/(E*A*A); if (parameterID == 3) // I ks(1,1) = -1.0/(E*I*I); return ks; }
int main() { SimulatorFT simulator; SortDS list; // Insert polynomials and sort the list for current time list.push_back(Polynomial("x^3 - 3")); list.push_back(Polynomial("x^2 - 2*x - 2")); list.push_back(Polynomial("2*x - 4")); list.push_back(Polynomial("x")); list.push_back(Polynomial("-x + 4")); list.push_back(Polynomial("2")); //list.sort(EvaluatedComparison(simulator.current_time())); list.sort(EvaluatedComparison(0)); // Print out the list for (SortDS::const_iterator cur = list.begin(); cur != list.end(); ++cur) std::cout << *cur << std::endl; // Setup kinetic sort KineticSortDS ks(list.begin(), list.end(), boost::bind(swap, &list, _1, _2), &simulator); while(!simulator.reached_infinity() && simulator.current_time() < 4) { std::cout << "Current time before: " << simulator.current_time() << std::endl; //if (!ks.audit(&simulator)) return 1; //simulator.print(std::cout << "Auditing "); simulator.process(); std::cout << "Current time after: " << simulator.current_time() << std::endl; } }
void write_tasks(transport::repository<>& repo, transport::dquad_mpi<>* model) { const double Mp = 1.0; const double Mphi = 9E-5 * Mp; const double Mchi = 1E-5 * Mp; transport::parameters<> params(Mp, {Mphi, Mchi}, model); const double phi_init = 10.0 * Mp; const double chi_init = 12.9 * Mp; const double N_init = 0.0; const double N_pre = 12.0; const double N_end = 60.0; transport::initial_conditions<> ics("dquad", params, {phi_init, chi_init}, N_init, N_pre); transport::basic_range<> ts(N_init, N_end, 300, transport::spacing::linear); const double kt_lo = std::exp(3.0); const double kt_hi = std::exp(8.0); transport::basic_range<> ks(kt_lo, kt_hi, 50, transport::spacing::log_bottom); transport::twopf_task<> tk2("dquad.twopf", ics, ts, ks); tk2.set_adaptive_ics_efolds(5.0); tk2.set_description("Compute time history of the 2-point function from k ~ e^3 to k ~ e^9"); transport::threepf_cubic_task<> tk3("dquad.threepf", ics, ts, ks); tk3.set_adaptive_ics_efolds(5.0); tk3.set_description("Compute time history of the 3-point function on a cubic lattice from k ~ e^3 to k ~ e^9"); repo.commit(tk2); repo.commit(tk3); }
WIND_API K K_DECL Wind_login(K username, K password) { std::wstring uid, pwd; try { uid = q::q2WString(username); pwd = q::q2WString(password); } catch (std::string const& error) { return q::error2q(error); } ::WQAUTH_INFO login = { true }; std::wmemset(login.strUserName, L'\0', _countof(login.strUserName)); std::wmemset(login.strPassword, L'\0', _countof(login.strPassword)); static_assert(std::is_same<std::wstring::value_type, TCHAR>::value, "UNICODE/_UNICODE not defined"); if (uid.size() >= _countof(login.strUserName)) return q::error2q("username too long"); if (pwd.size() >= _countof(login.strPassword)) return q::error2q("password too long"); # ifdef _MSC_VER ::wcsncpy_s(login.strUserName, uid.c_str(), uid.size()); ::wcsncpy_s(login.strPassword, pwd.c_str(), pwd.size()); # else std::wcsncpy(login.strUserName, uid.c_str(), uid.size()); std::wcsncpy(login.strPassword, pwd.c_str(), pwd.size()); # endif ::WQErr const error = ::WDataAuthorize(&login); if (error == WQERR_OK) { std::string const u = ml::convert(q::DEFAULT_CP, uid.c_str()); std::cerr << "<Wind> logged in as " << u << std::endl; return ks(const_cast<S>(u.c_str())); } else { return q::error2q(Wind::util::error2Text(error)); } }
void addKey(int limb){ float radian = ((float)limb/180.0) * 3.1415f; sf::Vector2f pos = sf::Vector2f(cos(radian)*radius, -sin(radian)*radius); pos += actSprite.sprite.getPosition(); pos += sf::Vector2f(actSprite.sprite.getGlobalBounds().width/2.f, actSprite.sprite.getGlobalBounds().height/2.f); std::string txt="W"; if(limb == HEAD) txt = "W"; if(limb == HAND_LEFT) txt = "A"; if(limb == HAND_RIGHT) txt = "D"; if(limb == HIPS_LEFT) txt = "H"; if(limb == HIPS_RIGHT) txt = "J"; if(limb == LEG_LEFT) txt = "B"; if(limb == LEG_RIGHT) txt = "M"; KeyText ks(txt, Common::Font::Comic_Sans, 1000, limb, tmpTime); ks.setColor(vecDiscoColors[rand()%vecDiscoColors.size()]); ks.setPosition(pos); vecKeyTexts.push_back(ks); }
K recieve_data(I x) { static char buf[BUFFER_SIZE]; read_bytes(sizeof(int), &buf); int tnamesize = 0; memcpy(&tnamesize, buf, sizeof(int)); read_bytes(tnamesize, &buf); buf[tnamesize] = '\0'; K tname = ks(buf); read_bytes(sizeof(J), &buf); J size = 0; memcpy(&size, buf, sizeof(J)); read_bytes(size, &buf); K bytes = ktn(KG, size); memcpy(kG(bytes), &buf, (size_t) size); K result = k(0, ".u.upd", tname, d9(bytes), (K) 0); r0(bytes); if (result != 0) { r0(result); } return (K) 0; }
/* mpf_freqt() -- Frequency test using KS on N real numbers between zero and one. See [Knuth vol 2, p.61]. */ void mpf_freqt (mpf_t Kp, mpf_t Km, mpf_t X[], const unsigned long int n) { ks (Kp, Km, X, P, n); }
/*! Simulate the press and release of \a keySequence. This is equivalent to calling the QtopiaInputEvents::processKeyEvent() method for a press and then a release. This slot corresponds to the QCop service message \c{VirtualKeyboard::keyPress(QString)}. \sa QKeySequence */ void VirtualKeyboardService::keyPress( QString keySequence ) { QKeySequence ks(keySequence); for (uint i = 0; i < ks.count(); ++i) { QtopiaInputEvents::processKeyEvent(0xffff, ks[i], 0, true, false); QtopiaInputEvents::processKeyEvent(0xffff, ks[i], 0, false, false); } }
//Calling functions with different valencies and with simple data types int eg3() { K result=NULL; //Monadic [Single argument function] result=k(c,"f1s",ks("Hello World"),(K)0); printf( "Executing f1s - This will return a symbol [type=%i] with value %s\n\n\n",result->t,result->s); //Dyadic function result=k(c,"f2i",ki(10),ki(1),(K)0); printf( "Executing f2s - This will return a integer [type=%i] with value %i\n\n\n",result->t,result->i); //Triadic function result=k(c,"f3f",kf(10),kf(-1.),kf(2.2),(K)0); printf( "Executing f2s - This will return a float [type=%i] with value %f\n\n\n",result->t,result->f); //The examples above can be extended to up to functions with eight arguments. //[Errors are discussed later] printf("Finished Example 3"); return 1; }