示例#1
0
    PARTICLES_FIXTURE()
    {
        testParticles.nParticles(test_nParticles);
        testParticles.initializeMatrices();
        mat & data = testParticles.data();
        mat & r = testParticles.r();

        auto & parameters = testParticles.parameters();
        parameters["v_x"] = 0;
        parameters["v_y"] = 1;
        parameters["volume"] = 2;

        vec v_x, v_y, volume;
        mat _r;
        _r << 0.313150 << 0.932484 << 0.731905 << 0.650592 << 0.109496 << 0.532164 << 0.685139 << 0.678746 << 0.384222 << 0.947418 << 0.294880 << arma::endr
                        << 0.597834 << 0.519061 << 0.547958 << 0.343276 << 0.449608 << 0.704623 << 0.468903 << 0.390759 << 0.581632 << 0.401296 << 0.368566 << arma::endr;
        v_x << 0.165347 << 0.001397  << 0.212907 << 0.529744  << 0.195344 << 0.504753 << 0.236449 << 0.546610 << 0.681405 << 0.665064 << 0.110014;
        v_y << 0.265347 << 0.101397 << 0.112907 << 0.329744 << 0.695344 << 0.0504753 << 0.536449 << 0.346610 << 0.168145 << 0.166564 << 0.111014;
        volume << 8.76566e-06 << 8.22899e-06 << 8.0501e-06  << 8.31843e-06 << 7.78176e-06 << 6.44008e-06 << 7.33453e-06 << 8.0501e-06 << 8.31843e-06 << 7.0662e-06 << 8.13954e-06 << arma::endr;

        r = _r.t();
        data.col(parameters["v_x"]) = v_x;
        data.col(parameters["v_y"]) = v_y;
        data.col(parameters["volume"]) = volume;

        unordered_map<int, int> & pIds = testParticles.pIds();
        for(int i=0; i<test_nParticles;i++)
        {
            pIds[i] = i;
        }
    }
示例#2
0
文件: grid.cpp 项目: ttnghia/PDtools
//------------------------------------------------------------------------------
void Grid::placeParticlesInGrid(Particles &particles)
{
    clearParticles();
    const mat & rParticles = particles.r();

#ifdef USE_OPENMP
# pragma omp parallel for
#endif
    for(int i=0; i<particles.nParticles(); i++)
    {
        pair<int, int> id_pos(i, i);
        const vec3 &r = rParticles.col(id_pos.second);
        int gId = gridId(r);
#ifdef USE_OPENMP
#pragma omp critical
#endif
        m_gridpoints[gId]->addParticle(id_pos);
    }
}
示例#3
0
void LoadParticles::loadBinaryBody(Particles &particles, FILE *rawData,
                                   unordered_map<string, int> parameters) {
  particles.maxParticles(m_nParticles);
  particles.nParticles(m_nParticles);
  particles.totParticles(m_nParticles);
  // Storing only non-basic parameters in the parameters
  int counter = 0;
  vector<pair<int, int>> data_config_mapping;
  for (auto param : parameters) {
    bool found = false;
    for (string basic_parameter : basicParameters) {
      if (param.first == basic_parameter) {
        found = true;
      }
    }

    if (!found) {
      particles.parameters()[param.first] = counter;
      data_config_mapping.push_back(pair<int, int>(counter, param.second));
      counter++;
    }
  }

  //--------------------------------------------------------------------------
  bool idIsset = false;
  int idPos = 0;
  if (parameters.count("id") > 0) {
    idIsset = true;
    idPos = parameters["id"];
  }

  vector<pair<int, int>> position_config;
  int dim = 0;
  if (parameters.count("x") > 0) {
    dim++;
    position_config.push_back(pair<int, int>(0, parameters["x"]));
  }
  if (parameters.count("y") > 0) {
    dim++;
    position_config.push_back(pair<int, int>(1, parameters["y"]));
  }
  if (parameters.count("z") > 0) {
    dim++;
    position_config.push_back(pair<int, int>(2, parameters["z"]));
  }
  particles.dim(dim);

  //--------------------------------------------------------------------------
  // Creating the data matrix
  particles.initializeMatrices();

  int nColumns = m_nColumns;
  ivec &idToCol = particles.getIdToCol_v();
  arma::ivec &colToId = particles.colToId();
  arma::mat &r = particles.r();
  arma::mat &data = particles.data();

  // Reading all the data from file
  for (unsigned int i = 0; i < particles.nParticles(); i++) {
    double line[nColumns];
    fread(&line[0], nColumns * sizeof(double), 1, rawData);

    // Collecting the data
    if (idIsset) {
      idToCol[int(line[idPos])] = i;
      colToId[i] = int(line[idPos]);
    } else {
      idToCol[i] = i;
      colToId[i] = i;
    }

    for (pair<int, int> pc : position_config) {
      r(i, pc.first) = line[pc.second];
    }
    for (pair<int, int> dfc : data_config_mapping) {
      data(i, dfc.first) = line[dfc.second];
    }
  }
}
示例#4
0
void LoadParticles::loadBody(Particles &particles, std::fstream &rawData,
                             unordered_map<string, int> parameters) {
  particles.maxParticles(m_nParticles);
  particles.nParticles(m_nParticles);
  particles.totParticles(m_nParticles);
  string line;

  //--------------------------------------------------------------------------
  // Storing only non-basic parameters in the parameters
  int counter = 0;
  vector<pair<int, int>> data_config_mapping;
  for (auto param : parameters) {
    bool found = false;

    for (string basic_parameter : basicParameters) {
      if (param.first == basic_parameter) {
        found = true;
      }
    }

    if (!found) {
      particles.parameters()[param.first] = counter;
      data_config_mapping.push_back(pair<int, int>(counter, param.second));
      counter++;
    }
  }

  //--------------------------------------------------------------------------
  bool idIsset = false;
  int idPos = 0;
  if (parameters.count("id") > 0) {
    idIsset = true;
    idPos = parameters["id"];
  }

  vector<pair<int, int>> position_config;
  int dim = 0;
  if (parameters.count("x") > 0) {
    dim++;
    position_config.push_back(pair<int, int>(0, parameters["x"]));
  }
  if (parameters.count("y") > 0) {
    dim++;
    position_config.push_back(pair<int, int>(1, parameters["y"]));
  }
  if (parameters.count("z") > 0) {
    dim++;
    position_config.push_back(pair<int, int>(2, parameters["z"]));
  }
  particles.dim(dim);

  //--------------------------------------------------------------------------
  // Creating the data matrix
  particles.initializeMatrices();
  ivec &idToCol = particles.getIdToCol_v();
  arma::ivec &colToId = particles.colToId();
  arma::mat &r = particles.r();
  arma::mat &data = particles.data();

  // Reading all the data from file
  for (unsigned int i = 0; i < particles.nParticles(); i++) {
    vector<string> lineSplit;
    getline(rawData, line);
    boost::trim_if(line, boost::is_any_of("\t "));
    boost::split(lineSplit, line, boost::is_any_of("\t "),
                 boost::token_compress_on);

    // Collecting the data
    if (idIsset) {
      idToCol[stoi(lineSplit[idPos])] = i;
      colToId[i] = stoi(lineSplit[idPos]);
    } else {
      idToCol[i] = i;
      colToId[i] = i;
    }

    for (pair<int, int> pc : position_config) {
      r(i, pc.first) = stod(lineSplit[pc.second]);
    }
    for (pair<int, int> dfc : data_config_mapping) {
      data(i, dfc.first) = stod(lineSplit[dfc.second]);
    }
  }
}