FAdaptUnifKernel.hpp 23.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#ifndef FADAPTUNIFKERNEL_HPP
#define FADAPTUNIFKERNEL_HPP
// ===================================================================================
// Copyright ScalFmm 2011 INRIA,
// 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".
// ===================================================================================
17 18
// Keep in private GIT
// @SCALFMM_PRIVATE
19
#include "Utils/FGlobal.hpp"
20

21 22
#include "Utils/FPoint.hpp"

23 24 25
#include "Adaptive/FAdaptiveCell.hpp"
#include "Adaptive/FAdaptiveKernelWrapper.hpp"
#include "Adaptive/FAbstractAdaptiveKernel.hpp"
26
#include "Kernels/Uniform/FUnifKernel.hpp"
27 28 29 30 31 32
#include "Kernels/Uniform/FUnifM2LHandler.hpp"

class FTreeCoordinate;

// ==== CMAKE =====
// @FUSE_BLAS
33
// @FUSE_FFT
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
// ================

// for verbosity only!!!
//#define COUNT_BLOCKED_INTERACTIONS

// if timings should be logged
//#define LOG_TIMINGS

/**
 * @author O. Coulaud
 * @class FAdaptUnifKernel
 * @brief
 * Please read the license
 *
 * This kernels implement the Lagrange interpolation based FMM operators.
 * It implements all interfaces (P2P, P2M, M2M, M2L, L2L, L2P) which are 
 * required by the FFmmAlgorithm and FFmmAlgorithmThread.
 *
 * @tparam CellClass Type of cell
 * @tparam ContainerClass Type of container to store particles
 * @tparam MatrixKernelClass Type of matrix kernel function
 * @tparam ORDER Chebyshev interpolation order
 */

58 59
template<class FReal, class CellClass, class ContainerClass, class MatrixKernelClass, int ORDER, int NVALS = 1>
class FAdaptiveUnifKernel : FUnifKernel<FReal,CellClass, ContainerClass, MatrixKernelClass, ORDER, NVALS>
60 61
, public FAbstractAdaptiveKernel<CellClass, ContainerClass> {
	//
62
	typedef FUnifKernel<FReal,CellClass, ContainerClass, MatrixKernelClass, ORDER, NVALS>	KernelBaseClass;
63

64
	enum {order = ORDER,
65 66
        nnodes = TensorTraits<ORDER>::nnodes};

67
  /// Needed for M2L operator
68 69 70 71 72 73
//  // If we choose to  pre-assemble adaptive M2L operators 
//  // then we need to provide an adaptive M2L handler 
//  // and the transfer in Fourier space is straightforward.
//  typedef FUnifM2LHandler<ORDER,MatrixKernelClass::Type> M2LHandlerClass;
//  const M2LHandlerClass M2LHandler;

74
  const MatrixKernelClass *const MatrixKernel;
COULAUD Olivier's avatar
COULAUD Olivier committed
75
  int sminM, sminL;
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
public:

	using KernelBaseClass::P2M;
	using KernelBaseClass::M2M;
	using KernelBaseClass::M2L;
	using KernelBaseClass::finishedLevelM2L;
	using KernelBaseClass::L2L;
	using KernelBaseClass::L2P;
	using KernelBaseClass::P2P;
	using KernelBaseClass::P2PRemote;
	//	/**
	//	 * The constructor initializes all constant attributes and it reads the
	//	 * precomputed and compressed M2L operators from a binary file (an
	//	 * runtime_error is thrown if the required file is not valid).
	//	 */
	FAdaptiveUnifKernel(const int inTreeHeight, const FReal inBoxWidth,
92
                      const FPoint<FReal>& inBoxCenter, const MatrixKernelClass *const inMatrixKernel, const int &minM, const int &minL) : KernelBaseClass(inTreeHeight, inBoxWidth, inBoxCenter, inMatrixKernel)
COULAUD Olivier's avatar
COULAUD Olivier committed
93
/*, M2LHandler(inMatrixKernel, inTreeHeight, inBoxWidth)*/, MatrixKernel(inMatrixKernel),sminM(minM),sminL(minM)
94 95 96
	{}
	//	/** Copy constructor */
	FAdaptiveUnifKernel(const FAdaptiveUnifKernel& other)
COULAUD Olivier's avatar
COULAUD Olivier committed
97
  : KernelBaseClass(other)/*, M2LHandler(other.M2LHandler)*/, MatrixKernel(other.MatrixKernel),sminM(other.sminM),sminL(other.sminL)
98 99 100 101 102 103 104 105 106
		{	}

	//
	//	/** Destructor */
		~FAdaptiveUnifKernel()
		{
			//this->~KernelBaseClass() ;
		}
	void P2M(CellClass* const pole, const int cellLevel, const ContainerClass* const particles) override {
107

108
        const FPoint<FReal> CellCenter(KernelBaseClass::getCellCenter(pole->getCoordinate(),cellLevel));
109
		const FReal BoxWidth = KernelBaseClass::BoxWidth / FMath::pow(2.0,cellLevel);
110 111 112

		for(int idxRhs = 0 ; idxRhs < NVALS ; ++idxRhs){
      // 1) apply Sy
113
			KernelBaseClass::Interpolator->applyP2M(CellCenter, BoxWidth,
114
                                              pole->getMultipole(idxRhs), particles);
115 116 117
//      // 2) apply Discrete Fourier Transform
//      M2LHandler.applyZeroPaddingAndDFT(pole->getMultipole(idxRhs), 
//                                        pole->getTransformedMultipole(idxRhs));
118 119 120 121 122

		}

	}

123
	void M2M(CellClass* const pole, const int poleLevel, const CellClass* const subCell, const int subCellLevel) override {
124

125
    const FPoint<FReal> subCellCenter(KernelBaseClass::getCellCenter(subCell->getCoordinate(),subCellLevel));
126 127
    const FReal subCellWidth(KernelBaseClass::BoxWidth / FReal(FMath::pow(2.0,subCellLevel))); 

128
    const FPoint<FReal> poleCellCenter(KernelBaseClass::getCellCenter(pole->getCoordinate(),poleLevel));
129 130 131 132 133 134 135 136
    const FReal poleCellWidth(KernelBaseClass::BoxWidth / FReal(FMath::pow(2.0, poleLevel))); 

//    ////////////////////////////////////////////////////////////////////////////
//    /// p^6 version
//    // allocate memory
//    FReal* subChildParentInterpolator = new FReal [nnodes * nnodes];
//
//    // set child info
137
//    FPoint<FReal> ChildRoots[nnodes], localChildRoots[nnodes];
138
//    FUnifTensor<FReal,ORDER>::setRoots(subCellCenter, subCellWidth, ChildRoots);
139 140
//
//    // map global position of roots to local position in parent cell
141
//    const map_glob_loc<FReal> map(poleCellCenter, poleCellWidth);
142 143 144 145 146 147
//    for (unsigned int n=0; n<nnodes; ++n)
//      map(ChildRoots[n], localChildRoots[n]);
//
//    // assemble child - parent - interpolator
//    KernelBaseClass::Interpolator->assembleInterpolator(nnodes, localChildRoots, subChildParentInterpolator);

148

149
    ////////////////////////////////////////////////////////////////////////////
150
    /// p^4 version
151

152 153
    // Set sub-child coords
    FReal globalChildCoords[3][ORDER];
154
    FUnifTensor<FReal,order>::setPolynomialsRoots(subCellCenter, subCellWidth, globalChildCoords);
155

156 157
    // Map global position of sub-child nodes to [-1,1]
    FReal localChildCoords[3][ORDER];
158
    const map_glob_loc<FReal> map(poleCellCenter, poleCellWidth);
159
    FPoint<FReal> localChildPoints;
160
    for (unsigned int n=0; n<ORDER; ++n) {
161
      map(FPoint<FReal>(globalChildCoords[0][n],globalChildCoords[1][n],globalChildCoords[2][n]), localChildPoints);
162 163 164 165
      localChildCoords[0][n] = localChildPoints.getX();
      localChildCoords[1][n] = localChildPoints.getY();
      localChildCoords[2][n] = localChildPoints.getZ();
    }
166

167 168 169 170 171
    // assemble interpolator
    FReal* subChildParentInterpolator = new FReal [3 * ORDER*ORDER];
    KernelBaseClass::Interpolator->assembleInterpolator(ORDER, localChildCoords[0], subChildParentInterpolator);
    KernelBaseClass::Interpolator->assembleInterpolator(ORDER, localChildCoords[1], subChildParentInterpolator + 1 * ORDER*ORDER);
    KernelBaseClass::Interpolator->assembleInterpolator(ORDER, localChildCoords[2], subChildParentInterpolator + 2 * ORDER*ORDER);
172

173 174 175 176 177
    // get permutation operators
    unsigned int perm[3][nnodes];
    for (unsigned int i=0;i<3; ++i) 
      for (unsigned int n=0; n<nnodes; ++n)
        perm[i][n] = KernelBaseClass::Interpolator->getPermutationsM2ML2L(i)[n];
178 179 180 181 182

    for(int idxRhs = 0 ; idxRhs < NVALS ; ++idxRhs){

      // 1) apply Sy (using tensor product M2M with an interpolator computed on the fly)

183 184
      // Do NOT reset multipole expansion !
      //FBlas::scal(nnodes, FReal(0.), pole->getMultipole(idxRhs));
185

186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
//      /// p^6 version
//      FBlas::gemtva(nnodes, nnodes, FReal(1.),
//                    subChildParentInterpolator,
//                    const_cast<FReal*>(subCell->getMultipole(idxRhs)), pole->getMultipole(idxRhs));

      /// p^4 version
      FReal Exp[nnodes], PermExp[nnodes];
      // ORDER*ORDER*ORDER * (2*ORDER-1)
      FBlas::gemtm(ORDER, ORDER, ORDER*ORDER, FReal(1.),
                   subChildParentInterpolator, ORDER,
                   const_cast<FReal*>(subCell->getMultipole(idxRhs)), ORDER, PermExp, ORDER);

      for (unsigned int n=0; n<nnodes; ++n)	Exp[n] = PermExp[perm[1][n]];
      // ORDER*ORDER*ORDER * (2*ORDER-1)
      FBlas::gemtm(ORDER, ORDER, ORDER*ORDER, FReal(1.),
                   subChildParentInterpolator + 2 * ORDER*ORDER, ORDER,
                   Exp, ORDER, PermExp, ORDER);

      for (unsigned int n=0; n<nnodes; ++n)	Exp[perm[1][n]] = PermExp[perm[2][n]];
      // ORDER*ORDER*ORDER * (2*ORDER-1)
      FBlas::gemtm(ORDER, ORDER, ORDER*ORDER, FReal(1.),
                   subChildParentInterpolator + 1 * ORDER*ORDER, ORDER,
                   Exp, ORDER, PermExp, ORDER);

      for (unsigned int n=0; n<nnodes; ++n)	pole->getMultipole(idxRhs)[perm[2][n]] += PermExp[n];
211 212 213 214 215 216 217



//      // 2) Apply Discete Fourier Transform
//      M2LHandler.applyZeroPaddingAndDFT(ParentCell->getMultipole(idxRhs), 
//                                         ParentCell->getTransformedMultipole(idxRhs));
    }
218 219
	}

220 221 222 223
	void P2L(CellClass* const local, const int localLevel, const ContainerClass* const particles) override {

    // Target cell: local
    const FReal localCellWidth(KernelBaseClass::BoxWidth / FReal(FMath::pow(2.0, localLevel))); 
224
    const FPoint<FReal> localCellCenter(KernelBaseClass::getCellCenter(local->getCoordinate(),localLevel));
225
 //   std::cout << "   call P2L  localLevel "<< localLevel << "  localCellCenter "<< localCellCenter <<std::endl;
226
    // interpolation points of target (X) cell
227
    FPoint<FReal> X[nnodes];
228
    FUnifTensor<FReal,order>::setRoots(localCellCenter, localCellWidth, X);
229 230 231 232 233 234 235 236 237 238 239 240

    // read positions
    const FReal*const positionsX = particles->getPositions()[0];
    const FReal*const positionsY = particles->getPositions()[1];
    const FReal*const positionsZ = particles->getPositions()[2];

    for(int idxRhs = 0 ; idxRhs < NVALS ; ++idxRhs){

      // read physicalValue
      const FReal*const physicalValues = particles->getPhysicalValues();

      // apply P2L
COULAUD Olivier's avatar
COULAUD Olivier committed
241
      for (int idxPart=0; idxPart<particles->getNbParticles(); ++idxPart){
242

243
        const FPoint<FReal> y = FPoint<FReal>(positionsX[idxPart],
244 245 246 247 248 249 250 251 252 253
                                positionsY[idxPart],
                                positionsZ[idxPart]);

        for (unsigned int m=0; m<nnodes; ++m)
          local->getLocal(idxRhs)[m]+=MatrixKernel->evaluate(X[m], y) * physicalValues[idxPart];

      }

    }// NVALS

254 255
	}

256
	void M2L(CellClass* const local, const int localLevel, const CellClass* const pole, const int poleLevel) override {
257

258
    // Source cell: pole
259
    const FReal poleCellWidth(KernelBaseClass::BoxWidth / FReal(FMath::pow(2.0, poleLevel))); 
260
    const FPoint<FReal> poleCellCenter(KernelBaseClass::getCellCenter(pole->getCoordinate(),poleLevel));
261

262
    // Target cell: local
263
    const FReal localCellWidth(KernelBaseClass::BoxWidth / FReal(FMath::pow(2.0, localLevel))); 
264
    const FPoint<FReal> localCellCenter(KernelBaseClass::getCellCenter(local->getCoordinate(),localLevel));
265 266

    // interpolation points of source (Y) and target (X) cell
267
    FPoint<FReal> X[nnodes], Y[nnodes];
268 269
    FUnifTensor<FReal,order>::setRoots(poleCellCenter, poleCellWidth, Y);
    FUnifTensor<FReal,order>::setRoots(localCellCenter, localCellWidth, X);
270

271

272 273 274 275
    for(int idxRhs = 0 ; idxRhs < NVALS ; ++idxRhs){

      // Dense M2L
      const FReal *const MultipoleExpansion = pole->getMultipole(idxRhs);
276
    
277
      for (unsigned int m=0; m<nnodes; ++m)
278 279 280 281
        for (unsigned int n=0; n<nnodes; ++n){
          local->getLocal(idxRhs)[m]+=MatrixKernel->evaluate(X[m], Y[n]) * MultipoleExpansion[n];
          
        }
282
    }
283 284
	}

285 286 287 288
	void M2P(const CellClass* const pole, const int poleLevel, ContainerClass* const particles) override {

    // Source cell: pole
    const FReal poleCellWidth(KernelBaseClass::BoxWidth / FReal(FMath::pow(2.0, poleLevel))); 
289
    const FPoint<FReal> poleCellCenter(KernelBaseClass::getCellCenter(pole->getCoordinate(),poleLevel));
290 291

    // interpolation points of source (Y) cell
292
    FPoint<FReal> Y[nnodes];
293
    FUnifTensor<FReal,order>::setRoots(poleCellCenter, poleCellWidth, Y);
294 295 296 297 298 299

    // read positions
    const FReal*const positionsX = particles->getPositions()[0];
    const FReal*const positionsY = particles->getPositions()[1];
    const FReal*const positionsZ = particles->getPositions()[2];

300
    // get potential
301
    FReal*const physVal = particles->getPhysicalValues(/*idxPot*/);
302 303 304 305 306
    FReal*const potentials = particles->getPotentials(/*idxPot*/);
    FReal*const fx = particles->getForcesX(/*idxPot*/);
    FReal*const fy = particles->getForcesY(/*idxPot*/);
    FReal*const fz = particles->getForcesZ(/*idxPot*/);

307 308 309 310 311
    for(int idxRhs = 0 ; idxRhs < NVALS ; ++idxRhs){

      const FReal *const MultipoleExpansion = pole->getMultipole(idxRhs);
    
      // apply M2P
COULAUD Olivier's avatar
COULAUD Olivier committed
312
      for ( int idxPart=0; idxPart<particles->getNbParticles(); ++idxPart){
313

314
        const FPoint<FReal> x = FPoint<FReal>(positionsX[idxPart],positionsY[idxPart],positionsZ[idxPart]);
315

316
        for (unsigned int n=0; n<nnodes; ++n){
317

318 319 320 321 322
          FReal Kxy[1];
          FReal dKxy[3];
          MatrixKernel->evaluateBlockAndDerivative(x,Y[n],Kxy,dKxy);

          potentials[idxPart] += Kxy[0] * MultipoleExpansion[/*idxLhs*nnodes+*/n];
323 324 325
          fx[idxPart] += -dKxy[0] * physVal[idxPart] * MultipoleExpansion[/*idxLhs*nnodes+*/n];
          fy[idxPart] += -dKxy[1] * physVal[idxPart] * MultipoleExpansion[/*idxLhs*nnodes+*/n];
          fz[idxPart] += -dKxy[2] * physVal[idxPart] * MultipoleExpansion[/*idxLhs*nnodes+*/n];
326 327

        }
328 329 330 331 332

      }// Particles

    }// NVALS

333 334
	}

335
	void L2L(const CellClass* const local, const int localLevel, CellClass* const subCell, const int subCellLevel) override {
336

337
    const FPoint<FReal> subCellCenter(KernelBaseClass::getCellCenter(subCell->getCoordinate(),subCellLevel));
338 339
    const FReal subCellWidth(KernelBaseClass::BoxWidth / FReal(FMath::pow(2.0,subCellLevel))); 

340
    const FPoint<FReal> localCenter(KernelBaseClass::getCellCenter(local->getCoordinate(),localLevel));
341
    const FReal localWidth(KernelBaseClass::BoxWidth / FReal(FMath::pow(2.0,localLevel))); 
342

343 344 345 346 347 348
//    ////////////////////////////////////////////////////////////////////////////
//    /// p^6 version
//    // allocate memory
//    FReal* subChildParentInterpolator = new FReal [nnodes * nnodes];
//
//    // set child info
349
//    FPoint<FReal> ChildRoots[nnodes], localChildRoots[nnodes];
350
//    FUnifTensor<FReal,ORDER>::setRoots(subCellCenter, subCellWidth, ChildRoots);
351 352
//
//    // map global position of roots to local position in parent cell
353
//    const map_glob_loc<FReal> map(localCenter, localWidth);
354 355 356 357 358
//    for (unsigned int n=0; n<nnodes; ++n)
//      map(ChildRoots[n], localChildRoots[n]);
//
//    // assemble child - parent - interpolator
//    KernelBaseClass::Interpolator->assembleInterpolator(nnodes, localChildRoots, subChildParentInterpolator);
359

360 361 362 363
    ////////////////////////////////////////////////////////////////////////////
    /// p^4 version
    // Set sub-child coords
    FReal globalChildCoords[3][ORDER];
364
    FUnifTensor<FReal,order>::setPolynomialsRoots(subCellCenter, subCellWidth, globalChildCoords);
365

366 367
    // Map global position of sub-child nodes to [-1,1]
    FReal localChildCoords[3][ORDER];
368
    const map_glob_loc<FReal> map(localCenter, localWidth);
369
    FPoint<FReal> localChildPoints;
370
    for (unsigned int n=0; n<ORDER; ++n) {
371
      map(FPoint<FReal>(globalChildCoords[0][n],globalChildCoords[1][n],globalChildCoords[2][n]), localChildPoints);
372 373 374 375
      localChildCoords[0][n] = localChildPoints.getX();
      localChildCoords[1][n] = localChildPoints.getY();
      localChildCoords[2][n] = localChildPoints.getZ();
    }
376

377 378 379 380 381
    // assemble interpolator
    FReal* subChildParentInterpolator = new FReal [3 * ORDER*ORDER];
    KernelBaseClass::Interpolator->assembleInterpolator(ORDER, localChildCoords[0], subChildParentInterpolator);
    KernelBaseClass::Interpolator->assembleInterpolator(ORDER, localChildCoords[1], subChildParentInterpolator + 1 * ORDER*ORDER);
    KernelBaseClass::Interpolator->assembleInterpolator(ORDER, localChildCoords[2], subChildParentInterpolator + 2 * ORDER*ORDER);
382

383 384 385 386 387
    // get permutation operators
    unsigned int perm[3][nnodes];
    for (unsigned int i=0;i<3; ++i) 
      for (unsigned int n=0; n<nnodes; ++n)
        perm[i][n] = KernelBaseClass::Interpolator->getPermutationsM2ML2L(i)[n];
388 389 390 391 392

    for(int idxRhs = 0 ; idxRhs < NVALS ; ++idxRhs){
//      // 1) Apply Inverse Discete Fourier Transform
//      M2LHandler.unapplyZeroPaddingAndDFT(local->getTransformedLocal(idxRhs),
//                                           const_cast<CellClass*>(local)->getLocal(idxRhs));
393

394
      // 2) apply Sx
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
//      /// p^6 version
//      FBlas::gemva(nnodes, nnodes, FReal(1.),
//                   subChildParentInterpolator,
//                   const_cast<FReal*>(local->getLocal(idxRhs)), subCell->getLocal(idxRhs));

      /// p^4 version
      FReal Exp[nnodes], PermExp[nnodes];
      // ORDER*ORDER*ORDER * (2*ORDER-1)
      FBlas::gemm(ORDER, ORDER, ORDER*ORDER, FReal(1.),
                  subChildParentInterpolator, ORDER,
                  const_cast<FReal*>(local->getLocal(idxRhs)), ORDER, PermExp, ORDER);

      for (unsigned int n=0; n<nnodes; ++n)	Exp[n] = PermExp[perm[1][n]];
      // ORDER*ORDER*ORDER * (2*ORDER-1)
      FBlas::gemm(ORDER, ORDER, ORDER*ORDER, FReal(1.),
                  subChildParentInterpolator + 2 * ORDER*ORDER, ORDER,
                  Exp, ORDER, PermExp, ORDER);

      for (unsigned int n=0; n<nnodes; ++n)	Exp[perm[1][n]] = PermExp[perm[2][n]];
      // ORDER*ORDER*ORDER * (2*ORDER-1)
      FBlas::gemm(ORDER, ORDER, ORDER*ORDER, FReal(1.),
                  subChildParentInterpolator + 1 * ORDER*ORDER, ORDER,
                  Exp, ORDER, PermExp, ORDER);

      for (unsigned int n=0; n<nnodes; ++n)	subCell->getLocal(idxRhs)[perm[2][n]] += PermExp[n];
      // total flops count: 3 * ORDER*ORDER*ORDER * (2*ORDER-1)
422 423 424

    }

425 426
	}

427
	void L2P(const CellClass* const local, const int cellLevel, ContainerClass* const particles)  override {
428

429
    const FPoint<FReal> CellCenter(KernelBaseClass::getCellCenter(local->getCoordinate(),cellLevel));
430
		const FReal BoxWidth = KernelBaseClass::BoxWidth / FMath::pow(2.0,cellLevel);
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446

    for(int idxRhs = 0 ; idxRhs < NVALS ; ++idxRhs){

//      // 1)  Apply Inverse Discete Fourier Transform
//      M2LHandler.unapplyZeroPaddingAndDFT(local->getTransformedLocal(idxRhs), 
//                                          const_cast<CellClass*>(local)->getLocal(idxRhs));

      // 2.a) apply Sx
      KernelBaseClass::Interpolator->applyL2P(CellCenter, BoxWidth,
                                              local->getLocal(idxRhs), particles);

      // 2.b) apply Px (grad Sx)
      KernelBaseClass::Interpolator->applyL2PGradient(CellCenter, BoxWidth,
                                                      local->getLocal(idxRhs), particles);

    }
447 448 449
	}

	void P2P(ContainerClass* target, const ContainerClass* sources)  override {
450
        ContainerClass* sourcesArray[27] = { const_cast<ContainerClass*> (sources) };
451
        DirectInteractionComputer<FReal,MatrixKernelClass::NCMP, NVALS>::template P2PRemote(target,sourcesArray,1,MatrixKernel);
452 453 454
	}

	bool preferP2M(const ContainerClass* const particles) override {
COULAUD Olivier's avatar
COULAUD Olivier committed
455
		return particles->getNbParticles() >this->sminM;
456 457 458 459 460 461
	}
	bool preferP2M(const int /*atLevel*/, const ContainerClass*const particles[], const int nbContainers) override {
		int counterParticles = 0;
		for(int idxContainer = 0 ; idxContainer < nbContainers ; ++idxContainer){
			counterParticles += particles[idxContainer]->getNbParticles();
		}
462
//		std::cout << " Part("<<counterParticles<< ") ";
COULAUD Olivier's avatar
COULAUD Olivier committed
463
		return counterParticles >this->sminM;
464 465 466 467 468 469
	}
};

//
//template < class CellClass,	class ContainerClass,	class MatrixKernelClass, int ORDER, int NVALS = 1>
//class FAdaptUnifKernel
470
//		: public FUnifKernel<FReal,CellClass, ContainerClass, MatrixKernelClass, ORDER, NVALS>
471
//{
472
//	typedef FUnifKernel<FReal,CellClass, ContainerClass, MatrixKernelClass, ORDER, NVALS>	KernelBaseClass;
473 474 475 476 477 478 479 480 481 482 483 484 485 486
//
//#ifdef LOG_TIMINGS
//	FTic time;
//	FReal t_m2l_1, t_m2l_2, t_m2l_3;
//#endif
//
//public:
//	/**
//	 * The constructor initializes all constant attributes and it reads the
//	 * precomputed and compressed M2L operators from a binary file (an
//	 * runtime_error is thrown if the required file is not valid).
//	 */
//	FAdaptUnifKernel(const int inTreeHeight,
//			const FReal inBoxWidth,
487
//			const FPoint<FReal>& inBoxCenter)
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
//: KernelBaseClass(inTreeHeight, inBoxWidth, inBoxCenter)
//{
//
//#ifdef LOG_TIMINGS
//		t_m2l_1 = FReal(0.);
//		t_m2l_2 = FReal(0.);
//		t_m2l_3 = FReal(0.);
//#endif
//}
//
//
//	/** Copy constructor */
//	FAdaptUnifKernel(const FAdaptUnifKernel& other)
//	: KernelBaseClass(other)
//	{	}
//
//
//
//	/** Destructor */
//	~FAdaptUnifKernel()
//	{
//		this->~KernelBaseClass() ;
//#ifdef LOG_TIMINGS
//		std::cout << "- Permutation took " << t_m2l_1 << "s"
//				<< "\n- GEMMT and GEMM took " << t_m2l_2 << "s"
//				<< "\n- Unpermutation took " << t_m2l_3 << "s"
//				<< std::endl;
//#endif
//	}
//
//
//	void P2MAdapt(CellClass* const ParentCell,  const int &level)
//	{
521
//		const FPoint<FReal> LeafCellCenter(KernelBaseClass::getLeafCellCenter(ParentCell->getCoordinate()));
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603
//		const FReal BoxWidth = KernelBaseClass::BoxWidthLeaf*FMath::pow(2.0,KernelBaseClass::TreeHeight-level);
//		//
//		for(int i = 0 ; i <ParentCell->getLeavesSize(); ++i ){
//			//
//			for(int idxRhs = 0 ; idxRhs < NVALS ; ++idxRhs){
//				KernelBaseClass::Interpolator->applyP2M(LeafCellCenter, BoxWidth,
//						ParentCell->getMultipole(idxRhs), ParentCell->getLeaf(i)->getSrc());
//			}
//		}
//	}
//	void M2MAdapt(CellClass* const FRestrict ParentCell, const int &TreeLevel, const int &numberOfM2M,
//			const int * FRestrict ChildLevel , const CellClass*const FRestrict *const FRestrict ChildCells)
//	{
//		for(int idxRhs = 0 ; idxRhs < NVALS ; ++idxRhs){
//			//            // apply Sy
//			for (unsigned int ChildIndex=0; ChildIndex < 8; ++ChildIndex){
//				if (ChildCells[ChildIndex]){
//					//			KernelBaseClass::Interpolator->applyM2M(ChildIndex, ChildCells[ChildIndex]->getMultipole(idxRhs), ParentCell->getMultipole(idxRhs));
//				}
//			}
//		}
//	}
//
//
//
//	void M2L(CellClass* const FRestrict TargetCell,
//			const CellClass* SourceCells[343],
//			const int /*NumSourceCells*/,
//			const int TreeLevel)
//	{
//
//	}
//
//
//	void L2L(const CellClass* const FRestrict ParentCell,
//			CellClass* FRestrict *const FRestrict ChildCells,
//			const int /*TreeLevel*/)
//	{
//		//        for(int idxRhs = 0 ; idxRhs < NVALS ; ++idxRhs){
//		//            // apply Sx
//		//            for (unsigned int ChildIndex=0; ChildIndex < 8; ++ChildIndex){
//		//                if (ChildCells[ChildIndex]){
//		//                    AbstractBaseClass::Interpolator->applyL2L(ChildIndex, ParentCell->getLocal(idxRhs), ChildCells[ChildIndex]->getLocal(idxRhs));
//		//                }
//		//            }
//		//        }
//	}
//
//	void L2P(const CellClass* const LeafCell,
//			ContainerClass* const TargetParticles)
//	{
//		KernelBaseClass::L2P(LeafCell,TargetParticles) ;
//	}
//
//	//    void P2P(const FTreeCoordinate& /* LeafCellCoordinate */, // needed for periodic boundary conditions
//	//                     ContainerClass* const FRestrict TargetParticles,
//	//                     const ContainerClass* const FRestrict /*SourceParticles*/,
//	//                     ContainerClass* const NeighborSourceParticles[27],
//	//                     const int /* size */)
//	//    {
//	//        DirectInteractionComputer<MatrixKernelClass::Identifier, NVALS>::P2P(TargetParticles,NeighborSourceParticles);
//	//    }
//	//
//	//
//	//    void P2PRemote(const FTreeCoordinate& /*inPosition*/,
//	//                   ContainerClass* const FRestrict inTargets, const ContainerClass* const FRestrict /*inSources*/,
//	//                   ContainerClass* const inNeighbors[27], const int /*inSize*/){
//	//       DirectInteractionComputer<MatrixKernelClass::Identifier, NVALS>::P2PRemote(inTargets,inNeighbors,27);
//	//    }
//
//};
//
//






#endif //FADAPTUNIFKERNELS_HPP

// [--END--]