Ejemplo n.º 1
0
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 OperatorEnergyChannels::initialize(ConfigReader& cr,Simulation& sim,SimulationClasses& simClasses) {
      initialized = true;
      simClasses.logger << "(SEP OP ENERGY CHANNELS) Starting initialization" << endl << write;
      
      // Init base class:
      if (OperatorAccumulationBase::initialize(cr,sim,simClasses) == false) {
	 simClasses.logger << "(SEP OP ENERGY CHANNELS) ERROR: OperatorAccumulationBase failed to initialize!" << endl << write;
	 initialized = false;
      }

      // Create a profiler section name for this DataOperator:
      #if PROFILE_LEVEL > 0
         stringstream ss;
         ss << "Energy Channels" << OperatorAccumulationBase::getOrder();
         profileName = ss.str();
         OperatorAccumulationBase::setProfileName(ss.str());
      #endif
      
      // Get names of instruments:
      vector<string> instrumentNames;
      cr.addComposed(PREFIX+".instrument_names","Names of energy instruments (string).");
      cr.parse();
      cr.get(PREFIX+".instrument_names",instrumentNames);

      //instrumentIndices.push_back(make_pair<size_t,size_t>(0,0));
      for (size_t i=0; i<instrumentNames.size(); ++i) {
	 // Skip empty lines
	 if (instrumentNames[i].size() == 0) continue;

	 // Read config file items for instrument and create it:
	 if (createInstrument(simClasses,cr,instrumentNames[i]) == false) {
	    simClasses.logger << "(SEP OP ENERGY CHANNELS) ERROR: Failed to read required config file items for ";
	    simClasses.logger << "instrument '" << instrumentNames[i] << "'" << endl << write;
	    initialized = false;
	 }
      }

      // Write init status and exit:
      simClasses.logger << "(SEP OP ENERGY CHANNELS) Initialization complete, status is ";
      if (initialized == true) simClasses.logger << "SUCCESS" << endl << write;
      else simClasses.logger << "FAILURE" << endl << write;
      
      return initialized;
   }
Ejemplo n.º 3
0
   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;
   }
Ejemplo n.º 4
0
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;
}
Ejemplo n.º 5
0
bool RestartBuilder::initialize(Simulation& sim,SimulationClasses& simClasses,ConfigReader& cr) {
   initialized = true;
   this->sim = &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;
}
Ejemplo n.º 6
0
   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;
   }
Ejemplo n.º 7
0
   bool SpatialSliceOP::initialize(ConfigReader& cr,Simulation& sim,SimulationClasses& simClasses) {
      if (baseClassInitialized == true) return baseClassInitialized;
      baseClassInitialized = true;
      
      if (DataOperator::initialize(cr,sim,simClasses) == false) {
	 baseClassInitialized = false; return baseClassInitialized;
      }
      
      // Add config file items:
      if (addConfigFileItems(cr) == false) {
	 baseClassInitialized = false; return baseClassInitialized;
      }
      
      vector<string> slicedCoordinateStrings;
      vector<string> sliceOriginStrings;
      vector<string> sliceGeometryString;
      cr.parse();
      cr.get(prefix+".sliced_coordinate",slicedCoordinateStrings);
      cr.get(prefix+".slice_origin",sliceOriginStrings);
      cr.get(prefix+".slice_geometry",sliceGeometryString);
      
      // Check that config file contains enough parameters for all slices:
      if (slicedCoordinateStrings.size() != sliceOriginStrings.size()) {
	 simClasses.logger << "(OP SPATIAL SLICE) ERROR: Number of sliced coordinates and number of slice origins differ." << endl << write;
	 baseClassInitialized = false; return baseClassInitialized;
      }
      if (slicedCoordinateStrings.size() != sliceGeometryString.size()) {
	 simClasses.logger << "(OP SPATIAL SLICE) ERROR: Number of sliced coordinates and number of slice geometries." << endl << write;
	 baseClassInitialized = false; return baseClassInitialized;
      }
      
      for (size_t i=0; i<slicedCoordinateStrings.size(); ++i) {
	 if (slicedCoordinateStrings[i] == "x") sliceCoordinates.push_back(0);
	 else if (slicedCoordinateStrings[i] == "y") sliceCoordinates.push_back(1);
	 else if (slicedCoordinateStrings[i] == "z") sliceCoordinates.push_back(2);
	 else {
	    simClasses.logger << "(OP SPATIAL SLICE) ERROR: Unknown slice coordinate '" << slicedCoordinateStrings[i];
	    simClasses.logger << "' given in config file, should be one of 'x', 'y' or 'z'." << endl << write;
	    baseClassInitialized = false; return baseClassInitialized;
	 }
      }
      
      for (size_t i=0; i<sliceGeometryString.size(); ++i) {
	 bool ok = false;
	 if (sliceGeometryString[i] == "cartesian") {ok = true; sliceGeometries.push_back(false);}
	 if (sliceGeometryString[i] == "cylindrical") {ok = true; sliceGeometries.push_back(true);}

	 if (ok == false) {
	    simClasses.logger << "(OP SPATIAL SLICE) ERROR: Unknown slice geometry '" << sliceGeometryString[i] << "'";
	    simClasses.logger << "' given in config file, should be 'cartesian' or 'cylindrical'." << endl << write;
	    baseClassInitialized = false; return baseClassInitialized;
	 }
      }
      
      for (size_t i=0; i<sliceOriginStrings.size(); ++i)
	sliceOrigins.push_back(atof(sliceOriginStrings[i].c_str()));

      sliceIndices.resize(sliceOrigins.size());
      for (size_t i=0; i<sliceIndices.size(); ++i) {
	 sliceIndices[i] = numeric_limits<uint32_t>::max();
      }

      return baseClassInitialized;
   }