int main(int narg, char **args)
{
  GRID grid(DIMENSIONALITY);
  EM_FIELD myfield;
  CURRENT current;
  std::vector<SPECIE*> species;
  std::vector<SPECIE*>::const_iterator spec_iterator;
  int istep;
  my_rng_generator rng;

  //*******************************************BEGIN GRID DEFINITION*******************************************************

  grid.setXrange(-4.0*Xfactor, 4.0*Xfactor);
  grid.setYrange(-4.0*Yfactor, 4.0*Yfactor);
  grid.setZrange(-0.5, +0.5);

  int Nxcell = (int)(Xfactor * 1024);
  int Nycell = (int)(Yfactor * 1024);
  grid.setNCells(Nxcell, Nycell, 100);
  grid.setNProcsAlongY(NPROC_ALONG_Y);

  //grid.enableStretchedGrid();
  grid.setXandNxLeftStretchedGrid(-20.0, 250);
  grid.setXandNxRightStretchedGrid(20.0, 250);
  grid.setYandNyLeftStretchedGrid(-20.0, 250);
  grid.setYandNyRightStretchedGrid(20.0, 250);

  grid.setBoundaries(xPBC | yPBC | zPBC);
  grid.mpi_grid_initialize(&narg, args);
  grid.setCourantFactor(0.98);

  grid.setSimulationTime(5.5);

  grid.withParticles = YES;//NO;
  grid.withCurrent = YES;//YES;
  //double start, beta_mw;	int frequency_of_shifts;
  //grid.setMovingWindow(start=0, beta_mw=0.0, frequency_of_shifts=10);

  grid.setMasterProc(0);

  grid.finalize();

  srand(time(NULL));
  grid.initRNG(rng, RANDOM_NUMBER_GENERATOR_SEED);

  grid.visualDiag();

  //********************************************END GRID DEFINITION********************************************************

  //*******************************************BEGIN FIELD DEFINITION*********************************************************
  myfield.allocate(&grid);
  myfield.setAllValuesToZero();

  myfield.boundary_conditions();
  //myfield.smooth_filter(10);

  current.allocate(&grid);
  current.setAllValuesToZero();

  //*******************************************END FIELD DEFINITION***********************************************************

  //*******************************************BEGIN SPECIES DEFINITION*********************************************************
  PLASMA plasma1;
  plasma1.density_function = box;
  plasma1.setMinBox(-10.0, -10.0, grid.rmin[2]);
  plasma1.setMaxBox(10.0, 10.0, grid.rmax[2]);
  plasma1.setRampLength(0.2);
  plasma1.setDensityCoefficient(1.0);

  SPECIE  electrons1(&grid);
  electrons1.plasma = plasma1;
  electrons1.setParticlesPerCellXYZ(10, 10, 1);
  electrons1.setName("ELE1");
  electrons1.type = ELECTRON;
  electrons1.creation();
  species.push_back(&electrons1);

  SPECIE electrons2(&grid);
  electrons2.plasma = plasma1;
  electrons2.setParticlesPerCellXYZ(10, 10, 1);
  electrons2.setName("ELE2");
  electrons2.type = ELECTRON;
  electrons2.creation();
  species.push_back(&electrons2);

  tempDistrib distribution;
  distribution.setMaxwell(1.0e-5);

  electrons1.add_momenta(rng, 0.0, 0.0, -1.0, distribution);
  electrons2.add_momenta(rng, 0.0, 0.0, 1.0, distribution);

  for (spec_iterator = species.begin(); spec_iterator != species.end(); spec_iterator++) {
    (*spec_iterator)->printParticleNumber();
  }
  //*******************************************END SPECIES DEFINITION***********************************************************

  //*******************************************BEGIN DIAG DEFINITION**************************************************
  OUTPUT_MANAGER manager(&grid, &myfield, &current, species);

  double startOutputA = 0.0, freqOutputA = 5.0;
  double startOutputB = 0.0, freqOutputB = 1.0;

  manager.addDiagFrom(startOutputB, freqOutputB);

  manager.addEFieldFrom(startOutputA, freqOutputA);
  manager.addBFieldFrom(startOutputA, freqOutputA);

  manager.addSpeciesDensityFrom("ELE1", startOutputA, freqOutputA);
  manager.addSpeciesDensityFrom("ELE2", startOutputA, freqOutputA);

  manager.addCurrentFrom(startOutputA, freqOutputA);

  manager.addSpeciesPhaseSpaceFrom("ELE1", startOutputA, freqOutputA);
  manager.addSpeciesPhaseSpaceFrom("ELE2", startOutputA, freqOutputA);


  manager.initialize(DIRECTORY_OUTPUT);
  //*******************************************END DIAG DEFINITION**************************************************

  //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ MAIN CYCLE (DO NOT MODIFY) @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  if (grid.myid == grid.master_proc) {
    printf("----- START temporal cicle -----\n");
    fflush(stdout);
  }

  int Nstep = grid.getTotalNumberOfTimesteps();
  int dumpID = 1, dumpEvery;
  if (DO_DUMP) {
    dumpEvery = (int)(TIME_BTW_DUMP / grid.dt);
  }
  grid.istep = 0;
  if (_DO_RESTART) {
    dumpID = _RESTART_FROM_DUMP;
    restartFromDump(&dumpID, &grid, &myfield, species);
  }
  while (grid.istep <= Nstep)
  {
    grid.printTStepEvery(FREQUENCY_STDOUT_STATUS);
    // manager.callDiags(grid.istep);

    myfield.openBoundariesE_1();
    myfield.new_halfadvance_B();
    myfield.boundary_conditions();

    current.setAllValuesToZero();
    for (spec_iterator = species.begin(); spec_iterator != species.end(); spec_iterator++) {
#ifdef ESIRKEPOV
      (*spec_iterator)->current_deposition(&current);
#else
      (*spec_iterator)->current_deposition_standard(&current);
#endif

    }
    current.pbc();

    for (spec_iterator = species.begin(); spec_iterator != species.end(); spec_iterator++) {
      (*spec_iterator)->position_parallel_pbc();
    }

    myfield.openBoundariesB();
    myfield.new_advance_E(&current);

    myfield.boundary_conditions();
    myfield.openBoundariesE_2();
    myfield.new_halfadvance_B();
    myfield.boundary_conditions();

    for (spec_iterator = species.begin(); spec_iterator != species.end(); spec_iterator++) {
#ifdef RADIATION_FRICTION
      (*spec_iterator)->momenta_advance_with_friction(&myfield, lambda);
#else
      (*spec_iterator)->momenta_advance(&myfield);
#endif
    }

    //        if(grid.istep%FIELD_FILTER_FREQ==0){
    //            myfield.applyFilter(fltr_Ex, dir_x);
    //            myfield.boundary_conditions();
    //        }

    grid.time += grid.dt;

    moveWindow(&grid, &myfield, species);

    grid.istep++;
    if (DO_DUMP) {
      if (grid.istep != 0 && !(grid.istep % (dumpEvery))) {
        dumpFilesForRestart(&dumpID, &grid, &myfield, species);
      }
    }
  }

  manager.close();
  MPI_Finalize();
  exit(0);

}
예제 #2
0
int main(int narg, char **args)
{
  GRID grid;
  EM_FIELD myfield;
  CURRENT current;
  std::vector<SPECIE*> species;
  std::vector<SPECIE*>::const_iterator spec_iterator;
  int istep;
  gsl_rng* rng = gsl_rng_alloc(gsl_rng_ranlxd1);

  //*******************************************INIZIO DEFINIZIONE GRIGLIA*******************************************************

  grid.setXrange(-3.530583, 3.530583);
  grid.setYrange(-1, 1);
  grid.setZrange(-1, +1);

  grid.setNCells(256, 1, 1);
  grid.setNProcsAlongY(NPROC_ALONG_Y);
  grid.setNProcsAlongZ(NPROC_ALONG_Z);

  //grid.enableStretchedGrid();
  grid.setXandNxLeftStretchedGrid(-20.0, 1000);
  grid.setYandNyLeftStretchedGrid(-15.0, 1000);
  grid.setXandNxRightStretchedGrid(20.0, 1000);
  grid.setYandNyRightStretchedGrid(15.0, 1000);

  grid.setBoundaries(xPBC | yPBC | zPBC); //LUNGO Z c'è solo PBC al momento !
  grid.mpi_grid_initialize(&narg, args);
  grid.setCourantFactor(0.98);

  grid.setSimulationTime(50.0);

  grid.with_particles = YES;//NO;
  grid.with_current = YES;//YES;

  //grid.setStartMovingWindow(0);
  grid.setBetaMovingWindow(1.0);
  //grid.setFrequencyMovingWindow(FREQUENCY);

  grid.setMasterProc(0);

  srand((unsigned int)time(NULL));
  grid.initRNG(rng, RANDOM_NUMBER_GENERATOR_SEED);

  grid.finalize();

  grid.visualDiag();

  //********************************************FINE DEFINIZIONE GRIGLIA********************************************************

  //*******************************************INIZIO DEFINIZIONE CAMPI*********************************************************
  myfield.allocate(&grid);
  myfield.setAllValuesToZero();

  laserPulse pulse1;
  pulse1.type = COS2_PLANE_WAVE;                        //Opzioni : GAUSSIAN, PLANE_WAVE, COS2_PLANE_WAVE
  pulse1.polarization = P_POLARIZATION;
  pulse1.t_FWHM = 10.0;
  pulse1.laser_pulse_initial_position = 0.0;
  pulse1.lambda0 = 1.0;
  pulse1.normalized_amplitude = 8.0;
  pulse1.waist = 3.0;
  pulse1.focus_position = 0.0;
  pulse1.rotation = false;
  pulse1.angle = 2.0*M_PI*(-30.0 / 360.0);
  pulse1.rotation_center_along_x = 0.0;

  //myfield.addPulse(&pulse1);
  myfield.addFieldsFromFile("campi.txt");
  laserPulse pulse2;
  pulse2 = pulse1;
  pulse2.angle = 2.0*M_PI*(30.0 / 360.0);

  //myfield.addPulse(&pulse2);

  myfield.boundary_conditions();

  current.allocate(&grid);
  current.setAllValuesToZero();
  //*******************************************FINE DEFINIZIONE CAMPI***********************************************************

  //*******************************************INIZIO DEFINIZIONE SPECIE*********************************************************
  PLASMA plasma1;
  plasma1.density_function = box;      //Opzioni: box, left_linear_ramp, left_soft_ramp, left_grating
  plasma1.setXRangeBox(grid.rmin[0], grid.rmax[0]);                  //double (* distrib_function)(double x, double y, double z, PLASMAparams plist, int Z, int A)
  plasma1.setYRangeBox(grid.rmin[1], grid.rmax[1]);                 //PLASMAparams: rminbox[3], rmaxbox[3], ramp_length, density_coefficient,
  plasma1.setZRangeBox(grid.rmin[2], grid.rmax[2]);
  plasma1.setRampLength(0.0);                       //ramp_min_density,void *additional_params
  plasma1.setDensityCoefficient(1.0);         // Per grating double g_depth = paramlist[0];double g_lambda = paramlist[1];
  plasma1.setRampMinDensity(0.0);                 //double g_phase = paramlist[2];
  double grating_peak_to_valley_depth = 0.2;
  double grating_lambda = 2.0;
  double grating_phase = 0.0;

  double additionalParams[3];
  additionalParams[0] = grating_peak_to_valley_depth;
  additionalParams[1] = grating_lambda;
  additionalParams[2] = grating_phase;

  plasma1.setAdditionalParams(additionalParams);


  PLASMA plasma2;
  plasma2.density_function = box;      //Opzioni: box, left_linear_ramp, left_soft_ramp, left_grating
  plasma2.setXRangeBox(0.8, 0.85);                  //double (* distrib_function)(double x, double y, double z, PLASMAparams plist, int Z, int A)
  plasma2.setYRangeBox(grid.rmin[1], grid.rmax[1]);                 //PLASMAparams: rminbox[3], rmaxbox[3], ramp_length, density_coefficient,
  plasma2.setZRangeBox(grid.rmin[2], grid.rmax[2]);
  plasma2.setRampLength(0.5);                       //ramp_min_density,void *additional_params
  plasma2.setDensityCoefficient(10);         // Per grating double g_depth = paramlist[0];double g_lambda = paramlist[1];
  plasma2.setRampMinDensity(0.0);                 //double g_phase = paramlist[2];


  SPECIE  electrons1(&grid);
  electrons1.plasma = plasma1;
  electrons1.setParticlesPerCellXYZ(100, 1, 1);       //Se < 1 il nPPC viene sostituito con 1
  electrons1.setName("ELE1");
  electrons1.type = ELECTRON;
  //electrons1.creation();                            //electrons.isTestSpecies=true disabilita deposizione corrente.
  electrons1.creationFromFile1D("elettroni.txt");
  species.push_back(&electrons1);


  //	SPECIE ions1(&grid);
  //	ions1.plasma = plasma1;
  //    ions1.setParticlesPerCellXYZ(12, 7, 1);
  //	ions1.setName("ION1");
  //    ions1.type = ION;
  //    ions1.Z = 6.0;
  //    ions1.A = 12.0;
  //    ions1.creation();
  //    species.push_back(&ions1);

  SPECIE  electrons2(&grid);
  electrons2.plasma = plasma1;
  electrons2.setParticlesPerCellXYZ(100, 1, 1);       //Se < 1 il nPPC viene sostituito con 1
  electrons2.setName("POS2");
  electrons2.type = POSITRON;
  electrons2.creationFromFile1D("positroni.txt");
  //electrons2.creation();                            //electrons.isTestSpecies=true disabilita deposizione corrente.
  species.push_back(&electrons2);


  //    SPECIE ions2(&grid);
  //    ions2.plasma = plasma2;
  //    ions2.setParticlesPerCellXYZ(10, 10, 1);
  //    ions2.setName("ION2");
  //    ions2.type = ION;
  //    ions2.Z = 1.0;
  //    ions2.A = 1.0;
  //    //ions2.creation();
  //    //species.push_back(&ions2);

  tempDistrib distribution;
  distribution.setSpecial(1.0e-2);

  electrons1.add_momenta(rng, 0.0, 0.0, 0.0, distribution);
  //    ions1.add_momenta(rng,0.0, 0.0, 0.0, distribution);
  electrons2.add_momenta(rng, 0.0, 0.0, 0.0, distribution);
  //    ions2.add_momenta(rng,0.0, 0.0, 0.0, distribution);

  /*
    for (spec_iterator = species.begin(); spec_iterator != species.end(); spec_iterator++){
    (*spec_iterator)->printParticleNumber();
    }
    */
  //    //*******************************************FINE DEFINIZIONE CAMPI***********************************************************

  //*******************************************INIZIO DEFINIZIONE DIAGNOSTICHE**************************************************

  OUTPUT_MANAGER manager(&grid, &myfield, &current, species);

  manager.addEBFieldFrom(0.0, 2.0);

  manager.addSpeciesDensityFrom(electrons1.name, 0.0, 2.0);
  manager.addSpeciesDensityFrom(electrons2.name, 0.0, 2.0);
  //manager.addSpecDensityBinaryFrom(ions1.name, 0.0, 2.0);
  //manager.addSpecDensityBinaryFrom(ions2.name, 0.0, 2.0);

  manager.addCurrentFrom(0.0, 2.0);

  manager.addSpeciesPhaseSpaceFrom(electrons1.name, 0.0, 2.0);
  manager.addSpeciesPhaseSpaceFrom(electrons2.name, 0.0, 2.0);
  //manager.addSpecPhaseSpaceBinaryFrom(ions1.name, 0.0, 5.0);
  //manager.addSpecPhaseSpaceBinaryFrom(ions2.name, 0.0, 5.0);

  manager.addDiagFrom(0.0, 1.0);

  manager.initialize(DIRECTORY_OUTPUT);

  //*******************************************FINE DEFINIZIONE DIAGNOSTICHE**************************************************

  //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ CICLO PRINCIPALE (NON MODIFICARE) @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

  int Nstep = grid.getTotalNumberOfTimesteps();
  if (grid.myid == grid.master_proc){
    printf("----- START temporal cicle: %i step -----\n", Nstep);
    fflush(stdout);
  }
  for (istep = 0; istep <= Nstep; istep++)
  {
    grid.istep = istep;

    grid.printTStepEvery(FREQUENCY_STDOUT_STATUS);


    manager.callDiags(istep);  /// deve tornare all'inizo del ciclo

    myfield.openBoundariesE_1();
    myfield.new_halfadvance_B();
    myfield.boundary_conditions();

    current.setAllValuesToZero();

    for (spec_iterator = species.begin(); spec_iterator != species.end(); spec_iterator++){
      (*spec_iterator)->current_deposition_standard(&current);
    }

    current.pbc();

    for (spec_iterator = species.begin(); spec_iterator != species.end(); spec_iterator++){
      (*spec_iterator)->position_parallel_pbc();
    }

    myfield.openBoundariesB();
    myfield.new_advance_E(&current);

    myfield.boundary_conditions();

    myfield.openBoundariesE_2();
    myfield.new_halfadvance_B();

    myfield.boundary_conditions();

    for (spec_iterator = species.begin(); spec_iterator != species.end(); spec_iterator++){
      (*spec_iterator)->momenta_advance(&myfield);
    }

    grid.time += grid.dt;


    grid.move_window();

    myfield.move_window();
    for (spec_iterator = species.begin(); spec_iterator != species.end(); spec_iterator++){
      (*spec_iterator)->move_window();
    }
  }

  manager.close();
  MPI_Finalize();
  exit(1);

}