Nous avons procédé ce jeudi matin 08 avril 2021 à une MAJ de sécurité urgente. Nous sommes passé de la version 13.9.3 à la version 13.9.5 les releases notes correspondantes sont ici:
https://about.gitlab.com/releases/2021/03/17/security-release-gitlab-13-9-4-released/
https://about.gitlab.com/releases/2021/03/31/security-release-gitlab-13-10-1-released/

FUnifTensorialKernel.hpp 10.6 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
// ===================================================================================
// Copyright ScalFmm 2011 INRIA, Olivier Coulaud, Bérenger Bramas, Matthias Messner
// olivier.coulaud@inria.fr, berenger.bramas@inria.fr
// 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".
// ===================================================================================
#ifndef FUNIFTENSORIALKERNEL_HPP
#define FUNIFTENSORIALKERNEL_HPP

#include "../../Utils/FGlobal.hpp"
#include "../../Utils/FTrace.hpp"
#include "../../Utils/FSmartPointer.hpp"

#include "./FAbstractUnifKernel.hpp"
24 25
#include "./FUnifM2LHandler.hpp"
#include "./FUnifTensorialM2LHandler.hpp" //PB: temporary version
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40

class FTreeCoordinate;

/**
 * @author Pierre Blanchard (pierre.blanchard@inria.fr)
 * @class FUnifTensorialKernel
 * @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.
 *
 * PB: 3 IMPORTANT remarks !!!
 *
41 42
 * 1) Handling tensorial kernels (DIM,NRHS,NLHS) and having multiple rhs 
 * (NVALS) are considered 2 distinct features and are currently combined.
43
 *
44 45 46 47 48 49
 * 2) When it comes to applying M2L it is NOT much faster to loop over 
 * NRHSxNLHS inside applyM2L (at least for the Lagrange case).
 * 2-bis) During precomputation the tensorial matrix kernels are evaluated 
 * blockwise, but this is not always possible. 
 * In fact, in the ChebyshevSym variant the matrix kernel needs to be 
 * evaluated compo-by-compo since we currently use a scalar ACA.
50
 *
51 52 53
 * 3) We currently use multiple 1D FFT instead of multidim FFT since embedding
 * is circulant. Multidim FFT could be used if embedding were block circulant.
 * TODO investigate possibility of block circulant embedding
54 55 56 57 58 59 60 61 62 63
 *
 * @tparam CellClass Type of cell
 * @tparam ContainerClass Type of container to store particles
 * @tparam MatrixKernelClass Type of matrix kernel function
 * @tparam ORDER Lagrange interpolation order
 */
template < class CellClass,	class ContainerClass,	class MatrixKernelClass, int ORDER, int NVALS = 1>
class FUnifTensorialKernel
  : public FAbstractUnifKernel< CellClass, ContainerClass, MatrixKernelClass, ORDER, NVALS>
{
64
  enum {nRhs = MatrixKernelClass::NRHS,
65 66 67
        nLhs = MatrixKernelClass::NLHS,
        nPot = MatrixKernelClass::NPOT,
        nPV = MatrixKernelClass::NPV};
68 69 70

protected://PB: for OptiDis

71
  // private types
72
  typedef FUnifTensorialM2LHandler<ORDER,MatrixKernelClass,MatrixKernelClass::Type> M2LHandlerClass;
73 74 75 76 77 78

  // using from
  typedef FAbstractUnifKernel< CellClass, ContainerClass, MatrixKernelClass, ORDER, NVALS>
  AbstractBaseClass;

  /// Needed for M2L operator
79
  const M2LHandlerClass M2LHandler;
80 81 82 83 84 85 86 87

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).
   */
  FUnifTensorialKernel(const int inTreeHeight,
88
                       const FReal inBoxWidth,
89
                       const FPoint& inBoxCenter,
90
                       const FReal inBoxWidthExtension, 
91
                       const double inMatParam = 0.0)
92
    : FAbstractUnifKernel< CellClass, ContainerClass, MatrixKernelClass, ORDER, NVALS>(inTreeHeight,inBoxWidth,inBoxCenter,inBoxWidthExtension,inMatParam),
93 94
      M2LHandler(AbstractBaseClass::MatrixKernel.getPtr(),
                 inTreeHeight,
95 96
                 inBoxWidth,
                 inBoxWidthExtension) 
97
  { }
98 99 100 101 102 103


  void P2M(CellClass* const LeafCell,
           const ContainerClass* const SourceParticles)
  {
    const FPoint LeafCellCenter(AbstractBaseClass::getLeafCellCenter(LeafCell->getCoordinate())); 
104 105
    const FReal ExtendedLeafCellWidth(AbstractBaseClass::BoxWidthLeaf 
                                      + AbstractBaseClass::BoxWidthExtension);
106

107
    for(int idxV = 0 ; idxV < NVALS ; ++idxV){
108 109

      // 1) apply Sy
110
      AbstractBaseClass::Interpolator->applyP2M(LeafCellCenter, ExtendedLeafCellWidth,
111 112
                                                LeafCell->getMultipole(idxV*nRhs), SourceParticles);

113 114 115 116 117
      for(int idxRhs = 0 ; idxRhs < nRhs ; ++idxRhs){
        // update multipole index
        int idxMul = idxV*nRhs + idxRhs;

        // 2) apply Discrete Fourier Transform
118 119
        M2LHandler.applyZeroPaddingAndDFT(LeafCell->getMultipole(idxMul), 
                                          LeafCell->getTransformedMultipole(idxMul));
120 121 122

      }
    }// NVALS
123 124 125 126 127
  }


  void M2M(CellClass* const FRestrict ParentCell,
           const CellClass*const FRestrict *const FRestrict ChildCells,
128
           const int TreeLevel)
129
  {
130 131 132 133 134 135 136 137 138
    for(int idxV = 0 ; idxV < NVALS ; ++idxV){
      for(int idxRhs = 0 ; idxRhs < nRhs ; ++idxRhs){
        // update multipole index
        int idxMul = idxV*nRhs + idxRhs;

        // 1) apply Sy
        FBlas::scal(AbstractBaseClass::nnodes, FReal(0.), ParentCell->getMultipole(idxMul));
        for (unsigned int ChildIndex=0; ChildIndex < 8; ++ChildIndex){
          if (ChildCells[ChildIndex]){
139 140 141 142
            AbstractBaseClass::Interpolator->applyM2M(ChildIndex, 
                                                      ChildCells[ChildIndex]->getMultipole(idxMul),
                                                      ParentCell->getMultipole(idxMul), 
                                                      TreeLevel/*Cell width extension specific*/);
143
          }
144
        }
145
        // 2) Apply Discete Fourier Transform
146 147
        M2LHandler.applyZeroPaddingAndDFT(ParentCell->getMultipole(idxMul), 
                                          ParentCell->getTransformedMultipole(idxMul));
148
      }
149
    }// NVALS
150 151 152 153 154 155 156 157
  }


  void M2L(CellClass* const FRestrict TargetCell,
           const CellClass* SourceCells[343],
           const int /*NumSourceCells*/,
           const int TreeLevel)
  {
158
    const FReal CellWidth(AbstractBaseClass::BoxWidth / FReal(FMath::pow(2, TreeLevel)));
159 160
    const FReal ExtendedCellWidth(CellWidth + AbstractBaseClass::BoxWidthExtension);
    const FReal scale(AbstractBaseClass::MatrixKernel.getPtr()->getScaleFactor(ExtendedCellWidth));
161 162 163

    for(int idxV = 0 ; idxV < NVALS ; ++idxV){
      for (int idxLhs=0; idxLhs < nLhs; ++idxLhs){
164

165 166 167 168 169
          // update local index
          const int idxLoc = idxV*nLhs + idxLhs;

          // load transformed local expansion
          FComplexe *const TransformedLocalExpansion = TargetCell->getTransformedLocal(idxLoc);
170

171 172
          // update idxRhs
          const int idxRhs = idxLhs % nPV; 
173

174
          // update multipole index
175 176
          const int idxMul = idxV*nRhs + idxRhs;

177
          // get index in matrix kernel
178 179 180
          const unsigned int d 
            = AbstractBaseClass::MatrixKernel.getPtr()->getPosition(idxLhs);

181 182
          for (int idx=0; idx<343; ++idx){
            if (SourceCells[idx]){
183

184
              M2LHandler.applyFC(idx, TreeLevel, scale, d,
185
                                  SourceCells[idx]->getTransformedMultipole(idxMul),
186
                                  TransformedLocalExpansion);
187

188
            }
189
          }
190
      }// NLHS=NPOT*NPV
191
    }// NVALS
192 193 194 195 196
  }


  void L2L(const CellClass* const FRestrict ParentCell,
           CellClass* FRestrict *const FRestrict ChildCells,
197
           const int TreeLevel)
198
  {
199 200 201 202
    for(int idxV = 0 ; idxV < NVALS ; ++idxV){
      for(int idxLhs = 0 ; idxLhs < nLhs ; ++idxLhs){
        int idxLoc = idxV*nLhs + idxLhs;
        // 1) Apply Inverse Discete Fourier Transform
203 204
        M2LHandler.unapplyZeroPaddingAndDFT(ParentCell->getTransformedLocal(idxLoc),
                                            const_cast<CellClass*>(ParentCell)->getLocal(idxLoc));
205 206 207
        // 2) apply Sx
        for (unsigned int ChildIndex=0; ChildIndex < 8; ++ChildIndex){
          if (ChildCells[ChildIndex]){
208 209 210 211
            AbstractBaseClass::Interpolator->applyL2L(ChildIndex, 
                                                      ParentCell->getLocal(idxLoc), 
                                                      ChildCells[ChildIndex]->getLocal(idxLoc),
                                                      TreeLevel/*Cell width extension specific*/);
212
          }
213 214
        }
      }
215
    }// NVALS
216 217 218 219 220 221
  }

  void L2P(const CellClass* const LeafCell,
           ContainerClass* const TargetParticles)
  {
    const FPoint LeafCellCenter(AbstractBaseClass::getLeafCellCenter(LeafCell->getCoordinate()));
222 223
    const FReal ExtendedLeafCellWidth(AbstractBaseClass::BoxWidthLeaf 
                                      + AbstractBaseClass::BoxWidthExtension);
224

225 226 227 228
    for(int idxV = 0 ; idxV < NVALS ; ++idxV){
      for(int idxLhs = 0 ; idxLhs < nLhs ; ++idxLhs){
        int idxLoc = idxV*nLhs + idxLhs;
        // 1)  Apply Inverse Discete Fourier Transform
229 230
        M2LHandler.unapplyZeroPaddingAndDFT(LeafCell->getTransformedLocal(idxLoc), 
                                            const_cast<CellClass*>(LeafCell)->getLocal(idxLoc));
231

232 233 234
      }

      // 2.a) apply Sx
235
      AbstractBaseClass::Interpolator->applyL2P(LeafCellCenter, ExtendedLeafCellWidth,
236
                                                LeafCell->getLocal(idxV*nLhs), TargetParticles);
237

238
      // 2.b) apply Px (grad Sx)
239
      AbstractBaseClass::Interpolator->applyL2PGradient(LeafCellCenter, ExtendedLeafCellWidth,
240
                                                        LeafCell->getLocal(idxV*nLhs), TargetParticles);
241

242
    }// NVALS
243 244 245 246 247 248 249 250
  }

  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 */)
  {
251
    DirectInteractionComputer<MatrixKernelClass::Identifier, NVALS>::P2P(TargetParticles,NeighborSourceParticles,AbstractBaseClass::MatrixKernel.getPtr());
252 253 254 255 256 257
  }


  void P2PRemote(const FTreeCoordinate& /*inPosition*/,
                 ContainerClass* const FRestrict inTargets, const ContainerClass* const FRestrict /*inSources*/,
                 ContainerClass* const inNeighbors[27], const int /*inSize*/){
258
    DirectInteractionComputer<MatrixKernelClass::Identifier, NVALS>::P2PRemote(inTargets,inNeighbors,27,AbstractBaseClass::MatrixKernel.getPtr());
259 260 261 262 263
  }

};


264
#endif //FUNIFTENSORIALKERNEL_HPP
265 266

// [--END--]