Exemple #1
0
static
int cfuncall (const double kc, const double c[], double f[], void *params) // calculate all components simultaneously
{
	size_t n,m,q;
	const size_t NB=model->total_bands;
    const size_t N2=NB*NB;
    
    const odeparams pars = * (odeparams *) params;
    const ThreeVector dir = pars.dir;
    
    complex double * cc = (complex double*) c;
    complex double * fc = (complex double*) f;
    
    // calculate matrix elements from c[]

    ThreeVector k = dir;
    three_vector_scale(&k,kc);
    if (!pars.pos)
        three_vector_scale(&k,-1.0);
    three_vector_incr(&k,&pars.kperp);
    
    if(fabs(dir.x[0])>1e-5*three_vector_length(&dir)) {
      model->dHdx (dHx, &k);
    }
    if(fabs(dir.x[1])>1e-5*three_vector_length(&dir)) {
      model->dHdy (dHy, &k);
    }
    if(fabs(dir.x[2])>1e-5*three_vector_length(&dir)) {
      model->dHdz (dHz, &k);
    }

    three_vector_array_project_inplace ((double*) wc, (double *) dHx, (double *) dHy, (double *) dHz, &dir, 2*N2);
    
    complex double *W = model->buffer1;
    complex_array_zero(W,N2);
    matrix_transform (W, cc, wc, NB);
    
    memset(f, 0, sizeof(double)*(2*N2+NB));

    for (n=0;n<NB;n++) {
        Op(n) = creal(W[n+n*NB]);
    }
    for (n=0;n<NB;n++) {
        for (q=0;q<NB;q++) {
            double omegadiff=O(n)-O(q);
            if (fabs(omegadiff)>1e-11) {  // was 1e-12
                complex double aa = W[q*NB+n]/omegadiff;
                for (m=0;m<NB;m++) {
                    F(m,n)+=aa*C(m,q);
                }
            }
        }
    }
    if (!pars.pos)
        for (m=0;m<2*N2+NB;m++)
        	f[m]=-f[m];
        
	return GSL_SUCCESS;
}
Exemple #2
0
DECLARE_TEST(matrix, vec) {
	vector_t vec;

	VECTOR_ALIGN float32_t aligned_rotm[] = {
		0, 2, 0, 11,
		0, 0, 3, 12,
		1, 0, 0, 13,
		7, 8, 9, 10
	};

	VECTOR_ALIGN float32_t aligned_tformm[] = {
		0, 2, 0, 0,
		0, 0, 3, 0,
		1, 0, 0, 0,
		-1, 2, 5, 1
	};

	vec = matrix_rotate(matrix_zero(), vector_zero());
	EXPECT_VECTOREQ(vec, vector_zero());

	vec = matrix_rotate(matrix_zero(), vector_one());
	EXPECT_VECTOREQ(vec, vector(0, 0, 0, 1));

	vec = matrix_rotate(matrix_identity(), vector_one());
	EXPECT_VECTOREQ(vec, vector_one());

	vec = matrix_rotate(matrix_aligned(aligned_rotm), vector_xaxis());
	EXPECT_VECTOREQ(vec, vector(0, 2, 0, 1));

	vec = matrix_rotate(matrix_aligned(aligned_rotm), vector_yaxis());
	EXPECT_VECTOREQ(vec, vector(0, 0, 3, 1));

	vec = matrix_rotate(matrix_aligned(aligned_rotm), vector_zaxis());
	EXPECT_VECTOREQ(vec, vector(1, 0, 0, 1));

	vec = matrix_transform(matrix_zero(), vector_zero());
	EXPECT_VECTOREQ(vec, vector_zero());

	vec = matrix_transform(matrix_zero(), vector_one());
	EXPECT_VECTOREQ(vec, vector(0, 0, 0, 0));

	vec = matrix_transform(matrix_identity(), vector_one());
	EXPECT_VECTOREQ(vec, vector_one());

	vec = matrix_transform(matrix_aligned(aligned_tformm), vector_xaxis());
	EXPECT_VECTOREQ(vec, vector(-1, 4, 5, 1));

	vec = matrix_transform(matrix_aligned(aligned_tformm), vector_yaxis());
	EXPECT_VECTOREQ(vec, vector(-1, 2, 8, 1));

	vec = matrix_transform(matrix_aligned(aligned_tformm), vector_zaxis());
	EXPECT_VECTOREQ(vec, vector(0, 2, 5, 1));

	return 0;
}
Exemple #3
0
void transform_starfield()
{
     int    i;
     Matrix m = *camera;

     matrix_multiply( &m, projection );

     for (i=0; i<STARFIELD_SIZE; i++) {
          matrix_transform( &m, &starfield[i].pos, &t_starfield[i].pos );

          if (t_starfield[i].pos.v[W]) {
               t_starfield[i].pos.v[X] /= t_starfield[i].pos.v[W];
               t_starfield[i].pos.v[Y] /= t_starfield[i].pos.v[W];
          }

          t_starfield[i].pos.v[X] += xres/2;
          t_starfield[i].pos.v[Y] += yres/2;
     }
}