/** Scalar product operator (vector) */ complex vector<complex>::operator*(const vector<complex>& v) const { complex z1(0., 0., false); vector<complex> v1(_vector); if (gsl_blas_zdotu(v1.as_gsl_type_ptr(), v.as_gsl_type_ptr(), z1.as_gsl_type_ptr())) { std::cout << "\n Error in vector<complex> *" << std::endl; exit(EXIT_FAILURE); } return z1; }
static VALUE rb_gsl_blas_zdotu(int argc, VALUE *argv, VALUE obj) { gsl_complex *r; int status; gsl_vector_complex *x = NULL, *y = NULL; get_vector_complex2(argc, argv, obj, &x, &y); r = ALLOC(gsl_complex); status = gsl_blas_zdotu(x, y, r); return Data_Wrap_Struct(cgsl_complex, 0, free, r); }
/** * C++ version of gsl_blas_zdotu(). * @param X First vector * @param Y Second vector * @param dotu Vector product * @return Error code on failure */ int zdotu( vector_complex const& X, vector_complex const& Y, complex* dotu ){ return gsl_blas_zdotu( X.get(), Y.get(), &dotu->get() ); }
double Calculator::getIntensity(double Q) { std::complex<double> cppf1, cppf2; gsl_complex alpha, beta; gsl_complex gslf1, gslf2; int s; double avFactor; cppf1 = m_sf1->F(0.0, 0.0, Q, m_energy); cppf2 = m_sf2->F(0.0, 0.0, Q, m_energy); gslf1 = gsl_complex_rect(cppf1.real(), cppf1.imag()); gslf2 = gsl_complex_rect(cppf2.real(), cppf2.imag()); avFactor = exp(-2.0 / m_N); alpha = gsl_complex_rect (1.0, 0.0); beta = gsl_complex_rect (0.0, 0.0); /*set vector F (scattering factors)*/ gsl_vector_complex_set(F, 0, gslf1); gsl_vector_complex_set(F, 1, gslf2); /*set vector conj(F) (scattering factors)*/ gsl_vector_complex_set(Fconj, 0, gsl_complex_conjugate(gslf1)); gsl_vector_complex_set(Fconj, 1, gsl_complex_conjugate(gslf2)); /*set exp matrix*/ setMatrixExp(m_Exp, Q); /*find W = P * Exp * Ps * conj(F) vector:*/ /* (1) W = alpha * Ps * conj(F) + beta * W */ gsl_blas_zgemv (CblasNoTrans, alpha, m_Ps, Fconj, beta, W); /*printf("W(1):\n"); gsl_vector_complex_fprintf (stdout, W, "%g");*/ /* (2) W = alpha * Exp * tmp_vec + beta * W */ gsl_blas_zgemv (CblasNoTrans, alpha, m_Exp, W, beta, tmp_vec); /*printf("W(2):\n"); gsl_vector_complex_fprintf (stdout, tmp_vec, "%g");*/ /* (3) W = alpha * P * tmp_vec + beta * W */ gsl_blas_zgemv (CblasNoTrans, alpha, m_P, tmp_vec, beta, W); /*Find J0 = F.(Ps * conj(F)) */ gsl_blas_zgemv (CblasNoTrans, alpha, m_Ps, Fconj, beta, tmp_vec); gsl_blas_zdotu (F, tmp_vec, &J0); /*alpha = exp(-2 / N)*/ alpha = gsl_complex_rect (avFactor, 0.0); beta = gsl_complex_rect (0.0, 0.0); /*find T matrix: T = alpha * P * exp + beta * T*/ gsl_blas_zgemm (CblasNoTrans, CblasNoTrans, alpha, m_P, m_Exp, beta, T); /*printf("T:\n"); gsl_matrix_complex_fprintf (stdout, T, "%g");*/ /*Find Jns = F. (G * W) */ /*tmp_mat = I */ gsl_matrix_complex_set_identity (tmp_mat); /*tmp_mat = I - T */ gsl_matrix_complex_sub (tmp_mat, T); /*LU decomposition*/ gsl_linalg_complex_LU_decomp(tmp_mat, perm, &s); /*calculate product G * W = (I - T)^(-1) W directly using LU decomposition*/ gsl_linalg_complex_LU_solve (tmp_mat, perm, W, tmp_vec); /*calculate F.(G * W)*/ gsl_blas_zdotu (F, tmp_vec, &Jns); /*Find Js = F.(G^2 * (I - T^N) * W) however, this term should be negligible*/ /*result = N *(2 * Jns + J0) - Js */ alpha = gsl_complex_mul_real (Jns, 2.0 * avFactor); alpha = gsl_complex_add (alpha, J0); return m_N * m_I0 * GSL_REAL(alpha) * getPLGfactor(getTheta(Q)) + m_Ibg; }