Exemple #1
0
main(int argc, char** argv)
{
  if (argc != 2) {
    fprintf(stderr, "usage: params filename\n");
    exit(1);
  }
  if (read_param_file(argv[1])) {
    print_params(stdout);
    for (;;) {
      char type;
      char name[100], line[100];

      printf("> ");
      gets(line);
      if (sscanf(line, "%c %s", &type, name) != 2) return;
      switch (type) {
        case 's': printf("%s\n", string_param(name)); break;
	case 'b': printf("%d\n", bool_param(name)); break;
	case 'i': printf("%d\n", int_param(name)); break;
	case 'd': printf("%lf\n", double_param(name)); break;
	default: printf("unknown type %c\n", type);
      }
    }
  }
}
Exemple #2
0
int main(int argc,char *argv[]){

  char f_out_name[BUFSIZ];
  double *A, *gh, *r, *c, *refl;
  int lgh,lr,lc,lA,lh;
  
  

  param_file_type param[Nparam] = 
    {{"gh:" ,"DATA_FILE" ,&gh  ,&lgh ,2*sizeof(double)},
     {"r:"  ,"DATA_FILE" ,&r   ,&lr  ,2*sizeof(double)},
     {"c:"  ,"DATA_FILE" ,&c   ,&lc  ,sizeof(double)},
     {"Al:" ,"DATA_FILE" ,&A   ,&lA  ,sizeof(double)},
     {"refl:","DATA_FILE",&refl,&lh  ,sizeof(double)},
     {"res1:","%s ",&f_out_name,NULL,0}};
    
  FILE *f_param;

  printf("\n ------ MTEX -- read paramater test -------- \n");

  if (argc<2) {
    printf("Error! Missing parameter - parameter_file.\n");
    printf("%s\n",argv[0]);
    abort();
  }
  
  /* read parameter file */
  f_param = check_fopen(argv[1],"r");
  if (read_param_file(f_param,param,Nparam,argc==2)+1<Nparam){
    printf("Some parameters not found!");
    abort();
  }
  fclose(f_param);

  printf("\n print A: \n");

  print_double(stdout,A,lA);

  printf("\n");
  
  /* free memory */
  free(gh);
  free(r);
  free(refl);
  free(c);
  
  return(0);
}
Exemple #3
0
int main (int argc, char *argv[]){

	mpfr_t *lambda, *kappa;
	
	char f_out_name[BUFSIZ];
	int d,iters,n, k, nk,nf,na,nb;
	double *lambdas, *kappas, *f,*a,*b;
		
	param_file_type param[Nparam] = 
    {{"d:"     , "%d", &d,       NULL, sizeof(int)},
     {"iter:"  , "%d", &iters,   NULL, sizeof(int)},
	 {"lambda:", "DATA_FILE", &lambdas, &n , sizeof(double)},
	 {"kappa:", "DATA_FILE", &kappas, &nk , sizeof(double)},  /*psi*/
	 {"h:", "DATA_FILE", &f, &nf , sizeof(double)},           /*odf*/
	 {"a:", "DATA_FILE", &a, &na , sizeof(double)},          /*pdf a*/
	 {"bc:", "DATA_FILE", &b, &nb , sizeof(double)},          /*pdf sqrt(b^2 + c^2)*/
	 {"res1:","%s ", &f_out_name,NULL, 0}};
    
	FILE *f_param;
	FILE *f_out;

	if (argc<2) {
		printf("Error! Missing parameter - parameter_file.\n");
		printf("%s\n",argv[0]);
		abort();
	}
	  
	/* read parameter file */
	f_param = check_fopen(argv[1],"r");
	if (read_param_file(f_param,param,Nparam,argc==2)<Nparam){	
		/*printf("Some parameters not found!");*/
		/*abort();*/
	}
	fclose(f_param);
	
	/* precission & delta */
	init_prec(d);
	
	long int prec = d;
	
	
	if (nk>0) {   /* kappas given*/
		mpfr_t C;
		
		kappa = (mpfr_t*) malloc (nk*sizeof(mpfr_t));
		
		for(k=0;k<nk;k++){ 
			mpfr_init2(kappa[k],prec);
			mpfr_init_set_d(kappa[k], kappas[k],prec);
		}
		
		mhyper(C, kappa, nk);
		
		/* gmp_printf("C: %.*Fe \n ", 20, C);	*/
		
		if (nf>0) /* eval odf values*/
		{
			eval_exp_Ah(C,f,nf);
			
			f_out = check_fopen(f_out_name,"wb");
			fwrite(f,sizeof(double),nf,f_out);
			fclose(f_out);
		} 
		if ( na > 0) {/* eval pdf values*/
		
		/* testing BesselI[0,a]
			mpfr_t in, out;					
						
			for(k=0;k<na;k++){
			
				mpfr_init2(in, prec);
				mpfr_set_d(in,	a[k],prec);
				mpfr_init2(out, prec);
				
				mpfr_i0(out, in, prec);
				
				
				mpfr_printf ("%.1028RNf\ndd", out);
				
				a[k] = mpfr_get_d(out,prec);
				
			}
				
			f_out = check_fopen(f_out_name,"wb");
			fwrite(a,sizeof(double),na,f_out);
			fclose(f_out);
		*/
		
			
			eval_exp_besseli(a,b,C,na);
				
			f_out = check_fopen(f_out_name,"wb");
			fwrite(a,sizeof(double),na,f_out);
			fclose(f_out);
		}
		
		if (nf == 0 && na == 0) { /* only return constant */
	
			double CC = mpfr_get_d(C,prec);
			
			f_out = check_fopen(f_out_name,"wb");
			fwrite(&CC,sizeof(double),1,f_out);
			fclose(f_out);
		
		}
	
	} else {	/* solve kappas */
		/* copy input variables */	
		lambda = (mpfr_t*) malloc (n*sizeof(mpfr_t));
		kappa = (mpfr_t*) malloc (n*sizeof(mpfr_t));	
		
		for(k=0;k<n;k++){ 
				mpfr_init_set_ui(kappa[k],0,prec);
				mpfr_init_set_d(lambda[k],lambdas[k],prec);
			}
			
				
		if(iters>0){		
			/* check input */
			mpfr_t tmp;
			mpfr_init(tmp);
			mpfr_set_d(tmp,0,prec);
			
			for(k=0;k<n;k++){
				mpfr_add(tmp,tmp,lambda[k],prec);
			}
			
			mpfr_ui_sub(tmp,1,tmp,prec);
			mpfr_div_ui(tmp,tmp,n,prec);
			
			for(k=0;k<n;k++){ 		
				mpfr_add(lambda[k],lambda[k],tmp,prec);
			}
			
			mpfr_init2(tmp,prec);
			for(k=0;k<n;k++){
				mpfr_add(tmp,tmp,lambda[k],prec);
			}
			
			mpfr_init2(tmp,prec);
			if( mpfr_cmp(lambda[min_N(lambda,n)],tmp) < 0 ){
				printf("not well formed! sum should be exactly 1 and no lambda negativ");
				exit(0);
			}
			
			
			/* solve the problem */	
			newton(iters,kappa, lambda, n);

		} else {
			guessinitial(kappa, lambda, n);
		}
		
				
		for(k=0;k<n;k++){
			lambdas[k] = mpfr_get_d(kappa[k],GMP_RNDN);	/* something wents wront in matlab for 473.66316276431799;*/
								/* % bug:   lambda= [0.97 0.01 0.001];*/
		}
			
		f_out = check_fopen(f_out_name,"wb");
		fwrite(lambdas,sizeof(double),n,f_out);
		fclose(f_out);
		
		free_N(lambda,n);
		free_N(kappa,n);
		
	}
	
	
	

	
  
	return EXIT_SUCCESS;
}
Exemple #4
0
int main(int argc, char *argv[]) {
    int j;
    int n;
    int status;
    char directory[256],outputdir[256];



    if (argc > 4) {
        printf("Too many arguments.Only using first 3.\n");
    }
    n = atoi(argv[1]);
    time_step = atof(argv[2]);
    strcpy(directory,argv[3]);

    nb = 2;

    sprintf(outputdir,"%stemp_files/",directory);
    status = mkdir(outputdir,S_IRWXU | S_IRWXG | S_IRWXO);
    if (status == -33)  {
        printf("Status is -33 for some reason.\n");
    }
    //sprintf(param_fname,"%sparam_file.txt",directory);


    
    read_param_file(directory);
    nx = params.nx;
    ny = params.ny;
    nz = params.nz;
    CFL = params.cfl;
    IndirectTerm = params.indirect;

    size_x = nx;
    size_y = ny+2*NGHY;
    size_z = nz;
    stride = size_x*size_y;
    pitch = size_x;
    pitch2d = 0;
    //size_t double_to_int = sizeof(double)/sizeof(int);
    pitch2d_int = 0 ;//pitch*(int)double_to_int;
    dx = 2*M_PI/nx;

    if (size_x % 2 == 0) NEVEN = TRUE;
    else NEVEN = FALSE;

    num_threads = 1;

#ifdef _OPENMP
    //omp_set_num_threads(8);
    num_threads = omp_get_max_threads();
    printf("Using %d threads\n",num_threads);
#endif
    allocate_all();
#ifdef _FFTW
    allocate_conv();
#endif
    read_domain(directory);
    
    
    read_files(n,directory);
    //read_single_file(n,1,directory);
    /*
    if (cfl_dt < dt) {
        printf("Using cfl limited timestep of %.4e instead of %.4e\n",cfl_dt,dt);
        dt = cfl_dt;
    }
    */

    
    //move_to_com();


    read_stockholm(directory);
/*
    for(j=0;j<size_y;j++) {
        dens0[j] = params.mdot/(3*M_PI*Nu(ymed(j)));
        vy0[j] = -1.5*Nu(ymin(j))/ymin(j);
        vx0[j] = pow(ymed(j),-.5);
	    vx0[j] *= sqrt(1.0+pow(params.h,2)*pow(ymed(j),2*params.flaringindex)*
			  (2.0*params.flaringindex - 1.5));
        vx0[j] -= omf*ymed(j);

    }
*/
    omf0 = omf;

    output_stock(outputdir);

    output_init(outputdir);
   
    init_rk5();
    nsteps = 0;
    double tstart = psys[0].t;
    double tend = psys[0].t + time_step;
    double time = tstart;


#ifdef _FFTW
    printf("Using FFTW to compute fourier transforms\n");
#endif
#ifdef ARTIFICIALVISCOSITY
    printf("Using ARTIFICIAL VISCOSITY\n");
#endif
#ifdef FARGO
    printf("Using FARGO TRANSPORT\n");
#endif
#ifdef STOCKHOLMACC
    printf("Damping to current average in stockholm boundaries.\n");
#endif
#ifdef NOWAVEKILLRHO
    printf("Not damping the density.\n");
#endif
#ifdef FIXEDPSYS
    printf("Planetary system is FIXED.\n");
#endif
    printf("Starting time = %.3f\nEnding time = %.3f\n",tstart,tend);
    set_bc();

    set_dtLt(-1.0);

    while ((time < tend) && nsteps<MAXSTEPS) {
#ifdef FARGO
        compute_vmed(vx);
#endif
        dt = cfl();
        if (dt <= MINDT) {
            printf("Timestep has fallen below minimum!\n");
            break;
        }
        if (time + dt > tend) {
            dt = tend-time;
        }
        printf("\r t=%.3f, dt = %.8f,  %02d%% complete...",time,dt,(int)(100*(time-tstart)/(tend-tstart)));
        fflush(stdout);
        set_avg(0);
    
        potential();
        
#ifndef FIXEDPSYS
        move_planet();
#endif
    
       
        source_step();
       
        set_Lamex();
        viscosity();
#ifdef ARTIFICIALVISCOSITY
        
        artificial_visc();
#endif
    
        temp_to_vel();
        set_bc();
        
        vel_to_temp();
       
#ifdef FARGO
        compute_vmed(vx_temp);
#endif        
        transport_step();
        
        time += dt;
      
        set_avg(1);

        set_Lamdep();

        set_bc();
        stockholm();
        //output_psys(outputdir,nsteps);
        nsteps++;
    }
//    temp_to_vel();   

    set_dtLt(1.0);

    
    dt = tend - tstart;
    for(j=0;j<size_y;j++) {
        dbart[j]/=dt;
        //Lt[j]/=dt;
        //Lt[j+size_y]/=dt;
        //Ld[j]/=dt;
        //Ld[j+size_y]/=dt;
        //Lw[j]/=dt;
        //Lw[j+size_y]/=dt;
        Lw[j] = Lt[j] - Ld[j];
        Lw[j+size_y] = Lt[j+size_y] - Ld[j+size_y];
        drFt[j]/=dt;
        drFd[j]/=dt;
        drFdB[j]/=dt;
        mdotl[j]/=dt;
        drFnu[j]/=dt;
        drFw[j]/=dt;
        drFwB[j]/=dt;
        Lamex[j]/=dt;
        //Lamex[j+size_y]/=dt;
        Lamdep[j]/=dt;
        LamdepB[j]/=dt;
        dtLt[j]/=dt;
        dtLd[j]/=dt;
        dtLw[j]/=dt;
        dtLd_rhs[j]/=dt;
        mdotavg[j] /= dt;
        LamdepS[j + size_y*0] /= dt;
        LamdepS[j + size_y*1] /= dt;
        LamdepS[j + size_y*2] /= dt;
        LamdepS[j + size_y*3] /= dt;
        LamdepS[j + size_y*4] /= dt;
        LamdepS[j + size_y*5] /= dt;
        LamdepS[j + size_y*6] /= dt;
    }
    int mi;
    for(mi=1;mi<MMAX+2;mi++) {
        for(j=0;j<size_y;j++) {
            Lamex[j + size_y*mi] /= dt;
            drFd[j + size_y*mi] /= dt;
            dtLt[j + size_y*mi] /= dt;

        }
    }

    output(outputdir);
    output_torque(directory,n);
    output_torque(outputdir,n);
    free_rk5();
#ifdef _FFTW
    free_conv();
#endif
    //free_all();
    return 0;
}