forked from rustychris/ugrid_visit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathavtUGRIDFileFormat.h
More file actions
255 lines (203 loc) · 8.51 KB
/
avtUGRIDFileFormat.h
File metadata and controls
255 lines (203 loc) · 8.51 KB
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
/*****************************************************************************
*
* Copyright (c) 2000 - 2015, Lawrence Livermore National Security, LLC
* Produced at the Lawrence Livermore National Laboratory
* LLNL-CODE-442911
* All rights reserved.
*
* This file is part of VisIt. For details, see https://visit.llnl.gov/. The
* full copyright notice is contained in the file COPYRIGHT located at the root
* of the VisIt distribution or at http://www.llnl.gov/visit/copyright.html.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the disclaimer below.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the disclaimer (as noted below) in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of the LLNS/LLNL nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY,
* LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
*****************************************************************************/
// ************************************************************************* //
// avtUGRIDFileFormat.h //
// ************************************************************************* //
#ifndef AVT_UGRID_FILE_FORMAT_H
#define AVT_UGRID_FILE_FORMAT_H
#include <avtMTSDFileFormat.h>
#include <avtMTMDFileFormat.h>
#include <vtkUnstructuredGrid.h>
#include <vector>
#include <map>
#define MAX_SIDES 50
#define MAX_DIMS 6
#define MAX_SUBDOMAINS 256
// forward declarations:
class avtUGRIDFileFormat;
class avtUGRIDSingle;
// corresponds 1:1 (I think) with meshes in the eyes of visit.
// so whether a variable is on the nodes or cells is up to the variable.
class MeshInfo {
public:
std::string name;
// formula terms in case of sigma layers:
std::string sigma_sigma,sigma_eta,sigma_bedlevel;
int ncid,varid;
int active_timestate;
std::vector<int> cell_kmin,cell_kmax;
avtUGRIDSingle *parent;
// dimension ids - set to -1 if this mesh doesn't have those
// dimensions
int node_dim, cell_dim, layer_dim;
int node_x_var,node_y_var, layer_z_var;
size_t n_nodes, n_cells2d, n_layers, n_cells3d;
MeshInfo(int ncid,int varid,int z_var=-1);
MeshInfo() {ncid=-1 ; varid=-1; layer_z_var=-1; active_timestate=-1; parent=NULL; };
vtkPoints *GetNodes(void);
vtkDataSet *GetMesh(int timestate);
vtkUnstructuredGrid *GetMesh2D(int timestate);
vtkUnstructuredGrid *ExtrudeTo3D(int timestate,vtkUnstructuredGrid *surface);
void set_layer_bounds(std::string z_std_name,
std::vector<float> &layer_bottom,
std::vector<float> &layer_top);
void activateTimestate(int);
vtkDataArray *ZoneToNode2D(vtkDataArray *,vtkUnstructuredGrid *);
};
class VarInfo {
public:
std::string name;
std::string mesh_name;
std::vector<std::string> spatial_dim_names;
int ndims;
int dims[MAX_DIMS];
// these are -1 if not present, and otherwise
// give where the respective dimension falls in the variable definition.
// node_dimi vs. cell_dimi control the staggering of the variable.
int time_dimi,cell_dimi,layer_dimi,node_dimi;
// cell, layer, node are stored in a mesh object - shared among variables
// which live on the same grid. time_dim is trickier - for a static grid,
// doesn't necessarily need to be shared.
int time_dim; // ,cell_dim,layer_dim,node_dim;
int var_id,ncid;
VarInfo(std::string);
VarInfo(void);
VarInfo(const VarInfo &);
void init(void);
float *read_cell_at_time(int,MeshInfo &);
float *read_node_at_time(int,MeshInfo &);
float *read_cell_z_at_time(int,MeshInfo &);
};
// ****************************************************************************
// Class: avtUGRIDSingle
//
// Purpose:
// Reads in UGRID files for a single subdomain.
//
// Programmer: rusty -- generated by xml2avt
// Creation: Sat Mar 5 18:27:45 PST 2016
//
// ****************************************************************************
class avtUGRIDSingle : public avtMTSDFileFormat
{
public:
avtUGRIDSingle(const char *);
virtual ~avtUGRIDSingle();
virtual int GetNTimesteps(void);
virtual void GetTimes(std::vector<double> &);
virtual void GetCycles(std::vector<int> &);
virtual const char *GetType(void) { return "UGRIDsingle"; };
virtual void FreeUpResources(void);
virtual vtkDataSet *GetMesh(int, const char *);
virtual vtkDataArray *GetVar(int, const char *);
virtual vtkDataArray *GetVectorVar(int, const char *);
vtkUnstructuredGrid *GetMeshNodes(const std::string);
// vtkDataSet *ExtrudeTo3D(const std::string,int,vtkUnstructuredGrid *);
vtkPoints *GetNodes(const std::string);
void initialize_metadata(void);
// DATA MEMBERS
virtual void PopulateDatabaseMetaData(avtDatabaseMetaData *, int);
protected:
int ncid; // handle for netcdf file
int time_dim; // some variables/meshes may have a different time - that's not tested, tho.
int time_var;
// int node_x_var,node_y_var;
std::string default_ugrid_mesh;
std::map<std::string,VarInfo> var_table;
std::map<std::string,MeshInfo> mesh_table;
// basic dimensions
// map 3D cell ids to real cells, because cells that are
// underground are not output.
// probably this needs to move to mesh
std::map<int,int> full_cell2valid;
// netcdf helpers:
// read a full field of values at a given timestate
// layer is the fastest changing index
float *read_cell_z_full(std::string,int);
std::string var_mesh2d(std::string);
std::string var_mesh2d(int);
bool setMeshInfo(VarInfo &);
void activateTimestate(int);
// various geometry-related data specific to the active timestate
int active_timestate;
int *cell_kmin;
int *cell_kmax;
int ncells_3d;
int vertical_coordinate_for_dimension(int dim);
std::string create_3d_mesh(std::string mesh2d,int z_dim,int z_var);
vtkDataArray *GetVar3D(int, VarInfo &);
vtkDataArray *GetVar2D(int, VarInfo &);
};
// ****************************************************************************
// Class: avtUGRIDFileFormat
//
// Purpose:
// Wraps one more single-domains into a multi-domain database
//
// Programmer: rusty -- generated by xml2avt
// Creation: Sat Mar 5 18:27:45 PST 2016
//
// ****************************************************************************
class avtUGRIDFileFormat : public avtMTMDFileFormat
{
public:
avtUGRIDFileFormat(const char *);
// virtual ~avtUGRIDFileFormat();
virtual int GetNTimesteps(void);
virtual void GetTimes(std::vector<double> &);
virtual void GetCycles(std::vector<int> &);
virtual const char *GetType(void) { return "UGRID"; };
virtual void FreeUpResources(void);
virtual vtkDataSet *GetMesh(int, int, const char *);
virtual vtkDataArray *GetVar(int, int, const char *);
virtual vtkDataArray *GetVectorVar(int, int, const char *);
protected:
// DATA MEMBERS
virtual void PopulateDatabaseMetaData(avtDatabaseMetaData *, int);
std::vector<avtUGRIDSingle*> domain_cache;
std::vector<avtDatabaseMetaData*> metadata_cache;
std::vector<std::string> filenames;
int domain_count;
avtUGRIDSingle *subdomain(int domain);
void populate_filenames(const char *);
// I think this can be handled within the subdomains.
// void activateTimestate(int);
// various geometry-related data specific to the active timestate
// int active_timestate;
};
#endif