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;
11 class vtkDataObject;
12 
13 namespace CamAdaptor
14 {
15 
17 {
22 };
23 
28 template <GridType gridType>
29 class Grid
30 {
31 public:
32  Grid();
35  ~Grid();
36 
38  void Create();
39  void SetMpiRank(int rank) { this->MpiRank = rank; }
40  void SetChunkCapacity(int capacity) { this->ChunkCapacity = capacity; }
41  void SetNCells2d(int ncells) { this->NCells2d = ncells; }
42  void SetNLon(int nlon) { this->NLon = nlon; }
43  void SetNLat(int nlat) { this->NLat = nlat; }
44  void SetLev(int nlev, double* lev)
45  {
46  this->NLev = nlev;
47  if (lev)
48  {
49  this->Lev = new double[nlev];
50  std::copy(lev, lev + nlev, this->Lev);
51  }
52  }
54  void AddPointsAndCells(double lonRad, double latRad);
55 
58  void SetAttributeValue(int chunkSize, double* lonRad, double* latRad, double* psScalar,
59  double* tScalar, double* uScalar, double* vScalar);
60 
62  vtkSmartPointer<vtkUnstructuredGrid> GetGrid2d() const { return this->Grid2d; }
64  vtkSmartPointer<vtkUnstructuredGrid> GetGrid3d() const { return this->Grid3d; }
66  static bool SetToCoprocessor(vtkCPDataDescription* coprocessorData, const char* name,
67  vtkSmartPointer<vtkUnstructuredGrid> grid);
68 
71  void SetLonStep(int step) { this->LonStep = step; }
72  void SetLatStep(int step) { this->LatStep = step; }
74  void SetCubeGridPoints(int ne, int np, int lonSize, double* lonRad, int latSize, double* latRad);
76 
77 private:
79  void PrintAddChunk(
80  int* nstep, int* chunkCols, double* lonRad, double* latRad, double* psScalar, double* tScalar);
81 
83  vtkSmartPointer<vtkUnstructuredGrid> CreateGrid2d();
84 
86  vtkSmartPointer<vtkUnstructuredGrid> CreateGrid3d();
87 
94  double LevelToRadius(double level) const;
95 
98  void GetLevMinusPlus(int levIndex, double* levMinus, double* levPlus) const;
99  void GetLatMinusPlus(int latIndex, double* latMinus, double* latPlus) const;
100  void GetLonMinusPlus(int lonIndex, double* lonMinus, double* lonPlus) const;
101 
104  void GetValueIndex(double lonRad, double latRad, std::vector<std::vector<int> >& index) const;
105 
107  void GetCellPoints(const int index[3], double cellPoints[4][3]) const;
108  void GetCellPoints(const int index[3], int level, double cell[8][3]) const;
109 
111  void GetPointIds(const int index[3], int pointIndexes[4]) const;
112  void GetPointIds(const int index[3], int level, int pointIndexes[8]) const;
113 
115  int GetCellId(const int index[3]) const;
116  int GetCellId(const int index[3], int level) const;
117 
121  size_t CubeToIndex(double side, const std::vector<double>& cubeCoordinates, double v[3],
122  std::vector<std::vector<int> >& index) const;
123 
126  void IndexToCube(const std::vector<double>& cubeCoordinates, double index[3], double v[3]) const;
127  void CubeToSpherical(double v[3], double* lonRad, double* latRad) const;
128 
131  void MinFaceIndex(int side, int index[3]) const;
132 
133 private:
134  int MpiRank;
135  int ChunkCapacity;
136  int NCells2d;
137  int NLon, NLat, NLev;
138  double* Lev;
141  double Radius;
144  int Ne;
145  int Np;
147  double LonStep;
151  double LatStep;
152  class Internals;
154  Internals* Impl;
155 
157  vtkSmartPointer<vtkUnstructuredGrid> Grid2d; // the grid
158  int RankArrayIndex2d; // index of the rank array
159  int CoordArrayIndex2d; // index of the coordinates array (lon x lat)
160  int PSArrayIndex;
161 
163  vtkSmartPointer<vtkUnstructuredGrid> Grid3d;
164  int RankArrayIndex3d;
165  int CoordArrayIndex3d;
166  int TArrayIndex;
167  int UArrayIndex;
168  int VArrayIndex;
169 };
170 };
171 #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:40
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:72
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:43
vtkSmartPointer< vtkUnstructuredGrid > GetGrid2d() const
Returns the 2D grid.
Definition: Grid.h:62
~Grid()
Deletes data used to build the grids.
Creates and accumulates data for a 2D and a 3D grid.
Definition: Grid.h:29
vtkSmartPointer< vtkUnstructuredGrid > GetGrid3d() const
Returns the 3D grid.
Definition: Grid.h:64
void SetLev(int nlev, double *lev)
Definition: Grid.h:44
void SetMpiRank(int rank)
Definition: Grid.h:39
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:41
void SetLonStep(int step)
used for the FV dynamic core only
Definition: Grid.h:71
GridType
Definition: Grid.h:16
void Create()
Creates a 2D and a 3D grid.
This class provides the description of the data for the coprocessor pipelines.
void SetNLon(int nlon)
Definition: Grid.h:42