Esempio n. 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;
        }
    }
Esempio n. 2
0
//------------------------------------------------------------------------------
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);
    }
}
Esempio n. 3
0
void updateVerletList(const string &verletStringId,
                      Particles & particles,
                      Grid & grid,
                      double radius)
{
    double radiusSquared = radius*radius;

    int verletId = particles.getVerletId(verletStringId);
    const unordered_map<int, GridPoint*> &gridpoints = grid.gridpoints();
    const mat & R = particles.r();
    const vector<int> &mygridPoints = grid.myGridPoints();
    particles.clearVerletList(verletId);

#ifdef USE_OPENMP
#pragma omp parallel for
#endif
    for(int i=0; i<mygridPoints.size(); i++)
    {
        double dx, dy, dz;
        int gridId = mygridPoints.at(i);
        const GridPoint & gridPoint = *gridpoints.at(gridId);

        for(const pair<int, int> & idCol_i:gridPoint.particles())
        {
            int id_i = idCol_i.first;
            vector<int> verletList;
            const vec & r_i = R.col(idCol_i.second);

            for(const pair<int, int> & idCol_j:gridPoint.particles())
            {
                int id_j = idCol_j.first;
                if(id_i == id_j)
                    continue;

                const vec & r_j = R.col(idCol_j.second);
                dx = r_i(0) - r_j(0);
                dy = r_i(1) - r_j(1);
                dz = r_i(2) - r_j(2);

                double drSquared = dx*dx + dy*dy + dz*dz;

                if(drSquared < radiusSquared)
                {
                    verletList.push_back(id_j);
                }
            }

            // Neighbouring cells
            const vector<GridPoint*> & neighbours = gridPoint.neighbours();

            for(const GridPoint *neighbour:neighbours)
            {
                for(const pair<int, int> & idCol_j:neighbour->particles())
                {
                    const vec & r_j = R.col(idCol_j.second);
                    dx = r_i(0) - r_j(0);
                    dy = r_i(1) - r_j(1);
                    dz = r_i(2) - r_j(2);

                    double drSquared = dx*dx + dy*dy + dz*dz;

                    if(drSquared < radiusSquared)
                    {
                        verletList.push_back(idCol_j.first);
                    }
                }
            }

#ifdef USE_OPENMP
#pragma omp critical
            {
                particles.setVerletList(id_i, verletList, verletId);
            }
#else
            particles.setVerletList(id_i, verletList, verletId);
#endif
        }
    }
}
Esempio n. 4
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];
    }
  }
}
Esempio n. 5
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]);
    }
  }
}