Example #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;
}
Example #2
0
void Game::readObjectPath(std::string &objectSprite, const ConfigReader reader, const std::string name, bool &successful)
{
    objectSprite = reader.get(name, "Sprite");
    if (objectSprite == "") {
        std::cerr << "error: [" << name << "]: Sprite was not set." << std::endl;
        objectSprite = ":/resources/block_brown.png";
        successful = false;
    }
}
Example #3
0
void Game::readObjectHeight(int &objectHeight, const ConfigReader reader, bool &parseOk, const std::string name, bool &successful)
{
    objectHeight = QString(reader.get(name, "Height").c_str()).toInt(&parseOk);
    if (!parseOk || objectHeight < 0) {
        std::cerr << "error: [" << name << "]: height was not an integer." << std::endl;
        objectHeight = 1;
        successful = false;
    }
}
Example #4
0
void SLErrorWidget::init_pointers (const ConfigReader& reader, const FieldGeometry& fg2) {
  vector<double> dval (2);
#if CFILTER
  if (reader.get ("CondensationFilter::sensor_probabilities", dval)>=2) {
    probability_line_sdev = abs(dval[0]);
    probability_line_min = abs(dval[1]);
  } else {
    probability_line_sdev = 500;
    probability_line_min = 0.2;
  }
#else
   if (!reader.get ("ErrorMinimiserSL::error_width", probability_line_sdev)>=1) {
     probability_line_sdev = 500;
   } 
#endif
  if (!reader.get ("ErrorMinimiserSL::error_width", optimiser_error_param))
    optimiser_error_param=250;
  if (!reader.get ("ErrorMinimiserSL::num_iterations", num_opt_iter))
    num_opt_iter=20;
  fg = new Tribots::FieldGeometry (fg2);
}
Example #5
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;
}
   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;
   }
   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;
   }
CalibrationRecorder::CalibrationRecorder (const ConfigReader& cfg, const char* hostname, unsigned int port) {
  widget = new TribotsTools::ImageWidget;
  qApp->setMainWidget(widget);
  widget->show();
  panel = new CalibrationRecorderControlPanel;
  panel->show();

  regionBefore = new Pixelset;
  regionWork = new Pixelset;
  regionAfter = new Pixelset;

  // Verbindung zu MarkerDisplay aufbauen:
  serverPort=port;
  image = oldImage=NULL;
  string camerasection="";
  cfg.get ("camerasection", camerasection);
  camera = new IIDC (cfg, camerasection.c_str(), true);
  mode=neutral;
  hostInfo = gethostbyname(hostname);
  if (hostInfo == NULL)
    throw TribotsException ("problem interpreting host");
  socketDescriptor = socket(AF_INET, SOCK_STREAM, 0);
  if (socketDescriptor < 0)
    throw TribotsException ("cannot create socket");
  serverAddress.sin_family = hostInfo->h_addrtype;
  memcpy((char *) &serverAddress.sin_addr.s_addr,
         hostInfo->h_addr_list[0], hostInfo->h_length);
  serverAddress.sin_port = htons(serverPort);
  if (connect(socketDescriptor,
              (struct sockaddr *) &serverAddress,
              sizeof(serverAddress)) < 0)
    throw TribotsException ("cannot connect to server");
  if (send (socketDescriptor, "blackScreen", 11,0)<0)
    throw TribotsException ("cannot send");
  char buffer [100];
  if (recv(socketDescriptor, buffer, 100,0)<0)
    throw TribotsException ("cannot receive");
  markerout=NULL;
}
Example #9
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;
}
Example #10
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;
   }
Example #11
0
bool Game::loadLevel(Level::Builder &levelBuilder, const ConfigReader &reader)
{

    bool parseOk = false;
    bool successful = true;

    int rangeStart = QString(reader.get("Level", "RangeStart").c_str()).toInt(&parseOk);
    if (!parseOk || rangeStart < 0) {
        rangeStart = 0;
        successful = false;
    }

    int rangeEnd = QString(reader.get("Level", "RangeEnd").c_str()).toInt(&parseOk);
    if (!parseOk || rangeEnd < 0) {
        rangeEnd = 0;
        successful = false;
    }

    int obst_unitsInPixels = QString(reader.get("Level", "UnitsInPixels").c_str()).toInt(&parseOk);
    if (!parseOk || obst_unitsInPixels < 0) {
        obst_unitsInPixels = 32;
        successful = false;
    }

    int powup_unitsInPixels = QString(reader.get("Powerups", "UnitsInPixels").c_str()).toInt(&parseOk);
    if (!parseOk || powup_unitsInPixels < 0) {
        powup_unitsInPixels = 32;
        successful = false;
    }

    float obstaclePosition = m_dialog->width(), powerUpPosition = m_dialog->width();
    int obst_previousWidth = 0, powup_previousWidth = 0;

    /* When obstacles are properly defined */
    int i = rangeStart;
    while (i <= rangeEnd) {
        std::stringstream indexStream;
        indexStream << i;

        std::string obstacle_pair = reader.get("Level", indexStream.str());
        std::string powerup_pair = reader.get("Powerups", indexStream.str());

        if (obstacle_pair.empty() && powerup_pair.empty()) {
            break;
        }

        std::string name;
        int gap;
        int height;

        if (!obstacle_pair.empty())
        {
            std::istringstream ss(obstacle_pair.c_str());
            ss >> name;
            ss >> gap;
            ss >> height;

            /* Sprite image path*/
            std::string obstacleSprite;
            readObjectPath(obstacleSprite, reader, name, successful);

            /* Obstacle width */
            int obstacleWidth;
            readObjectWidth(obstacleWidth, reader, parseOk, name, successful);

            /* Obstacle height */
            int obstacleHeight;
            readObjectHeight(obstacleHeight, reader, parseOk, name, successful);

            obstaclePosition += ((obst_previousWidth / 2.0f) + (obstacleWidth / 2.0f)) * obst_unitsInPixels;
            obst_previousWidth = obstacleWidth;

            levelBuilder.buildObstacle(
                        QSize(obstacleWidth * obst_unitsInPixels, obstacleHeight * obst_unitsInPixels),
                        QPoint(obstaclePosition, (obstacleHeight * obst_unitsInPixels / 2.0f) + height * obst_unitsInPixels),
                        QPixmap(obstacleSprite.c_str())
                        );

            obstaclePosition += gap * obst_unitsInPixels;
        }

        if (!powerup_pair.empty())
        {
            int type = GROW;
            std::istringstream ss(powerup_pair.c_str());
            ss >> name;
            ss >> gap;
            ss >> height;
            ss >> type;

            /* Adjust type if invalid */
            if (type < 0 || type > 1) type = 0;

            /* Sprite image path*/
            std::string powerUpSprite;
            readObjectPath(powerUpSprite, reader, name, successful);

            /* Obstacle width */
            int powerUpWidth;
            readObjectWidth(powerUpWidth, reader, parseOk, name, successful);

            /* Obstacle height */
            int powerUpHeight;
            readObjectHeight(powerUpHeight, reader, parseOk, name, successful);

            powerUpPosition += ((powup_previousWidth / 2.0f) + (powerUpWidth / 2.0f)) * powup_unitsInPixels;
            powup_previousWidth = powerUpWidth;

            levelBuilder.buildPowerup(
                        QSize(powerUpWidth * powup_unitsInPixels, powerUpHeight * powup_unitsInPixels),
                        QPoint(powerUpPosition, (powerUpHeight * powup_unitsInPixels / 2.0f) + height * powup_unitsInPixels),
                        QPixmap(powerUpSprite.c_str()), type
                        );

            powerUpPosition += gap * powup_unitsInPixels;
        }
   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;
   }