Example #1
0
void PicParams::readSpecies(InputData &ifile) {
    bool ok;
    for (int ispec = 0; ispec < ifile.nComponents("Species"); ispec++) {
        SpeciesStructure tmpSpec;

        ifile.extract("species_type",tmpSpec.species_type,"Species",ispec);
        if(tmpSpec.species_type.empty()) {
            ERROR("For species #" << ispec << " empty species_type");
        }
        ifile.extract("initPosition_type",tmpSpec.initPosition_type ,"Species",ispec);
        if (tmpSpec.initPosition_type.empty()) {
            ERROR("For species #" << ispec << " empty initPosition_type");
        } else if ( (tmpSpec.initPosition_type!="regular")&&(tmpSpec.initPosition_type!="random") ) {
            ERROR("For species #" << ispec << " bad definition of initPosition_type " << tmpSpec.initPosition_type);
        }

        ifile.extract("initMomentum_type",tmpSpec.initMomentum_type ,"Species",ispec);
        if ( (tmpSpec.initMomentum_type=="mj") || (tmpSpec.initMomentum_type=="maxj") ) {
            tmpSpec.initMomentum_type="maxwell-juettner";
        }
        if (   (tmpSpec.initMomentum_type!="cold")
            && (tmpSpec.initMomentum_type!="maxwell-juettner")
            && (tmpSpec.initMomentum_type!="rectangular") ) {
            ERROR("For species #" << ispec << " bad definition of initMomentum_type");
        }

        tmpSpec.c_part_max = 1.0;// default value
        ifile.extract("c_part_max",tmpSpec.c_part_max,"Species",ispec);

        if( !ifile.extract("mass",tmpSpec.mass ,"Species",ispec) ) {
            ERROR("For species #" << ispec << ", mass not defined.");
        }

        tmpSpec.dynamics_type = "norm"; // default value
        if (!ifile.extract("dynamics_type",tmpSpec.dynamics_type ,"Species",ispec) )
            WARNING("For species #" << ispec << ", dynamics_type not defined: assumed = 'norm'.");
        if (tmpSpec.dynamics_type!="norm"){
            ERROR("dynamics_type different than norm not yet implemented");
        }

        tmpSpec.time_frozen = 0.0; // default value
        ifile.extract("time_frozen",tmpSpec.time_frozen ,"Species",ispec);
        if (tmpSpec.time_frozen > 0 && \
            tmpSpec.initMomentum_type!="cold") {
            WARNING("For species #" << ispec << " possible conflict between time-frozen & not cold initialization");
        }

        tmpSpec.radiating = false; // default value
        ifile.extract("radiating",tmpSpec.radiating ,"Species",ispec);
        if (tmpSpec.dynamics_type=="rrll" && (!tmpSpec.radiating)) {
            WARNING("For species #" << ispec << ", dynamics_type='rrll' forcing radiating=True");
            tmpSpec.radiating=true;
        }

        if (!ifile.extract("bc_part_type_west",tmpSpec.bc_part_type_west,"Species",ispec) )
            ERROR("For species #" << ispec << ", bc_part_type_west not defined");
        if (!ifile.extract("bc_part_type_east",tmpSpec.bc_part_type_east,"Species",ispec) )
            ERROR("For species #" << ispec << ", bc_part_type_east not defined");

        if (nDim_particle>1) {
            if (!ifile.extract("bc_part_type_south",tmpSpec.bc_part_type_south,"Species",ispec) )
                ERROR("For species #" << ispec << ", bc_part_type_south not defined");
            if (!ifile.extract("bc_part_type_north",tmpSpec.bc_part_type_north,"Species",ispec) )
                ERROR("For species #" << ispec << ", bc_part_type_north not defined");
        }

        // for thermalizing BCs on particles check if thermT is correctly defined
        bool thermTisDefined=false;
        if ( (tmpSpec.bc_part_type_west=="thermalize") || (tmpSpec.bc_part_type_east=="thermalize") ){
            thermTisDefined=ifile.extract("thermT",tmpSpec.thermT,"Species",ispec);
            if (!thermTisDefined) ERROR("thermT needs to be defined for species " <<ispec<< " due to x-BC thermalize");
        }
        if ( (nDim_particle==2) && (!thermTisDefined) &&
             (tmpSpec.bc_part_type_south=="thermalize" || tmpSpec.bc_part_type_north=="thermalize") ) {
            thermTisDefined=ifile.extract("thermT",tmpSpec.thermT,"Species",ispec);
            if (!thermTisDefined) ERROR("thermT needs to be defined for species " <<ispec<< " due to y-BC thermalize");
        }
        if (thermTisDefined) {
            if (tmpSpec.thermT.size()==1) {
                tmpSpec.thermT.resize(3);
                for (unsigned int i=1; i<3;i++)
                    tmpSpec.thermT[i]=tmpSpec.thermT[0];
            }
        } else {
            tmpSpec.thermT.resize(3);
            for (unsigned int i=0; i<3;i++)
                tmpSpec.thermT[i]=0.0;
        }


        tmpSpec.ionization_model = "none"; // default value
        ifile.extract("ionization_model", tmpSpec.ionization_model, "Species",ispec);

        ok = ifile.extract("atomic_number", tmpSpec.atomic_number, "Species",ispec);
        if( !ok && tmpSpec.ionization_model!="none" ) {
            ERROR("For species #" << ispec << ", `atomic_number` not found => required for the ionization model .");
        }

        tmpSpec.isTest = false; // default value
        ifile.extract("isTest",tmpSpec.isTest ,"Species",ispec);
        if (tmpSpec.ionization_model!="none" && (!tmpSpec.isTest)) {
            ERROR("Disabled for now : test & ionized");
        }

        // Species geometry
        // ----------------

        // Density
        bool ok1, ok2;
        ok1 = extractOneProfile(ifile, "nb_density"    , tmpSpec.dens_profile, ispec);
        ok2 = extractOneProfile(ifile, "charge_density", tmpSpec.dens_profile, ispec);
        if(  ok1 &&  ok2 ) ERROR("For species #" << ispec << ", cannot define both `nb_density` and `charge_density`.");
        if( !ok1 && !ok2 ) ERROR("For species #" << ispec << ", must define `nb_density` or `charge_density`.");
        if( ok1 ) tmpSpec.density_type = "nb";
        if( ok2 ) tmpSpec.density_type = "charge";

        // Number of particles per cell
        if( !extractOneProfile(ifile, "n_part_per_cell", tmpSpec.ppc_profile, ispec) )
            ERROR("For species #" << ispec << ", n_part_per_cell not found or not understood");

        // Charge
        if( !extractOneProfile(ifile, "charge", tmpSpec.charge_profile, ispec) )
            ERROR("For species #" << ispec << ", charge not found or not understood");

        // Mean velocity
        vector<ProfileStructure*> vecMvel;
        extractVectorOfProfiles(ifile, "mean_velocity", vecMvel, ispec);
        tmpSpec.mvel_x_profile = *(vecMvel[0]);
        tmpSpec.mvel_y_profile = *(vecMvel[1]);
        tmpSpec.mvel_z_profile = *(vecMvel[2]);

        // Temperature
        vector<ProfileStructure*> vecTemp;
        extractVectorOfProfiles(ifile, "temperature", vecTemp, ispec);
        tmpSpec.temp_x_profile = *(vecTemp[0]);
        tmpSpec.temp_y_profile = *(vecTemp[1]);
        tmpSpec.temp_z_profile = *(vecTemp[2]);


        // Save the Species params
        // -----------------------
        species_param.push_back(tmpSpec);
    }
}
Example #2
0
// ---------------------------------------------------------------------------------------------------------------------
// PicParams : open & parse the input data file, test that parameters are coherent
// ---------------------------------------------------------------------------------------------------------------------
PicParams::PicParams(InputData &ifile) {


    // --------------
    // Stop & Restart
    // --------------
    dump_step=1;
    ifile.extract("dump_step", dump_step);

    dump_minutes=0.0;
    ifile.extract("dump_minutes", dump_minutes);

    exit_after_dump=true;
    ifile.extract("exit_after_dump", exit_after_dump);

    restart=false;
    ifile.extract("restart", restart);
    if (restart) MESSAGE("Code running from restart"); //! \todo Give info on restart properties

    //!\todo MG is this still used ?? I cannot find it anywhere
    check_stop_file=false;
    ifile.extract("check_stop_file", check_stop_file);

    dump_file_sequence=2;
    ifile.extract("dump_file_sequence", dump_file_sequence);
    dump_file_sequence=std::max((unsigned int)1,dump_file_sequence);


    // ---------------------
    // Normalisation & units
    // ---------------------

    wavelength_SI = 0.;
    ifile.extract("wavelength_SI",wavelength_SI);


    // -------------------
    // Simulation box info
    // -------------------

    // geometry of the simulation
    ifile.extract("dim", geometry);
    if (geometry!="1d3v" && geometry!="2d3v") {
        ERROR("Geometry " << geometry << " does not exist");
    }
    setDimensions();

    // interpolation order
    ifile.extract("interpolation_order", interpolation_order);
    /*
    if (interpolation_order!=2 && interpolation_order!=4) {
        ERROR("Interpolation/projection order " << interpolation_order << " not defined");
    }
    if (geometry=="2d3v" && interpolation_order==4) {
        ERROR("Interpolation/projection order " << interpolation_order << " not yet defined in 2D");
    }
    */

    //!\todo (MG to JD) Please check if this parameter should still appear here
    // Disabled, not compatible for now with particles sort
    // if ( !ifile.extract("exchange_particles_each", exchange_particles_each) )
    exchange_particles_each = 1;


    // TIME & SPACE RESOLUTION/TIME-STEPS

    // reads timestep & cell_length
    ifile.extract("timestep", timestep);
    res_time = 1.0/timestep;
    ifile.extract("cell_length",cell_length);
    if (cell_length.size()!=nDim_field) {
        ERROR("Dimension of cell_length ("<< cell_length.size() << ") != " << nDim_field << " for geometry " << geometry);
    }
    res_space.resize(nDim_field);
    for (unsigned int i=0;i<nDim_field;i++){
        res_space[i] = 1.0/cell_length[i];
    }

    time_fields_frozen=0.0;
    ifile.extract("time_fields_frozen", time_fields_frozen);

    // testing the CFL condition
    //!\todo (MG) CFL cond. depends on the Maxwell solv. ==> Move this computation to the ElectroMagn Solver
    double res_space2=0;
    for (unsigned int i=0; i<nDim_field; i++) {
        res_space2 += res_space[i]*res_space[i];
    }
    dtCFL=1.0/sqrt(res_space2);
    if ( timestep>dtCFL ) {
        //ERROR("CFL problem: timestep=" << timestep << " should be smaller than " << dtCFL);
    }


    // simulation duration & length
    ifile.extract("sim_time", sim_time);

    ifile.extract("sim_length",sim_length);
    if (sim_length.size()!=nDim_field) {
        ERROR("Dimension of sim_length ("<< sim_length.size() << ") != " << nDim_field << " for geometry " << geometry);
    }


    //! Boundary conditions for ElectroMagnetic Fields
    if ( !ifile.extract("bc_em_type_x", bc_em_type_x)  ) {
        ERROR("Electromagnetic boundary condition type (bc_em_type_x) not defined" );
    }
    if (bc_em_type_x.size()==1) { // if just one type is specified, then take the same bc type in a given dimension
        bc_em_type_x.resize(2); bc_em_type_x[1]=bc_em_type_x[0];
    }

    if ( !ifile.extract("bc_em_value_x", bc_em_value_x)  ) {
        ERROR("Electromagnetic boundary condition type (bc_em_type_x) not defined" );
    }
    if (bc_em_value_x.size()==1) { // if just one type is specified, then take the same bc type in a given dimension
        bc_em_value_x.resize(2); bc_em_value_x[1]=bc_em_value_x[0];
    }


    if ( geometry == "2d3v" || geometry == "3d3v" ) {
        if ( !ifile.extract("bc_em_type_y", bc_em_type_y) )
            ERROR("Electromagnetic boundary condition type (bc_em_type_y) not defined" );
        if (bc_em_type_y.size()==1) { // if just one type is specified, then take the same bc type in a given dimension
            bc_em_type_y.resize(2); bc_em_type_y[1]=bc_em_type_y[0];
        }
    }
    if ( geometry == "3d3v" ) {
        if ( !ifile.extract("bc_em_type_z", bc_em_type_z) )
            ERROR("Electromagnetic boundary condition type (bc_em_type_z) not defined" );
        if (bc_em_type_z.size()==1) { // if just one type is specified, then take the same bc type in a given dimension
            bc_em_type_z.resize(2); bc_em_type_z[1]=bc_em_type_z[0];
        }
    }

    // ------------------------
    // Moving window parameters
    // ------------------------
    if (!ifile.extract("clrw",clrw)) {
        clrw = 1;
    }


    // ------------------
    // Species properties
    // ------------------
    readSpecies(ifile);

    global_every=0;

    ifile.extract("every",global_every);

    // --------------------
    // Number of processors
    // --------------------
    if ( !ifile.extract("number_of_procs", number_of_procs) )
        number_of_procs.resize(nDim_field, 0);

    // -------------------------------------------------------
    // Compute usefull quantities and introduce normalizations
    // also defines defaults values for the species lengths
    // -------------------------------------------------------
    compute();
    computeSpecies();

}