本文整理汇总了C++中ParticleList::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ ParticleList::begin方法的具体用法?C++ ParticleList::begin怎么用?C++ ParticleList::begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ParticleList
的用法示例。
在下文中一共展示了ParticleList::begin方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AdvanceTime
void AdvanceTime(ParticleList& list, float dt, float timeStep)
{
Time += dt;
for (size_t i = 0; i < list.size(); ++i) {
Point3 p(list[i].Px, list[i].Py, list[i].Pz);
Vector3 v = ComputeCurl(p);
Point3 midx = p + 0.5f * timeStep * v;
p += timeStep * ComputeCurl(midx);
list[i].Px = p.getX();
list[i].Py = p.getY();
list[i].Pz = p.getZ();
list[i].Vx = v.getX();
list[i].Vy = v.getY();
list[i].Vz = v.getZ();
}
for (ParticleList::iterator i = list.begin(); i != list.end();) {
if (i->Py > PlumeCeiling) {
i = list.erase(i);
} else {
++i;
}
}
noise.set_time(0.5f*NoiseGain[0]/NoiseLengthScale[0]*Time);
if (!ShowStreamlines || Time < 0.1f)
SeedParticles(list, dt);
}
示例2: add_particles_mpi
void add_particles_mpi(ParticleList &particles, CellMatrix &cells)
{
ParticleList::iterator iter = particles.begin();
while(iter != particles.end())
{
particle_t tmp = (*iter);
Point p = get_cell_index(tmp);
cells[p.y][p.x].push_back(&(*iter));
++iter;
}
}
示例3: apply_forces
// apply force from actors to reactors
void Bin::apply_forces(ParticleList& reactors, ParticleList& actors) {
for( ParticleIterator reactor = reactors.begin(); reactor != reactors.end(); reactor++ ) {
if ((*reactor)->tag < 0)
continue;
for (ParticleIterator actor = actors.begin(); actor != actors.end(); actor++ ){
if ( *reactor == *actor)
continue;
double dx = (*actor)->x - (*reactor)->x;
double dy = (*actor)->y - (*reactor)->y;
double r2 = dx * dx + dy * dy;
if( r2 > cutoff * cutoff )
continue;
r2 = fmax( r2, min_r*min_r );
double r = sqrt( r2 );
// very simple short-range repulsive force
double coef = ( 1 - cutoff / r ) / r2 / mass;
(*reactor)->ax += coef * dx;
(*reactor)->ay += coef * dy;
}
}
}
示例4:
void VarianceDiffusionStrategy<StateType>::diffuse(const ParticleList &_src, ParticleList &_dest)
{
if(_src.size() == 0) return;
if(_dest.size() != _src.size()) _dest = _src;
const unsigned numDofs = _src[0].state.size();
unsigned index = 0;
StateType noise = _dest[0].state;
if(mVariance.size() != noise.size())
{
TRACE("------------- variance has wrong size. (should not be possible) ---------- ABORTING");
return;
}
if(mVarianceFactor.size() != noise.size())
{
TRACE("----------resizing variance factors. (should not happen) -------------- ");
mVarianceFactor.resize(noise.size(), 1);
}
// iterate over all source particles
for(ParticleListConstIterator it = _src.begin(); it != _src.end(); it++)
{
// for every dof
for(unsigned i=0; i < numDofs; i++)
{
noise[i] = this->mNormDistGenerator() * mVariance[i] * mVarianceFactor[i];
}
_dest[index].state = noise;
_dest[index].state += _src[index].state;
index++;
}
}
示例5: main
int main( int argc, char **argv )
{
//
// process command line parameters
//
if( find_option( argc, argv, "-h" ) >= 0 )
{
printf( "Options:\n" );
printf( "-h to see this help\n" );
printf( "-n <int> to set the number of particles\n" );
printf( "-o <filename> to specify the output file name\n" );
return 0;
}
int n = read_int( argc, argv, "-n", 1000 );
char *savename = read_string( argc, argv, "-o", NULL );
//
// set up MPI
//
int n_proc, rank;
set_size(n);
int num_cells = get_num_cells();
MPI_Init( &argc, &argv );
MPI_Comm_size( MPI_COMM_WORLD, &n_proc );
MPI_Comm_rank( MPI_COMM_WORLD, &rank );
//
// allocate generic resources
//
// FILE *fsave = savename && rank == 0 ? fopen( savename, "w" ) : NULL;
FILE *fsave = savename ? fopen( savename, "w" ) : NULL;
particle_t *particles = (particle_t*) malloc( n * sizeof(particle_t) );
MPI_Datatype PARTICLE;
MPI_Type_contiguous( 6, MPI_DOUBLE, &PARTICLE );
MPI_Type_commit( &PARTICLE );
ParticleList reference_particles; // the particles needed to compute correct forces on my_particles.
ParticleList my_particles; // the particles that this process is responsible for updating.
CellMatrix cells(num_cells);
// dummy particle
particle_t dummy;
dummy.x = -1;
dummy.y = -1;
//
// set up the data partitioning across processors
//
int *partition_offsets = (int*) malloc( (n_proc+1) * sizeof(int) );
int *partition_sizes = (int*) malloc( n_proc * sizeof(int) );
//
// allocate storage for local partition
//
int rows_per_thread = (num_cells + n_proc - 1) / n_proc;
int top_row = min( rank * rows_per_thread, num_cells); // the top row that the process is responsible for.
int bottom_row = min( (rank+1) * rows_per_thread, num_cells); // the bottow row that this process needs but is not responsible for
int my_amount;
//
// initialize and distribute the particles (that's fine to leave it unoptimized)
//
ParticleList all_particles;
all_particles.clear();
init_cell_matrix(cells);
if( rank == 0 )
{
all_particles.clear();
init_particles( n, particles );
update_cells(particles, cells, n);
for(int rankId = 0; rankId < n_proc; rankId++)
{
partition_offsets[rankId] = all_particles.size();
int first_row = min( rankId * rows_per_thread, num_cells);
int last_row = min( (rankId+1) * rows_per_thread, num_cells);
ParticleList tmp;
tmp.clear();
get_particles_from_rows(first_row, last_row, &tmp, cells);
all_particles.insert(all_particles.end(), tmp.begin(), tmp.end());
partition_sizes[rankId] = tmp.size();
}
partition_offsets[n_proc] = n;
}
// broadcast all offsets and sizes so we can scatter later.
MPI_Bcast(partition_offsets, n_proc+1, MPI_INT, 0, MPI_COMM_WORLD);
MPI_Bcast(partition_sizes, n_proc, MPI_INT, 0, MPI_COMM_WORLD);
// get my_amount from the partition sizes array and rezise the my_particles vector.
my_amount = partition_sizes[rank];
my_particles.resize(my_amount);
//.........这里部分代码省略.........