ParaView
Grid.h
Go to the documentation of this file.
1 #ifndef __GRID_H__
2 #define __GRID_H__
3 
4 #include <string>
5 #include <vector>
6 
7 #include "vtkSmartPointer.h"
8 
9 class vtkUnstructuredGrid;
10 class vtkCPDataDescription;
11 class vtkDataObject;
12 
13 namespace CamAdaptor
14 {
15 
17 {
22 };
23 
24 
25 
30 template<GridType gridType>
31 class Grid
32 {
33 public:
34 
35  Grid();
38  ~Grid();
39 
41  void Create();
42  void SetMpiRank(int rank)
43  {
44  this->MpiRank = rank;
45  }
46  void SetChunkCapacity(int capacity)
47  {
48  this->ChunkCapacity = capacity;
49  }
50  void SetNCells2d(int ncells)
51  {
52  this->NCells2d = ncells;
53  }
54  void SetNLon(int nlon)
55  {
56  this->NLon = nlon;
57  }
58  void SetNLat(int nlat)
59  {
60  this->NLat = nlat;
61  }
62  void SetLev(int nlev, double* lev)
63  {
64  this->NLev = nlev;
65  if (lev)
66  {
67  this->Lev = new double[nlev];
68  std::copy(lev, lev + nlev, this->Lev);
69  }
70  }
72  void AddPointsAndCells(double lonRad, double latRad);
73 
76  void SetAttributeValue(int chunkSize,
77  double* lonRad, double* latRad,
78  double* psScalar, double *tScalar, double* uScalar,
79  double* vScalar);
80 
82  vtkSmartPointer<vtkUnstructuredGrid> GetGrid2d() const
83  {
84  return this->Grid2d;
85  }
87  vtkSmartPointer<vtkUnstructuredGrid> GetGrid3d() const
88  {
89  return this->Grid3d;
90  }
92  static bool SetToCoprocessor(
93  vtkCPDataDescription* coprocessorData, const char* name,
94  vtkSmartPointer<vtkUnstructuredGrid> grid);
95 
96 
99  void SetLonStep(int step)
100  {
101  this->LonStep = step;
102  }
103  void SetLatStep(int step)
104  {
105  this->LatStep = step;
106  }
108  void SetCubeGridPoints(
109  int ne, int np, int lonSize, double* lonRad, int latSize, double* latRad);
111 
112 private:
114  void PrintAddChunk(
115  int* nstep, int* chunkCols,
116  double* lonRad, double* latRad, double* psScalar, double *tScalar);
117 
119  vtkSmartPointer<vtkUnstructuredGrid> CreateGrid2d();
120 
122  vtkSmartPointer<vtkUnstructuredGrid> CreateGrid3d();
123 
130  double LevelToRadius(double level) const;
131 
134  void GetLevMinusPlus(int levIndex, double* levMinus, double* levPlus) const;
135  void GetLatMinusPlus(int latIndex, double* latMinus, double* latPlus) const;
136  void GetLonMinusPlus(int lonIndex, double* lonMinus, double* lonPlus) const;
137 
140  void GetValueIndex(double lonRad, double latRad,
141  std::vector<std::vector<int> >& index) const;
142 
144  void GetCellPoints(const int index[3], double cellPoints[4][3]) const;
145  void GetCellPoints(const int index[3], int level, double cell[8][3]) const;
146 
148  void GetPointIds(const int index[3], int pointIndexes[4]) const;
149  void GetPointIds(const int index[3], int level, int pointIndexes[8]) const;
150 
152  int GetCellId(const int index[3]) const;
153  int GetCellId(const int index[3], int level) const;
154 
158  size_t CubeToIndex (double side, const std::vector<double>& cubeCoordinates, double v[3],
159  std::vector<std::vector<int> >& index) const;
160 
163  void IndexToCube (const std::vector<double>& cubeCoordinates,
164  double index[3], double v[3]) const;
165  void CubeToSpherical (double v[3], double* lonRad, double* latRad) const;
166 
169  void MinFaceIndex(int side, int index[3]) const;
170 
171 private:
172  int MpiRank;
173  int ChunkCapacity;
174  int NCells2d;
175  int NLon, NLat, NLev;
176  double* Lev;
179  double Radius;
182  int Ne;
183  int Np;
185  double LonStep;
189  double LatStep;
190  class Internals;
192  Internals* Impl;
193 
195  vtkSmartPointer<vtkUnstructuredGrid> Grid2d;//the grid
196  int RankArrayIndex2d; //index of the rank array
197  int CoordArrayIndex2d; //index of the coordinates array (lon x lat)
198  int PSArrayIndex;
199 
201  vtkSmartPointer<vtkUnstructuredGrid> Grid3d;
202  int RankArrayIndex3d;
203  int CoordArrayIndex3d;
204  int TArrayIndex;
205  int UArrayIndex;
206  int VArrayIndex;
207 };
208 
209 };
210 #endif
static bool SetToCoprocessor(vtkCPDataDescription *coprocessorData, const char *name, vtkSmartPointer< vtkUnstructuredGrid > grid)
Attach the grid to the coprocessor data.
void SetChunkCapacity(int capacity)
Definition: Grid.h:46
void SetCubeGridPoints(int ne, int np, int lonSize, double *lonRad, int latSize, double *latRad)
used for the SE dynamic core only
void SetLatStep(int step)
Definition: Grid.h:103
void AddPointsAndCells(double lonRad, double latRad)
Adds the points and the cells for a vertical column to the grid.
void SetNLat(int nlat)
Definition: Grid.h:58
vtkSmartPointer< vtkUnstructuredGrid > GetGrid2d() const
Returns the 2D grid.
Definition: Grid.h:82
~Grid()
Deletes data used to build the grids.
Creates and accumulates data for a 2D and a 3D grid.
Definition: Grid.h:31
vtkSmartPointer< vtkUnstructuredGrid > GetGrid3d() const
Returns the 3D grid.
Definition: Grid.h:87
void SetLev(int nlev, double *lev)
Definition: Grid.h:62
void SetMpiRank(int rank)
Definition: Grid.h:42
void SetAttributeValue(int chunkSize, double *lonRad, double *latRad, double *psScalar, double *tScalar, double *uScalar, double *vScalar)
Sets attributes for a chunk (a list of vertical columns) to the 2D and 3D grids.
void SetNCells2d(int ncells)
Definition: Grid.h:50
void SetLonStep(int step)
used for the FV dynamic core only
Definition: Grid.h:99
GridType
Definition: Grid.h:16
void Create()
Creates a 2D and a 3D grid.
void SetNLon(int nlon)
Definition: Grid.h:54