FInterEngine.hpp 25.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
// ===================================================================================
// Copyright ScalFmm 2014 I
// This software is a computer program whose purpose is to compute the FMM.
//
// This software is governed by the CeCILL-C and LGPL licenses and
// abiding by the rules of distribution of free software.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public and CeCILL-C Licenses for more details.
// "http://www.cecill.info".
// "http://www.gnu.org/licenses".
// ===================================================================================


/**
 * @file This file contains a class that inherits from FScalFMMEngine,
 * and will implement the API functions for Interpolations kernels.
 */

#ifndef FINTERENGINE_HPP
#define FINTERENGINE_HPP

#include "FScalFMMEngine.hpp"
#include "Kernels/Interpolation/FInterpMatrixKernel.hpp"
27 28 29
#include "Kernels/P2P/FP2PLeafInterface.hpp"
#include "Arranger/FOctreeArranger.hpp"
#include "Arranger/FArrangerPeriodic.hpp"
30

31 32
#include "Core/FFmmAlgorithmThread.hpp"
#include "Core/FFmmAlgorithm.hpp"
33
#include "Core/FFmmAlgorithmPeriodic.hpp"
34 35 36 37 38 39 40 41


/**
 * @class FInterEngine implements API for Interpolations kernels, its
 * templates can be ChebCell/ChebKernel or UnifCell/UnifKernel
 */
template<class InterCell,class InterKernel,
         class ContainerClass = FP2PParticleContainerIndexed<>,
42
         class LeafClass = FSimpleLeaf<FP2PParticleContainerIndexed<> >,
43 44 45
         class MatrixKernelClass = FInterpMatrixKernelR>
class FInterEngine : public FScalFMMEngine{
private:
46 47 48 49 50 51 52 53
    //Typedef on the octree class, in order to clarify following code
    typedef FOctree<InterCell,ContainerClass,LeafClass> OctreeClass;
    typedef FP2PLeafInterface<OctreeClass>            LeafInterface;


    //Typedef on Octree Arranger, in order to clarify following code
    typedef FOctreeArranger<OctreeClass,ContainerClass,LeafInterface>   ArrangerClass;
    typedef FArrangerPeriodic<OctreeClass,ContainerClass,LeafInterface> ArrangerClassPeriodic;
54 55
    //Pointer to the kernel to be executed
    InterKernel * kernel;
56
    MatrixKernelClass * matrix;
57
    //Link to the tree
58 59 60
    OctreeClass * octree;
    ArrangerClass * arranger;

61 62
public:
    /**
63 64
     * @brief Constructor : build the tree and the interpolation
     * kernel
65 66 67 68 69
     * @param TreeHeight Height of the tree
     * @param BoxWidth box Width
     * @param BoxCenter double[3] coordinate of the center of the
     * simulation box
     */
70 71
    FInterEngine(int TreeHeight, double BoxWidth , double * BoxCenter,scalfmm_kernel_type KernelType) :
        kernel(nullptr), matrix(nullptr), octree(nullptr),arranger(nullptr){
72
        octree = new OctreeClass(TreeHeight,FMath::Min(3,TreeHeight-1),BoxWidth,FPoint(BoxCenter));
73 74
        this->matrix = new MatrixKernelClass();
        this->kernel = new InterKernel(TreeHeight,BoxWidth,FPoint(BoxCenter),matrix);
75
        kernelType = KernelType;
76
        arranger = nullptr;
77 78 79 80 81
    }

    //TODO free kernel too
    ~FInterEngine(){
        free(octree);
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
        free(kernel);
    }

    //Inserting array of position
    void tree_insert_particles_xyz(int NbPositions, double * XYZ){
        for(int idPart = 0; idPart<NbPositions ; ++idPart){
            octree->insert(FPoint(&XYZ[3*idPart]),idPart);
        }
        nbPart += NbPositions;
    }

    //Inserting arrayS of position
    void tree_insert_particles(int NbPositions, double * X, double * Y, double * Z){
        for(int idPart = 0; idPart<NbPositions ; ++idPart){
            octree->insert(FPoint(X[idPart],Y[idPart],Z[idPart]),idPart);
        }
        nbPart += NbPositions;
    }

    //Set the physical values
    void set_physical_values(int nbPhysicalValues,double * physicalValues){
        octree->forEachLeaf([&](LeafClass* leaf){
                ContainerClass * sources = leaf->getSrc();
105
                const FVector<int>& indexes = sources->getIndexes();
106 107 108 109 110 111 112 113 114 115 116 117 118
                int nbPartThere = sources->getNbParticles();
                for(int idxPart = 0 ; idxPart<nbPartThere ; ++idxPart){
                    sources->getPhysicalValues()[idxPart] = physicalValues[indexes[idxPart]];
                }
            });
    }

    //Set only a subpart of physical values
    //Algorithm : loop over each leaf, and then search in user array
    //if any index matches
    void set_physical_values_npart( int nbPhysicalValues, int* idxOfParticles, double * physicalValues){
        octree->forEachLeaf([&](LeafClass* leaf){
                ContainerClass * sources = leaf->getSrc();
119
                const FVector<int>& indexes = sources->getIndexes();
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
                int nbPartThere = sources->getNbParticles();
                for(int idxPart = 0 ; idxPart<nbPartThere ; ++idxPart){
                    int iterPart = 0;
                    bool notFoundYet = true;
                    while(iterPart < nbPhysicalValues && notFoundYet){
                        if(indexes[idxPart] == idxOfParticles[iterPart]){
                            sources->getPhysicalValues()[idxPart] = physicalValues[indexes[idxPart]];
                            notFoundYet = false;
                        }
                        else{
                            ++iterPart;
                        }
                    }
                }
            });
    }

    //get back the physical values
    void get_physical_values( int nbPhysicalValues, double * physicalValues){
        octree->forEachLeaf([&](LeafClass* leaf){
                ContainerClass * sources = leaf->getSrc();
141
                const FVector<int>& indexes = sources->getIndexes();
142 143 144 145 146 147 148 149 150 151 152
                int nbPartThere = sources->getNbParticles();
                for(int idxPart = 0 ; idxPart<nbPartThere ; ++idxPart){
                    physicalValues[indexes[idxPart]] = sources->getPhysicalValues()[idxPart];
                }
            });
    }

    //Same algorithm as in set_physical_values_npart
    void get_physical_values_npart( int nbPhysicalValues, int* idxOfParticles, double * physicalValues){
        octree->forEachLeaf([&](LeafClass* leaf){
                ContainerClass * sources = leaf->getSrc();
153
                const FVector<int>& indexes = sources->getIndexes();
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
                int nbPartThere = sources->getNbParticles();
                for(int idxPart = 0 ; idxPart<nbPartThere ; ++idxPart){
                    int iterPart = 0;
                    bool notFoundYet = true;
                    while(iterPart < nbPhysicalValues && notFoundYet){
                        if(indexes[idxPart] == idxOfParticles[iterPart]){
                            physicalValues[indexes[idxPart]] = sources->getPhysicalValues()[idxPart];
                            notFoundYet = false;
                        }
                        else{
                            ++iterPart;
                        }
                    }
                }
            });
    }

    void get_forces_xyz( int nbParts, double * forcesToFill){
        octree->forEachLeaf([&](LeafClass* leaf){
                ContainerClass * sources = leaf->getSrc();
174
                const FVector<int>& indexes = sources->getIndexes();
175 176 177 178 179
                int nbPartThere = sources->getNbParticles();
                for(int idxPart = 0 ; idxPart<nbPartThere ; ++idxPart){
                    forcesToFill[indexes[idxPart]*3+0] = sources->getForcesX()[idxPart];
                    forcesToFill[indexes[idxPart]*3+1] = sources->getForcesY()[idxPart];
                    forcesToFill[indexes[idxPart]*3+2] = sources->getForcesZ()[idxPart];
PIACIBELLO Cyrille's avatar
PIACIBELLO Cyrille committed
180 181
                    printf("forces found : %e,%e,%e\n",
                           sources->getForcesX()[idxPart],sources->getForcesY()[idxPart],sources->getForcesZ()[idxPart]);
182 183 184 185 186 187 188
                }
            });
    }

    void get_forces_xyz_npart(int nbParts, int* idxOfParticles , double * forcesToFill){
        octree->forEachLeaf([&](LeafClass* leaf){
                ContainerClass * sources = leaf->getSrc();
189
                const FVector<int>& indexes = sources->getIndexes();
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
                int nbPartThere = sources->getNbParticles();
                for(int idxPart = 0 ; idxPart<nbPartThere ; ++idxPart){
                    int iterPart = 0;
                    bool notFoundYet = true;
                    while(iterPart < nbParts && notFoundYet){
                        if(indexes[idxPart] == idxOfParticles[iterPart]){
                            forcesToFill[indexes[idxPart]*3+0] = sources->getForcesX()[idxPart];
                            forcesToFill[indexes[idxPart]*3+1] = sources->getForcesY()[idxPart];
                            forcesToFill[indexes[idxPart]*3+2] = sources->getForcesZ()[idxPart];
                            notFoundYet = false;
                        }
                        else{
                            ++iterPart;
                        }
                    }
                }
            });
    }

    void get_forces( int nbParts, double * fX, double* fY, double* fZ){
        octree->forEachLeaf([&](LeafClass* leaf){
                ContainerClass * sources = leaf->getSrc();
212
                const FVector<int>& indexes = sources->getIndexes();
213 214 215 216 217 218 219
                int nbPartThere = sources->getNbParticles();
                for(int idxPart = 0 ; idxPart<nbPartThere ; ++idxPart){
                    fX[indexes[idxPart]] = sources->getForcesX()[idxPart];
                    fY[indexes[idxPart]] = sources->getForcesY()[idxPart];
                    fZ[indexes[idxPart]] = sources->getForcesZ()[idxPart];
                }
            });
220
    }
221 222 223 224

    void get_forces_npart(int nbParts, int* idxOfParticles ,double * fX, double* fY, double* fZ){
        octree->forEachLeaf([&](LeafClass* leaf){
                ContainerClass * sources = leaf->getSrc();
225
                const FVector<int>& indexes = sources->getIndexes();
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
                int nbPartThere = sources->getNbParticles();
                for(int idxPart = 0 ; idxPart<nbPartThere ; ++idxPart){
                    int iterPart = 0;
                    bool notFoundYet = true;
                    while(iterPart < nbParts && notFoundYet){
                        if(indexes[idxPart] == idxOfParticles[iterPart]){
                            fX[indexes[idxPart]] = sources->getForcesX()[idxPart];
                            fY[indexes[idxPart]] = sources->getForcesY()[idxPart];
                            fZ[indexes[idxPart]] = sources->getForcesZ()[idxPart];
                            notFoundYet = false;
                        }
                        else{
                            ++iterPart;
                        }
                    }
                }
            });
    }

    //To set initial condition
246
    void set_forces_xyz( int nbParts, double * forcesToRead){
247 248
        octree->forEachLeaf([&](LeafClass* leaf){
                ContainerClass * sources = leaf->getSrc();
249
                const FVector<int>& indexes = sources->getIndexes();
250 251
                int nbPartThere = sources->getNbParticles();
                for(int idxPart = 0 ; idxPart<nbPartThere ; ++idxPart){
252 253 254
                    sources->getForcesX()[idxPart] = forcesToRead[indexes[idxPart]*3+0];
                    sources->getForcesY()[idxPart] = forcesToRead[indexes[idxPart]*3+1];
                    sources->getForcesZ()[idxPart] = forcesToRead[indexes[idxPart]*3+2];
255 256 257
                }
            });
    }
258
    void set_forces_xyz_npart( int nbParts, int* idxOfParticles, double * forcesToRead){
259 260
        octree->forEachLeaf([&](LeafClass* leaf){
                ContainerClass * sources = leaf->getSrc();
261
                const FVector<int>& indexes = sources->getIndexes();
262 263 264 265 266 267
                int nbPartThere = sources->getNbParticles();
                for(int idxPart = 0 ; idxPart<nbPartThere ; ++idxPart){
                    int iterPart = 0;
                    bool notFoundYet = true;
                    while(iterPart < nbParts && notFoundYet){
                        if(indexes[idxPart] == idxOfParticles[iterPart]){
268 269 270
                            sources->getForcesX()[idxPart] = forcesToRead[indexes[idxPart]*3+0];
                            sources->getForcesY()[idxPart] = forcesToRead[indexes[idxPart]*3+1];
                            sources->getForcesZ()[idxPart] = forcesToRead[indexes[idxPart]*3+2];
271 272 273 274 275 276 277 278 279 280 281 282
                            notFoundYet = false;
                        }
                        else{
                            ++iterPart;
                        }
                    }
                }
            });
    }
    void set_forces( int nbParts, double * fX, double* fY, double* fZ){
        octree->forEachLeaf([&](LeafClass* leaf){
                ContainerClass * sources = leaf->getSrc();
283
                const FVector<int>& indexes = sources->getIndexes();
284 285 286 287 288 289 290 291 292 293 294
                int nbPartThere = sources->getNbParticles();
                for(int idxPart = 0 ; idxPart<nbPartThere ; ++idxPart){
                    sources->getForcesX()[idxPart] = fX[indexes[idxPart]];
                    sources->getForcesY()[idxPart] = fY[indexes[idxPart]];
                    sources->getForcesZ()[idxPart] = fZ[indexes[idxPart]];
                }
            });
    }
    void set_forces_npart( int nbParts, int* idxOfParticles, double * fX, double* fY, double* fZ){
        octree->forEachLeaf([&](LeafClass* leaf){
                ContainerClass * sources = leaf->getSrc();
295
                const FVector<int>& indexes = sources->getIndexes();
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
                int nbPartThere = sources->getNbParticles();
                for(int idxPart = 0 ; idxPart<nbPartThere ; ++idxPart){
                    int iterPart = 0;
                    bool notFoundYet = true;
                    while(iterPart < nbParts && notFoundYet){
                        if(indexes[idxPart] == idxOfParticles[iterPart]){
                            sources->getForcesX()[idxPart] = fX[indexes[idxPart]];
                            sources->getForcesY()[idxPart] = fY[indexes[idxPart]];
                            sources->getForcesZ()[idxPart] = fZ[indexes[idxPart]];
                            notFoundYet = false;
                        }
                        else{
                            ++iterPart;
                        }
                    }
                }
            });
    }

    //Set the potentials
    void set_potentials(int nbPotentials,double * potentialsToRead){
        octree->forEachLeaf([&](LeafClass* leaf){
                ContainerClass * sources = leaf->getSrc();
319
                const FVector<int>& indexes = sources->getIndexes();
320 321 322 323 324 325 326 327 328 329 330 331 332
                int nbPartThere = sources->getNbParticles();
                for(int idxPart = 0 ; idxPart<nbPartThere ; ++idxPart){
                    sources->getPotentials()[idxPart] = potentialsToRead[indexes[idxPart]];
                }
            });
    }

    //Set only a subpart of potentials
    //Algorithm : loop over each leaf, and then search in user array
    //if any index matches
    void set_potentials_npart( int nbPotentials, int* idxOfParticles, double * potentialsToRead){
        octree->forEachLeaf([&](LeafClass* leaf){
                ContainerClass * sources = leaf->getSrc();
333
                const FVector<int>& indexes = sources->getIndexes();
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354
                int nbPartThere = sources->getNbParticles();
                for(int idxPart = 0 ; idxPart<nbPartThere ; ++idxPart){
                    int iterPart = 0;
                    bool notFoundYet = true;
                    while(iterPart < nbPotentials && notFoundYet){
                        if(indexes[idxPart] == idxOfParticles[iterPart]){
                            sources->getPotentials()[idxPart] = potentialsToRead[indexes[idxPart]];
                            notFoundYet = false;
                        }
                        else{
                            ++iterPart;
                        }
                    }
                }
            });
    }

    //get back the potentials
    void get_potentials( int nbPotentials, double * potentialsToFill){
        octree->forEachLeaf([&](LeafClass* leaf){
                ContainerClass * sources = leaf->getSrc();
355
                const FVector<int>& indexes = sources->getIndexes();
356 357 358 359 360 361 362 363 364 365 366
                int nbPartThere = sources->getNbParticles();
                for(int idxPart = 0 ; idxPart<nbPartThere ; ++idxPart){
                    potentialsToFill[indexes[idxPart]] = sources->getPotentials()[idxPart];
                }
            });
    }

    //Same algorithm as in set_potentials_npart
    void get_potentials_npart( int nbPotentials, int* idxOfParticles, double * potentialsToFill){
        octree->forEachLeaf([&](LeafClass* leaf){
                ContainerClass * sources = leaf->getSrc();
367
                const FVector<int>& indexes = sources->getIndexes();
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384
                int nbPartThere = sources->getNbParticles();
                for(int idxPart = 0 ; idxPart<nbPartThere ; ++idxPart){
                    int iterPart = 0;
                    bool notFoundYet = true;
                    while(iterPart < nbPotentials && notFoundYet){
                        if(indexes[idxPart] == idxOfParticles[iterPart]){
                            potentialsToFill[indexes[idxPart]] = sources->getPotentials()[idxPart];
                            notFoundYet = false;
                        }
                        else{
                            ++iterPart;
                        }
                    }
                }
            });
    }

385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527
    void get_positions_xyz(int NbPositions, double * positionsToFill){
        octree->forEachLeaf([&](LeafClass* leaf){
                ContainerClass * sources = leaf->getSrc();
                const FVector<int>& indexes = sources->getIndexes();
                int nbPartThere = sources->getNbParticles();
                for(int idxPart = 0 ; idxPart<nbPartThere ; ++idxPart){
                    positionsToFill[indexes[idxPart]*3+0] = sources->getPositions()[0][idxPart];
                    positionsToFill[indexes[idxPart]*3+1] = sources->getPositions()[1][idxPart];
                    positionsToFill[indexes[idxPart]*3+2] = sources->getPositions()[2][idxPart];
                }
            });
    }

    void get_positions_xyz_npart(int NbPositions, int * idxOfParticles, double * positionsToFill){
        octree->forEachLeaf([&](LeafClass* leaf){
                ContainerClass * sources = leaf->getSrc();
                const FVector<int>& indexes = sources->getIndexes();
                int nbPartThere = sources->getNbParticles();
                for(int idxPart = 0 ; idxPart<nbPartThere ; ++idxPart){
                    int iterPart = 0;
                    bool notFoundYet = true;
                    while(iterPart < NbPositions && notFoundYet){
                        if(indexes[idxPart] == idxOfParticles[iterPart]){
                            positionsToFill[indexes[idxPart]*3+0] =  sources->getPositions()[0][idxPart];
                            positionsToFill[indexes[idxPart]*3+1] =  sources->getPositions()[1][idxPart];
                            positionsToFill[indexes[idxPart]*3+2] =  sources->getPositions()[2][idxPart];
                            notFoundYet = false;
                        }
                        else{
                            ++iterPart;
                        }
                    }
                }
            });
    }

    void get_positions( int NbPositions, double * X, double * Y , double * Z){
        octree->forEachLeaf([&](LeafClass* leaf){
                ContainerClass * sources = leaf->getSrc();
                const FVector<int>& indexes = sources->getIndexes();
                int nbPartThere = sources->getNbParticles();
                for(int idxPart = 0 ; idxPart<nbPartThere ; ++idxPart){
                    X[indexes[idxPart]] = sources->getPositions()[0][idxPart];
                    Y[indexes[idxPart]] = sources->getPositions()[1][idxPart];
                    Z[indexes[idxPart]] = sources->getPositions()[2][idxPart];
                }
            });
    }

    void get_positions_npart(int NbPositions, int * idxOfParticles,double * X, double * Y , double * Z){
        octree->forEachLeaf([&](LeafClass* leaf){
                ContainerClass * sources = leaf->getSrc();
                const FVector<int>& indexes = sources->getIndexes();
                int nbPartThere = sources->getNbParticles();
                for(int idxPart = 0 ; idxPart<nbPartThere ; ++idxPart){
                    int iterPart = 0;
                    bool notFoundYet = true;
                    while(iterPart < NbPositions && notFoundYet){
                        if(indexes[idxPart] == idxOfParticles[iterPart]){
                            X[indexes[idxPart]] =  sources->getPositions()[0][idxPart];
                            Y[indexes[idxPart]] =  sources->getPositions()[1][idxPart];
                            Z[indexes[idxPart]] =  sources->getPositions()[2][idxPart];
                            notFoundYet = false;
                        }
                        else{
                            ++iterPart;
                        }
                    }
                }
            });
    }


    //Arranger parts : following function provide a way to move parts
    //inside the tree
    void add_to_positions_xyz(int NbPositions,double * updatedXYZ){
        octree->forEachLeaf([&](LeafClass* leaf){
                ContainerClass * sources = leaf->getSrc();
                const FVector<int>& indexes = sources->getIndexes();
                int nbPartThere = sources->getNbParticles();
                for(int idxPart = 0 ; idxPart<nbPartThere ; ++idxPart){
                    sources->getWPositions()[0][idxPart] += updatedXYZ[indexes[idxPart]*3+0];
                    sources->getWPositions()[1][idxPart] += updatedXYZ[indexes[idxPart]*3+1];
                    sources->getWPositions()[2][idxPart] += updatedXYZ[indexes[idxPart]*3+2];
                }
            });
    }

    void add_to_positions(int NbPositions,double * X, double * Y , double * Z){
        octree->forEachLeaf([&](LeafClass* leaf){
                ContainerClass * sources = leaf->getSrc();
                const FVector<int>& indexes = sources->getIndexes();
                int nbPartThere = sources->getNbParticles();
                for(int idxPart = 0 ; idxPart<nbPartThere ; ++idxPart){
                    sources->getWPositions()[0][idxPart] += X[indexes[idxPart]];
                    sources->getWPositions()[1][idxPart] += Y[indexes[idxPart]];
                    sources->getWPositions()[2][idxPart] += Z[indexes[idxPart]];
                }
            });
    }


    void set_positions_xyz(int NbPositions, double * updatedXYZ){
        octree->forEachLeaf([&](LeafClass* leaf){
                ContainerClass * sources = leaf->getSrc();
                const FVector<int>& indexes = sources->getIndexes();
                int nbPartThere = sources->getNbParticles();
                for(int idxPart = 0 ; idxPart<nbPartThere ; ++idxPart){
                    sources->getWPositions()[0][idxPart] = updatedXYZ[indexes[idxPart]*3+0];
                    sources->getWPositions()[1][idxPart] = updatedXYZ[indexes[idxPart]*3+1];
                    sources->getWPositions()[2][idxPart] = updatedXYZ[indexes[idxPart]*3+2];
                }
            });
    }

    void set_positions(int NbPositions, double * X, double * Y, double * Z){
        octree->forEachLeaf([&](LeafClass* leaf){
                ContainerClass * sources = leaf->getSrc();
                const FVector<int>& indexes = sources->getIndexes();
                int nbPartThere = sources->getNbParticles();
                for(int idxPart = 0 ; idxPart<nbPartThere ; ++idxPart){
                    sources->getWPositions()[0][idxPart] = X[indexes[idxPart]];
                    sources->getWPositions()[1][idxPart] = Y[indexes[idxPart]];
                    sources->getWPositions()[2][idxPart] = Z[indexes[idxPart]];
                }
            });
    }

    void update_tree(){
        if(arranger){
            arranger->rearrange();
        }
        else{
            if(Algorithm == 2){ //case in wich the periodic algorithm is used
                arranger = new ArrangerClassPeriodic(octree);
                arranger->rearrange();
            }
            else{
                arranger = new ArrangerClass(octree);
                arranger->rearrange();
            }
        }
    }
528 529 530


    void execute_fmm(){
531
        //typedef FOctree<InterCell,ContainerClass,LeafClass> OctreeClass;
532 533 534 535 536 537 538 539 540 541 542 543 544 545 546
        switch(Algorithm){
        case 0:
            {
                typedef FFmmAlgorithm<OctreeClass,InterCell,ContainerClass,InterKernel,LeafClass> AlgoClassSeq;
                AlgoClassSeq algoSeq(octree,kernel);
                algoSeq.execute();
                break;
            }
        case 1:
            {
                typedef FFmmAlgorithmThread<OctreeClass,InterCell,ContainerClass,InterKernel,LeafClass> AlgoClassThread;
                AlgoClassThread algoThread(octree,kernel);
                algoThread.execute();
                break;
            }
547 548 549 550
        case 2:
            {
                typedef FFmmAlgorithmPeriodic<OctreeClass,InterCell,ContainerClass,InterKernel,LeafClass> AlgoClassPeriodic;
                AlgoClassPeriodic algoPeriod(octree,2);
PIACIBELLO Cyrille's avatar
PIACIBELLO Cyrille committed
551
                algoPeriod.setKernel(kernel);
552 553 554
                algoPeriod.execute();
                break;
            }
555 556 557 558 559 560
        default :
            std::cout<< "No algorithm found (probably for strange reasons) : "<< Algorithm <<" exiting" << std::endl;
        }
    }


561 562 563 564
};


#endif