当前位置: 首页>>代码示例>>C++>>正文


C++ Particles::totParticles方法代码示例

本文整理汇总了C++中Particles::totParticles方法的典型用法代码示例。如果您正苦于以下问题:C++ Particles::totParticles方法的具体用法?C++ Particles::totParticles怎么用?C++ Particles::totParticles使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Particles的用法示例。


在下文中一共展示了Particles::totParticles方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: loadBinaryBody

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];
    }
  }
}
开发者ID:sigvebs,项目名称:PDtools,代码行数:79,代码来源:loadparticles.cpp

示例2: loadBody

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]);
    }
  }
}
开发者ID:sigvebs,项目名称:PDtools,代码行数:84,代码来源:loadparticles.cpp


注:本文中的Particles::totParticles方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。