bool Species::readParameters(Simulation& sim,SimulationClasses& simClasses,ConfigReader& cr,const std::string& name) { bool success = true; this->name = name; // Read species' parameters from config file: string q_unit,m_unit; cr.add(name+".mass_unit","Unit in which 'mass' is given (string).",string("")); cr.add(name+".charge_unit","Unit which 'charge' is given (string).",string("")); cr.add(name+".mass","Mass in mass units (float).",numeric_limits<Real>::infinity()); cr.add(name+".charge","Charge in charge units (float).",numeric_limits<Real>::infinity()); cr.add(name+".type","What type of species this is (string)?",string("")); cr.parse(); cr.get(name+".mass_unit",m_unit); cr.get(name+".charge_unit",q_unit); cr.get(name+".mass",m); cr.get(name+".charge",q); cr.get(name+".type",speciesType); // Check input parameters for sanity: Real charge = simClasses.constants.get(q_unit); if (charge == simClasses.constants.notFound()) { simClasses.logger << "(SPECIES) ERROR: illegal charge unit '" << q_unit << "' !" << endl << write; success = false; } Real mass = simClasses.constants.get(m_unit); if (mass == simClasses.constants.notFound()) { simClasses.logger << "(SPECIES) ERROR: illegal mass unit '" << m_unit << "' !" << endl << write; success = false; } if (q == numeric_limits<Real>::infinity()) { simClasses.logger << "(SPECIES) ERROR: Charge was not specified with parameter '" << name+".charge' !" << endl << write; success = false; } if (m == numeric_limits<Real>::infinity()) { simClasses.logger << "(SPECIES) ERROR: Mass was not specified with parameter '" << name+".mass' !" << endl << write; success = false; } if (speciesType == "") { simClasses.logger << "(SPECIES) ERROR: Species type was not specified with parameter '" << name+".type' !" << endl << write; success = false; } q *= charge; m *= mass; q_per_m = q/m; return success; }
bool ConstantB::initialize(Simulation& sim,SimulationClasses& simClasses,ConfigReader& cr) { bool success = true; // Define parameters read from configuration file(s) and parse: const string configName = "ConstantB"; const Real DEFVALUE = NAN; Real B_mag = NAN; cr.add(configName+".direction_x","Vector to direction of B, x-component (float).",DEFVALUE); cr.add(configName+".direction_y","Vector to direction of B, y-component (float).",DEFVALUE); cr.add(configName+".direction_z","Vector to direction of B, z-component (float).",DEFVALUE); cr.add(configName+".magnitude","Magnitude of B in nT (float).",DEFVALUE); cr.parse(); cr.get(configName+".direction_x",B[0]); cr.get(configName+".direction_y",B[1]); cr.get(configName+".direction_z",B[2]); cr.get(configName+".magnitude",B_mag); // Check input values for sanity: if (B[0] != B[0]) { simClasses.logger << "(CONSTANT_B) ERROR: x-component of vector to direction of B was not given with parameter '" << configName << ".direction_x' !" << endl << write; success = false; } if (B[1] != B[1]) { simClasses.logger << "(CONSTANT_B) ERROR: y-component of vector to direction of B was not given with parameter '" << configName << ".direction_y' !" << endl << write; success = false; } if (B[2] != B[2]) { simClasses.logger << "(CONSTANT_B) ERROR: z-component of vector to direction of B was not given with parameter '" << configName << ".direction_z' !" << endl << write; success = false; } if (B_mag != B_mag) { simClasses.logger << "(CONSTANT_B) ERROR: Magnitude of B was not given with parameter '" << configName << ".magnitude' !" << endl << write; success = false; } const Real magnitude = vectorMagnitude<3>(B); for (int i=0; i<3; ++i) B[i] = B[i]*B_mag/magnitude; return success; }
bool pitchDistribMonoInitialize(Simulation& sim,SimulationClasses& simClasses,ConfigReader& cr,const std::string& regionName) { // Prevent multiple initializations: if (pitchMono.initialized == true) return true; pitchMono.simClasses = &simClasses; // Read injection pitch from config file: const Real DEF_VALUE = numeric_limits<Real>::infinity(); cr.add(regionName+".injection_pitch","Injection pitch (float).",DEF_VALUE); cr.parse(); cr.get(regionName+".injection_pitch",pitchMono.injectionPitch); if (pitchMono.injectionPitch == DEF_VALUE) { simClasses.logger << "(PITCH DISTRIB MONO) ERROR: Parameter '" << regionName+".injection_pitch' was not found" << endl << write; return false; } pitchMono.initialized = true; return true; }
bool RestartBuilder::initialize(Simulation& sim,SimulationClasses& simClasses,ConfigReader& cr) { initialized = true; this->sim = ∼ this->simClasses = &simClasses; simClasses.logger << "(RESTART BUILDER) Starting initialization." << endl; string restartFileName; const string regionName = "Restart"; cr.add(regionName+".filename","Name of the restart file (string).",string("")); cr.parse(); cr.get(regionName+".filename",restartFileName); vlsvReader = new vlsv::ParallelReader(); if (vlsvReader->open(restartFileName,sim.comm,sim.MASTER_RANK,MPI_INFO_NULL) == false) { simClasses.logger << "\t Failed to open file '" << restartFileName << "' for restarting!" << endl; initialized = false; } // Attempt to read mesh name: map<string,string> attribsOut; list<pair<string,string> > attribsIn; attribsIn.push_back(make_pair("type","mesh name")); if (initialized == true) if (vlsvReader->getArrayAttributes("MESH_NAME",attribsIn,attribsOut) == false) { simClasses.logger << "(RESTART BUILDER) ERROR: Failed to get mesh name from restart file!" << endl; initialized = false; } if (initialized == true) { if (attribsOut.find("name") == attribsOut.end()) { simClasses.logger << "(RESTART BUILDER) ERROR: Array 'MESH_NAME' did not contain mesh name!" << endl; initialized = false; } else { meshName = attribsOut["name"]; } } simClasses.logger << write; return initialized; }
static bool addConfigFileOptions(ConfigReader& cr) { cr.add(PREFIX+".B_magnitude","Magnitude of magnetic field in T (float)",DEF_VALUE); cr.add(PREFIX+".B_x","Magnetic field direction, x-component (float).",DEF_VALUE); cr.add(PREFIX+".B_y","Magnetic field direction, y-component (float).",DEF_VALUE); cr.add(PREFIX+".B_z","Magnetic field direction, z-component (float).",DEF_VALUE); cr.add(PREFIX+".V_plasma_magnitude","Plasma speed in m/s in simulation frame (float).",DEF_VALUE); cr.add(PREFIX+".V_plasma_x","Plasma velocity direction, x-component (float).",DEF_VALUE); cr.add(PREFIX+".V_plasma_y","Plasma velocity direction, y-component (float).",DEF_VALUE); cr.add(PREFIX+".V_plasma_z","Plasma velocity direction, z-component (float).",DEF_VALUE); cr.add(PREFIX+".ion_number_density","Ion number density in 1/m3 (float).",DEF_VALUE); cr.add(PREFIX+".ion_mass","Ion mass in proton masses (float).",DEF_VALUE); cr.add(PREFIX+".ion_polytropic_index","Ion polytropic index (float).",DEF_VALUE); cr.add(PREFIX+".ion_temperature","Ion temperature in Kelvins (float).",DEF_VALUE); cr.add(PREFIX+".reference_distance","Distance in length units where plasma parameters are given (float).",1.0); cr.add(SHOCKPREFIX+".leading_shock.speed","Speed of leading shock in simulation frame (float).",DEF_VALUE); cr.add(SHOCKPREFIX+".leading_shock.centroid_x","Leading shock centroid position at t=0, x-component (float).",DEF_VALUE); cr.add(SHOCKPREFIX+".leading_shock.centroid_y","Leading shock centroid position at t=0, y-component (float).",DEF_VALUE); cr.add(SHOCKPREFIX+".leading_shock.centroid_z","Leading shock centroid position at t=0, z-component (float).",DEF_VALUE); cr.add(SHOCKPREFIX+".trailing_shock.speed","Speed of trailing shock in simulation frame (float).",DEF_VALUE); cr.add(SHOCKPREFIX+".trailing_shock.centroid_x","Trailing shock centroid position at t=0, x-component (float).",DEF_VALUE); cr.add(SHOCKPREFIX+".trailing_shock.centroid_y","Trailing shock centroid position at t=0, y-component (float).",DEF_VALUE); cr.add(SHOCKPREFIX+".trailing_shock.centroid_z","Trailing shock centroid position at t=0, z-component (float).",DEF_VALUE); cr.add(SHOCKPREFIX+".length_units","Units in which positions are given, defaults to 'm' (string).",string("m")); return true; }
bool ShockParaboloid::initialize(Simulation& sim,SimulationClasses& simClasses,ConfigReader& cr) { bool success = true; const Real defValue = numeric_limits<Real>::infinity(); cr.add(PREFIX+".length_units","Units in which lengths are given, defaults to 'RS' (string)",string("RS")); cr.add(PREFIX+".reference_height","Height at which reference radius is given (float)",defValue); cr.add(PREFIX+".reference_radius1","Shock radius1 at reference height (float)",defValue); cr.add(PREFIX+".reference_radius2","Shock radius2 at reference height (float)",defValue); cr.add(PREFIX+".size_radius","Number of nodes in circular direction (int)",(uint32_t)0); cr.add(PREFIX+".size_height","Number of nodes in height direction (int)",(uint32_t)0); cr.add(PREFIX+".maximum_height","Maximum height (float)",defValue); cr.add(PREFIX+".initial_x_position","Position of shock at t=0 (float)",defValue); cr.parse(); string lengthUnitsString; cr.get(PREFIX+".length_units",lengthUnitsString); cr.get(PREFIX+".reference_height",height0); cr.get(PREFIX+".reference_radius1",radius0_x); cr.get(PREFIX+".reference_radius2",radius0_y); cr.get(PREFIX+".size_radius",N_nodes_v); cr.get(PREFIX+".size_height",N_nodes_u); cr.get(PREFIX+".maximum_height",maxHeight); cr.get(PREFIX+".initial_x_position",x0); // Check input values for sanity: const double lengthUnits = simClasses.constants.getDistanceInSI(lengthUnitsString); if (lengthUnits == numeric_limits<double>::infinity()) { simClasses.logger << "(SEP SHOCK) ERROR: Unsupported length units '" << lengthUnitsString << "'" << endl << write; success = false; } if (height0 == defValue) { simClasses.logger << "(SEP SHOCK) ERROR: Reference height was not given in config file" << endl << write; success = false; } if (radius0_x == defValue) { simClasses.logger << "(SEP SHOCK) ERROR: Reference radius was not given in config file" << endl << write; success = false; } if (radius0_y == defValue) { simClasses.logger << "(SEP SHOCK) ERROR: Reference radius was not given in config file" << endl << write; success = false; } if (maxHeight == defValue) { simClasses.logger << "(SEP SHOCK) ERROR: Maximum height was not given in config file" << endl << write; success = false; } if (N_nodes_u == 0) { simClasses.logger << "(SEP SHOCK) ERROR: Number of radial nodes was not given in config file" << endl << write; success = false; } if (N_nodes_v == 0) { simClasses.logger << "(SEP SHOCK) ERROR: Number of height nodes was not given in config file" << endl << write; success = false; } if (x0 == defValue) { simClasses.logger << "(SEP SHOCK) ERROR: Shock initial position was not given in config file" << endl << write; success = false; } // Exit if error(s) have occurred: if (success == false) return success; // Scale distances to SI units: height0 *= lengthUnits; radius0_x *= lengthUnits; radius0_y *= lengthUnits; maxHeight *= lengthUnits; x0 *= lengthUnits; ++N_nodes_u; success = createNodes(); return success; }