FUnifCellPOD.hpp 4.64 KB
Newer Older
BRAMAS Berenger's avatar
BRAMAS Berenger committed
1 2 3 4
#ifndef FUNIFCELLPOD_HPP
#define FUNIFCELLPOD_HPP

#include "../../Utils/FGlobal.hpp"
5
#include "../Core/FBasicCellPOD.hpp"
BRAMAS Berenger's avatar
BRAMAS Berenger committed
6 7 8 9
#include "../StarPUUtils/FStarPUDefaultAlign.hpp"
#include "../../Kernels/Uniform//FUnifTensor.hpp"
#include "../../Utils/FComplex.hpp"

10
typedef FBasicCellPOD FUnifCellPODCore;
BRAMAS Berenger's avatar
BRAMAS Berenger committed
11

12
template <class FReal, int ORDER, int NRHS = 1, int NLHS = 1, int NVALS = 1>
BRAMAS Berenger's avatar
BRAMAS Berenger committed
13 14 15 16
struct alignas(FStarPUDefaultAlign::StructAlign) FUnifCellPODPole {
    static const int VectorSize = TensorTraits<ORDER>::nnodes;
    static const int TransformedVectorSize = (2*ORDER-1)*(2*ORDER-1)*(2*ORDER-1);
    FReal multipole_exp[NRHS * NVALS * VectorSize]; //< Multipole expansion
17
    FComplex<FReal> transformed_multipole_exp[NRHS * NVALS * TransformedVectorSize];
BRAMAS Berenger's avatar
BRAMAS Berenger committed
18 19
};

20
template <class FReal, int ORDER, int NRHS = 1, int NLHS = 1, int NVALS = 1>
BRAMAS Berenger's avatar
BRAMAS Berenger committed
21 22 23
struct alignas(FStarPUDefaultAlign::StructAlign) FUnifCellPODLocal {
    static const int VectorSize = TensorTraits<ORDER>::nnodes;
    static const int TransformedVectorSize = (2*ORDER-1)*(2*ORDER-1)*(2*ORDER-1);
24
    FComplex<FReal>     transformed_local_exp[NLHS * NVALS * TransformedVectorSize];
BRAMAS Berenger's avatar
BRAMAS Berenger committed
25 26 27
    FReal     local_exp[NLHS * NVALS * VectorSize]; //< Local expansion
};

28
template <class FReal, int ORDER, int NRHS = 1, int NLHS = 1, int NVALS = 1>
BRAMAS Berenger's avatar
BRAMAS Berenger committed
29 30
class FUnifCellPOD {
  FUnifCellPODCore* symb;
31 32
  FUnifCellPODPole<FReal,ORDER,NRHS,NLHS,NVALS>* up;
  FUnifCellPODLocal<FReal,ORDER,NRHS,NLHS,NVALS>* down;
BRAMAS Berenger's avatar
BRAMAS Berenger committed
33 34

public:
35 36
  FUnifCellPOD(FUnifCellPODCore* inSymb, FUnifCellPODPole<FReal,ORDER,NRHS,NLHS,NVALS>* inUp,
            FUnifCellPODLocal<FReal,ORDER,NRHS,NLHS,NVALS>* inDown): symb(inSymb), up(inUp), down(inDown){
BRAMAS Berenger's avatar
BRAMAS Berenger committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
  }

  FUnifCellPOD()
      : symb(nullptr), up(nullptr), down(nullptr){
  }


  /** To get the morton index */
  MortonIndex getMortonIndex() const {
      return symb->mortonIndex;
  }

  /** To set the morton index */
  void setMortonIndex(const MortonIndex inMortonIndex) {
      symb->mortonIndex = inMortonIndex;
  }

54 55 56 57 58 59 60 61 62 63
  /** To get the cell level */
  int getLevel() const {
      return symb->level;
  }

  /** To set the cell level */
  void setLevel(const int level) {
      symb->level = level;
  }

BRAMAS Berenger's avatar
BRAMAS Berenger committed
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
  /** To get the position */
  FTreeCoordinate getCoordinate() const {
      return FTreeCoordinate(symb->coordinates[0],
              symb->coordinates[1], symb->coordinates[2]);
  }

  /** To set the position */
  void setCoordinate(const FTreeCoordinate& inCoordinate) {
      symb->coordinates[0] = inCoordinate.getX();
      symb->coordinates[1] = inCoordinate.getY();
      symb->coordinates[2] = inCoordinate.getZ();
  }

  /** To set the position from 3 FReals */
  void setCoordinate(const int inX, const int inY, const int inZ) {
      symb->coordinates[0] = inX;
      symb->coordinates[1] = inY;
      symb->coordinates[2] = inZ;
  }

  /** Get Multipole */
  const FReal* getMultipole(const int inRhs) const
  {	return up->multipole_exp + inRhs*up->VectorSize;
  }
  /** Get Local */
  const FReal* getLocal(const int inRhs) const{
    return down->local_exp + inRhs*down->VectorSize;
  }

  /** Get Multipole */
  FReal* getMultipole(const int inRhs){
    return up->multipole_exp + inRhs*up->VectorSize;
  }
  /** Get Local */
  FReal* getLocal(const int inRhs){
    return down->local_exp + inRhs*down->VectorSize;
  }

  /** To get the leading dim of a vec */
  int getVectorSize() const{
    return down->VectorSize;
  }

  /** Get Transformed Multipole */
108
  const FComplex<FReal>* getTransformedMultipole(const int inRhs) const{
BRAMAS Berenger's avatar
BRAMAS Berenger committed
109 110 111
    return up->transformed_multipole_exp + inRhs*up->TransformedVectorSize;
  }
  /** Get Transformed Local */
112
  const FComplex<FReal>* getTransformedLocal(const int inRhs) const{
BRAMAS Berenger's avatar
BRAMAS Berenger committed
113 114 115 116
    return down->transformed_local_exp + inRhs*down->TransformedVectorSize;
  }

  /** Get Transformed Multipole */
117
  FComplex<FReal>* getTransformedMultipole(const int inRhs){
BRAMAS Berenger's avatar
BRAMAS Berenger committed
118 119 120
    return up->transformed_multipole_exp + inRhs*up->TransformedVectorSize;
  }
  /** Get Transformed Local */
121
  FComplex<FReal>* getTransformedLocal(const int inRhs){
BRAMAS Berenger's avatar
BRAMAS Berenger committed
122 123 124 125 126 127 128 129 130 131 132 133 134
    return down->transformed_local_exp + inRhs*down->TransformedVectorSize;
  }

  /** To get the leading dim of a vec */
  int getTransformedVectorSize() const{
    return down->TransformedVectorSize;
  }

  /** Make it like the begining */
  void resetToInitialState(){
    memset(up->multipole_exp, 0, sizeof(FReal) * NRHS * NVALS * up->VectorSize);
    memset(down->local_exp, 0, sizeof(FReal) * NLHS * NVALS * down->VectorSize);
    memset(up->transformed_multipole_exp, 0,
135
           sizeof(FComplex<FReal>) * NRHS * NVALS * up->TransformedVectorSize);
BRAMAS Berenger's avatar
BRAMAS Berenger committed
136
    memset(down->transformed_local_exp, 0,
137
           sizeof(FComplex<FReal>) * NLHS * NVALS * down->TransformedVectorSize);
BRAMAS Berenger's avatar
BRAMAS Berenger committed
138 139 140 141
  }
};

#endif // FUNIFCELLPOD_HPP