示例#1
0
文件: test.c 项目: majorana/QED3
void calculate_fermion_force() 
{
  	int i;
	double fft[GRIDPOINTS];
	double ffx[GRIDPOINTS];
	double ffy[GRIDPOINTS];

	for(i=0; i<GRIDPOINTS; i++)
 	{
  		g_R[i] = (gauss() + I*gauss())/sqrt(2); //Pseudofermion fields times M^{-1} 
 	};
  	fermion(g_fermion, g_R); //g_fermion the pseudofermion field, i.e. phi = M R

  	//g_cgiterations1 += cg(g_eta, g_fermion, ITER_MAX, DELTACG, &fermion_sqr);
  	for(i = 0; i < GRIDPOINTS; i++) {
		//printf("%d \n", i);
		//printf("Brute-force %f\n", stupid_fermion_force_x(i));
		//printf("Smart %f\n", fermion_forcex(i));
		ffx[i] = stupid_fermion_force_x(i);
		printf("Brute-force %d, %f\n", i, ffx[i]);
		//fft[i] = fermion_forcet(i);
		//ffy[i] = fermion_forcey(i);
  	}
	print_vector_r(ffx);
	//print_vector_r(fft);
	printf("Max x fermion force: %f\n", max_r(ffx));
	//printf("Max t fermion force: %f\n", max_r(fft));
  	return;
}
Real GreensFunction3DSym::drawR(Real rnd, Real t) const
{
    // input parameter range checks.
    if ( !(rnd <= 1.0 && rnd >= 0.0 ) )
    {
        throw std::invalid_argument( ( boost::format( "GreensFunction3DSym: rnd <= 1.0 && rnd >= 0.0 : rnd=%.16g" ) % rnd ).str() );
    }

    if ( !(t >= 0.0 ) )
    {
        throw std::invalid_argument( ( boost::format( "GreensFunction3DSym: t >= 0.0 : t=%.16g" ) % t ).str() );
    }


    // t == 0 or D == 0 means no move.
    if( t == 0.0 || getD() == 0.0 )
    {
        return 0.0;
    }

    ip_r_params params = { this, t, rnd };

    gsl_function F = 
        {
            reinterpret_cast<double (*)(double, void*)>( &ip_r_F ),
            &params 
        };

    Real max_r( 4.0 * sqrt( 6.0 * getD() * t ) );

    while( GSL_FN_EVAL( &F, max_r ) < 0.0 )
    {
        max_r *= 10;
    }

    const gsl_root_fsolver_type* solverType( gsl_root_fsolver_brent );
    gsl_root_fsolver* solver( gsl_root_fsolver_alloc( solverType ) );
    gsl_root_fsolver_set( solver, &F, 0.0, max_r );

    const unsigned int maxIter( 100 );

    unsigned int i( 0 );
    while( true )
    {
        gsl_root_fsolver_iterate( solver );
        const Real low( gsl_root_fsolver_x_lower( solver ) );
        const Real high( gsl_root_fsolver_x_upper( solver ) );
        const int status( gsl_root_test_interval( low, high, 1e-15, 
                                                  this->TOLERANCE ) );

        if( status == GSL_CONTINUE )
        {
            if( i >= maxIter )
            {
                gsl_root_fsolver_free( solver );
                throw std::runtime_error("GreensFunction3DSym: drawR: failed to converge");
            }
        }
        else
        {
            break;
        }

        ++i;
    }
  
    //printf("%d\n", i );

    const Real r( gsl_root_fsolver_root( solver ) );
    gsl_root_fsolver_free( solver );
    
    return r;
}