VsStaggeredField.h 5.09 KB
Newer Older
apletzer's avatar
apletzer committed
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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 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 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
/**
 * @file VsStaggeredField.h
 *      
 *  @class VsStaggeredField
 *  @brief Represents staggered fields in memory
 *  
 *  Created on: Apr 23, 2013
 *      Author: pletzer
 */

#ifndef VS_STAGGERED_FIELD_H_
#define VS_STAGGERED_FIELD_H_

#include <string>
#include "VsObject.h"
#include <vector>
#include <valarray>

template <class TYPE>
class VsStaggeredField {

public:

  /**
   * Constructor
   * @param subRes sub-grid resolution, number of sub-cells is 2^subRes in each direction
   */
  VsStaggeredField(size_t subRes);

  /** 
   * Destructor
   */
  virtual ~VsStaggeredField();

  /**
   * Set the data pointer
   * @param dataPtr data pointer
   * @param numDims number of dimensions (incl. components)
   * @param dims dimensions along each axis (incl. component axis)
   * @param indexOrder index order (e.g. VsSchema::compMajorFKey)
   * @param centering (e.g. VsSchema::faceCenteringKey)
   */
   void setDataPtr(const TYPE* dataPtr, size_t numDims, const int dims[], 
                   const std::string& indexOrder, const std::string& centering);

   /**
    * Get the interpolated field dimensions
    * @return dimensions along each axis (incl. component axis)
    */
   std::vector<int> getNewNodalDataDims() const;

   /**
    * Get the new field data values
    * @param pointer to the new data, caller is responsible to allocating and freeing
    */
   void getNewNodalData(TYPE* dataPtr) const;

  
private:

   std::valarray<int> getOriCellIndexSet(size_t bigIndx) const;
   std::valarray<int> getOriDisplacements(size_t subBigIndx) const;
   size_t getOriBigIndex(const std::valarray<int>& indx) const;
   std::valarray<TYPE> getOriFieldVals(size_t bigInx) const;
   std::valarray<int> getSubCellIndexSet(size_t subBigIndex) const;
   size_t getNewBigIndex(const std::valarray<int>& newCellInds) const;

   /**
    * Fill interpolated values 
    * @param newBigInd big (flat) index of the new data array
    * @param sigmaVals displacements (array of 1s and 0s) from the original cells
    * @param neighVals field values corresponding to the sigmaVals displacements
    * @param dataPtr pointer to the new data, some values will be filled in
    */
   void fillNewVals(size_t newBigIndx, 
                    const std::valarray<TYPE>& xiVals,
                    const std::vector< std::valarray<TYPE> >& sigmaVals,
                    const std::vector< std::valarray<TYPE> >& neighVals, 
                    TYPE* dataPtr) const; 


   void setNodalInterpFieldVals(size_t newBigIndx, 
                                const std::valarray<TYPE>& xiVals, 
                                const std::vector< std::valarray<TYPE> >& sigmaVals,
                                const std::vector< std::valarray<TYPE> >& neighVals, 
                                TYPE* dataPtr) const;
   void setEdgeInterpFieldVals(size_t newBigIndx, 
                               const std::valarray<TYPE>& xiVals, 
                               const std::vector< std::valarray<TYPE> >& sigmaVals,
                               const std::vector< std::valarray<TYPE> >& neighVals, 
                               TYPE* dataPtr) const;
   void setFaceInterpFieldVals(size_t newBigIndx, 
                               const std::valarray<TYPE>& xiVals, 
                               const std::vector< std::valarray<TYPE> >& sigmaVals,
                               const std::vector< std::valarray<TYPE> >& neighVals, 
                               TYPE* dataPtr) const;
   void setZonalInterpFieldVals(size_t newBigIndx, 
                                const std::valarray<TYPE>& xiVals, 
                                const std::vector< std::valarray<TYPE> >& sigmaVals,
                                const std::vector< std::valarray<TYPE> >& neighVals, 
                                TYPE* dataPtr) const;
   

   /** number of sub-cells is 2^subRes in each topological direction */
  size_t subRes;

  /** pointer to the original data, assumed to have dimension nodal data times number of components */
  TYPE* oriDataPtr;

  /** total number of original grid cells */
  size_t totNumOriCells;
  
  /** total number of new grid cells */
  size_t totNumNewCells;

  /** total number of data values (number of nodes times number of components) */
  size_t totNumOriVals;

  /** total number of new data values (number of nodes times number of components) */
  size_t totNumNewVals;

  /** 2^subRes */
  size_t twoPowSubRes;

  /** number neighbors forming a cell (2^d) */
  size_t numNeighbors;

  /** number of topological dimensions */
  size_t numTopoDims;
  
  /** component index */
  int indexComp;

  /** index order, see VsSchema */
  std::string indexOrder;

  /** type of field centering (nodal, edge, ...) */
  std::string centering;
  
  /** number of cells along each direction for the original data */
  std::valarray<int> oriCellDim;

  /** number of cells along each direction for the new data */
  std::valarray<int> newCellDims;

  /** array to map big index to index set for original data */
  std::valarray<int> oriCellDimProd;

  /** array to map big index to index set for new data */
  std::valarray<int> newCellDimProd;

};

#endif /* VS_STAGGERED_FIELD_H_ */