Attention une mise à jour du service Gitlab va être effectuée le mardi 30 novembre entre 17h30 et 18h00. Cette mise à jour va générer une interruption du service dont nous ne maîtrisons pas complètement la durée mais qui ne devrait pas excéder quelques minutes. Cette mise à jour intermédiaire en version 14.0.12 nous permettra de rapidement pouvoir mettre à votre disposition une version plus récente.

Commit 8e9039ad authored by BRAMAS Berenger's avatar BRAMAS Berenger
Browse files

add an insert using std::array

parent 80a0057b
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
#include "Utils/FPoint.hpp" #include "Utils/FPoint.hpp"
#include "FParticleType.hpp" #include "FParticleType.hpp"
#include <array>
/** /**
* @author Berenger Bramas (berenger.bramas@inria.fr) * @author Berenger Bramas (berenger.bramas@inria.fr)
* @class FBasicParticle * @class FBasicParticle
...@@ -74,6 +76,35 @@ protected: ...@@ -74,6 +76,35 @@ protected:
addParticleValue<index+1>( insertPosition, args...); addParticleValue<index+1>( insertPosition, args...);
} }
/////////////////////////////////////////////////////
/////////////////////////////////////////////////////
void increaseSizeIfNeeded(){
if( nbParticles == allocatedParticles ){
// allocate memory
const int moduloParticlesNumber = (32/sizeof(FReal)); // We want to be rounded to 32B
allocatedParticles = (FMath::Max(10,int(FReal(nbParticles+1)*1.5)) + moduloParticlesNumber - 1) & ~(moduloParticlesNumber-1);
// init with 0
const size_t allocatedBytes = (sizeof(FReal)*3 + sizeof(AttributeClass)*NbAttributesPerParticle)*allocatedParticles;
FReal* newData = reinterpret_cast<FReal*>(FAlignedMemory::Allocate32BAligned(allocatedBytes));
memset( newData, 0, allocatedBytes);
// copy memory
const char*const toDelete = reinterpret_cast<const char*>(positions[0]);
for(int idx = 0 ; idx < 3 ; ++idx){
memcpy(newData + (allocatedParticles * idx), positions[idx], sizeof(FReal) * nbParticles);
positions[idx] = newData + (allocatedParticles * idx);
}
// copy attributes
AttributeClass* startAddress = reinterpret_cast<AttributeClass*>(positions[2] + allocatedParticles);
for(unsigned idx = 0 ; idx < NbAttributesPerParticle ; ++idx){
memcpy(startAddress + (allocatedParticles * idx), attributes[idx], sizeof(AttributeClass) * nbParticles);
attributes[idx] = startAddress + (idx * allocatedParticles);
}
// delete old
FAlignedMemory::Dealloc32BAligned(toDelete);
}
}
public: public:
///////////////////////////////////////////////////// /////////////////////////////////////////////////////
///////////////////////////////////////////////////// /////////////////////////////////////////////////////
...@@ -173,29 +204,8 @@ public: ...@@ -173,29 +204,8 @@ public:
template<typename... Args> template<typename... Args>
void push(const FPoint& inParticlePosition, Args... args){ void push(const FPoint& inParticlePosition, Args... args){
// enought space? // enought space?
if( nbParticles == allocatedParticles ){ increaseSizeIfNeeded();
// allocate memory
const int moduloParticlesNumber = (32/sizeof(FReal)); // We want to be rounded to 32B
allocatedParticles = (FMath::Max(10,int(FReal(nbParticles+1)*1.5)) + moduloParticlesNumber - 1) & ~(moduloParticlesNumber-1);
// init with 0
const size_t allocatedBytes = (sizeof(FReal)*3 + sizeof(AttributeClass)*NbAttributesPerParticle)*allocatedParticles;
FReal* newData = reinterpret_cast<FReal*>(FAlignedMemory::Allocate32BAligned(allocatedBytes));
memset( newData, 0, allocatedBytes);
// copy memory
const char*const toDelete = reinterpret_cast<const char*>(positions[0]);
for(int idx = 0 ; idx < 3 ; ++idx){
memcpy(newData + (allocatedParticles * idx), positions[idx], sizeof(FReal) * nbParticles);
positions[idx] = newData + (allocatedParticles * idx);
}
// copy attributes
AttributeClass* startAddress = reinterpret_cast<AttributeClass*>(positions[2] + allocatedParticles);
for(unsigned idx = 0 ; idx < NbAttributesPerParticle ; ++idx){
memcpy(startAddress + (allocatedParticles * idx), attributes[idx], sizeof(AttributeClass) * nbParticles);
attributes[idx] = startAddress + (idx * allocatedParticles);
}
// delete old
FAlignedMemory::Dealloc32BAligned(toDelete);
}
// insert particle data // insert particle data
positions[0][nbParticles] = inParticlePosition.getX(); positions[0][nbParticles] = inParticlePosition.getX();
positions[1][nbParticles] = inParticlePosition.getY(); positions[1][nbParticles] = inParticlePosition.getY();
...@@ -205,6 +215,27 @@ public: ...@@ -205,6 +215,27 @@ public:
nbParticles += 1; nbParticles += 1;
} }
/**
* Push called bu FSimpleLeaf
* Should have a particle position fallowed by attributes
*/
template<typename... Args>
void push(const FPoint& inParticlePosition, const std::array<AttributeClass , NbAttributesPerParticle>& values){
// enought space?
increaseSizeIfNeeded();
// insert particle data
positions[0][nbParticles] = inParticlePosition.getX();
positions[1][nbParticles] = inParticlePosition.getY();
positions[2][nbParticles] = inParticlePosition.getZ();
// insert attribute data
for(int idxVal = 0 ; idxVal < NbAttributesPerParticle ; ++idxVal){
attributes[idxVal][nbParticles] = values[idxVal];
}
nbParticles += 1;
}
/** /**
* Push called usually by FTypedLeaf with the isTarget flag in addition * Push called usually by FTypedLeaf with the isTarget flag in addition
*/ */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment