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;
  my_rng_generator rng;

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

  grid.setXrange(-50.0, 0.0);
  grid.setYrange(-15.0, 15.0);
  grid.setZrange(-15, +15);

  grid.setNCells(1536, 512, 512);
  grid.setNProcsAlongY(NPROC_ALONG_Y);
  grid.setNProcsAlongZ(NPROC_ALONG_Z);

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

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

  grid.setSimulationTime(100.0);

  grid.withParticles = YES;//NO;
  grid.withCurrent = YES;//YES;

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

  grid.setMasterProc(0);

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

  grid.finalize();

  grid.visualDiag();

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

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

  laserPulse pulse1;
  pulse1.setGaussianPulse();
  pulse1.setWaist(4.0);
  pulse1.setDurationFWHM(10.0);
  pulse1.setNormalizedAmplitude(0.5);
  pulse1.setCircularPolarization();
  pulse1.setPulseInitialPosition(-10.1);
  pulse1.setFocusPosition(0.0);
  pulse1.setLambda(1.0);
  pulse1.setFocusPosition(0.0);
  //    pulse1.setRotationAngleAndCenter(2.0*M_PI*(-30.0 / 360.0), 0.0);
  myfield.addPulse(&pulse1);

  myfield.boundary_conditions();

  current.allocate(&grid);
  current.setAllValuesToZero();
  //*******************************************END FIELD DEFINITION***********************************************************

  //*******************************************BEGIN SPECIES DEFINITION*********************************************************
  PLASMA plasma1;
  plasma1.density_function = box;
  plasma1.setXRangeBox(0.0, 100.0);
  plasma1.setYRangeBox(grid.rmin[1], grid.rmax[1]);
  plasma1.setZRangeBox(grid.rmin[2], grid.rmax[2]);
  plasma1.setDensityCoefficient(0.0025);

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


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


  //tempDistrib distribution;
  //distribution.setWaterbag(1.0e-8);
  //electrons1.add_momenta(rng,0.0,0.0,0.0,distribution);
  //ions1.add_momenta(rng,0.0, 0.0, 0.0, distribution);

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

  //*******************************************END SPECIED DEFINITION***********************************************************

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

  //manager.addEBFieldFrom(0.0,20.0);
  //manager.addSpeciesDensityFrom(electrons1.name, 0.0, 20.0);
  //manager.addSpeciesPhaseSpaceFrom(electrons1.name, 0.0, 10.0);
  //manager.addSpeciesDensityFrom(ions1.name, 0.0, 1.0);
  //manager.addDiagFrom(0.0, 1.0);

  manager.initialize(DIRECTORY_OUTPUT);
  //*******************************************END DIAGNOSTICS DEFINITION**************************************************
  grid.setDumpPath(DIRECTORY_DUMP);
  //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 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++) {
      (*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;

    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(1);

}
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);

}
Esempio n. 3
0
int main(int narg, char **args)
{
  MPI_Init(&narg, &args);
#ifdef _USE_FFTW_FILTER
  fftw_mpi_init();
#endif
  Json::Value root;
  jsonParser::parseJsonInputFile(root, narg, args);
  int dim = jsonParser::getDimensionality(root, DEFAULT_DIMENSIONALITY);

  GRID grid(dim);
  EM_FIELD myfield;
  CURRENT current;
  std::vector<SPECIE*> species;
  std::vector<SPECIE*>::const_iterator spec_iterator;
  my_rng_generator rng;

  //*******************************************BEGIN GRID DEFINITION*******************************************************
  jsonParser::setXrange(root, &grid);
  jsonParser::setYrange(root, &grid);
  jsonParser::setZrange(root, &grid);
  jsonParser::setNCells(root, &grid);
  jsonParser::setNprocs(root, &grid);
  jsonParser::setStretchedGrid(root, &grid);
  jsonParser::setBoundaryConditions(root, &grid);

  jsonParser::setRadiationFriction(root, &grid);
  jsonParser::setMasterProc(root, &grid);

  grid.mpi_grid_initialize(&narg, args);

  jsonParser::setCourantFactor(root, &grid);
  jsonParser::setSimulationTime(root, &grid);
  jsonParser::setMovingWindow(root, &grid);

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

  grid.finalize();

  jsonParser::setDumpControl(root, &grid);
  grid.visualDiag();

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


  jsonParser::setLaserPulses(root, &myfield);
  myfield.boundary_conditions();

  current.allocate(&grid);
  current.setAllValuesToZero();
  //*******************************************END FIELD DEFINITION***********************************************************
  //******************** BEGIN TO READ OF user defined INPUT - PARAMETERS ****************************************
  bool isThereSpecial = false;
  bool areThereSpheres = false;

  std::string fileSpheresName;
  Json::Value special;
  SPHERES myspheres;
  if (isThereSpecial = jsonParser::setValue(special, root, "special")) {
    if (areThereSpheres = jsonParser::setString(&fileSpheresName, special, "spheresFile")) {
      readAndAllocateSpheres(myspheres, fileSpheresName, grid);
      selectSpheres(myspheres, grid);
    }
  }
  std::map<std::string, PLASMA*>::iterator pIterator;

  //********************  END READ OF "SPECIAL" (user defined) INPUT - PARAMETERS  ****************************************

  //*******************************************BEGIN SPECIES DEFINITION*********************************************************

  std::map<std::string, PLASMA*> plasmas;
  jsonParser::setPlasmas(root, plasmas);

  if (areThereSpheres) {
    for (pIterator = plasmas.begin(); pIterator != plasmas.end(); pIterator++) {
      (pIterator)->second->params.spheres = &myspheres;
    }
  }
  jsonParser::setSpecies(root, species, plasmas, &grid, rng);

  uint64_t totPartNum = 0;
  for (spec_iterator = species.begin(); spec_iterator != species.end(); spec_iterator++) {
    totPartNum += (*spec_iterator)->printParticleNumber();
  }
  if (grid.myid == grid.master_proc) {
    std::cout << "Total particle number: " << totPartNum << std::endl;
  }


  if (areThereSpheres) {
    delete[] myspheres.coords;
  }
  //*******************************************END SPECIES DEFINITION***********************************************************

  //*******************************************BEGIN DIAG DEFINITION**************************************************
  std::map<std::string, outDomain*> outDomains;
  OUTPUT_MANAGER manager(&grid, &myfield, &current, species);
  jsonParser::setDomains(root, outDomains);
  jsonParser::setOutputRequests(root, manager, outDomains, species);
  jsonParser::setOutputDirPath(root, manager);

  manager.initialize();
  //*******************************************END DIAG DEFINITION**************************************************
  grid.setDumpPath(DIRECTORY_DUMP);
  //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ MAIN CYCLE (DO NOT MODIFY) @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

  if (grid.myid == grid.master_proc) {
    printf("----- START temporal cicle -----\n");
    fflush(stdout);
  }

  int dumpID = 1;
  grid.istep = 0;
  if (grid.dumpControl.doRestart) {
    dumpID = grid.dumpControl.restartFromDump;
    restartFromDump(&dumpID, &grid, &myfield, species);
  }

  while (grid.istep <= grid.getTotalNumberOfTimesteps())
  {
#ifdef NO_ALLOCATION
    manager.close();
    MPI_Finalize();
    exit(0);
#endif

    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++) {
      (*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();

#ifdef _USE_FFTW_FILTER
    myfield.fftw_filter_Efield();
    myfield.boundary_conditions();
#endif

    myfield.openBoundariesE_2();

    if (!(grid.istep % 20)) {
      //myfield.applyFilter(fltr_Ex|fltr_Ey, dir_x|dir_y);
    }

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

    for (spec_iterator = species.begin(); spec_iterator != species.end(); spec_iterator++) {
      if (grid.isRadiationFrictionEnabled()) {
        (*spec_iterator)->momenta_advance_with_friction(&myfield, grid.getLambda0());
      }
      else {
        (*spec_iterator)->momenta_advance(&myfield);
      }
    }

    grid.time += grid.dt;

    moveWindow(&grid, &myfield, species);

    grid.istep++;
    if (grid.dumpControl.doDump) {
      if (grid.istep != 0 && !(grid.istep % ((int)(grid.dumpControl.dumpEvery / grid.dt)))) {
        dumpFilesForRestart(&dumpID, &grid, &myfield, species);
      }
    }
  }

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

}
Esempio n. 4
0
int main(int narg, char **args)
{
  MPI_Init(&narg, &args);
  Json::Value root;
  std::string inputFileName = jsonParser::parseJsonInputFile(root, narg, args);
  int dim = jsonParser::getDimensionality(root, DEFAULT_DIMENSIONALITY);

  GRID grid(dim);
  EM_FIELD myfield;
  EM_FIELD exfield;
  CURRENT current;
  std::vector<SPECIE*> species;
  std::vector<SPECIE*>::const_iterator spec_iterator;

  //*******************************************BEGIN GRID DEFINITION*******************************************************
  jsonParser::setGridGeometry(root, &grid);
  grid.mpi_grid_initialize(&narg, args);
  jsonParser::setRemainingGridParameters(root, &grid);
  grid.initRNG(RANDOM_NUMBER_GENERATOR_SEED);
  grid.finalize();

  jsonParser::setDumpControl(root, &grid);
  grid.visualDiag();
  //********************************************END GRID DEFINITION********************************************************

  //*******************************************BEGIN SPECIES DEFINITION*********************************************************
  std::map<std::string, PLASMA*> plasmas;
  jsonParser::setPlasmas(root, plasmas);
  jsonParser::setSpecies(root, species, plasmas, &grid, grid.mt_rng);
  UTILITIES::printTotalNumberOfParticles(species, grid);
  //*******************************************END SPECIES DEFINITION***********************************************************

  //*******************************************  START LANGMUIR SET  *********************************************************
  //*******************************************  READ  LANGMUIR SET  *********************************************************
  LANGMUIRset langmuirSet;

  jsonParser::setLangmuirWavesSet(root,langmuirSet);
  UTILITIES::setLangmuirWaveSet(langmuirSet, grid);

  //************** IF IF IF ********** MOVE PARTICLES USING LANGMUIR SET  *********************************************************
  bool moveParticleForLangmuir=false;
  if(langmuirSet.checkLangmuirSetValidity&&moveParticleForLangmuir){
    for (spec_iterator = species.begin(); spec_iterator != species.end(); spec_iterator++){
      UTILITIES::moveParticles(&grid,(*spec_iterator),langmuirSet.myKModes);
      (*spec_iterator)->position_parallel_pbc();
    }
  }
  //*******************************************  END LANGMUIR SET  *********************************************************

  //*******************************************  OLD WAVE INITIALIZATION  *********************************************************
  bool isThereSpecial=false;
  bool isThereAmpli=false;
  bool isThereLambda=false;
  bool isWaveOK = false;
  double amplitude;
  double lambda;
  Json::Value special;
  isThereSpecial=jsonParser::setValue(special,root,"special");
  if(isThereSpecial){
    isThereAmpli  = jsonParser::setDouble(&amplitude, special, "amplitude");
    isThereLambda = jsonParser::setDouble(&lambda,    special, "lambda");
    isWaveOK = isThereAmpli&&isThereLambda;
  }
  if(isWaveOK){
    for (spec_iterator = species.begin(); spec_iterator != species.end(); spec_iterator++){
      UTILITIES::OldMoveParticles(&grid,(*spec_iterator),amplitude,lambda);
      (*spec_iterator)->position_parallel_pbc();
      (*spec_iterator)->position_parallel_pbc();
    }
  }

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

  UTILITIES::launchPoissonSolver(myfield, species, grid, current);
  jsonParser::setLaserPulses(root, &myfield);
  //*******************************************END FIELD DEFINITION***********************************************************

  //*******************************************BEGIN DIAG DEFINITION**************************************************
  OUTPUT_MANAGER manager(&grid, &myfield, &current, species);
  //OUTPUT_MANAGER manager(&grid, &exfield, &current, species);
  jsonParser::setOutputManagerParameters(root, manager, species);
  manager.initialize();
  manager.copyInputFileInOutDir(inputFileName);
  //*******************************************END DIAG DEFINITION**************************************************

  //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ MAIN CYCLE (DO NOT MODIFY) @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  grid.printMessage("---- START temporal cicle -----\n");
  UTILITIES::considerRestartFromDump(&grid, &myfield, species);

  while (grid.istep <= grid.getTotalNumberOfTimesteps())
  {
    grid.printTStepAsPlanned();
    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++) {
      (*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();

    UTILITIES::setExternaField(exfield, grid, grid.time+grid.dt, langmuirSet);
    exfield.boundary_conditions();

    for (spec_iterator = species.begin(); spec_iterator != species.end(); spec_iterator++) {
      if (grid.isRadiationFrictionEnabled()) {
        (*spec_iterator)->momenta_advance_with_friction(&myfield, grid.getLambda0());
      }
      else if(langmuirSet.checkLangmuirSetValidity&&langmuirSet.keepForcing){
        (*spec_iterator)->momenta_advance_with_externalFields(&myfield, &exfield);
      }
      else{
        (*spec_iterator)->momenta_advance(&myfield);
      }
    }

    grid.time += grid.dt;
    grid.istep++;
    UTILITIES::moveWindow(&grid, &myfield, species);
    UTILITIES::considerDumpForRestart(&grid, &myfield, species);
  }

  manager.close();
  MPI_Finalize();
  exit(0);
}
Esempio n. 5
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);

}