int soltrack_init(double deg_lat, double deg_long) { // Check domain if (!(check_lat(deg_lat) && check_long(deg_long))) { return SOL_DOMAIN_ERROR; } // Calculate latitude and longitude in radians double rad_lat = deg_to_rad(deg_lat); double rad_long = deg_to_rad(deg_long); // Create a 3-dimensional vector uv_orth_w_spin = gsl_vector_alloc(V_DIM); gsl_vector_set(uv_orth_w_spin, X_AXIS, \ gsl_sf_cos(rad_long) * gsl_sf_cos(rad_lat)); gsl_vector_set(uv_orth_w_spin, Y_AXIS, \ gsl_sf_sin(rad_long) * gsl_sf_cos(rad_lat)); gsl_vector_set(uv_orth_w_spin, Z_AXIS, gsl_sf_sin(rad_lat)); // Create the rotation matrix for axial tilt of the earth rm_ax_tilt = gsl_matrix_calloc(V_DIM, V_DIM); // Initialize 0 // X-Axis gsl_matrix_set(rm_ax_tilt, X_AXIS, X_AXIS, gsl_sf_cos(rad_ax_tilt)); gsl_matrix_set(rm_ax_tilt, X_AXIS, Z_AXIS, -gsl_sf_sin(rad_ax_tilt)); // Y-Axis (no rotation) gsl_matrix_set(rm_ax_tilt, Y_AXIS, Y_AXIS, 1.0); // Z-Axis gsl_matrix_set(rm_ax_tilt, Z_AXIS, X_AXIS, gsl_sf_sin(rad_ax_tilt)); gsl_matrix_set(rm_ax_tilt, Z_AXIS, Z_AXIS, gsl_sf_cos(rad_ax_tilt)); // Initialisation complete initialized = 1; return 0; }
int main(){ int i, j, k, l; int n = 14; // size of solution vector int m = 103; // number of shooting points int maxiter = 251; // maximum number of iterations double tol = 1e-8; // tolerance int nrk; // number of Runge-Kutta steps int flag; // error flag bool info; // boolean for file check int redvol; // reduced volume int tubrad; // tube radius at x = 0 (COM at t = 0) int tapang; // taper angle int benmod; // bending modulus int compos; // center-of-mass axial position // output directory string opath = "../output"; // abscissa, source, and solution vectors vector<double> t(m), u(m,0.0), si(n*m), sm(n*m), sf(n*m); // timestep double ts, dts; // parameters double par[5]; for (i = 0; i < 5; i++) par[i] = 0.0; double v = par[0]; // reduced volume double kb = par[1]; // bending modulus (scaled by dp*a^3) double alph = par[2]; // taper angle of tube wall double R0 = par[3]; // tube radius at center-of-mass axial position (scaled by a) double xcom = par[4]; // center-of-mass position // = time integral of center-of-mass translational speed vector<int> vecV ; vector<int> vecKb; vector<int> vecAl; vector<int> vecR0; // should have auxiliary functions to get the parameters, but for now just use the following // trial parameters: v = 0.99; v = 0.90; kb = 1e-5; kb = 1e2; alph = 0.0 ; R0 = 0.9116; // conf = 80 for v = 90 xcom = 0.0 ; par[0] = v ; par[1] = kb ; par[2] = alph; par[3] = R0 ; par[4] = xcom; double tana = gsl_sf_sin(alph)/gsl_sf_cos(alph); // increments for first-order continuation double dp0, dp1, slope; // initialize nrk = 60; cout << "Initializing... " << endl; init(n, m, par, u.data(), t.data(), si.data()); for (j = 0; j < m*n; j++){ sm[j] = si[j]; } cout << "Initialization complete." << endl; // multiple shooting method cout << "Shooting for v = " << v << ", R0 = " << R0 << ", kb = " << kb << "." << endl; mshoot(n, m, nrk, maxiter, tol, par, u.data(), t.data(), si.data(), sf.data(), flag); // for (i = 0; i < m; i++){ // //cout << t[i] << endl; // cout << si[i*n + 10] << endl; // } // // check if file exists // fileCheck(v, conf, vecCa[i], info); // if (info){ // file exists // // update solution // readOutput(n, m, v, conf, vecCa[i], t.data(), si.data()); // for (j = 0; j < m*n; j++){ // sm[j] = si[j]; // } // } // evolve in time // - recalculate u // - update parameters (specifically R0 and xcom) // // write to file // if (flag == 0) // writeSoln(n, m, v, conf, Ca, t.data(), sf.data(), opath); // // /* update next initial guess using // * first-order continuation */ // if (flag == 0){ // if (i != vecCa.size() - 1){ // if (i == 0) { // dp0 = vecCa[i ] - 0; // dp1 = vecCa[i+1] - 0; // } // else { // dp0 = vecCa[i ] - vecCa[i-1]; // dp1 = vecCa[i+1] - vecCa[i-1]; // } // slope = dp1/dp0; // for (j = 0; j < m*n; j++){ // //si[j] = sm[j] + slope*(sf[j] - sm[j]); // si[j] = sm[j]; // sm[j] = sf[j]; // } // } // } return(0); }
void MCPMPCoeffs::Setup() { //////// initialization of dynamic data structures gsl_rng_env_setup(); cout << BlockName << ".gsl_rng_default_seed=" << gsl_rng_default_seed << endl; // ch : channel coeffs matrix h(n) (M**2xN) // ij // ch matrix structure // // +- -+ // | h(0) . . . . h(n) | | // | 11 11 | | // | | | Rx1 // | h(0) . . . . h(n) | | // | 12 12 | | // | | // | h(0) . . . . h(n) | | // | 21 21 | | // | | | Rx2 // | h(0) . . . . h(n) | | // | 22 22 | | // +- -+ // // where h(n) represents the channel impulse response // ij // // at time n, from tx i to rx j // the matrix has MxM rows and N comumns. // The (i,j) channel is locater at row i*M+j // with i,j in the range [0,M-1] and rows counting from 0 // // _M = M(); ch = gsl_matrix_complex_alloc(_M*_M,N()); ran = gsl_rng_alloc( gsl_rng_default ); runCount = 0; // path loss matrix pathLoss = gsl_matrix_alloc(_M,_M); gsl_matrix_set_all(pathLoss,1.0); // tx, rx positions geoPositions = gsl_vector_complex_alloc(2*M()); geoVelocities = gsl_vector_complex_alloc(2*M()); double pwr=0.0; for (int j=0; j<L(); j++) { pwr += exp(-j*2.0/PTau()); } gain=sqrt(1.0/(pwr*(Ricean()+1.0))); gainrice=sqrt(Ricean()/(Ricean()+1.0)); // cout << "Sum(taps^2)=" << pwr << endl // << "gain=" << gain << endl // << "gainrice=" << gainrice << endl; // // GEO // // geo initialization GeoInit(); // check if rendering is desired string geofn(GeoFn()); if (GeoFn()=="none") // check if GEO rendering is desired geoRenderEnabled = 0; else { // GEO rendering enabled geoRenderEnabled = 1; GeoRender(); } // // SOS Spatial Channel Model // SOSN = 2.0 * SOSM() * SOSM(); sosc = sqrt(2.0/SOSN); sosfrn = gsl_vector_alloc(SOSM()+2); sosfxn = gsl_vector_alloc(SOSN); sosfyn = gsl_vector_alloc(SOSN); // // we generate the radial spatial frequency // gsl_vector_set(sosfrn,0,0.0); for (int i=0;i<SOSM()+1;i++) { double old = gsl_vector_get(sosfrn,i); double tmp1 = 1.0 / sqrt(SOSa()*SOSa() + 4.0 * M_PI * M_PI * old * old ) - SOSP() / (SOSM() * SOSa()); double nextval = 1.0 / (2.0 * M_PI) * sqrt( 1.0 / (tmp1 * tmp1) - SOSa() * SOSa() ); gsl_vector_set(sosfrn,i+1,nextval); //cout << "fr_" << i+1 << " = " << nextval << endl; } // // we compute the cartesian spatial frequency // for (int i=0; i<SOSM();i++) { // radius values for(int j=0; j<2*SOSM(); j++) { // angle values double phi = M_PI * (2 * j - 2 * SOSM() +1) / (4 * SOSM()); double frm = gsl_vector_get(sosfrn,i+1); double fxn = frm * gsl_sf_cos(phi); double fyn = frm * gsl_sf_sin(phi); gsl_vector_set(sosfxn,j+i*2*(SOSM()),fxn); gsl_vector_set(sosfyn,j+i*2*(SOSM()),fyn); //cout << "fx_" << i << "," << j << " = " << fxn << ", " << fyn << endl; } } cout << "Spatial frequencies generated." << endl; // // now we generate the random phases theta_n for each link tx->rx (M x SOSN ) // sostheta = gsl_matrix_alloc(M()*M(),SOSN); for (int i=0; i<_M; i++) { // user i (tx) for (int ii=0;ii<_M;ii++) { // user ii (rx) for (int j=0; j<SOSN; j++ ) { // phase of spatial frequency j gsl_matrix_set(sostheta,i*_M+ii,j,gsl_ran_flat(ran,0,2.0*M_PI)); } } } cout << "Spatial phases generated." << endl; // // Spatial Channel (first) Update // SpatialChannelUpdate(); if (geoRenderEnabled) { // header and footer of kml section kmlhead << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl << "<kml xmlns=\"http://earth.google.com/kml/2.0\">" << endl << "<Document>" << endl << "<name>MuDiSP User locations</name>" << endl << "<Style id=\"greenIcon\">" << endl << "\t<IconStyle>" << endl << "\t\t<scale>2.0</scale>" << endl << "\t\t<Icon>" << endl << "\t\t\t<href>http://maps.google.com/mapfiles/ms/icons/yellow-dot.png</href>" << endl << "\t\t</Icon>" << endl << "\t</IconStyle>" << endl << "</Style>" << endl << "<Style id=\"blueIcon\">" << endl << "\t<IconStyle>" << endl << "\t\t<scale>2.0</scale>" << endl << "\t\t<Icon>" << endl << "\t\t\t<href>http://maps.google.com/mapfiles/ms/icons/red-dot.png</href>" << endl << "\t\t</Icon>" << endl << "\t</IconStyle>" << endl << "</Style>" << endl; kmlheadend << "</Document>" << endl << "</kml>" << endl; } //////// rate declaration for ports }
void init(int n, int m, double *par, double *u, double *t, double *s){ // declare variables int i, j; vector<double> T(m), U(m), S(m*n), Rtube(m); double a, b; // major and minor axes int info; double v = par[0]; // reduced volume double kb = par[1]; // bending modulus (scaled by dp*a^3) double alph = par[2]; // taper angle of tube wall double R0 = par[3]; // tube radius at center-of-mass axial position (scaled by a) double xcom = par[4]; // center-of-mass position // = time integral of center-of-mass translational speed double tana = gsl_sf_sin(alph)/gsl_sf_cos(alph); // get surface area and volume double area = 4.0*M_PI; double vlme = 4.0*M_PI*v/3.0; // get spheroid vector<double> Sarc(m), R(m), X(m), XCOM(m), CS(m), CPHI(m), THET(m), PSI(m), A(m), V(m); proAxes(area, vlme, 1.01, 1.0, a, b, info); if (info == 1) proAxes(area, vlme, 1.5, 1.0, a, b, info); proShape(m, a, b, Sarc.data(), X.data(), R.data(), XCOM.data(), CS.data(), CPHI.data(), PSI.data(), THET.data(), A.data(), V.data()); // for (i = 0; i < m; i++){ // cout << XCOM[i] << endl; // } double Stot = Sarc[m-1]; // get tube radius for (i = 0; i < m; i++){ Rtube[i] = R0 - tana*X[i]; } // polynomial expressions for p and tau (from static solution) double p, sig; p = - 0.39632; p += 2.89243*v; p += - 8.71787*v*v; p += 13.91363*v*v*v; p += -12.41387*v*v*v*v; p += 5.87473*v*v*v*v*v; p += -1.15262*v*v*v*v*v*v; p *= 1e5*kb; sig = 1.2935; sig += - 9.3499*v; sig += 27.9266*v*v; sig += -44.1844*v*v*v; sig += 39.0880*v*v*v*v; sig += -18.3432*v*v*v*v*v; sig += 3.5688*v*v*v*v*v*v; sig *= 1e4*kb; for (i = 0; i < m; i++){ t[i ] = Sarc[i]/Stot; u[i ] = 0.0; s[i*n + 0 ] = R [i]; s[i*n + 1 ] = X [i]; s[i*n + 2 ] = PSI[i]; s[i*n + 3 ] = CS [i]; s[i*n + 4 ] = 0.0 ; // transverse shear tension s[i*n + 5 ] = p ; s[i*n + 6 ] = sig ; s[i*n + 7 ] = A [i]; s[i*n + 8 ] = V [i]; s[i*n + 9 ] = 0.0 ; // leakback flux s[i*n + 10] = Rtube[i]; s[i*n + 11] = XCOM[i]; s[i*n + 12] = 0.0 ; // center of mass speed s[i*n + 13] = Stot ; } // read input file int id[3]; id[0] = 90; // reduced volume id[1] = 80; // confinement id[2] = 0 ; // bending modulus readInput(n, m, id, T.data(), S.data()); for (i = 0; i < m; i++){ t[i] = T[i]; for (j = 0; j < n; j++){ s[i*n + j] = S[i*n + j]; } } // // for debugging // for (i = 0; i < m; i++){ // printf("%.4f ", T[i]); // for (j = 0; j < n; j++) // printf("%.4f ", S[i*n + j]); // printf("\n"); // } // // get critical confinement parameter and set nominal radius // getCritCf(v, crit); // a = 0.01*double(conf)*crit; // // area = 4.0*M_PI*a*a; // vlme = (4.0/3.0)*M_PI*a*a*a*(0.01*double(v)); // proShape(m, a, b, // double &S, double *t, double *x, double *r, // double *cs, double *cphi, double *psi, // double *A, double *V){ // b > a // // read file // readEquil(n, m, 90, conf, T.data(), S.data()); // //readOutput(n, m, v, conf-1, Ca, T.data(), S.data()); // initialize using slightly smaller vesicle (useful at high Ca) // // // copy abscissa and solution vectors // for (i = 0; i < m; i++){ // t[i] = T[i]; // for (j = 0; j < n; j++){ // s[i*n + j] = S[i*n + j]; // } // } }
void MCPMPCoeffs::GeoInit(geo_init_type t) { // initial geo positions double lat, lon, velmod, veldir, deltalon, deltalat, dx, dy, azimut, dist; gsl_complex vel; switch (t) { // all users around case uniform: // tx[i] uniform for (int i=0;i<M();i++) { azimut = gsl_ran_flat(ran,0,2*M_PI); dist = gsl_ran_flat(ran,0,GEO_AREA_RADIUS); dx = GEO_AREA_RADIUS * gsl_sf_cos(azimut); dy = GEO_AREA_RADIUS * gsl_sf_sin(azimut); // wikipedia coordinates to create lat/lon -> x,y conversion functions // ____ ___ _ _ ___ ___ _ _ ___ _ // / ___| / _ \| \ | |/ _ \ / _ \| | | |_ _| | // \___ \| | | | \| | | | | | | | | | | || || | // ___) | |_| | |\ | |_| | | |_| | |_| || ||_| // |____/ \___/|_| \_|\___/ \__\_\\___/|___(_) // lon = GEO_AREA_CENTER_LON + dx / londeg(GEO_AREA_CENTER_LAT); lat = GEO_AREA_CENTER_LAT + dy / latdeg(GEO_AREA_CENTER_LAT); velmod=gsl_ran_flat(ran, GEO_VELOCITY_MIN, GEO_VELOCITY_MAX); veldir=gsl_ran_flat(ran, 0.0, 2*M_PI); vel = gsl_complex_polar(velmod,veldir); // vel in km/h // deltalon, deltalat in deg/s deltalon = GSL_REAL(vel) / 3.6 / londeg(GEO_AREA_CENTER_LAT); deltalat = GSL_IMAG(vel) / 3.6 / latdeg(GEO_AREA_CENTER_LAT); // expressed in deg LON and LAT gsl_vector_complex_set(geoPositions,i,gsl_complex_rect(lat,lon)); // expressed in deg/s LON and LAT gsl_vector_complex_set(geoVelocities,i,gsl_complex_rect(deltalon,deltalat)); } // for tx[i] // rx[i] center of area - zero velocity for (int i=M();i<2*M();i++) { // expressed in deg, LON and LAT gsl_vector_complex_set(geoPositions,i,gsl_complex_rect(GEO_AREA_CENTER_LAT,GEO_AREA_CENTER_LON)); // expressed in deg/s, LON and LAT gsl_vector_complex_set(geoVelocities,i,gsl_complex_polar(0.0,0.0)); } // for rx[i] break; case center: break; case belt: break; } // end case }