FChebCell.hpp 4.66 KB
Newer Older
BRAMAS Berenger's avatar
BRAMAS Berenger committed
1
// ===================================================================================
2 3 4 5 6 7 8 9 10 11 12 13 14
// 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".
BRAMAS Berenger's avatar
BRAMAS Berenger committed
15
// ===================================================================================
16 17
#ifndef FCHEBCELL_HPP
#define FCHEBCELL_HPP
18

19
#include "../../Components/FBasicCell.hpp"
20 21
#include "../../Extensions/FExtendMortonIndex.hpp"
#include "../../Extensions/FExtendCoordinate.hpp"
22 23

#include "./FChebTensor.hpp"
24
#include "../../Extensions/FExtendCellType.hpp"
25 26

/**
27 28 29 30 31 32 33
 * @author Matthias Messner (matthias.messner@inria.fr)
 * @class FChebCell
 * Please read the license
 *
 * This class defines a cell used in the Chebyshev based FMM.
 * @param NVALS is the number of right hand side.
 */
34
template <int ORDER, int NRHS = 1, int NLHS = 1, int NVALS = 1>
35
class FChebCell : public FBasicCell
36
{
37
  static const int VectorSize = TensorTraits<ORDER>::nnodes * 2;
38

39 40
  FReal multipole_exp[NRHS * NVALS * VectorSize]; //< Multipole expansion
  FReal     local_exp[NLHS * NVALS * VectorSize]; //< Local expansion
41

42
public:
43
  FChebCell(){
44 45
    memset(multipole_exp, 0, sizeof(FReal) * NRHS * NVALS * VectorSize);
    memset(local_exp, 0, sizeof(FReal) * NLHS * NVALS * VectorSize);
46
  }
47

48
  ~FChebCell() {}
49
	
50 51 52 53 54 55 56 57
  /** Get Multipole */
  const FReal* getMultipole(const int inRhs) const
  {	return this->multipole_exp + inRhs*VectorSize;
  }
  /** Get Local */
  const FReal* getLocal(const int inRhs) const{
    return this->local_exp + inRhs*VectorSize;
  }
58
	
59 60 61 62 63 64 65 66 67 68 69 70 71
  /** Get Multipole */
  FReal* getMultipole(const int inRhs){
    return this->multipole_exp + inRhs*VectorSize;
  }
  /** Get Local */
  FReal* getLocal(const int inRhs){
    return this->local_exp + inRhs*VectorSize;
  }

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

73 74
  /** Make it like the begining */
  void resetToInitialState(){
75 76
    memset(multipole_exp, 0, sizeof(FReal) * NRHS * NVALS * VectorSize);
    memset(local_exp, 0, sizeof(FReal) * NLHS * NVALS * VectorSize);
77 78 79 80 81 82 83
  }
  
  ///////////////////////////////////////////////////////
  // to extend FAbstractSendable
  ///////////////////////////////////////////////////////
  template <class BufferWriterClass>
  void serializeUp(BufferWriterClass& buffer) const{
84
    buffer.write(multipole_exp, VectorSize*NVALS*NRHS);
85 86 87
  }
  template <class BufferReaderClass>
  void deserializeUp(BufferReaderClass& buffer){
88
    buffer.fillArray(multipole_exp, VectorSize*NVALS*NRHS);
89 90 91 92
  }
  
  template <class BufferWriterClass>
  void serializeDown(BufferWriterClass& buffer) const{
93
    buffer.write(local_exp, VectorSize*NVALS*NLHS);
94 95 96
  }
  template <class BufferReaderClass>
  void deserializeDown(BufferReaderClass& buffer){
97
    buffer.fillArray(local_exp, VectorSize*NVALS*NLHS);
98 99 100 101 102 103 104 105
  }
  
  ///////////////////////////////////////////////////////
  // to extend Serializable
  ///////////////////////////////////////////////////////
  template <class BufferWriterClass>
  void save(BufferWriterClass& buffer) const{
    FBasicCell::save(buffer);
106 107
    buffer.write(multipole_exp, VectorSize*NVALS*NRHS);
    buffer.write(local_exp, VectorSize*NVALS*NLHS);
108 109 110 111
  }
  template <class BufferReaderClass>
  void restore(BufferReaderClass& buffer){
    FBasicCell::restore(buffer);
112 113
    buffer.fillArray(multipole_exp, VectorSize*NVALS*NRHS);
    buffer.fillArray(local_exp, VectorSize*NVALS*NLHS);
114 115
  }
  
116
  static constexpr int GetSize(){
PIACIBELLO Cyrille's avatar
PIACIBELLO Cyrille committed
117
    return int(sizeof(FReal)) * VectorSize*(NRHS+NLHS)*NVALS;
118
  }
119

120 121
};

122 123
template <int ORDER, int NRHS = 1, int NLHS = 1, int NVALS = 1>
class FTypedChebCell : public FChebCell<ORDER,NRHS,NLHS,NVALS>, public FExtendCellType {
124
public:
125 126
  template <class BufferWriterClass>
  void save(BufferWriterClass& buffer) const{
127
    FChebCell<ORDER,NRHS,NLHS,NVALS>::save(buffer);
128 129 130 131
    FExtendCellType::save(buffer);
  }
  template <class BufferReaderClass>
  void restore(BufferReaderClass& buffer){
132
    FChebCell<ORDER,NRHS,NLHS,NVALS>::restore(buffer);
133 134 135
    FExtendCellType::restore(buffer);
  }
  void resetToInitialState(){
136
    FChebCell<ORDER,NRHS,NLHS,NVALS>::resetToInitialState();
137 138
    FExtendCellType::resetToInitialState();
  }
139
};
140 141 142

#endif //FCHEBCELL_HPP

143