Commit 30819ad9 authored by berenger-bramas's avatar berenger-bramas
Browse files

Extension

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/scalfmm/scalfmm/trunk@15 2616d619-271b-44dc-8df4-d4a8f33a7222
parent 7a737b27
......@@ -2,14 +2,13 @@
#define FLIST_HPP
// /!\ Please, you must read the license at the bottom of this page
/**
* @author Berenger Bramas (berenger.bramas@inria.fr)
* @class FList
* Please read the license
*
* This class is a linked list container.
* It is a very basic list to enable strong performance.
*
* Please refere to unit test flistUTest.cpp
*/
......@@ -67,7 +66,7 @@ public:
/**
* Copy constructor
* @param other the source list
* @param other the source/original list
*/
FList(const FList& other): root(0) , size(0) {
copy(other);
......@@ -95,7 +94,7 @@ public:
newNode->next = this->root;
this->root = newNode;
++size;
++this->size;
}
/**
......@@ -108,7 +107,7 @@ public:
newNode->next = this->root;
this->root = newNode;
++size;
++this->size;
}
/**
......@@ -118,7 +117,7 @@ public:
* @return first value if exists or defaultValue otherwise
*/
Object& front(Object& defaultValue = Object()){
if(size) return this->root->target;
if(this->size) return this->root->target;
else return defaultValue;
}
......@@ -129,7 +128,7 @@ public:
* @return first value if exists or defaultValue otherwise
*/
const Object& front(const Object& defaultValue = Object()) const {
if(size) return this->root->target;
if(this->size) return this->root->target;
else return defaultValue;
}
......@@ -139,7 +138,7 @@ public:
* @warning you must check the list's size before calling this function!
*/
Object popFront(){
--size;
--this->size;
Node* newNode = this->root;
this->root = this->root->next;
......@@ -154,7 +153,7 @@ public:
* @return size
*/
int getSize() const{
return size;
return this->size;
}
/**
......@@ -185,7 +184,7 @@ public:
/** to progress on the list */
void progress(){
if(iter) iter = iter->next;
if(this->iter) this->iter = this->iter->next;
}
/**
......@@ -193,7 +192,7 @@ public:
* current iterator must be valide (isValide()) to use this function
*/
Object& value(){
return iter->target;
return this->iter->target;
}
/**
......@@ -201,7 +200,7 @@ public:
* current iterator must be valide (isValide()) to use this function
*/
const Object& value() const{
return iter->target;
return this->iter->target;
}
/**
......
......@@ -22,6 +22,10 @@
* // can be used as : <br>
* FOctree<TestParticule, TestCell, 10, 3> tree(1.0,F3DPosition(0.5,0.5,0.5));
* </code>
*
* Particules and cells has to respect the Abstract class definition.
* Particule can extend {FExtendPosition}
* Cell can extend {FExtendPosition,FExtendMortonIndex}
*/
template< class ParticuleClass, class CellClass, int OctreeHeight, int SubtreeHeight = 3>
class FOctree {
......@@ -50,7 +54,7 @@ class FOctree {
* @param inPosition position to compute
* @return the morton index
*/
MortonIndex getLeafMortonFromPosition(const F3DPosition& inPosition){
MortonIndex getLeafMortonFromPosition(const F3DPosition& inPosition) const {
// box coordinate to host the particule
FTreeCoordinate host;
// position has to be relative to corner not center
......@@ -66,11 +70,11 @@ class FOctree {
* @param inRelativePosition a position from the corner of the box
* @return the box num at the leaf level that contains inRelativePosition
*/
long getTreeCoordinate(const double inRelativePosition){
long getTreeCoordinate(const double inRelativePosition) const {
const double indexDouble = inRelativePosition / this->boxWidthAtLevel[this->leafIndex];
long index = FMath::dfloor(indexDouble);
const long index = FMath::dfloor(indexDouble);
if( index && FMath::LookEqual(inRelativePosition, this->boxWidthAtLevel[this->leafIndex] * index ) ){
--index;
return index - 1;
}
return index;
}
......@@ -106,8 +110,8 @@ public:
* @param inParticule the particule to insert (must inherite from FAbstractParticule)
*/
void insert(ParticuleClass* const inParticule){
const MortonIndex particuleIndex = getLeafMortonFromPosition(inParticule->getPosition());
root.insert( particuleIndex, inParticule, height, this->boxWidthAtLevel);
const MortonIndex particuleIndex = getLeafMortonFromPosition( inParticule->getPosition() );
root.insert( particuleIndex, inParticule, this->height, this->boxWidthAtLevel);
}
......@@ -212,10 +216,10 @@ public:
while(1) {
this->currentLocalLevel = this->current.tree->getSubOctreeHeight() - 1;
this->currentLocalIndex = this->current.tree->getLeftLeafIndex();
if(isAtLeafLevel()){
if( isAtLeafLevel() ){
return;
}
this->current.tree = this->current.middleTree->leafs(this->currentLocalIndex);
this->current.tree = this->current.middleTree->leafs( this->currentLocalIndex );
}
}
......@@ -227,12 +231,12 @@ public:
const int currentLevel = level();
// Goto root sutoctree
while(this->current.tree->hasParent()){
while( this->current.tree->hasParent() ){
this->current.tree = this->current.tree->getParent();
}
// Go down on the left until arriving on the same global level
while(this->current.tree->getSubOctreeHeight() + this->current.tree->getSubOctreePosition() - 1 < currentLevel) {
while( this->current.tree->getSubOctreeHeight() + this->current.tree->getSubOctreePosition() - 1 < currentLevel ) {
this->current.tree = this->current.middleTree->leafs(this->current.tree->getLeftLeafIndex());
}
......@@ -248,11 +252,11 @@ public:
// Function variables
const int currentLevel = level();
// Goto root sutoctree
while(this->current.tree->hasParent()){
while( this->current.tree->hasParent() ){
this->current.tree = this->current.tree->getParent();
}
// Go down on the left until arriving on the same global level
while(this->current.tree->getSubOctreeHeight() + this->current.tree->getSubOctreePosition() - 1 < currentLevel) {
while( this->current.tree->getSubOctreeHeight() + this->current.tree->getSubOctreePosition() - 1 < currentLevel ) {
this->current.tree = this->current.middleTree->leafs(this->current.tree->getRightLeafIndex());
}
// Level still unchanged we only go to the left
......@@ -367,13 +371,13 @@ public:
*/
bool moveUp() {
// It is on the top level?
if(this->currentLocalLevel){
if( this->currentLocalLevel ){
// No so simply go up
--this->currentLocalLevel;
this->currentLocalIndex >>= 3;
}
// Yes need to change suboctree
else if(this->current.tree->hasParent()){
else if( this->current.tree->hasParent() ){
this->currentLocalIndex = this->current.tree->getIndexInParent();
this->current.tree = this->current.tree->getParent();
this->currentLocalLevel = this->current.tree->getSubOctreeHeight() - 1;
......@@ -483,7 +487,7 @@ public:
* // is equivalent to :<br>
* iter.getCurrentCell()->getMortonIndex();</code>
*/
MortonIndex getCurrentGlobalIndex(){
MortonIndex getCurrentGlobalIndex() const{
return this->current.tree->cellsAt(this->currentLocalLevel)[this->currentLocalIndex]->getMortonIndex();
}
......@@ -521,6 +525,7 @@ public:
return workingTree.tree->cellsAt(inLevel - workingTree.tree->getSubOctreePosition())[treeLeafMask & inIndex];
}
/** This function fill a array with the neighbors of a cell
* it does not put the brothers in the array (brothers are cells
* at the same level with the same parent) because they are of course
......@@ -568,6 +573,7 @@ public:
return idxNeighbors;
}
/** This function return an adresse of cell array from a morton index and a level
*
* @param inIndex the index of the desired cell array has to contains
......@@ -601,7 +607,12 @@ public:
return &workingTree.tree->cellsAt(levelInTree)[treeLeafMask & inIndex];
}
/** This function fill an array with the distant neighbors of a cell
* @param inNeighbors the array to store the elements
* @param inIndex the index of the element we want the neighbors
* @param inLevel the level of the element
* @return the number of neighbors
*/
int getDistantNeighbors(CellClass* inNeighbors[208], const MortonIndex inIndex, const int inLevel){
// Take the neighbors != brothers
CellClass* directNeighbors[26];
......
......@@ -28,7 +28,7 @@
* If the sub-octree is a bottom subtree then the leaf level is pointers on
* lists<particule>
*
* This two situations are implemented in tow different classes that inherite of FAbstractSubOctree.
* This two situations are implemented in two different classes that inherite of FAbstractSubOctree.
*
* Please refere to testOctree.cpp to see an example
* @warning Give the particuleClass & cellClass
......
......@@ -2,7 +2,6 @@
#define FTREECOORDINATE_HPP
// /!\ Please, you must read the license at the bottom of this page
#include <cstring>
/** Morton index */
typedef long long MortonIndex;
......@@ -13,7 +12,7 @@ typedef long long MortonIndex;
* Please read the license
*
* This class represents tree coordinate. It is used to save
* the position in "box unit" (not system unit!).
* the position in "box unit" (not system/space unit!).
*/
class FTreeCoordinate{
private:
......@@ -52,8 +51,10 @@ public:
* @param other the source class to copy
* @return this a reference to the current object
*/
FTreeCoordinate& operator=(const FTreeCoordinate& other){
memcpy(this, &other, sizeof(other));
FTreeCoordinate& operator=(const FTreeCoordinate& other){
this->x = other.x;
this->y = other.y;
this->z = other.z;
return *this;
}
......
This diff is collapsed.
#ifndef FSIMPLEKERNELS_HPP
#define FSIMPLEKERNELS_HPP
// /!\ Please, you must read the license at the bottom of this page
#include "FAbstractKernels.hpp"
#include "../Utils/FDebug.hpp"
/**
* @author Berenger Bramas (berenger.bramas@inria.fr)
* @class AbstractKernels
* @brief
* Please read the license
*
* This kernels simply shows the details of the information
* it receives
*/
template< class ParticuleClass, class CellClass>
class FSimpleKernels : public FAbstractKernels<ParticuleClass,CellClass> {
public:
/** Default destructor */
virtual ~FSimpleKernels(){
}
/** When init the kernel */
virtual void init(){}
/** Print the number of particules */
virtual void P2M(CellClass* const pole, FList<ParticuleClass*>* const particules) {
FDEBUG( FDebug::Controller << "P2M : " << particules->getSize() << "\n" );
}
/** Print the morton index */
virtual void M2M(CellClass* const pole, CellClass** const child, const int inLevel) {
FDEBUG( FDebug::Controller << "M2M : " << pole->getMortonIndex() << "\n" );
}
/** Print the morton index */
virtual void M2L(CellClass* const pole, CellClass** const distantNeighbors, const int size, const int inLevel) {
FDEBUG( FDebug::Controller << "M2L : " << pole->getMortonIndex() << " (" << size << ")\n" );
}
/** Print the morton index */
virtual void L2L(CellClass* const pole, CellClass** const child, const int inLevel) {
FDEBUG( FDebug::Controller << "L2L : " << pole->getMortonIndex() << "\n" );
}
/** Print the number of particules */
virtual void L2P(CellClass* const pole, FList<ParticuleClass*>* const particules){
FDEBUG( FDebug::Controller << "L2P : " << particules->getSize() << "\n" );
}
/** Print the number of particules */
virtual void P2P(FList<ParticuleClass*>* const currentBox, FList<ParticuleClass*>** directNeighbors, const int size) {
FDEBUG( FDebug::Controller << "P2P : " << currentBox->getSize() << " (" << size << ")\n" );
}
};
#endif //FSIMPLEKERNELS_HPP
// [--LICENSE--]
......@@ -32,6 +32,8 @@
* tree.insert(part); <br>
* } <br>
* </code>
*
* Particule has to extend {FExtendValue,FExtendPosition}
*/
template <class ParticuleClass>
class FFMALoader : public FAbstractLoader<ParticuleClass> {
......@@ -108,7 +110,7 @@ public:
void fillParticule(ParticuleClass* const inParticule){
double x,y,z,data;
this->file >> x >> y >> z >> data;
inParticule->setPosition(F3DPosition(x,y,z));
inParticule->setPosition(x,y,z);
inParticule->setValue(data);
}
......
......@@ -36,7 +36,7 @@ public:
* Copy constructor
* @param other the source class to copy
*/
F3DPosition(const F3DPosition& other):x(other.x), y(other.y), z(other.z){
F3DPosition(const F3DPosition& other): x(other.x), y(other.y), z(other.z){
}
/**
......@@ -156,6 +156,18 @@ public:
return *this;
}
/**
* Affect to all dim the other position
* @param other the value to afect
* @return the current object after being affected
*/
F3DPosition& operator*=(const double value){
this->x *= value;
this->y *= value;
this->z *= value;
return *this;
}
};
/**
......
......@@ -9,78 +9,120 @@
* @class
* Please read the license
*
* Propose basic complexe class
* Propose basic complexe class.
*/
class FComplexe {
double imag;
double real;
double imag; //< Imaginary
double real; //< Real
public:
FComplexe()
: imag(0), real(0){
/** Default Constructor */
FComplexe() : imag(0), real(0){
}
/** Constructor with default value
* @param inImag the imaginary
* @param inReal the real
*/
FComplexe(const double inImag, const double inReal)
: imag(inImag), real(inReal){
}
/** Copy constructor */
FComplexe(const FComplexe& other)
: imag(other.imag), real(other.real){
}
/** Copy operator */
FComplexe& operator=(const FComplexe& other){
this->imag = other.imag;
this->real = other.real;
return *this;
}
/** Equality operator */
bool operator==(const FComplexe& other){
return FMath::LookEqual(this->imag,other.imag)
&& FMath::LookEqual(this->real,other.real);
}
/** Different equal */
bool operator!=(const FComplexe& other){
return !(*this == other);
}
/** Get imaginary */
double getImag() const{
return this->imag;
}
/** Get real */
double getReal() const{
return this->real;
}
/** Set Imaginary */
void setImag(const double inImag) {
this->imag = inImag;
}
/** Set Real */
void setReal(const double inReal) {
this->real = inReal;
}
/**
* Operator +=
* in real with other real, same for imag
* @param other the complexe to use data
*/
FComplexe& operator+=(const FComplexe& other){
this->real += other.real;
this->imag += other.imag;
return *this;
}
/** Mul real and imaginary by a double
* @param inValue the coef to mul data
*/
void mulRealAndImag(const double inValue){
this->imag *= inValue;
this->real *= inValue;
}
/** Inc real and imaginary by doubles
* @param inIncReal to inc the real
* @param inIncImag to inc the imag
*/
void inc(const double inIncReal, const double inIncImag){
this->real += inIncReal;
this->imag += inIncImag;
}
/** Inc real by double
* @param inIncReal to inc the real
*/
void incReal(const double inIncReal){
this->real += inIncReal;
}
/** Inc imaginary by double
* @param inIncImag to inc the imag
*/
void incImag(const double inIncImag){
this->imag += inIncImag;
}
/** Dec real by double
* @param inDecReal to dec the real
*/
void decReal(const double inIncReal){
this->real -= inIncReal;
}
/** Dec imaginary by double
* @param inDecImag to dec the imag
*/
void decImag(const double inIncImag){
this->imag -= inIncImag;
}
......
......@@ -6,10 +6,16 @@
#define FUSE_DEBUG
#ifndef FUSE_DEBUG
#define FDEBUG( X )
#define FDEBUG_TRACE( X )
#define FDEBUG_TIME( X )
#else
#define FDEBUG( X ) X
#define FDEBUG_TRACE( X ) X
#define FDEBUG_TIME( X ) X
#include <iostream>
#include <fstream>
......@@ -33,8 +39,7 @@ private:
std::ostream* stream; //< Standart c++ ostream
/** Default constructor forbiden */
FDebug(){
this->stream = &std::cout;
FDebug() : stream(&std::cout) {
}
/** Default destructor forbiden */
......@@ -63,7 +68,9 @@ private:
* @param other the source class to copy
* @return this a reference to the current class
*/
FDebug& operator=(const FDebug& ){return *this;}
FDebug& operator=(const FDebug& ){
return *this;
}
public:
......
......@@ -12,24 +12,27 @@
* Propose basic math functions or indirections
*/
struct FMath{
static const double FPi;
static const double FPiDiv2;
static const double FPi; //< Pi constant
static const double FPiDiv2; //< Pi/2 constant
/** To get absolute value */
template <class NumType>
static NumType Abs(const NumType inV){
static NumType Abs(const NumType inV){
return (inV < 0 ? -inV : inV);
}
/** To get max between 2 values */
template <class NumType>
static NumType Max(const NumType inV1, const NumType inV2){
static NumType Max(const NumType inV1, const NumType inV2){
return (inV1 > inV2 ? inV1 : inV2);
}
/** To get min between 2 values */
template <class NumType>
static NumType Min(const NumType inV1, const NumType inV2){
static NumType Min(const NumType inV1, const NumType inV2){
return (inV1 < inV2 ? inV1 : inV2);
}
/** To know if 2 values seems to be equal */
template <class NumType>
static bool LookEqual(const NumType inV1, const NumType inV2){
......@@ -38,10 +41,12 @@ struct FMath{
return (Abs(inV1 - inV2) <= Max(absTol, relTol * Max(Abs(inV1), Abs(inV2))));*/
return Abs(inV1 - inV2) <= (Abs(inV1 < Abs(inV2) ? Abs(inV2) : Abs(inV1)) * 0.00001);
}
/** To get floor of a double */
static double dfloor(const double inValue){
return floor(inValue);
}
/** To get pow */
template <class NumType>
static NumType pow(const NumType inValue, long power){
......@@ -49,23 +54,37 @@ struct FMath{
while(power-- > 0) result *= inValue;
return result;
}
/** To get max between 2 values */
/** To know if a value is between two others */
template <class NumType>
static bool Between(const NumType inValue, const NumType inMin, const NumType inMax){
return ( inMin <= inValue && inValue < inMax ? true : false);
return ( inMin <= inValue && inValue < inMax );
}
/** To get sqrt of a double */
static double Sqrt(const double inValue){
return sqrt(inValue);
}
/** To get sqrt of a double */
/** To get atan2 of a double */
static double Atan2(const double inValue1,const double inValue2){
return atan2(inValue1,inValue2);
}
/** To get sqrt of a double */
static double Sin(const double inValue){