void initialize() {
  int i,j ;

  idum =   -long( time(0) ) ; // 9 ; //

//  read_input() ;

  if ( phiP + phiHA + phiHB + phiHC> 1.0 )
    die("Invalid volume fractions!\n") ;

   
  for(i =0 ; i<4 ; i++)
    wall_lamb[i] *= kappa;
  lagrange_weights = 0 ;
  spline_weights = 1 ;

  mem_use = 0. ;

  M = 1 ;
  V = 1.0 ;
  grid_per_partic = 1 ;
  for ( j=0 ; j<Dim ; j++ ) {
    V *= L[j] ;
    M *= Nx[j] ;
    dx[j] = L[j] / double( Nx[j] ) ;
    Lh[j] = 0.5 * L[j] ;
    grid_per_partic *= ( pmeorder + 1 ) ;
    printf("dx: %lf\n" , dx[j] ) ;
  }
  gvol = V / double( M ) ;

  // This is used for density fields //
  ntypes = Nsp+1 ;
  
  cout<<"ntypes "<<ntypes<<endl;

  Rg = sqrt( double( Nda + Ndb ) / 6.0 ) ;
  Rg3 = Rg * Rg * Rg ;
  Range = Rg *0.2;
  cout<<"Range "<<Range<<endl;
  Range2 = Range *Range;
  rho0 = C * double( Nda + Ndb ) / Rg3 ;
  chiAB = chiAB / double( Nda + Ndb ) ;
  chiAC = chiAC / double( Nda + Ndb ) ;
  chiBC = chiBC / double( Nda + Ndb ) ;
  
  kappa = kappa / double( Nda + Ndb ) ;
  kappa_p = kappa_p / double( Nda + Ndb ) ;
  cout<<"kN "<<kappa*( Nda + Ndb )<<" chiABN "<<( Nda + Ndb )*chiAB<<endl;
  
 double  rdc_V = V * (L[2]-wall_thick*2)/L[2];

  nD = int( ( 1.0 - phiHA - phiHB - phiP -phiHC) * rho0 * rdc_V / ( Nda + Ndb ) * CG_ratio ) ;
  nA = int( phiHA * rho0 * rdc_V / Nha * CG_ratio ) ;
  nB = int( phiHB * rho0 * rdc_V / Nhb * CG_ratio ) ;
  nC = int( phiHC * rho0 * rdc_V / Nhc * CG_ratio ) ; 

  Vp = rho0 ;

  if ( Dim == 2 )
    Vp *= PI * Rp * Rp ;
  else if ( Dim == 3 )
    Vp *= 4.0 * PI * Rp * Rp * Rp / 3.0 ;



  ////////////////////////////////////////
  // Initialize nanoparticle parameters //
  ////////////////////////////////////////
  Diff[2] *= 1.0 / Vp ;

  p_m = Vp;

  Diff_rot *= 1.0 / Vp / Rp / Rp ;


  nP = nsP = 0.0 ;

  if ( phiP > 0.0 ) {

    if ( sigma > 0.0 ) {
      if ( Dim == 2 )
        ng_per_partic = int( sigma * PI * Rp * 2.0 ) ;
      else if ( Dim == 3 )
        ng_per_partic = int ( sigma * 4.0 * PI * Rp * Rp ) ;
    }
    else
      ng_per_partic = 0 ;

    nP = int( phiP * rho0 * rdc_V /(Vp+ Ng * ng_per_partic * CG_ratio )) ;
    //nP = int( phiP * rho0 * V /(Vp));

    printf("nP = %d particles with %d grafted chains per particle\n" , 
        nP , ng_per_partic ) ;

  }

  //nD = int( (( 1.0 - phiHA - phiHB - phiP ) * rho0 * V - nP*Ng*ng_per_partic )/ ( Nda + Ndb ) * CG_ratio ) ;
  //nA = int( phiHA * rho0 * V / Nha * CG_ratio ) ;
  //nB = int( phiHB * rho0 * V / Nhb * CG_ratio ) ;

 
  nsD = nD * (Nda + Ndb) ;
  nsA = nA * Nha ;
  nsB = nB * Nhb ;
  nsC = nC * Nhc ; 
  nsP = nP * ( 1 + ng_per_partic * ( Ng + 1 ) ) ; // + 1 because of the graft site

  printf("Input rho0: %lf , " , rho0 ) ;
 
  rho0 = ( nD * (Nda + Ndb ) + nA * Nha + nB * Nhb + nC*Nhc+nP * (Vp + ng_per_partic * Ng ) ) / rdc_V / CG_ratio ;
  printf("actual rho0: %lf\n" , rho0 ) ;

  printf("\nnD: %d\nnA: %d\nnB: %d\nnC: %d\nnP: %d\n\n" , nD, nA, nB, nC, nP ) ;

  // Derived quantities //
  nstot = nA * Nha + nB * Nhb + nD * ( Nda + Ndb ) + nC*Nhc 
    + nP * ( 1 + ng_per_partic * ( Ng + 1 ) ) ;
 
  step = 0 ;
  num_averages = 0.0 ;
  
  buff_ind = 0 ;
  if ( stress_freq > print_freq )
    stress_freq = print_freq ;

  if ( stress_freq > 0 )
    buff_size = print_freq / stress_freq + 1;
  else
    buff_size = 0 ;

  I = complex<double>( 0.0 , 1.0 ) ;

    printf("Total segments: %d\n" , nstot ) ;
    printf("grid_vol: %lf\n" , gvol ) ;
    printf("Particles per grid point: %lf\n" , double(nstot) / double(M) ) ;

  fft_init() ;
    printf("FFTW-MPI Initialized\n") ; fflush( stdout ) ;

  allocate() ;
 

  for(j=0; j<ntypes;  j++){

	if(Diff[j] > 0 ){
	    verlet_a[j] = (1 - delt/2.0/Diff[j]/(j==2 ? p_m: 1.0))/(1 + delt/2.0/Diff[j]/(j==2 ? p_m: 1.0));
	     verlet_b[j] = 1.0 / (1 + delt/2.0/Diff[j]/(j==2 ? p_m: 1.0));
			         
	}
	else{
		            verlet_a[j] = -1;
			                verlet_b[j] = 0;
	}

	printf("verlet_a: %lf and verlet_b: %lf for  type: %d\n" , verlet_a[j],verlet_b[j], j ) ;fflush(stdout) ;

  }//ntypes

  printf("Memory allocated: %lf MB\n" , mem_use / 1.0E6 ) ; 
  fflush(stdout) ;
  
  initialize_configuration() ;
 
  //calc_A();//calc A and dAdang


  printf("Initial config generated\n") ; fflush(stdout) ;

  charge_grid() ;

  printf("grid charged\n"); fflush(stdout); 
  
  initialize_potential() ;

  printf("potentials initialized, written\n") ; fflush( stdout ) ; 
}
Exemple #2
0
int main(int args, char *argv[]) {

	char *save_file;
	ines_file *nes_rom;

	/* Print NOW everything :D */
#ifdef _MSC_VER
	setvbuf(stdout,NULL,_IONBF,0);
	setvbuf(stderr,NULL,_IONBF,0);
#else
	setbuf(stdout,NULL);
	setbuf(stderr,NULL);
#endif

	/* i18n stuff */
	setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE, LOCALEDIR);
	textdomain(PACKAGE);

	/* Parse command line options */
	initialize_configuration();
	switch ( parse_options(args, argv) ) {
		case -1:
			usage(stderr,argv);
			exit(EXIT_FAILURE);
		case 0:
			exit(EXIT_SUCCESS);
		default:
			break;
	}

	load_user_configuration();

	/* Initialize static data */
	initialize_palette();
	initialize_instruction_set();
	initialize_playback();
	initialize_apu();
	initialize_cpu();
	initialize_ppu();
	initialize_clock();
	initialize_pads();

	/* Read the ines file and get all the ROM/VROM */
	config.rom_file = argv[optind];
	nes_rom = check_ines_file(config.rom_file);
	map_rom_memory(nes_rom);
	save_file = load_sram(config.rom_file);

	/* Init the graphics engine */
	init_screen();
	init_gui();

	/* Main execution loop */
	main_loop();

	/* After finishing the emulation, save the SRAM if necessary */
	save_sram(save_file);
	free(save_file);

	/* Free all the used resources */
	mapper->end_mapper();
	end_screen();
	end_gui();
	end_ppu();
	end_cpu();
	end_apu();
	end_playback();
	free_ines_file(nes_rom);

	return 0;
}