File: vtkMPASReader.h

package info (click to toggle)
vtk9 9.5.2%2Bdfsg3-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 205,916 kB
  • sloc: cpp: 2,336,565; ansic: 327,116; python: 111,200; yacc: 4,104; java: 3,977; sh: 3,032; xml: 2,771; perl: 2,189; lex: 1,787; makefile: 178; javascript: 165; objc: 153; tcl: 59
file content (315 lines) | stat: -rw-r--r-- 9,315 bytes parent folder | download | duplicates (4)
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
// SPDX-FileCopyrightText: Copyright (c) 2002-2005 Los Alamos National Laboratory
// SPDX-License-Identifier: BSD-3-Clause-Sandia-LANL-California-USGov
/**
 * @class   vtkMPASReader
 * @brief   Read an MPAS netCDF file
 *
 * This program reads an MPAS netCDF data file to allow paraview to
 * display a dual-grid sphere or latlon projection.  Also allows
 * display of primal-grid sphere.
 * The variables that have time dim are available to ParaView.
 *
 * Assume all variables are of interest if they have dims
 * (Time, nCells|nVertices, nVertLevels, [nTracers]).
 * Does not deal with edge data.
 *
 * When using this reader, it is important that you remember to do the
 *following:
 *   1.  When changing a selected variable, remember to select it also
 *       in the drop down box to "color by".  It doesn't color by that variable
 *       automatically.
 *   2.  When selecting multilayer sphere view, make layer thickness around
 *       100,000.
 *   3.  When selecting multilayer lat/lon view, make layer thickness around 10.
 *   4.  Always click the -Z orientation after making a switch from lat/lon to
 *       sphere, from single to multilayer or changing thickness.
 *   5.  Be conservative on the number of changes you make before hitting Apply,
 *       since there may be bugs in this reader.  Just make one change and then
 *       hit Apply.
 *
 *
 * Christine Ahrens (cahrens@lanl.gov)
 * Version 1.3
 */

#ifndef vtkMPASReader_h
#define vtkMPASReader_h

#include "vtkIONetCDFModule.h" // For export macro
#include "vtkUnstructuredGridAlgorithm.h"

#include <string> // for std::string

VTK_ABI_NAMESPACE_BEGIN
class vtkCallbackCommand;
class vtkDataArraySelection;
class vtkDoubleArray;
class vtkStringArray;

class VTKIONETCDF_EXPORT vtkMPASReader : public vtkUnstructuredGridAlgorithm
{
public:
  static vtkMPASReader* New();
  vtkTypeMacro(vtkMPASReader, vtkUnstructuredGridAlgorithm);
  void PrintSelf(ostream& os, vtkIndent indent) override;

  ///@{
  /**
   * Specify file name of MPAS data file to read.
   */
  vtkSetFilePathMacro(FileName);
  vtkGetFilePathMacro(FileName);
  ///@}

  ///@{
  /**
   * Get the number of data cells
   */
  vtkGetMacro(MaximumCells, int);
  ///@}

  ///@{
  /**
   * Get the number of points
   */
  vtkGetMacro(MaximumPoints, int);
  ///@}

  ///@{
  /**
   * Get the number of data variables at the cell centers and points
   */
  virtual int GetNumberOfCellVars();
  virtual int GetNumberOfPointVars();
  ///@}

  ///@{
  /**
   * Get the reader's output
   */
  vtkUnstructuredGrid* GetOutput();
  vtkUnstructuredGrid* GetOutput(int idx);
  ///@}

  ///@{
  /**
   * If true, dimension info is included in the array name. For instance,
   * "tracers" will become "tracers(Time, nCells, nVertLevels, nTracers)".
   * This is useful for user-visible array selection, but is disabled by default
   * for backwards compatibility.
   */
  vtkSetMacro(UseDimensionedArrayNames, bool);
  vtkGetMacro(UseDimensionedArrayNames, bool);
  vtkBooleanMacro(UseDimensionedArrayNames, bool);
  ///@}

  ///@{
  /**
   * The following methods allow selective reading of solutions fields.
   * By default, ALL data fields on the nodes are read, but this can
   * be modified.
   */
  int GetNumberOfPointArrays();
  const char* GetPointArrayName(int index);
  int GetPointArrayStatus(const char* name);
  void SetPointArrayStatus(const char* name, int status);
  void DisableAllPointArrays();
  void EnableAllPointArrays();
  ///@}

  int GetNumberOfCellArrays();
  const char* GetCellArrayName(int index);
  int GetCellArrayStatus(const char* name);
  void SetCellArrayStatus(const char* name, int status);
  void DisableAllCellArrays();
  void EnableAllCellArrays();

  ///@{
  /**
   * If the point/cell arrays contain dimensions other than Time, nCells, or
   * nVertices, they are configured here. Use GetNumberOfDimensions to get the
   * number of arbitrary dimensions in the loaded arrays and GetDimensionName to
   * retrieve the dimension names. GetDimensionSize returns the number of values
   * in the dimensions, and Set/GetDimensionCurrentIndex controls the value
   * to fix a given dimension at when extracting slices of data.
   */
  vtkIdType GetNumberOfDimensions();
  std::string GetDimensionName(int idx);
  vtkStringArray* GetAllDimensions();
  int GetDimensionCurrentIndex(const std::string& dim);
  void SetDimensionCurrentIndex(const std::string& dim, int idx);
  int GetDimensionSize(const std::string& dim);
  ///@}

  ///@{
  /**
   * Get/Set the name to the dimension that identifies the vertical dimension.
   * Defaults to "nVertLevels".
   */
  vtkSetMacro(VerticalDimension, std::string);
  vtkGetMacro(VerticalDimension, std::string);
  ///@}

  ///@{
  /**
   * Convenience function for setting/querying [GS]etDimensionCurrentIndex
   * for the dimension returned by GetVerticalDimension.
   */
  void SetVerticalLevel(int level);
  int GetVerticalLevel();
  ///@}

  vtkGetVector2Macro(VerticalLevelRange, int);

  vtkSetMacro(LayerThickness, int);
  vtkGetMacro(LayerThickness, int);
  vtkGetVector2Macro(LayerThicknessRange, int);

  void SetCenterLon(int val);
  vtkGetVector2Macro(CenterLonRange, int);

  vtkSetMacro(ProjectLatLon, bool);
  vtkGetMacro(ProjectLatLon, bool);

  vtkSetMacro(IsAtmosphere, bool);
  vtkGetMacro(IsAtmosphere, bool);

  vtkSetMacro(IsZeroCentered, bool);
  vtkGetMacro(IsZeroCentered, bool);

  vtkSetMacro(ShowMultilayerView, bool);
  vtkGetMacro(ShowMultilayerView, bool);

  /**
   * Returns true if the given file can be read.
   */
  static int CanReadFile(VTK_FILEPATH const char* filename);

  vtkMTimeType GetMTime() override;

protected:
  vtkMPASReader();
  ~vtkMPASReader() override;
  void ReleaseNcData();
  void DestroyData();

  char* FileName; // First field part file giving path

  size_t NumberOfTimeSteps; // Temporal domain
  double DTime;             // The current time

  // Observer to modify this object when array selections are modified
  vtkCallbackCommand* SelectionObserver;

  int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override;
  int RequestInformation(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override;

  static void SelectionCallback(
    vtkObject* caller, unsigned long eid, void* clientdata, void* calldata);

  // Selected field of interest
  vtkDataArraySelection* PointDataArraySelection;
  vtkDataArraySelection* CellDataArraySelection;

  /**
   * Update the list of available dimensions. Only does work when
   * PointDataArraySelection or CellDataArraySelection is changed.
   */
  void UpdateDimensions(bool force = false);

  std::string VerticalDimension;
  int VerticalLevelRange[2];

  int LayerThickness;
  int LayerThicknessRange[2];

  int CenterLon;
  int CenterLonRange[2];

  enum GeometryType
  {
    Spherical,
    Projected,
    Planar
  };

  GeometryType Geometry;

  bool ProjectLatLon; // User option
  bool OnASphere;     // Data file attribute
  bool IsAtmosphere;
  bool IsZeroCentered;
  bool ShowMultilayerView;

  bool IncludeTopography;
  bool DoBugFix;
  double CenterRad;

  bool UseDimensionedArrayNames;

  // geometry
  size_t MaximumNVertLevels;
  size_t NumberOfCells;
  size_t NumberOfPoints;
  int CellOffset;
  size_t PointOffset;
  size_t PointsPerCell;
  size_t CurrentExtraPoint; // current extra point
  size_t CurrentExtraCell;  // current extra cell
  double* PointX;           // x coord of point
  double* PointY;           // y coord of point
  double* PointZ;           // z coord of point
  size_t ModNumPoints;
  size_t ModNumCells;
  int* OrigConnections;   // original connections
  int* ModConnections;    // modified connections
  size_t* CellMap;        // maps from added cell to original cell #
  size_t* PointMap;       // maps from added point to original point #
  int* MaximumLevelPoint; //
  int MaximumCells;       // max cells
  int MaximumPoints;      // max points

  void SetDefaults();
  int GetNcDims();
  int GetNcAtts();
  int CheckParams();
  int GetNcVars(const char* cellDimName, const char* pointDimName);
  int ReadAndOutputGrid();
  int BuildVarArrays();
  int AllocSphericalGeometry();
  int AllocProjectedGeometry();
  int AllocPlanarGeometry();
  void ShiftLonData();
  int AddMirrorPoint(int index, double dividerX, double offset);
  void FixPoints();
  int EliminateXWrap();
  void OutputPoints();
  void OutputCells();
  unsigned char GetCellType();

  vtkDataArray* LoadPointVarData(int variable);
  vtkDataArray* LoadCellVarData(int variable);
  vtkDataArray* LookupPointDataArray(int varIdx);
  vtkDataArray* LookupCellDataArray(int varIdx);

  /**
   * Update the "Time" vtkStringArray in dataset's FieldData to contain the
   * xtime string for the current timestep.
   * If there is an error getting xtime, the current timestep number is inserted
   * instead.
   * If a non-string array named Time already exists in the FieldData, dataset
   * is not modified in any way.
   */
  void LoadTimeFieldData(vtkUnstructuredGrid* dataset);

private:
  vtkMPASReader(const vtkMPASReader&) = delete;
  void operator=(const vtkMPASReader&) = delete;

  class Internal;
  Internal* Internals;
};

VTK_ABI_NAMESPACE_END
#endif