void Calculator::setMatrixExp(gsl_matrix_complex * m, double Q) { /*set matrix Exp*/ /* * ||exp(i * q * L1) 0.0 || * Exp = || || * ||0.0 exp(i * q * L2 )|| */ gsl_matrix_complex_set(m, 0, 0, gsl_complex_polar (1.0, Q * m_L1)); gsl_matrix_complex_set(m, 0, 1, gsl_complex_polar (0.0, 0.0)); gsl_matrix_complex_set(m, 1, 0, gsl_complex_polar (0.0, 0.0)); gsl_matrix_complex_set(m, 1, 1, gsl_complex_polar (1.0, Q * m_L2)); }
void complex::assign(const double& real=0., const double& imag=0., bool polar=false) { if (polar) _complex = gsl_complex_polar(real,imag); else { GSL_SET_COMPLEX(&_complex, real, imag); // *_complex = gsl_complex_rect(real,imag); } }
/* internal function used by qpb_sun_project(). Gets the diagonal matrix D, which contains the phases to be used in the back-projection to SU(3) */ void get_theta_matrix(gsl_matrix_complex *D, gsl_vector *S, qpb_double phi){ qpb_double pi = 4. * atan2(1.0, 1.0); qpb_double theta_step = pi / 3.; qpb_double th_initial[NC-1] = {0, 0}; qpb_double max_f = -1e10; gsl_vector *th_trial = gsl_vector_alloc(NC-1); struct func_params f_params; f_params.phi = phi; for(int i=0; i<NC; i++) f_params.s[i] = gsl_vector_get(S, i); for(qpb_double th1 = pi; th1 > -pi; th1-=theta_step) for(qpb_double th2 = pi; th2 > -pi; th2-=theta_step) { gsl_vector_set(th_trial, 0, th1); gsl_vector_set(th_trial, 1, th2); qpb_double f_trial = -func(th_trial, &f_params); if(f_trial > max_f){ max_f = f_trial; th_initial[0] = gsl_vector_get(th_trial, 0); th_initial[1] = gsl_vector_get(th_trial, 1); } } gsl_vector_set(th_trial, 0, th_initial[0]); gsl_vector_set(th_trial, 1, th_initial[1]); minimize_for_thetas(th_trial, &f_params); gsl_matrix_complex_set_zero(D); qpb_double th_sum = 0; for(int i=0; i<NC-1; i++) { gsl_matrix_complex_set(D, i, i, gsl_complex_polar(1., gsl_vector_get(th_trial, i))); th_sum += gsl_vector_get(th_trial, i); } gsl_matrix_complex_set(D, NC-1, NC-1, gsl_complex_polar (1., -phi-th_sum)); gsl_vector_free(th_trial); return; }
void PSKMapper::Run() { unsigned int nbits,nsymbs,count; /// fetch data objects gsl_vector_uint_class input = vin1.GetDataObj(); // number of input bits nbits = input.vec->size; // number of output symbols nsymbs = nbits / Nb(); gsl_vector_complex *tmp=gsl_vector_complex_alloc(nsymbs); count=0; for (int n=0; n<nsymbs; n++) { symbol_id=0; //////// I take Nb bits from input and map it in new_symbol for (int i=0;i<Nb();i++) { symbol_id = (symbol_id << 1); symbol_id += gsl_vector_uint_get(input.vec,count++); } new_symbol = gsl_complex_polar(1.0, symbol_arg * double(gsl_vector_uint_get(gray_encoding, symbol_id))); gsl_vector_complex_set(tmp,n,new_symbol); } // show output // gsl_vector_complex_show(tmp); // deliver data vout1.DeliverDataObj(gsl_vector_complex_class(tmp)); gsl_vector_complex_free(tmp); }
/* computes the svd of a complex matrix. Missing in gsl. */ int svd(gsl_matrix_complex *A, gsl_matrix_complex *V, gsl_vector *S) { int n = A->size1; gsl_eigen_hermv_workspace *gsl_work = gsl_eigen_hermv_alloc(n); gsl_matrix_complex *Asq = gsl_matrix_complex_alloc(n, n); gsl_complex zero = gsl_complex_rect(0., 0.); gsl_complex one = gsl_complex_rect(1., 0.); gsl_vector *e = gsl_vector_alloc(n); gsl_matrix_complex *U = gsl_matrix_complex_alloc(n, n); gsl_blas_zgemm(CblasNoTrans, CblasConjTrans, one, A, A, zero, Asq); gsl_eigen_hermv(Asq, e, U, gsl_work); gsl_eigen_hermv_sort(e, U, GSL_EIGEN_SORT_VAL_DESC); gsl_blas_zgemm(CblasConjTrans, CblasNoTrans, one, A, A, zero, Asq); gsl_eigen_hermv(Asq, e, V, gsl_work); gsl_eigen_hermv_sort(e, V, GSL_EIGEN_SORT_VAL_DESC); gsl_blas_zgemm(CblasNoTrans, CblasNoTrans, one, A, V, zero, Asq); gsl_blas_zgemm(CblasConjTrans, CblasNoTrans, one, U, Asq, zero, A); for(int i=0; i<n; i++){ gsl_complex x = gsl_matrix_complex_get(A, i, i); double phase = gsl_complex_arg(gsl_complex_mul_real(x, 1./sqrt(e->data[i]))); gsl_vector_complex_view U_col = gsl_matrix_complex_column(U, i); gsl_vector_complex_scale(&U_col.vector, gsl_complex_polar(1., phase)); gsl_vector_set(S, i, sqrt(gsl_vector_get(e, i))); } gsl_matrix_complex_memcpy(A, U); gsl_vector_free(e); gsl_matrix_complex_free(U); gsl_matrix_complex_free(Asq); gsl_eigen_hermv_free(gsl_work); return 0; }
void SoftDemapper::Run() { unsigned int nbits,nsymbs,count; /// fetch data objects gsl_vector_complex_class input = vin1.GetDataObj(); // number of input symbs nsymbs = input.vec->size; // cout << "received " << nsymbs << " elements in vector." << endl; // number of output symbols nbits = nsymbs * Nb(); gsl_vector *llr=gsl_vector_alloc(nbits); double *den = (double *)calloc( Nb(), sizeof(double) ); double *num = (double *)calloc( Nb(), sizeof(double) ); // determine symb_likelyhood for (int i=0;i<nsymbs;i++) { // cycle through received symbols for (int k=0;k<Nb();k++) { num[k] = GSL_NEGINF; den[k] = GSL_NEGINF; } // the received symbol gsl_complex recsym = gsl_vector_complex_get(input.vec,i); // cout << "received symbol = (" // << GSL_REAL(recsym) // << "," // << GSL_IMAG(recsym) // << ") " << endl; for (int j=0;j<Ns;j++) { // cycle through postulated symbol // gray encoded symbol id unsigned int symbol_id = gsl_vector_uint_get(gray_encoding,j); // complex symbol gsl_complex refsym = gsl_complex_polar(1.0,symbol_arg * symbol_id ); // likelyhood metric double metric = gsl_complex_abs( gsl_complex_sub(refsym,recsym) ); metric = -EsNo()*metric*metric; //gsl_matrix_complex_set(symb_likelihoods,j,i); // // HERE is available a metric for symb i and refsymb j // int mask = 1 << Nb() - 1; for (int k=0;k<Nb();k++) { /* loop over bits */ if (mask&j) { /* this bit is a one */ num[k] = ( *max_star[LMAP()] )( num[k], metric ); } else { /* this bit is a zero */ den[k] = ( *max_star[LMAP()] )( den[k], metric ); } mask = mask >> 1; } //bits } // alphabet for (int k=0;k<Nb();k++) { gsl_vector_set(llr,Nb()*i+k,num[k] - den[k]); } } // symbols gsl_vector_class outv(llr); // outv.show(); // output bitwise LLR vout1.DeliverDataObj(outv); gsl_vector_free(llr); // free dynamic structures free(num); free(den); }
// // // BlockUser // // void MBlockUser::Setup() { //////// initialization of dynamic data structures // number of symbols Ns=(1 << Nb()); /// vector and matrix allocation gray_encoding = gsl_vector_uint_alloc(Ns); symbol_arg = 2.0*double(PI/Ns); count=0; coding_mat = gsl_matrix_complex_calloc(J(),K()); selection_mat = gsl_matrix_complex_calloc(N(),J()); transform_mat = gsl_matrix_complex_calloc(N(),N()); outmat = gsl_matrix_complex_calloc(N(),M()); // outmat(i,j) = symbol at time i from user j tmp = gsl_vector_complex_calloc(K()); tmp1 = gsl_vector_complex_calloc(J()); tmp2 = gsl_vector_complex_calloc(N()); // tmpout = gsl_vector_complex_calloc(N()); // tmpout is a view from outmat // // // IFFT MATRIX UNITARY // // double ifftarg=2.0*double(M_PI/N()); double ifftamp=1.0/sqrt(double(N())); for (int i=0; i<N(); i++) for (int j=0; j<N(); j++) gsl_matrix_complex_set(transform_mat, i, j, gsl_complex_polar(ifftamp,ifftarg*i*j) ); //////// rate declaration for ports // in1.SetRate( Nb()*K()*M() ); // M users K symbols Nb bits ///////// Gray Encoder SetUp for (unsigned int i=0; i<Ns; i++) { gsl_vector_uint_set(gray_encoding,i,0); for (unsigned int k=0; k<Nb(); k++) { unsigned int t=(1<<k); unsigned int tt=2*t; unsigned int ttt= gsl_vector_uint_get(gray_encoding,i) + t * (((t+i)/tt) % 2); gsl_vector_uint_set(gray_encoding,i,ttt); } } }
void MBlockUser::Run() { // // Allocation Matrices // gsl_matrix_uint signature_frequencies=min2.GetDataObj(); gsl_matrix signature_powers=min3.GetDataObj(); // // input bits // gsl_matrix_uint inputbits = min1.GetDataObj(); // // outer loop: the users // for (int u=0;u<M();u++) { gsl_vector_complex_view tmpout = gsl_matrix_complex_column(outmat,u); // // // FETCH K INPUT SYMBOLS // // for (int j=0;j<K();j++) { symbol_id=0; //////// I take Nb bits from input and map it in new_symbol for (int i=0;i<Nb();i++) { symbol_id = (symbol_id << 1); // symbol_id += in1.GetDataObj(); symbol_id += gsl_matrix_uint_get(&inputbits,u,j*Nb()+i); } new_symbol = gsl_complex_polar(1.0, symbol_arg * double(gsl_vector_uint_get(gray_encoding, symbol_id))); gsl_vector_complex_set(tmp,j,new_symbol); } // // // SELECTION MATRIX UPDATE and POWER // // // gsl_matrix_complex_set_identity(selection_mat); gsl_matrix_complex_set_zero(selection_mat); for (int i=0;i<J(); i++) { unsigned int carrier=gsl_matrix_uint_get(&signature_frequencies,u,i); double power=gsl_matrix_get(&signature_powers,u,i); gsl_complex one=gsl_complex_polar(power,0.0); gsl_matrix_complex_set(selection_mat,carrier,i,one); } // // // PRECODING MATRIX UPDATE // // #ifdef GIANNAKIS_PRECODING double roarg=2.0*double(M_PI/N()); for (int i=0;i<J(); i++) { unsigned int carrier=gsl_matrix_uint_get(&signature_frequencies,u,i); for (int j=0; j<K(); j++) { gsl_complex ro=gsl_complex_polar(sqrt(1.0/double(J())),-j*carrier*roarg); gsl_matrix_complex_set(coding_mat,i,j,ro); } } #else double roarg=2.0*double(M_PI/J()); for (int i=0;i<J(); i++) { for (int j=0; j<K(); j++) { gsl_complex ro=gsl_complex_polar(sqrt(1.0/double(J())),-j*i*roarg); gsl_matrix_complex_set(coding_mat,i,j,ro); } } #endif #ifdef SHOW_MATRIX cout << endl << BlockName << " user: "******"coding matrix (theta) = " << endl; gsl_matrix_complex_show(coding_mat); cout << "T^h*T matrix = " << endl; gsl_matrix_complex_show(THT); cout << "T^h*T trace = " << GSL_REAL(trace) << ", " << GSL_IMAG(trace) << endl; gsl_matrix_complex_free(THT); #endif // // // PRECODING // // gsl_blas_zgemv(CblasNoTrans, gsl_complex_rect(1.0,0), coding_mat, tmp, gsl_complex_rect(0,0), tmp1); // // // CARRIER SELECTION // // gsl_blas_zgemv(CblasNoTrans, gsl_complex_rect(1.0,0), selection_mat, tmp1, gsl_complex_rect(0,0), tmp2); // // // IFFT TRANSFORM // // gsl_blas_zgemv(CblasNoTrans, gsl_complex_rect(1.0,0), transform_mat, tmp2, gsl_complex_rect(0,0), &tmpout.vector); // cout << "\n\n symbols (user " << u << ") = " << endl; // gsl_vector_complex_fprintf(stdout,tmp,"%f"); #ifdef SHOW_MATRIX cout << "\n\n symbols (user " << u << ") = " << endl; gsl_vector_complex_fprintf(stdout,tmp,"%f"); cout << "\n\n precoded = " << endl; gsl_vector_complex_fprintf(stdout,tmp1,"%f"); cout << "\n\n precoded selected = " << endl; gsl_vector_complex_fprintf(stdout,tmp2,"%f"); cout << "\n\n precoded selected transformed = " << endl; gsl_vector_complex_fprintf(stdout,&tmpout.vector,"%f"); #endif } // close user loop mout1.DeliverDataObj(*outmat); }
void MAIAllocator::Setup() { //////// initialization of dynamic data structures Hmat = gsl_matrix_complex_alloc(N(),M()); Hchan = gsl_vector_complex_alloc(N()); Hperm = gsl_matrix_uint_alloc(N(),M()); p = gsl_permutation_alloc(N()); huserabs = gsl_vector_alloc(N()); nextcarr = gsl_vector_uint_alloc(M()); usedcarr = gsl_vector_uint_alloc(N()); errs = gsl_vector_uint_alloc(M()); habs = gsl_matrix_alloc(N(),M()); huu = gsl_matrix_complex_alloc(N(),M()); framecount = 0; ericount = 0; csicount = 0; noDecisions = 0; ostringstream cmd; // // time // time(&reporttime); // // Random Generator // ran = gsl_rng_alloc( gsl_rng_default ); // SIGNATURE FREQUENCIES INITIAL SETUP signature_frequencies = gsl_matrix_uint_alloc(M(),J()); signature_frequencies_init = gsl_matrix_uint_alloc(M(),J()); signature_powers = gsl_matrix_alloc(M(),J()); for (int i=0; i<M(); i++) for (int j=0; j<J(); j++) gsl_matrix_uint_set(signature_frequencies_init,i,j,(j*M()+i) % N()); // // INITIAL ALLOCATION // gsl_matrix_uint_memcpy(signature_frequencies, signature_frequencies_init); // maximum initial powers for all carriers gsl_matrix_set_all(signature_powers,INIT_CARR_POWER); gsl_vector_uint_set_zero(errs); // // // FFT Transform Matrix // // transform_mat = gsl_matrix_complex_calloc(N(),N()); double fftarg=-2.0*double(M_PI/N()); double fftamp=1.0/sqrt(double(N())); for (int i=0; i<N(); i++) for (int j=0; j<N(); j++) gsl_matrix_complex_set(transform_mat,i,j, gsl_complex_polar(fftamp,fftarg*i*j) ); switch (Mode()) { case 0: cout << BlockName << " - Allocator type FIXED_ALLOCATION selected" << endl; break; case 1: cout << BlockName << " - Allocator type GIVE_BEST_CARR selected" << endl; break; case 2: cout << BlockName << " - Allocator type SWAP_BAD_GOOD selected" << endl; break; case 3: cout << BlockName << " - Allocator type BEST_OVERLAP selected" << endl; break; case 4: cout << BlockName << " - Allocator type SOAR_AI selected" << endl; // // SOAR INITIALIZATION // max_errors = MAX_ERROR_RATE * ERROR_REPORT_INTERVAL * Nb() * K(); cout << BlockName << " - Max errors tuned to " << max_errors << " errors/frame." << endl; // // first we initialize the vectors and matrices // in the order of appearance in the header file. // umapUserVec = vector < Identifier * > (M()); umapUserUidVec = vector < IntElement * > (M()); umapUserErrsVec = vector < IntElement * > (M()); umapUserPowerVec = vector < FloatElement * > (M()); umapUserCarrMat = vector < Identifier * > (M()*J()); umapUserCarrCidMat = vector < IntElement * > (M()*J()); umapUserCarrPowerMat = vector < FloatElement * > (M()*J()); chansCoeffMat = vector < Identifier * > (M()*N()); chansCoeffUserMat = vector < IntElement * > (M()*N()); chansCoeffCarrMat = vector < IntElement * > (M()*N()); chansCoeffValueMat = vector < FloatElement * > (M()*N()); carmapCarrVec = vector < Identifier * > (N()); carmapCarrCidVec = vector < IntElement * > (N()); // // then we create an instance of the Soar kernel in our process // pKernel = Kernel::CreateKernelInNewThread() ; //pKernel = Kernel::CreateRemoteConnection() ; // Check that nothing went wrong. We will always get back a kernel object // even if something went wrong and we have to abort. if (pKernel->HadError()) { cerr << BlockName << ".SOAR - " << pKernel->GetLastErrorDescription() << endl ; exit(1); } // We check if an agent has been prevoiusly created, otherwise we create it // NOTE: We don't delete the agent pointer. It's owned by the kernel pAgent = pKernel->GetAgent("AIAllocator") ; if (! pKernel->IsAgentValid(pAgent)) { pAgent = pKernel->CreateAgent("AIAllocator") ; } // Check that nothing went wrong // NOTE: No agent gets created if there's a problem, so we have to check for // errors through the kernel object. if (pKernel->HadError()) { cerr << BlockName << ".SOAR - " << pKernel->GetLastErrorDescription() << endl ; exit(1); } // // load productions // pAgent->LoadProductions(SoarFn()); // spawn debugger #ifdef SPAWN_DEBUGGER pAgent->SpawnDebugger(); #endif // Check that nothing went wrong // NOTE: No agent gets created if there's a problem, so we have to check for // errors through the kernel object. if (pKernel->HadError()) { cerr << BlockName << ".SOAR - " << pKernel->GetLastErrorDescription() << endl ; exit(1); } // keypress //cout << "pause maillocator:203 ... (press ENTER key)" << endl; //cin.ignore(); // // we can now generate initial input link structure // // NO MORE adjust max-nil-output-cycle //cmd << "max-nil-output-cycles " << 120; //pAgent->ExecuteCommandLine(cmd.str().c_str()); // the input-link pInputLink = pAgent->GetInputLink(); // input-time input_time = 0; inputTime = pAgent->CreateIntWME(pInputLink,"input-time",input_time); // the usrmap structure (common wmes) umap = pAgent->CreateIdWME(pInputLink,"usrmap"); // BITS_PER_REPORT = ERROR_REPORT_INTERVAL * Nb() * K() // MAX_ERRORS = MAX_ERROR_RATE * BITS_PER_REPORT umapMaxerr = pAgent->CreateIntWME(umap,"maxerr",max_errors); umapPstep = pAgent->CreateFloatWME(umap,"pstep",POWER_STEP); umapPmax = pAgent->CreateFloatWME(umap,"pmax",MAX_POWER); // the channels chans = pAgent->CreateIdWME(pInputLink,"channels"); // the carmap carmap = pAgent->CreateIdWME(pInputLink,"carmap"); // the usrmap structure (users substructure) for (int i=0;i<M();i++) { // user loop umapUserVec[i] = pAgent->CreateIdWME(umap,"user"); umapUserUidVec[i] = pAgent->CreateIntWME(umapUserVec[i],"uid",i); umapUserErrsVec[i] = pAgent->CreateIntWME(umapUserVec[i],"errs",int(0)); umapUserPowerVec[i] = pAgent->CreateFloatWME(umapUserVec[i],"power",J()); // update the current allocation for (int j=0;j<J();j++) { // allocated carriers loop unsigned int usedcarr = gsl_matrix_uint_get(signature_frequencies,i,j); double usedpow = gsl_matrix_get(signature_powers,i,j); umapUserCarrMat[i*J()+j] = pAgent->CreateIdWME(umapUserVec[i],"carr"); umapUserCarrCidMat[i*J()+j] = pAgent->CreateIntWME(umapUserCarrMat[i*J()+j],"cid",usedcarr); umapUserCarrPowerMat[i*J()+j] = pAgent->CreateFloatWME(umapUserCarrMat[i*J()+j],"power",usedpow); } // allocated carriers loop // the channels for (int j=0;j<N();j++) { // all channels loop chansCoeffMat[i*N()+j] = pAgent->CreateIdWME(chans,"coeff"); chansCoeffUserMat[i*N()+j] = pAgent->CreateIntWME(chansCoeffMat[i*N()+j],"user",i); chansCoeffCarrMat[i*N()+j] = pAgent->CreateIntWME(chansCoeffMat[i*N()+j],"carr",j); chansCoeffValueMat[i*N()+j] = pAgent->CreateFloatWME(chansCoeffMat[i*N()+j],"value",0.0); } // all channels loop } // user loop // the carmap structure for (int j=0;j<N();j++) { // all carriers loop carmapCarrVec[j] = pAgent->CreateIdWME(carmap,"carr"); carmapCarrCidVec[j] = pAgent->CreateIntWME(carmapCarrVec[j],"cid",j); } // all carriers loop // // END OF SOAR INITIALIZAZION // break; default: cerr << BlockName << " - Unhandled allocator type !" << endl; exit(1); } //////// rate declaration for ports }
int main (void) { size_t i = 0; const double tol = TEST_FACTOR * 10 * GSL_DBL_EPSILON; const double tolf = TEST_FACTOR * 10 * GSL_FLT_EPSILON; gsl_ieee_env_setup(); for (i = 0 ; i < 10; i++) { double r = (i - 5.0) * 0.3 ; double t = 2.0 * M_PI * i / 5 ; double x = r * cos(t), y = r * sin(t) ; gsl_complex z = gsl_complex_polar (r, t) ; gsl_test_rel (GSL_REAL(z), x, tol, "gsl_complex_polar real part at (r=%g,t=%g)", r, t); gsl_test_rel (GSL_IMAG(z), y, tol, "gsl_complex_polar imag part at (r=%g,t=%g)", r, t); } i = 0; while (list[i].f) { struct f t = list[i]; gsl_complex z = gsl_complex_rect (t.x, t.y); double f = (t.f) (z); gsl_test_rel (f, t.fx, tol, "%s at (%g,%g)", t.name, t.x, t.y); i++; } i = 0; while (listz[i].f) { struct fz t = listz[i]; gsl_complex z = gsl_complex_rect (t.x, t.y); gsl_complex fz = (t.f) (z); double fx = GSL_REAL (fz), fy = GSL_IMAG (fz); #ifdef DEBUG printf("x = "); gsl_ieee_fprintf_double (stdout, &t.x); printf("\n"); printf("y = "); gsl_ieee_fprintf_double (stdout, &t.y); printf("\n"); printf("fx = "); gsl_ieee_fprintf_double (stdout, &fx); printf("\n"); printf("ex = "); gsl_ieee_fprintf_double (stdout, &t.fx); printf("\n"); printf("fy = "); gsl_ieee_fprintf_double (stdout, &fy); printf("\n"); printf("ey = "); gsl_ieee_fprintf_double (stdout, &t.fy); printf("\n"); #endif gsl_test_rel (fx, t.fx, tol, "%s real part at (%g,%g)", t.name, t.x, t.y); gsl_test_rel (fy, t.fy, tol, "%s imag part at (%g,%g)", t.name, t.x, t.y); i++; } i = 0; while (listzz[i].f) { struct fzz t = listzz[i]; gsl_complex z1 = gsl_complex_rect (t.x1, t.y1); gsl_complex z2 = gsl_complex_rect (t.x2, t.y2); gsl_complex fz = (t.f) (z1, z2); double fx = GSL_REAL (fz), fy = GSL_IMAG (fz); #ifdef DEBUG printf("x1 = "); gsl_ieee_fprintf_double (stdout, &t.x1); printf("\n"); printf("y1 = "); gsl_ieee_fprintf_double (stdout, &t.y1); printf("\n"); printf("x2 = "); gsl_ieee_fprintf_double (stdout, &t.x2); printf("\n"); printf("y2 = "); gsl_ieee_fprintf_double (stdout, &t.y2); printf("\n"); printf("fx = "); gsl_ieee_fprintf_double (stdout, &fx); printf("\n"); printf("ex = "); gsl_ieee_fprintf_double (stdout, &t.fx); printf("\n"); printf("fy = "); gsl_ieee_fprintf_double (stdout, &fy); printf("\n"); printf("ey = "); gsl_ieee_fprintf_double (stdout, &t.fy); printf("\n"); #endif gsl_test_rel (fx, t.fx, tolf, "%s real part at (%g,%g;%g,%g)", t.name, t.x1, t.y1, t.x2, t.y2); gsl_test_rel (fy, t.fy, tolf, "%s imag part at (%g,%g;%g,%g)", t.name, t.x1, t.y1, t.x2, t.y2); i++; } i = 0; while (listreal[i].f) { struct freal t = listreal[i]; gsl_complex fz = (t.f) (t.x); double fx = GSL_REAL (fz), fy = GSL_IMAG (fz); #ifdef DEBUG printf("x = "); gsl_ieee_fprintf_double (stdout, &t.x); printf("\n"); printf("fx = "); gsl_ieee_fprintf_double (stdout, &fx); printf("\n"); printf("ex = "); gsl_ieee_fprintf_double (stdout, &t.fx); printf("\n"); printf("fy = "); gsl_ieee_fprintf_double (stdout, &fy); printf("\n"); printf("ey = "); gsl_ieee_fprintf_double (stdout, &t.fy); printf("\n"); #endif gsl_test_rel (fx, t.fx, tol, "%s real part at (%g,0)", t.name, t.x); gsl_test_rel (fy, t.fy, tol, "%s imag part at (%g,0)", t.name, t.x); i++; } exit (gsl_test_summary ()); }
void Spectrometer::countDispersion_BS(Medium &Osrodek, QString DataName, QProgressBar *Progress, int factor) { //lsfgerhla double a=Osrodek.itsBasis.getLatticeConstant(); double thickness=Osrodek.itsStructure.getThickness(); int RecVec=itsRecVectors; int k_prec=itsK_Precision; double wi=itsFrequencies[0]; double w_prec=itsFrequencies[1]; double wf=itsFrequencies[2]; int half=3*(2*RecVec+1)*(2*RecVec+1); int dimension=6*(2*RecVec+1)*(2*RecVec+1); int EigValStrNumber=6*(2*RecVec+1)*(2*RecVec+1); int EigValNumber=9*(2*RecVec+1)*(2*RecVec+1); std::ofstream plik; DataName="results/"+ DataName + ".dat"; QByteArray bytes = DataName.toAscii(); const char * CDataName = bytes.data(); plik.open(CDataName); //inicjalizacje wektorów i macierzy gsl_matrix *gammaA=gsl_matrix_calloc(dimension, dimension); gsl_matrix *gammaB=gsl_matrix_calloc(dimension, dimension); gsl_matrix *gammaC=gsl_matrix_calloc(dimension, dimension); gsl_matrix *gammaD=gsl_matrix_calloc(dimension, dimension); gsl_eigen_genv_workspace *wspce=gsl_eigen_genv_alloc(dimension); gsl_eigen_genv_workspace *wspce2=gsl_eigen_genv_alloc(dimension); gsl_vector_complex *StrAlpha =gsl_vector_complex_alloc(dimension); gsl_vector *StrBeta = gsl_vector_alloc(dimension); gsl_matrix_complex *StrEigenVec=gsl_matrix_complex_calloc(dimension, dimension); gsl_vector_complex *BAlpha =gsl_vector_complex_alloc(dimension); gsl_vector *BBeta = gsl_vector_alloc(dimension); gsl_matrix_complex *BasisEigenVec=gsl_matrix_complex_calloc(dimension, dimension); gsl_matrix_complex *ChosenVectors = gsl_matrix_complex_calloc(half, EigValNumber); gsl_vector_complex *ChosenValues = gsl_vector_complex_calloc(EigValNumber); gsl_matrix_complex *Boundaries=gsl_matrix_complex_calloc(EigValNumber, EigValNumber); double kx, ky, krokx, kroky, boundary_x, boundary_y; double k_zred, k_zred0; double krok = M_PI/(k_prec*a); for (int droga=0; droga<3; droga++) { //int droga = 1; if (droga==0) //droga M->Gamma { kx=-M_PI/a; krokx=krok; boundary_x=0; ky=-M_PI/a; kroky=krok; boundary_y=0; k_zred0=-1*sqrt(pow(kx/(2*M_PI/a), 2)+pow(ky/(2*M_PI/a), 2)); } else if (droga==1) { kx=0; //droga Gamma->X krokx=krok; boundary_x=M_PI/a; ky=0; kroky=0; boundary_y=0; k_zred0=sqrt(2)/2; //k_zred0=0; } else if (droga==2) { kx=M_PI/a; //Droga X->M krokx=0; boundary_x=M_PI/a; ky=0; kroky=krok; boundary_y=M_PI/a; k_zred0=sqrt(2)/2; } //petla dla wektorów falowych for (; kx <= boundary_x && ky <= boundary_y; kx=kx+krokx, ky=ky+kroky) { if (droga==0) { k_zred = abs(k_zred0 + sqrt( pow(kx/(2*M_PI/a), 2)+pow(ky/(2*M_PI/a), 2))); } else { k_zred = k_zred0 + kx/(2*M_PI/a) + ky/(2*M_PI/a); } int postep=int(100*k_zred/1.7); Progress->setValue(postep); Progress->update(); QApplication::processEvents(); //pętla dla częstości w for (double w=wi; w<wf; w=w+w_prec) { gsl_matrix_complex_set_all(Boundaries, gsl_complex_rect (0,0)); //ustawienie wartosci wyznacznika na 0 gsl_matrix_set_all(gammaA, 0); gsl_matrix_set_all(gammaB, 0); gsl_matrix_set_all(gammaC, 0); gsl_matrix_set_all(gammaD, 0); gsl_vector_complex_set_all(StrAlpha, gsl_complex_rect (0,0)); gsl_vector_set_all(BBeta, 0); gsl_vector_complex_set_all(BAlpha, gsl_complex_rect (0,0)); gsl_vector_set_all(StrBeta, 0); gsl_matrix_complex_set_all(BasisEigenVec, gsl_complex_rect (0,0)); gsl_matrix_complex_set_all(StrEigenVec, gsl_complex_rect (0,0)); gsl_matrix_complex_set_all(ChosenVectors, gsl_complex_rect (0,0)); gsl_vector_complex_set_all(ChosenValues, gsl_complex_rect (0,0)); //gammaA,B dla struktury //gammaA,B dla struktury /* S - numeruje transformaty tensora sprężystoci i gestosci i - numeruje wiersze macierzy j - numeruje kolumny macierzy half - druga polowa macierzy */ for(int Nx=-RecVec, i=0, S=0; Nx<=RecVec; Nx++) { for(int Ny=-RecVec; Ny<=RecVec; Ny++, i=i+3) { for(int Nx_prim=-RecVec, j=0; Nx_prim<=RecVec; Nx_prim++) { for(int Ny_prim=-RecVec; Ny_prim<=RecVec; Ny_prim++, j=j+3, S++) { double Elasticity[6][6]; itsRecStructureSubstance[S].getElasticity(Elasticity); double Density=itsRecStructureSubstance[S].getDensity(); double gx=2*M_PI*Nx/a; double gy=2*M_PI*Ny/a; double gx_prim=2*M_PI*Nx_prim/a; double gy_prim=2*M_PI*Ny_prim/a; gsl_matrix_set(gammaA, i, j, Elasticity[3][3]); gsl_matrix_set(gammaA, i+1, j+1, Elasticity[3][3]); gsl_matrix_set(gammaA, i+2, j+2, Elasticity[0][0]); gsl_matrix_set(gammaB, i+2, j, -Elasticity[0][1]*(kx+gx_prim)-Elasticity[3][3]*(kx+gx)); gsl_matrix_set(gammaB, i+2, j+1, -Elasticity[0][1]*(ky+gy_prim)-Elasticity[3][3]*(ky+gy)); gsl_matrix_set(gammaB, i, j+2, -Elasticity[0][1]*(kx+gx)-Elasticity[3][3]*(kx+gx_prim)); gsl_matrix_set(gammaB, i+1, j+2, -Elasticity[0][1]*(ky+gy)-Elasticity[3][3]*(ky+gy_prim)); gsl_matrix_set(gammaB, i, j+half, -Elasticity[0][0]*(kx+gx)*(kx+gx_prim)-Elasticity[3][3]*(ky+gy)*(ky+gy_prim)+Density*w*w); gsl_matrix_set(gammaB, i+1, j+half, -Elasticity[0][1]*(kx+gx_prim)*(ky+gy)-Elasticity[3][3]*(ky+gy_prim)*(kx+gx)); gsl_matrix_set(gammaB, i, j+half+1, -Elasticity[0][1]*(ky+gy_prim)*(kx+gx)-Elasticity[3][3]*(kx+gx_prim)*(ky+gy)); gsl_matrix_set(gammaB, i+1, j+half+1, -Elasticity[0][0]*(ky+gy_prim)*(ky+gy)-Elasticity[3][3]*(kx+gx_prim)*(kx+gx)+Density*w*w); gsl_matrix_set(gammaB, i+2, j+half+2, -Elasticity[3][3]*(ky+gy_prim)*(ky+gy)-Elasticity[3][3]*(kx+gx_prim)*(kx+gx)+Density*w*w); if (i==j) { gsl_matrix_set(gammaA, i+half, j+half, 1); gsl_matrix_set(gammaA, i+half+1, j+half+1, 1); gsl_matrix_set(gammaA, i+half+2, j+half+2, 1); gsl_matrix_set(gammaB, i+half, j, 1); gsl_matrix_set(gammaB, i+half+1, j+1, 1); gsl_matrix_set(gammaB, i+half+2, j+2, 1); } } } } } //rozwiazanie zagadnienienia własnego gsl_eigen_genv(gammaB, gammaA, StrAlpha, StrBeta, StrEigenVec, wspce); //gammaC,D dla Podłoża for(int Nx=-RecVec, i=0, S=0; Nx<=RecVec; Nx++) { for(int Ny=-RecVec; Ny<=RecVec; Ny++, i=i+3) { for(int Nx_prim=-RecVec, j=0; Nx_prim<=RecVec; Nx_prim++) { for(int Ny_prim=-RecVec; Ny_prim<=RecVec; Ny_prim++, j=j+3, S++) { double Elasticity[6][6]; itsRecBasisSubstance[S].getElasticity(Elasticity); double Density=itsRecBasisSubstance[S].getDensity(); double gx=2*M_PI*Nx/a; double gy=2*M_PI*Ny/a; double gx_prim=2*M_PI*Nx_prim/a; double gy_prim=2*M_PI*Ny_prim/a; gsl_matrix_set(gammaC, i, j, Elasticity[3][3]); gsl_matrix_set(gammaC, i+1, j+1, Elasticity[3][3]); gsl_matrix_set(gammaC, i+2, j+2, Elasticity[0][0]); gsl_matrix_set(gammaD, i+2, j, -Elasticity[0][1]*(kx+gx_prim)-Elasticity[3][3]*(kx+gx)); gsl_matrix_set(gammaD, i+2, j+1, -Elasticity[0][1]*(ky+gy_prim)-Elasticity[3][3]*(ky+gy)); gsl_matrix_set(gammaD, i, j+2, -Elasticity[0][1]*(kx+gx)-Elasticity[3][3]*(kx+gx_prim)); gsl_matrix_set(gammaD, i+1, j+2, -Elasticity[0][1]*(ky+gy)-Elasticity[3][3]*(ky+gy_prim)); gsl_matrix_set(gammaD, i, j+half, -Elasticity[0][0]*(kx+gx)*(kx+gx_prim)-Elasticity[3][3]*(ky+gy)*(ky+gy_prim)+Density*w*w); gsl_matrix_set(gammaD, i+1, j+half, -Elasticity[0][1]*(kx+gx_prim)*(ky+gy)-Elasticity[3][3]*(ky+gy_prim)*(kx+gx)); gsl_matrix_set(gammaD, i, j+half+1, -Elasticity[0][1]*(ky+gy_prim)*(kx+gx)-Elasticity[3][3]*(kx+gx_prim)*(ky+gy)); gsl_matrix_set(gammaD, i+1, j+half+1, -Elasticity[0][0]*(ky+gy_prim)*(ky+gy)-Elasticity[3][3]*(kx+gx_prim)*(kx+gx)+Density*w*w); gsl_matrix_set(gammaD, i+2, j+half+2, -Elasticity[3][3]*(ky+gy_prim)*(ky+gy)-Elasticity[3][3]*(kx+gx_prim)*(kx+gx)+Density*w*w); if (i==j) { gsl_matrix_set(gammaC, i+half, j+half, 1); gsl_matrix_set(gammaC, i+half+1, j+half+1, 1); gsl_matrix_set(gammaC, i+half+2, j+half+2, 1); gsl_matrix_set(gammaD, i+half, j, 1); gsl_matrix_set(gammaD, i+half+1, j+1, 1); gsl_matrix_set(gammaD, i+half+2, j+2, 1); } } } } } //rozwiazanie zagadnienienia własnego gsl_eigen_genv(gammaD, gammaC, BAlpha, BBeta, BasisEigenVec, wspce2); double imagL, realL; //części Re i Im wartości własnych int n=0; for (int i = 0; i<dimension; i++) { //przepisanie wartości i wektorów własnych struktury do macierzy Chosen* gsl_complex StrValue; StrValue= gsl_complex_div_real(gsl_vector_complex_get(StrAlpha, i), gsl_vector_get(StrBeta,i)); gsl_vector_complex_set(ChosenValues, i, StrValue); for (int j = half, m=0; j < dimension; j++, m++) { gsl_matrix_complex_set(ChosenVectors, m, i, gsl_matrix_complex_get(StrEigenVec, j, i)); } //wybieranie odpowiednich wartości i wektorów własnych dla podłoża i przepisanie do macierzy Chosen* gsl_complex BValue; BValue= gsl_complex_div_real(gsl_vector_complex_get(BAlpha, i), gsl_vector_get(BBeta,i)); imagL=GSL_IMAG(BValue); realL=GSL_REAL(BValue); if (imagL > 0.00001 && n+EigValStrNumber<EigValNumber) //warunek na wartości własne && żeby nie było ich więcej niż połowa { gsl_vector_complex_set(ChosenValues, n+EigValStrNumber, BValue); //wybranie wartości własnej for (int j = half, m=0; j < dimension; j++, m++) { gsl_matrix_complex_set(ChosenVectors, m, n+EigValStrNumber, gsl_complex_mul_real(gsl_matrix_complex_get(BasisEigenVec, j, i), -1)); //wybranie drugiej połowy wektora własnego } n++; } } if (n+EigValStrNumber<EigValNumber) { for (int i = 0; i<dimension; i++) { gsl_complex BValue; BValue= gsl_complex_div_real(gsl_vector_complex_get(BAlpha, i), gsl_vector_get(BBeta,i)); imagL=GSL_IMAG(BValue); realL=GSL_REAL(BValue); if (imagL < 0.00001 && imagL > -0.00001 && realL < -0.00001 && n+EigValStrNumber<EigValNumber) //warunek na wartości własne && żeby nie było ich więcej niż połowa { gsl_vector_complex_set(ChosenValues, n+EigValStrNumber, BValue); //wybranie wartości własnej for (int j = half, m=0; j < dimension; j++, m++) { gsl_matrix_complex_set(ChosenVectors, m, n+EigValStrNumber, gsl_complex_mul_real(gsl_matrix_complex_get(BasisEigenVec, j, i), -1)); //wybranie drugiej połowy wektora własnego } n++; } } } //wyznacznik warunków brzegowych - konstrukcja /* S, S' - numerujš transformaty tensora sprężystoci i - numeruje wektory własne A w pętli dla G j - numeruje warunki brzegowe dla kolejnych wektorow odwrotnych G k - numeruje wektory własne A w pętli dla G' L - numeruje wartoci własne */ for (int Nx=-RecVec, S=0, S_prim=0, i=0, j=0; Nx <= RecVec; Nx++) { for (int Ny=-RecVec; Ny <= RecVec; Ny++, j=j+9, i=i+3) { for (int L=0; L < EigValNumber; L++) { S_prim = S; for (int Nx_prim=-RecVec, k=0; Nx_prim <= RecVec; Nx_prim++) { for (int Ny_prim=-RecVec; Ny_prim <= RecVec; Ny_prim++, S_prim++, k=k+3) { double StrElasticity[6][6]; itsRecStructureSubstance[S_prim].getElasticity(StrElasticity); double BasisElasticity[6][6]; itsRecBasisSubstance[S_prim].getElasticity(BasisElasticity); double gx_prim=2*M_PI*Nx_prim/a; double gy_prim=2*M_PI*Ny_prim/a; if (L < EigValStrNumber) { //eksponens gsl_complex exponent = gsl_complex_polar(exp(GSL_IMAG(gsl_vector_complex_get(ChosenValues, L))*thickness), -1*GSL_REAL(gsl_vector_complex_get(ChosenValues, L))*thickness); //warunki zerowania się naprężenia na powierzchni gsl_complex w1 = gsl_complex_mul_real(exponent, StrElasticity[3][3]); gsl_complex w2 = gsl_complex_mul_real(gsl_matrix_complex_get(ChosenVectors, k+2, L), (kx+gx_prim)); gsl_complex w3 = gsl_complex_mul(gsl_vector_complex_get(ChosenValues, L), gsl_matrix_complex_get(ChosenVectors, k, L)); gsl_complex BCjL = gsl_complex_add(gsl_complex_mul(gsl_complex_add(w2, w3), w1), gsl_matrix_complex_get(Boundaries, j, L)); gsl_matrix_complex_set(Boundaries, j, L, BCjL); w1 = gsl_complex_mul_real(exponent, StrElasticity[3][3]); w2 = gsl_complex_mul_real(gsl_matrix_complex_get(ChosenVectors, k+2, L), (ky+gy_prim)); w3 = gsl_complex_mul(gsl_vector_complex_get(ChosenValues, L), gsl_matrix_complex_get(ChosenVectors, k+1, L)); BCjL = gsl_complex_add(gsl_complex_mul(gsl_complex_add(w2, w3), w1), gsl_matrix_complex_get(Boundaries, j+1, L)); gsl_matrix_complex_set(Boundaries, j+1, L, BCjL); w1 = gsl_complex_mul_real(exponent, StrElasticity[0][0]); gsl_complex w11 = gsl_complex_mul_real(exponent, StrElasticity[0][1]); w2 = gsl_complex_mul_real(gsl_matrix_complex_get(ChosenVectors, k, L), (kx+gx_prim)); gsl_complex w22 = gsl_complex_mul_real(gsl_matrix_complex_get(ChosenVectors, k+1, L), (ky+gy_prim)); w3 = gsl_complex_mul(gsl_vector_complex_get(ChosenValues, L), gsl_matrix_complex_get(ChosenVectors, k+2, L)); gsl_complex w4 = gsl_complex_add(gsl_complex_mul(gsl_complex_add(w2, w22), w11), gsl_complex_mul(w3, w1)); BCjL = gsl_complex_add(w4, gsl_matrix_complex_get(Boundaries, j+2, L)); gsl_matrix_complex_set(Boundaries, j+2, L, BCjL); //warunki równości naprężeń na granicy ośrodków - część dla struktury w2 = gsl_complex_mul_real(gsl_matrix_complex_get(ChosenVectors, k+2, L), (kx+gx_prim)); w3 = gsl_complex_mul(gsl_vector_complex_get(ChosenValues, L), gsl_matrix_complex_get(ChosenVectors, k, L)); BCjL = gsl_complex_add(gsl_complex_mul_real(gsl_complex_add(w2, w3), StrElasticity[3][3]), gsl_matrix_complex_get(Boundaries, j+3, L)); gsl_matrix_complex_set(Boundaries, j+3, L, BCjL); w2 = gsl_complex_mul_real(gsl_matrix_complex_get(ChosenVectors, k+2, L), (ky+gy_prim)); w3 = gsl_complex_mul(gsl_vector_complex_get(ChosenValues, L), gsl_matrix_complex_get(ChosenVectors, k+1, L)); BCjL = gsl_complex_add(gsl_complex_mul_real(gsl_complex_add(w2, w3), StrElasticity[3][3]), gsl_matrix_complex_get(Boundaries, j+4, L)); gsl_matrix_complex_set(Boundaries, j+4, L, BCjL); w2 = gsl_complex_mul_real(gsl_matrix_complex_get(ChosenVectors, k, L), (kx+gx_prim)); w22 = gsl_complex_mul_real(gsl_matrix_complex_get(ChosenVectors, k+1, L), (ky+gy_prim)); w3 = gsl_complex_mul(gsl_vector_complex_get(ChosenValues, L), gsl_matrix_complex_get(ChosenVectors, k+2, L)); w4 = gsl_complex_add(gsl_complex_mul_real(gsl_complex_add(w2, w22), StrElasticity[0][1]), gsl_complex_mul_real(w3, StrElasticity[0][0])); BCjL = gsl_complex_add(w4, gsl_matrix_complex_get(Boundaries, j+5, L)); gsl_matrix_complex_set(Boundaries, j+5, L, BCjL); } else { //warunki równości naprężeń na granicy ośrodków - część dla podłoża gsl_complex w2 = gsl_complex_mul_real(gsl_matrix_complex_get(ChosenVectors, k+2, L), (kx+gx_prim)); gsl_complex w3 = gsl_complex_mul(gsl_vector_complex_get(ChosenValues, L), gsl_matrix_complex_get(ChosenVectors, k, L)); gsl_complex BCjL = gsl_complex_add(gsl_complex_mul_real(gsl_complex_add(w2, w3), BasisElasticity[3][3]), gsl_matrix_complex_get(Boundaries, j+3, L)); gsl_matrix_complex_set(Boundaries, j+3, L, BCjL); w2 = gsl_complex_mul_real(gsl_matrix_complex_get(ChosenVectors, k+2, L), (ky+gy_prim)); w3 = gsl_complex_mul(gsl_vector_complex_get(ChosenValues, L), gsl_matrix_complex_get(ChosenVectors, k+1, L)); BCjL = gsl_complex_add(gsl_complex_mul_real(gsl_complex_add(w2, w3), BasisElasticity[3][3]), gsl_matrix_complex_get(Boundaries, j+4, L)); gsl_matrix_complex_set(Boundaries, j+4, L, BCjL); w2 = gsl_complex_mul_real(gsl_matrix_complex_get(ChosenVectors, k, L), (kx+gx_prim)); gsl_complex w22 = gsl_complex_mul_real(gsl_matrix_complex_get(ChosenVectors, k+1, L), (ky+gy_prim)); w3 = gsl_complex_mul(gsl_vector_complex_get(ChosenValues, L), gsl_matrix_complex_get(ChosenVectors, k+2, L)); gsl_complex w4 = gsl_complex_add(gsl_complex_mul_real(gsl_complex_add(w2, w22), BasisElasticity[0][1]), gsl_complex_mul_real(w3, BasisElasticity[0][0])); BCjL = gsl_complex_add(w4, gsl_matrix_complex_get(Boundaries, j+5, L)); gsl_matrix_complex_set(Boundaries, j+5, L, BCjL); } } } // warunek równości wychyleń na granicy ośrodków gsl_matrix_complex_set(Boundaries, j+6, L, gsl_matrix_complex_get(ChosenVectors, i, L)); gsl_matrix_complex_set(Boundaries, j+7, L, gsl_matrix_complex_get(ChosenVectors, i+1, L)); gsl_matrix_complex_set(Boundaries, j+8, L, gsl_matrix_complex_get(ChosenVectors, i+2, L)); } S=S_prim; } } //skalowanie macierzy Boundaries gsl_complex scale=gsl_complex_rect(pow(10, factor), 0); gsl_matrix_complex_scale(Boundaries, scale); //obliczenie wyznacznika z Boundaries gsl_permutation *Bpermutation = gsl_permutation_alloc(EigValNumber); int Bsignum; gsl_linalg_complex_LU_decomp(Boundaries, Bpermutation, &Bsignum); double DetVal = gsl_linalg_complex_LU_lndet(Boundaries); //usuwanie NaN if(DetVal != DetVal) DetVal = 0; //zapisanie wartości do pliku plik << k_zred << "\t" << w << "\t" << DetVal << "\n"; } plik << "\n"; } } plik.close(); gsl_matrix_free(gammaA); gsl_matrix_free(gammaB); gsl_vector_free(BBeta); gsl_vector_free(StrBeta); gsl_matrix_free(gammaC); gsl_matrix_free(gammaD); gsl_vector_complex_free(StrAlpha); gsl_vector_complex_free(BAlpha); gsl_eigen_genv_free(wspce); gsl_eigen_genv_free(wspce2); gsl_matrix_complex_free(Boundaries); gsl_matrix_complex_free(ChosenVectors); gsl_vector_complex_free(ChosenValues); }
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 }