示例#1
0
int particles::pidt::mappings::MoveParticles::moveParticlesOfOneVertexWithinCell(
  int                                   vertexIndex,
  const peano::grid::VertexEnumerator&  fineGridVerticesEnumerator
) {
  #if defined(SharedTBB) && !defined(__WIN32__)
  tbb::atomic<int>     numberOfParticlesMoved;
  #elif SharedOMP
    #error not implemented yet
  #else
  int    numberOfParticlesMoved;
  #endif

  numberOfParticlesMoved = 0;

  ParticleHeap::HeapEntries& sourceVertexParticles = ParticleHeap::getInstance().getData(vertexIndex);
  pfor(i,0,static_cast<int>(sourceVertexParticles.size()),200)
    particles::pidt::records::Particle& currentParticle = sourceVertexParticles.at(i);

    const bool particleHasNotBeenMovedYet =
      currentParticle.getMovedParticle() != particles::pidt::records::Particle::Moved;

    const bool particleIsContainedInCell = fineGridVerticesEnumerator.overlaps(
      currentParticle._persistentRecords._x,
      0.0
    );

    if (particleHasNotBeenMovedYet && particleIsContainedInCell) {
      currentParticle._persistentRecords._x             += (_state.getTimeStepSize() * currentParticle._persistentRecords._v);
      currentParticle.setMovedParticle( particles::pidt::records::Particle::Moved );

      reflectParticle(currentParticle);

      numberOfParticlesMoved++;
    }
  endpfor

  return numberOfParticlesMoved;
}
示例#2
0
int particles::pidt::mappings::MoveParticles::moveParticlesOfOneVertexWithinCellIfTheyAreSorted(
  int                                   vertexIndex,
  const peano::grid::VertexEnumerator&  fineGridVerticesEnumerator
) {
  ParticleHeap::HeapEntries& sourceVertexParticles = ParticleHeap::getInstance().getData(vertexIndex);

  int numberOfParticlesMoved = 0;

  int biggestIndexPointingToUnmovedParticle  = static_cast<int>(sourceVertexParticles.size())-1;
  int smallestIndexPointingToUnmovedParticle = 0;

  while (
    biggestIndexPointingToUnmovedParticle>=0 &&
    sourceVertexParticles.at(biggestIndexPointingToUnmovedParticle).getMovedParticle() == particles::pidt::records::Particle::Moved
  ) {
    biggestIndexPointingToUnmovedParticle--;
  }

  #ifdef Asserts
  for (int i=0; i<biggestIndexPointingToUnmovedParticle; i++) {
    assertion3(
      sourceVertexParticles.at(i).getMovedParticle() != particles::pidt::records::Particle::Moved,
      i,
      biggestIndexPointingToUnmovedParticle,
      sourceVertexParticles.at(i).toString()
    );
  }
  #endif

  logDebug(
    "moveParticlesOfOneVertexWithinCellIfTheyAreSorted(...)",
    "moved index from " << static_cast<int>(sourceVertexParticles.size())-1 <<
    " to " << biggestIndexPointingToUnmovedParticle <<
    ": " << sourceVertexParticles.at(biggestIndexPointingToUnmovedParticle).toString() <<
    " with first element " << sourceVertexParticles.at(smallestIndexPointingToUnmovedParticle).toString()
  );

  // has to be equals as the two might just have been exchanged
  while (biggestIndexPointingToUnmovedParticle >= smallestIndexPointingToUnmovedParticle) {
    particles::pidt::records::Particle& currentParticle = sourceVertexParticles.at(smallestIndexPointingToUnmovedParticle);

    assertion( biggestIndexPointingToUnmovedParticle>=0 );
    assertion( smallestIndexPointingToUnmovedParticle>=0 );
    assertion( biggestIndexPointingToUnmovedParticle<static_cast<int>(sourceVertexParticles.size()) );
    assertion( smallestIndexPointingToUnmovedParticle<static_cast<int>(sourceVertexParticles.size()) );

    assertion4(
      currentParticle.getMovedParticle() != particles::pidt::records::Particle::Moved ||
      (smallestIndexPointingToUnmovedParticle==biggestIndexPointingToUnmovedParticle),
      smallestIndexPointingToUnmovedParticle,
      biggestIndexPointingToUnmovedParticle,
      sourceVertexParticles.at(smallestIndexPointingToUnmovedParticle).toString(),
      sourceVertexParticles.at(biggestIndexPointingToUnmovedParticle).toString()
    );

    const bool particleIsContainedInCell = fineGridVerticesEnumerator.overlaps(
      currentParticle._persistentRecords._x,
      0.0
    );

    if (particleIsContainedInCell) {
      currentParticle._persistentRecords._x             += (_state.getTimeStepSize() * currentParticle._persistentRecords._v);
      currentParticle.setMovedParticle( particles::pidt::records::Particle::Moved );
      reflectParticle(currentParticle);

      if (smallestIndexPointingToUnmovedParticle!=biggestIndexPointingToUnmovedParticle) {
        particles::pidt::records::Particle tmp                        =  currentParticle;
        currentParticle                                               =  sourceVertexParticles.at(biggestIndexPointingToUnmovedParticle);
        sourceVertexParticles[biggestIndexPointingToUnmovedParticle]  =  tmp;
      }

      numberOfParticlesMoved++;
      biggestIndexPointingToUnmovedParticle--;
    }
    else {
      smallestIndexPointingToUnmovedParticle++;
    }
  }

  return numberOfParticlesMoved;
}