Skip to main content

Post-processing tools 2023 R2

test_dvs_reader.cpp

Last update: 17.04.2023
Go to the documentation of this file.
1 /**************************************************************
2 *
3 * (C) 2021 ANSYS, Inc. Unauthorized use, distribution, or duplication is prohibited.
4 *
5 * Restricted Rights Legend
6 *
7 * Use, duplication, or disclosure of this
8 * software and its documentation by the
9 * Government is subject to restrictions as
10 * set forth in subdivision [(b)(3)(ii)] of
11 * the Rights in Technical Data and Computer
12 * Software clause at 52.227-7013.
13 *
14 **************************************************************
15 */
16 
24 #include <string.h>
25 
27 #include "logger_verbose.h"
28 
29 #include <array>
30 #include <chrono>
31 #include <functional>
32 #include <memory>
33 #include <string>
34 #include <thread>
35 #include <vector>
36 #include <cfloat>
37 
38 static void logging_function(void* user_data, const char* message)
39 {
40  fprintf(stdout, message);
41 }
42 
43 static void print(const DVS::IObject* object)
44 {
45  if (object)
46  {
47  std::string object_name = "Unknown:";
48  if (object->get_type() == DVS::IObject::PART) {
49  object_name = "Part";
50  }
51  else if (object->get_type() == DVS::IObject::PLOT) {
52  object_name = "Plot";
53  }
54 
55  fprintf( stdout, "%s: Name: %s Type: %i\n", object_name.c_str(), object->get_name(), object->get_type() );
56  fprintf( stdout, "Dataset Name: %s\n", object->get_dataset()->get_name());
57  fprintf( stdout, "Metadata Size: %u\n", object->get_num_metadata());
58  if (object->get_num_metadata()) {
59  for (uint32_t metadata_idx = 0; metadata_idx < object->get_num_metadata(); metadata_idx++) {
60  fprintf(stdout, "Key: %s, Val:%s ", object->get_metadata_key(metadata_idx), object->get_metadata_value(metadata_idx));
61  }
62  fprintf(stdout, "\n");
63  }
64  fprintf(stdout, "\n");
65  }
66 }
67 
68 static void print(const DVS::IVar* var)
69 {
70  if (var)
71  {
72  fprintf( stdout, "Var: Name: %s, Type: %i, Location: %i, Unit Dim: %s, Unit Label: %s\n",
73  var->get_name(), var->get_var_type(), var->get_var_location(), var->get_unit_dimension(), var->get_unit_label());
74  fprintf(stdout, "Dataset Name: %s\n", var->get_dataset()->get_name());
75  fprintf( stdout, "Metadata Size: %u\n", var->get_num_metadata());
76  if (var->get_num_metadata()) {
77  for (uint32_t metadata_idx = 0; metadata_idx < var->get_num_metadata(); metadata_idx++) {
78  fprintf(stdout, "Key: %s, Val:%s ", var->get_metadata_key(metadata_idx), var->get_metadata_value(metadata_idx));
79  }
80  fprintf(stdout, "\n");
81  }
82  fprintf(stdout, "\n");
83  }
84 }
85 
93 int main(int argc, char** argv)
94 {
95  char cache_uri[512] = {0};
96  uint32_t debug_wait = 0;
97  bool all_coords = false;
98  bool all_connectivity = false;
99  bool all_variable_data = false;
100 
101  uint32_t i = 1;
102  while (i < argc)
103  {
104  if ((strcmp(argv[i], "-cache_uri") == 0) && (i < argc - 1))
105  {
106  i++;
107  strncpy(cache_uri, argv[i], 512);
108  }
109  else if ((strcmp(argv[i], "-all_coords") == 0))
110  {
111  all_coords = true;
112  }
113  else if ((strcmp(argv[i], "-all_conn") == 0))
114  {
115  all_connectivity = true;
116  }
117  else if ((strcmp(argv[i], "-all_vars") == 0))
118  {
119  all_variable_data = true;
120  }
121  else if ((strcmp(argv[i], "-debug_wait") == 0) && (i < argc - 1))
122  {
123  i++;
124  debug_wait = atoi(argv[i]);
125  }
126  else
127  {
128  fprintf(stderr, "Unknown option: %s\n", argv[i]);
129  fprintf(stderr, "Usage: %s [-uri str] [-debug_wait ms] \n", argv[0]);
130  fprintf(stderr, "Options:\n");
131  fprintf(stderr, " -cache_uri str The URI for the reader to use for the cache. Default: No cache\n");
132  fprintf(stderr, " -all_coords Print the full coordinates for the mesh chunks iterated over (not a good idea for large datasets)\n");
133  fprintf(stderr, " -all_conn Print the full connectivity for the element blocks iterated over (not a good idea for large datasets)\n");
134  fprintf(stderr, " -all_vars Print the full variable values for mesh chunks and element blocks (not a good idea for large datasets)\n");
135  fprintf(stderr, " -debug_wait s Wait for [s] for debugging\n");
136  exit(1);
137  }
138  i++;
139  }
140 
141  if (debug_wait > 0) {
142  std::this_thread::sleep_for(std::chrono::seconds(debug_wait));
143  }
144 
145  std::unique_ptr<DVS::IQuery, std::function<void(DVS::IQuery*)>> dataset_query(DVS::CREATE_QUERY_INSTANCE(),
146  [](DVS::IQuery* p){p->release();});
147  dataset_query->set_logger(new DVS::LoggerVerbose(nullptr, dvs_verbosity::DVS_VERBOSE, &logging_function));
148  auto err = dataset_query->add_uri(cache_uri);
149  if (DVS_NONE != err) {
150  return err;
151  }
152 
153  fprintf(stdout, "---------------------------\n");
154  fprintf(stdout, "Listing All Timesteps for Query\n");
155  fprintf(stdout, "---------------------------\n");
156  uint32_t num_timesteps = 0;
157  err = dataset_query->get_num_timesteps(num_timesteps);
158  if (DVS_NONE != err) {
159  fprintf(stdout, "Error getting number of timesteps\n");
160  return err;
161  }
162  std::vector<float> timesteps(num_timesteps, 0.f);
163  dataset_query->get_timesteps(timesteps.data());
164 
165  fprintf(stdout, "Timesteps: ");
166  for (auto time : timesteps) {
167  fprintf (stdout, " %f", time);
168  }
169  fprintf(stdout, "\n");
170 
171  fprintf(stdout, "---------------------------\n");
172  fprintf(stdout, "Listing All Ranks for Query\n");
173  fprintf(stdout, "---------------------------\n");
174  uint32_t num_ranks = 0;
175  err = dataset_query->get_num_ranks(num_ranks);
176  if (DVS_NONE != err) {
177  fprintf(stdout, "Error getting number of ranks\n");
178  return err;
179  }
180  std::vector<uint32_t> global_ranks(num_ranks, 0);
181  dataset_query->get_ranks(global_ranks.data());
182  for (auto rank : global_ranks) {
183  fprintf(stdout, "%u ", rank);
184  }
185  fprintf(stdout, "\n");
186 
187  fprintf(stdout, "---------------------------\n");
188  fprintf(stdout, "Listing Max Chunks for Query\n");
189  fprintf(stdout, "---------------------------\n");
190 
191  uint32_t num_chunks_per_rank = 0;
192  err = dataset_query->get_num_chunks_per_rank(num_chunks_per_rank);
193  if (DVS_NONE != err) {
194  fprintf(stdout, "Error getting number of chunks per rank\n");
195  return err;
196  }
197  std::vector<uint32_t> global_chunk_max(num_chunks_per_rank, 0);
198  dataset_query->get_chunks_per_rank(global_chunk_max.data());
199  for (auto chunk : global_chunk_max) {
200  fprintf(stdout, "%u ", chunk);
201  }
202  fprintf(stdout, "\n");
203 
204  fprintf(stdout, "---------------------------\n");
205  fprintf(stdout, "Listing All Parts for Query\n");
206  fprintf(stdout, "---------------------------\n");
207  uint32_t num_parts = 0;
208  err = dataset_query->get_num_parts(num_parts);
209  if (DVS_NONE != err) {
210  fprintf(stdout, "Error getting number of parts\n");
211  return err;
212  }
213  for (uint32_t part_index = 0; part_index < num_parts; part_index++)
214  {
215  auto part = dataset_query->get_part(part_index);
216  if (!part) continue;
217  print(part);
218  }
219  fprintf(stdout, "---------------------------\n");
220  fprintf(stdout, "Listing All Plots for Query\n");
221  fprintf(stdout, "---------------------------\n");
222  uint32_t num_plots = 0;
223  err = dataset_query->get_num_plots(num_plots);
224  if (DVS_NONE != err) {
225  fprintf(stdout, "Error getting number of plots\n");
226  return err;
227  }
228  for (uint32_t plot_index = 0; plot_index < num_plots; plot_index++)
229  {
230  auto plot = dataset_query->get_plot(plot_index);
231  if (!plot) continue;
232  print(plot);
233  }
234  fprintf(stdout, "---------------------------\n");
235  fprintf(stdout, "Listing All Vars for Query\n");
236  fprintf(stdout, "---------------------------\n");
237  uint32_t num_vars = 0;
238  err = dataset_query->get_num_variables(num_vars);
239  if (DVS_NONE != err) {
240  fprintf(stdout, "Error getting number of vars\n");
241  return err;
242  }
243  for (uint32_t var_index = 0; var_index < num_vars; var_index++)
244  {
245  auto var = dataset_query->get_variable(var_index);
246  if (!var) continue;
247  print(var);
248  }
249  fprintf(stdout, "---------------------------\n");
250  fprintf(stdout, "Listing All Case Variables for Query\n\n");
251  num_vars = 0;
252  err = dataset_query->get_num_variables(num_vars);
253  if (DVS_NONE != err) {
254  fprintf(stdout, "Error getting number of vars for case vars\n");
255  return err;
256  }
257  for (uint32_t var_index = 0; var_index < num_vars; var_index++)
258  {
259  auto var = dataset_query->get_variable(var_index);
260  if (var && var->get_var_location() == dvs_var_location::CASE) {
261  const DVS::IDataset* dataset = var->get_dataset();
262  std::vector<float> var_value(var->get_float_count_per_value());
263  for (float timestep : timesteps) {
264  if (DVS_NONE == dataset_query->get_variable_data(dataset, var, timestep, var_value.data())) {
265  //Only scalars are supported for case/part variables right now so we
266  //can just look at the first value
267  fprintf(stdout, "Dataset: %s, Var: %s, Time: %f, Value: %f\n",
268  dataset->get_name(), var->get_name(), timestep, var_value[0]);
269  }
270  else {
271  fprintf(stdout, "Dataset: %s, Var: %s, Time: %f, No Value Found\n",
272  dataset->get_name(), var->get_name(), timestep);
273  }
274  }
275  }
276  }
277  fprintf(stdout, "---------------------------\n");
278  fprintf(stdout, "Listing All Part Variables for Query\n\n");
279  num_vars = 0;
280  err = dataset_query->get_num_variables(num_vars);
281  if (DVS_NONE != err) {
282  fprintf(stdout, "Error getting number of vars for part vars\n");
283  return err;
284  }
285  for (uint32_t var_index = 0; var_index < num_vars; var_index++)
286  {
287  auto var = dataset_query->get_variable(var_index);
288  if (var && var->get_var_location() == dvs_var_location::PART) {
289  auto dataset = var->get_dataset();
290  std::vector<float> var_value(var->get_float_count_per_value());
291  for (float timestep : timesteps) {
292  for (uint32_t part_index = 0; part_index < dataset->get_num_parts(); part_index++) {
293  const DVS::IObject* part = dataset->get_part(part_index);
294  if (!part) {
295  continue;
296  }
297  if (DVS_NONE == dataset_query->get_variable_data(part, var, timestep, var_value.data())) {
298  //Only scalars are supported for case/part variables right now so we
299  //can just look at the first value
300  fprintf(stdout, "Dataset: %s, Part: %s, Var: %s, Time: %f, Value: %f\n",
301  dataset->get_name(), part->get_name(), var->get_name(), timestep, var_value[0]);
302  }
303  else {
304  fprintf(stdout, "Dataset: %s, Part: %s, Var: %s, Time: %f, No Value Found\n",
305  dataset->get_name(), part->get_name(), var->get_name(), timestep);
306  }
307  }
308  }
309  }
310  }
311  fprintf(stdout, "---------------------------\n");
312  fprintf(stdout, "Listing All Datasets for Query\n");
313  uint32_t num_datasets = 0;
314  err = dataset_query->get_num_datasets(num_datasets);
315  if (DVS_NONE != err) {
316  fprintf (stdout, "Error getting number of datasets\n");
317  return err;
318  }
319  for (uint32_t dataset_idx = 0; dataset_idx < num_datasets; dataset_idx++)
320  {
321  DVS::IDataset* dataset = dataset_query->get_dataset(dataset_idx);
322  if (dataset)
323  {
324  fprintf(stdout, "---------------------------\n");
325  fprintf(stdout, "Dataset: %s Units System: %s\n",
326  dataset->get_name(), dataset->get_unit_system() );
327  for (uint32_t cur_pair = 0; cur_pair < dataset->get_num_metadata(); cur_pair++) {
328  fprintf(stdout, "Key: %s, Val: %s\n", dataset->get_metadata_key(cur_pair), dataset->get_metadata_value(cur_pair));
329  }
330  fprintf(stdout, "\n");
331 
332  std::vector<uint32_t> ranks(dataset->get_num_ranks(), 0);
333  dataset->get_ranks(ranks.data());
334 
335  fprintf(stdout, "Ranks: ");
336  for (auto rank : ranks) {
337  fprintf(stdout, " %u", rank);
338  }
339  fprintf(stdout, "\n");
340 
341  std::vector<uint32_t> chunks(dataset->get_num_chunks_per_rank(), 0);
342  dataset->get_chunks_per_rank(chunks.data());
343  fprintf(stdout, "Chunks: ");
344  for (auto chunk : chunks) {
345  fprintf(stdout, " %u", chunk);
346  }
347  fprintf(stdout, "\n");
348 
349  for (uint32_t part_idx = 0; part_idx < dataset->get_num_parts(); part_idx++) {
350  const DVS::IObject* part = dataset->get_part(part_idx);
351  if (!part) continue;
352  print(part);
353  }
354 
355  for (uint32_t plot_idx = 0; plot_idx < dataset->get_num_plots(); plot_idx++) {
356  const DVS::IObject* plot = dataset->get_plot(plot_idx);
357  if (!plot) continue;
358  print(plot);
359  }
360 
361  for (uint32_t var_idx = 0; var_idx < dataset->get_num_variables(); var_idx++) {
362  const DVS::IVar* var = dataset->get_var(var_idx);
363  if (!var) continue;
364  print(var);
365  }
366  }
367  }
368 
369  fprintf(stdout, "---------------------------\n");
370  fprintf(stdout, "Listing All Mesh Chunks for Query\n");
371  fprintf(stdout, "---------------------------\n");
372  uint32_t num_mesh_chunks = 0;
373  err = dataset_query->get_num_mesh_chunks(num_mesh_chunks);
374  if (DVS_NONE != err) {
375  fprintf(stdout, "Error getting number of mesh chunks\n");
376  return err;
377  }
378  for (uint32_t index = 0; index < num_mesh_chunks; index++) {
379  DVS::IMeshChunk* mesh_chunk = dataset_query->get_mesh_chunk(index);
380  if (mesh_chunk) {
381  DVS::IMeshChunk::MeshType type = mesh_chunk->get_type();
382  const DVS::IObject* part = mesh_chunk->get_object();
383  float time = mesh_chunk->get_time();
384  uint32_t rank = mesh_chunk->get_rank();
385  uint32_t chunk = mesh_chunk->get_chunk();
386 
387  std::string coords_hash(mesh_chunk->get_hash_size(), 0);
388  if (coords_hash.empty() || DVS_NONE != mesh_chunk->get_hash(&(coords_hash[0]))) {
389  fprintf(stdout, "ERROR: Could not load coordinates hash\n");
390  }
391 
392  fprintf(stdout, "Mesh Chunk %u Type: %i Part: %s Rank: %u Chunk: %u Time: %f Hash: %s\n",
393  index, type, part->get_name(), rank, chunk, time, coords_hash.c_str());
394 
395  std::array<uint32_t,3> num_coords;
396 
397  dvs_ret coord_ret = DVS_NONE;
398 
399  if (type == DVS::IMeshChunk::MeshType::UNSTRUCTURED) {
400  coord_ret = mesh_chunk->get_coords_size(num_coords[0]);
401  //Coords of all axis match for unstructured
402  num_coords[1] = num_coords[2] = num_coords[0];
403  }
404  else if (type == DVS::IMeshChunk::MeshType::CURVILINEAR) {
405  coord_ret = mesh_chunk->get_coords_curv_size(num_coords[0]);
406  //Coords of all axis match for curvilinear
407  num_coords[1] = num_coords[2] = num_coords[0];
408  }
410  coord_ret = mesh_chunk->get_coords_parallele_size(num_coords[0], num_coords[1], num_coords[2]);
411  }
412  if (coord_ret != DVS_NONE) {
413  fprintf(stdout, "ERROR: %d Loading Coords Size\n", coord_ret);
414  }
415  else {
416  fprintf(stdout, "Size of coords arrays: X(I): %d Y(J): %d Z(K): %d\n", num_coords[0], num_coords[1], num_coords[2]);
417  }
418  if (coord_ret == DVS_NONE && all_coords) {
419 
420  std::vector<float> x_coords(num_coords[0]);
421  std::vector<float> y_coords(num_coords[1]);
422  std::vector<float> z_coords(num_coords[2]);
423 
424  //The vars are for structured data if needed
425  std::array<float,3> origin;
426  std::array<float,3> dir_vec_i, dir_vec_j, dir_vec_k;
427  std::array<float,3> local_ijk_min, local_ijk_max, global_ijk_max;
428 
429  if (type == DVS::IMeshChunk::MeshType::UNSTRUCTURED) {
430  coord_ret = mesh_chunk->get_coords(x_coords.data(), y_coords.data(), z_coords.data());
431 
432  //Validating the coords match if interleaved
433  std::vector<float> interleaved(num_coords[0]+num_coords[1]+num_coords[2]);
434  auto interleaved_ret = mesh_chunk->get_coords_interleaved(interleaved.data());
435  if (coord_ret == DVS_NONE && interleaved_ret == DVS_NONE) {
436  bool good_values = x_coords[0] == interleaved[0];
437  good_values &= y_coords[0] == interleaved[1];
438  good_values &= z_coords[0] == interleaved[2];
439  for (uint32_t i = 1; i < num_coords[0] && good_values; i++) {
440  good_values &= x_coords[i] == interleaved[i*3];
441  good_values &= y_coords[i] == interleaved[i*3+1];
442  good_values &= z_coords[i] == interleaved[i*3+2];
443  }
444  if (!good_values) {
445  fprintf(stdout, "ERROR: Interleaved coords don't match non-interleaved\n");
446  }
447  }
448  else if (interleaved_ret != DVS_NONE) {
449  //Error message for coord_ret handled later
450  fprintf(stdout, "ERROR: %d, Getting interleaved coords\n", interleaved_ret);
451  }
452  }
453  else if (type == DVS::IMeshChunk::MeshType::CURVILINEAR) {
454  coord_ret = mesh_chunk->get_coords_curv(local_ijk_min.data(),
455  local_ijk_max.data(),
456  global_ijk_max.data(),
457  x_coords.data(),
458  y_coords.data(),
459  z_coords.data());
460  if (coord_ret == DVS_NONE) {
461  //Error message for coord_ret handled later
462  fprintf(stdout, "LocalIJKMin: %f %f %f\n", local_ijk_min[0], local_ijk_min[1], local_ijk_min[2]);
463  fprintf(stdout, "LocalIJKMax: %f %f %f\n", local_ijk_max[0], local_ijk_max[1], local_ijk_max[2]);
464  fprintf(stdout, "GlobalIJKMax: %f %f %f\n", global_ijk_max[0], global_ijk_max[1], global_ijk_max[2]);
465  }
466 
467  //Validating the coords match if interleaved
468  std::vector<float> interleaved(num_coords[0]+num_coords[1]+num_coords[2]);
469  std::array<float,3> local_ijk_min_2, local_ijk_max_2, global_ijk_max_2;
470  auto interleaved_ret = mesh_chunk->get_coords_curv_interleaved(local_ijk_min_2.data(),
471  local_ijk_max_2.data(),
472  global_ijk_max_2.data(),
473  interleaved.data());
474  if (coord_ret == DVS_NONE && interleaved_ret == DVS_NONE) {
475  bool good_values = x_coords[0] == interleaved[0];
476  good_values &= y_coords[0] == interleaved[1];
477  good_values &= z_coords[0] == interleaved[2];
478  for (uint32_t i = 1; i < num_coords[0] && good_values; i++) {
479  good_values &= x_coords[i] == interleaved[i*3];
480  good_values &= y_coords[i] == interleaved[i*3+1];
481  good_values &= z_coords[i] == interleaved[i*3+2];
482  }
483  for (uint32_t i = 0; i < 3 && good_values; i++) {
484  good_values &= local_ijk_min[i] == local_ijk_min_2[i];
485  good_values &= local_ijk_max[i] == local_ijk_max_2[i];
486  good_values &= global_ijk_max[i] == global_ijk_max_2[i];
487  }
488  if (!good_values) {
489  fprintf(stdout, "ERROR: Interleaved curv coords don't match non-interleaved\n");
490  }
491  }
492  else if (interleaved_ret != DVS_NONE) {
493  //Error message for coord_ret handled later
494  fprintf(stdout, "ERROR: %d, Getting interleaved curv coords\n", interleaved_ret);
495  }
496  }
498  coord_ret = mesh_chunk->get_coords_parallele(origin.data(),
499  dir_vec_i.data(),
500  dir_vec_j.data(),
501  dir_vec_k.data(),
502  local_ijk_min.data(),
503  local_ijk_max.data(),
504  global_ijk_max.data(),
505  x_coords.data(),
506  y_coords.data(),
507  z_coords.data());
508  if (coord_ret == DVS_NONE) {
509  fprintf(stdout, "Origin: %f %f %f\n", origin[0], origin[1], origin[2]);
510  fprintf(stdout, "DirVecI: %f, %f, %f\n", dir_vec_i[0], dir_vec_i[1], dir_vec_i[2]);
511  fprintf(stdout, "DirVecJ: %f, %f, %f\n", dir_vec_j[0], dir_vec_j[1], dir_vec_j[2]);
512  fprintf(stdout, "DirVecK: %f, %f, %f\n", dir_vec_k[0], dir_vec_k[1], dir_vec_k[2]);
513  fprintf(stdout, "LocalIJKMin: %f %f %f\n", local_ijk_min[0], local_ijk_min[1], local_ijk_min[2]);
514  fprintf(stdout, "LocalIJKMax: %f %f %f\n", local_ijk_max[0], local_ijk_max[1], local_ijk_max[2]);
515  fprintf(stdout, "GlobalIJKMax: %f %f %f\n", global_ijk_max[0], global_ijk_max[1], global_ijk_max[2]);
516  }
517  }
518 
519  if (coord_ret == DVS_NONE) {
520  fprintf(stdout, "X:");
521  for (uint32_t i = 0; i < num_coords[0]; i++) {
522  fprintf(stdout, " %f", x_coords[i]);
523  }
524  fprintf(stdout, "\n");
525 
526  fprintf(stdout, "Y:");
527  for (uint32_t i = 0; i < num_coords[1]; i++) {
528  fprintf(stdout, " %f", y_coords[i]);
529  }
530  fprintf(stdout, "\n");
531 
532  fprintf(stdout, "Z:");
533  for (uint32_t i = 0; i < num_coords[2]; i++) {
534  fprintf(stdout, " %f", z_coords[i]);
535  }
536  fprintf(stdout, "\n");
537  }
538  else {
539  fprintf(stdout, "ERROR: %d, Getting coords\n", coord_ret);
540  }
541  }
542 
543  uint32_t num_nodal_vars = 0;
544  if (DVS_NONE != mesh_chunk->get_num_variables(num_nodal_vars)) {
545  fprintf(stdout, "ERROR: Could not get num nodal vars\n");
546  }
547  for (uint32_t var_index = 0; var_index < num_nodal_vars; var_index++) {
548  auto var = mesh_chunk->get_variable(var_index);
550  fprintf(stdout, "ERROR: Var is not nodal and should be\n");
551  }
552 
553  uint32_t num_var_values = 0;
554  if (DVS_NONE != mesh_chunk->get_variable_data(var_index, &num_var_values, nullptr)) {
555  fprintf(stdout, "ERROR: Could not get nodal var data\n");
556  }
557 
558  std::string nodal_var_hash_1(mesh_chunk->get_var_hash_size(var_index), 0);
559  std::string nodal_var_hash_2(mesh_chunk->get_var_hash_size(var), 0);
560  if (nodal_var_hash_1.empty() || DVS_NONE != mesh_chunk->get_var_hash(var_index, &(nodal_var_hash_1[0]))) {
561  fprintf(stdout, "ERROR: Could not get nodal var hash 1\n");
562  }
563  if (nodal_var_hash_2.empty() || DVS_NONE != mesh_chunk->get_var_hash(var, &(nodal_var_hash_2[0]))) {
564  fprintf(stdout, "ERROR: Could not get nodal var hash 2\n");
565  }
566  if (nodal_var_hash_1 != nodal_var_hash_2) {
567  fprintf(stdout, "ERROR: Nodal var hashes do not match\n");
568  }
569 
570  fprintf(stdout, "Nodal Var: %s, Num Values: %u, Hash: %s\n", var->get_name(), num_var_values, nodal_var_hash_1.c_str());
571  if (all_variable_data) {
572  float min = FLT_MAX-1;
573  float max = -1*min;
574  std::vector<float> var_data(num_var_values);
575  if (DVS_NONE != mesh_chunk->get_variable_data(var_index, nullptr, var_data.data())) {
576  fprintf(stdout, "ERROR: Could not get nodal var data\n");
577  }
578  fprintf(stdout, "VarData:");
579  for (const auto& val : var_data) {
580  fprintf(stdout, " %f", val);
581  if (val < min) {
582  min = val;
583  }
584  if (val > max) {
585  max = val;
586  }
587  }
588  fprintf(stdout, "\n");
589  fprintf(stdout, "Min: %f, Max: %f\n", min, max);
590  }
591  }
592 
593  uint32_t num_element_blocks = 0;
594  if (DVS_NONE != mesh_chunk->get_num_element_blocks(num_element_blocks)) {
595  fprintf(stdout, "ERROR: Could not get number of element blocks\n");
596  }
597  std::vector<dvs_element_type> element_block_types(num_element_blocks);
598  mesh_chunk->get_element_block_types(element_block_types.data());
599  for (const auto& elem_type : element_block_types) {
600  auto elem_block = mesh_chunk->get_element_block_by_type(elem_type);
601  if (elem_block) {
602  switch(elem_block->get_element_type())
603  {
604  case N_SIDED_POLYGON:
605  case N_SIDED_POLYGON_GHOST:
606  {
607  uint32_t dummy = 0;
608  uint32_t num_elements = 0;
609  uint32_t nodes_per_polygon_size = 0;
610  uint32_t indices_size = 0;
611  if (DVS_NONE != elem_block->get_num_elements(num_elements)) {
612  fprintf(stdout, "ERROR getting number of elements\n");
613  }
614  if (DVS_NONE == elem_block->get_nodes_per_element(dummy)) {
615  fprintf(stdout, "ERROR get_nodes_per_element should be invalid for this type\n");
616  }
617  if (DVS_NONE == elem_block->get_connectivity_size(dummy)) {
618  fprintf(stdout, "ERROR get_connectivity_size should be invalid for this type\n");
619  }
620  if (DVS_NONE == elem_block->get_connectivity(nullptr)) {
621  fprintf(stdout, "ERROR get_connectivity should be invalid for this type\n");
622  }
623  if (DVS_NONE == elem_block->get_connectivity_polyhedral_size(dummy, dummy, dummy)) {
624  fprintf(stdout, "ERROR get_connectivity_polyhedral_size should be invalid for this type\n");
625  }
626  if (DVS_NONE == elem_block->get_connectivity_polyhedral(nullptr,nullptr,nullptr)) {
627  fprintf(stdout, "ERROR get_connectivity_polyhedral should be invalid for this type\n");
628  }
629 
630  if (DVS_NONE != elem_block->get_connectivity_polygon_size(nodes_per_polygon_size, indices_size)) {
631  fprintf(stdout, "ERROR with get_connectivity_polygon_size()\n");
632  }
633 
634  std::string conn_hash(elem_block->get_hash_size(), 0);
635  if (conn_hash.empty() || elem_block->get_hash(&(conn_hash[0]))) {
636  fprintf(stdout, "ERROR: Could not load connectivity hash\n");
637  }
638  fprintf(stdout, "- Unstructured Polygon Element: Type: %i, Ghost: %u, Number of Elements: %u, Nodes Per Poly: %u, Indices Size: %u, Hash: %s\n",
639  elem_type, elem_block->get_is_ghost(), num_elements, nodes_per_polygon_size, indices_size, conn_hash.c_str());
640 
641 
642  if (DVS_NONE != elem_block->get_connectivity_polygon(nullptr, nullptr)) {
643  fprintf(stdout, "ERROR get_connectivity_polygon\n");
644  }
645 
646  if (all_connectivity) {
647  std::vector<uint32_t> nodes_per_polygon(nodes_per_polygon_size);
648  std::vector<uint32_t> indices(indices_size);
649 
650  if (DVS_NONE != elem_block->get_connectivity_polygon(nodes_per_polygon.data(),
651  indices.data())) {
652  fprintf(stdout, "ERROR get_connectivity_polygon\n");
653  }
654  else {
655  fprintf(stdout, "NPP:");
656  for (const auto& nodes : nodes_per_polygon) {
657  fprintf(stdout, " %u", nodes);
658  }
659  fprintf(stdout, "\n");
660  fprintf(stdout, "Indices:");
661  for (const auto& index : indices) {
662  fprintf(stdout, " %u", index);
663  }
664  fprintf(stdout, "\n");
665  }
666  }
667  break;
668  }
669  case CONVEX_POLYHEDRON:
670  case CONVEX_POLYHEDRON_GHOST:
671  {
672  uint32_t dummy = 0;
673  uint32_t num_elements = 0;
674  uint32_t faces_per_elem_size = 0;
675  uint32_t nodes_per_face_size = 0;
676  uint32_t indices_size = 0;
677  if (DVS_NONE != elem_block->get_num_elements(num_elements)) {
678  fprintf(stdout, "ERROR getting number of elements\n");
679  }
680  if (DVS_NONE == elem_block->get_nodes_per_element(dummy)) {
681  fprintf(stdout, "ERROR get_nodes_per_element should be invalid for this type\n");
682  }
683  if (DVS_NONE == elem_block->get_connectivity_size(dummy)) {
684  fprintf(stdout, "ERROR get_connectivity_size should be invalid for this type\n");
685  }
686  if (DVS_NONE == elem_block->get_connectivity_polygon_size(dummy, dummy)) {
687  fprintf(stdout, "ERROR get_connectivity_polygon_size should be invalid for this type\n");
688  }
689 
690  if (DVS_NONE != elem_block->get_connectivity_polyhedral_size(faces_per_elem_size, nodes_per_face_size, indices_size)) {
691  fprintf(stdout, "ERROR with get_connectivity_polyhedral_size\n");
692  }
693 
694  std::string conn_hash(elem_block->get_hash_size(), 0);
695  if (conn_hash.empty() || elem_block->get_hash(&(conn_hash[0]))) {
696  fprintf(stdout, "ERROR: Could not load connectivity hash\n");
697  }
698 
699  fprintf(stdout, "- Unstructured Polyhedral Element: Type: %i, Ghost: %u, Number of Elements: %u, FPE: %u NPF: %u Indices: %u, Hash: %s\n",
700  elem_type, elem_block->get_is_ghost(), num_elements, faces_per_elem_size, nodes_per_face_size, indices_size, conn_hash.c_str());
701 
702  if (DVS_NONE != elem_block->get_connectivity_polyhedral(nullptr, nullptr, nullptr)) {
703  fprintf(stdout, "ERROR get_connectivity_polyhedral\n");
704  }
705 
706  if (all_connectivity) {
707  std::vector<uint32_t> faces_per_element(faces_per_elem_size);
708  std::vector<uint32_t> nodes_per_face(nodes_per_face_size);
709  std::vector<uint32_t> indices(indices_size);
710 
711  if (DVS_NONE != elem_block->get_connectivity_polyhedral(faces_per_element.data(),
712  nodes_per_face.data(),
713  indices.data())) {
714  fprintf(stdout, "ERROR get_connectivity_polyhedral\n");
715  }
716  else {
717  fprintf(stdout, "FPE:");
718  for (const auto& faces : faces_per_element) {
719  fprintf(stdout, " %u", faces);
720  }
721  fprintf(stdout, "\n");
722  fprintf(stdout, "NPF:");
723  for (const auto& nodes : nodes_per_face) {
724  fprintf(stdout, " %u", nodes);
725  }
726  fprintf(stdout, "\n");
727  fprintf(stdout, "Indices:");
728  for (const auto& index : indices) {
729  fprintf(stdout, " %u", index);
730  }
731  fprintf(stdout, "\n");
732  }
733  }
734  break;
735  }
736  case STRUCTURED:
737  {
738  uint32_t dummy = 0;
739  uint32_t num_elements = 0;
740  uint32_t nodes_per_element = 0;
741  if (DVS_NONE != elem_block->get_num_elements(num_elements)) {
742  fprintf(stdout, "ERROR get_num_elements\n");
743  }
744  if (DVS_NONE != elem_block->get_nodes_per_element(nodes_per_element)) {
745  fprintf(stdout, "Error get_nodes_per_element\n");
746  }
747  if (DVS_NONE == elem_block->get_connectivity_size(dummy)) {
748  fprintf(stdout, "Error get_connectivity_size should be invalid for this type\n");
749  }
750  if (DVS_NONE == elem_block->get_connectivity(nullptr)) {
751  fprintf(stdout, "Error get_connectivity should be invalid for this type\n");
752  }
753  if (DVS_NONE == elem_block->get_connectivity_polygon_size(dummy,dummy)) {
754  fprintf(stdout, "Error get_connectivity_polygon_size should be invalid for this type\n");
755  }
756  if (DVS_NONE == elem_block->get_connectivity_polygon(nullptr,nullptr)) {
757  fprintf(stdout, "Error get_connectivity_polygon should be invalid for this type\n");
758  }
759  if (DVS_NONE == elem_block->get_connectivity_polyhedral_size(dummy,dummy,dummy)) {
760  fprintf(stdout, "Error get_connectivity_polyhedral_size should be invalid for this type\n");
761  }
762  std::string conn_hash(elem_block->get_hash_size(), 0);
763  if (conn_hash.empty() || elem_block->get_hash(&(conn_hash[0]))) {
764  fprintf(stdout, "ERROR: Could not load connectivity hash\n");
765  }
766  fprintf(stdout, "- Structured Element: Type: %i NPE: %u Hash: %s\n", elem_type, nodes_per_element, conn_hash.c_str());
767  break;
768  }
769  case UNDEFINED:
770  case UNDEFINED_PARALLELEPIPED:
771  case UNDEFINED_CURVILINEAR:
772  fprintf(stdout, "ERROR, undefined element type found\n");
773  break;
774 
775  default:
776  {
777  uint32_t dummy = 0;
778  uint32_t num_elements = 0;
779  uint32_t nodes_per_elem = 0;
780  uint32_t indices_size = 0;
781  if (DVS_NONE != elem_block->get_num_elements(num_elements)) {
782  fprintf(stdout, "ERROR getting number of elements\n");
783  }
784  if (DVS_NONE != elem_block->get_nodes_per_element(nodes_per_elem)) {
785  fprintf(stdout, "ERROR getting nodes per element\n");
786  }
787 
788  if (DVS_NONE == elem_block->get_connectivity_polygon_size(dummy, dummy)) {
789  fprintf(stdout, "ERROR get_connectivity_polygon_size should be invalid for this type\n");
790  }
791  if (DVS_NONE == elem_block->get_connectivity_polygon(nullptr, nullptr)) {
792  fprintf(stdout, "ERROR get_connectivity_polygon should be invalid for this type\n");
793  }
794  if (DVS_NONE == elem_block->get_connectivity_polyhedral_size(dummy, dummy, dummy)) {
795  fprintf(stdout, "ERROR get_connectivity_polyhedral_size should be invalid for this type\n");
796  }
797  if (DVS_NONE == elem_block->get_connectivity_polyhedral(nullptr, nullptr, nullptr)) {
798  fprintf(stdout, "ERROR get_connectivity_polyhedral should be invalid for this type\n");
799  }
800 
801  if (DVS_NONE != elem_block->get_connectivity_size(indices_size)) {
802  fprintf(stdout, "ERROR get_connectivity_size\n");
803  }
804 
805  std::string conn_hash(elem_block->get_hash_size(), 0);
806  if (conn_hash.empty() || elem_block->get_hash(&(conn_hash[0]))) {
807  fprintf(stdout, "ERROR: Could not load connectivity hash\n");
808  }
809 
810  fprintf(stdout, "- Unstructured Basic Element: Type: %i, Ghost: %u, Number of Elements: %u, Nodes Per Elem: %u, Indices Size: %u, Hash: %s\n",
811  elem_type, elem_block->get_is_ghost(), num_elements, nodes_per_elem, indices_size, conn_hash.c_str());
812 
813  if (DVS_NONE != elem_block->get_connectivity(nullptr)) {
814  fprintf(stdout, "ERROR get_connectivity\n");
815  }
816 
817  if (all_connectivity) {
818  std::vector<uint32_t> indices(indices_size);
819  if (DVS_NONE != elem_block->get_connectivity(indices.data())) {
820  fprintf(stdout, "ERROR get_connectivity\n");
821  }
822  else {
823  fprintf(stdout, "Indices:");
824  for (const auto& index : indices) {
825  fprintf(stdout, " %u", index);
826  }
827  fprintf(stdout, "\n");
828  }
829  }
830  break;
831  }
832  }
833 
834  uint32_t num_elemental_vars = 0;
835  if (DVS_NONE != elem_block->get_num_variables(num_elemental_vars)) {
836  fprintf(stdout, "ERROR: Could not get num elemental vars\n");
837  }
838  for (uint32_t var_index = 0; var_index < num_elemental_vars; var_index++) {
839  auto var = elem_block->get_variable(var_index);
841  fprintf(stdout, "ERROR: Var is not elemental and should be\n");
842  }
843 
844  uint32_t num_elem_var_values = 0;
845  if (DVS_NONE != elem_block->get_variable_data(var_index, &num_elem_var_values, nullptr)) {
846  fprintf(stdout, "ERROR: Could not get elemental var data\n");
847  }
848  std::string elem_var_hash_1(elem_block->get_var_hash_size(var_index), 0);
849  std::string elem_var_hash_2(elem_block->get_var_hash_size(var), 0);
850  if (elem_var_hash_1.empty() || DVS_NONE != elem_block->get_var_hash(var_index, &(elem_var_hash_1[0]))) {
851  fprintf(stdout, "ERROR: Could not get elem var hash 1\n");
852  }
853  if (elem_var_hash_2.empty() || DVS_NONE != elem_block->get_var_hash(var, &(elem_var_hash_2[0]))) {
854  fprintf(stdout, "ERROR: Could not get elem var hash 2\n");
855  }
856  if (elem_var_hash_1 != elem_var_hash_2) {
857  fprintf(stdout, "ERROR: Elem var hashes do not match\n");
858  }
859  fprintf(stdout, "Elemental Var: %s, Num Values: %u, Hash: %s\n", var->get_name(), num_elem_var_values, elem_var_hash_1.c_str());
860 
861  if (all_variable_data) {
862  std::vector<float> elem_var_data(num_elem_var_values);
863  float min = FLT_MAX-1;
864  float max = -1*min;
865  if (DVS_NONE != elem_block->get_variable_data(var_index, nullptr, elem_var_data.data())) {
866  fprintf(stdout, "ERROR: Could not get elemental var data\n");
867  }
868  fprintf(stdout, "VarData:");
869  for (const auto& val : elem_var_data) {
870  fprintf(stdout, " %f", val);
871  if (val < min) {
872  min = val;
873  }
874  if (val > max) {
875  max = val;
876  }
877  }
878  fprintf(stdout, "\n");
879  fprintf(stdout, "Min: %f, Max: %f\n", min, max);
880  }
881  }
882  }
883  } // For elem block types
884  }
885  fprintf (stdout, "\n");
886  } // For mesh chunks
887 
888  fprintf(stdout, "---------------------------\n");
889  fprintf(stdout, "Listing All Plot Chunks for Query\n");
890  fprintf(stdout, "---------------------------\n");
891 
892  uint32_t num_plot_chunks = 0;
893  err = dataset_query->get_num_plot_chunks(num_plot_chunks);
894  if (DVS_NONE != err) {
895  fprintf(stdout, "Error getting number of plot chunks\n");
896  return err;
897  }
898  for (uint32_t plot_index = 0; plot_index < num_plot_chunks; plot_index++) {
899  auto plot = dataset_query->get_plot_chunk(plot_index);
900  if (plot) {
901  auto plot_def = plot->get_object();
902  std::string name;
903  if (plot_def) {
904  name = plot_def->get_name();
905  }
906  else {
907  fprintf(stdout, "ERROR: No plot definition for plot data\n");
908  }
909  float time = plot->get_time();
910  uint32_t rank = plot->get_rank();
911 
912  std::string hash(plot->get_hash_size(), 0);
913  if (hash.empty() || DVS_NONE != plot->get_hash(&(hash[0]))) {
914  fprintf(stdout, "ERROR: Could not get plot hash\n");
915  }
916 
917  fprintf(stdout, "Plot: %s, Time: %f, Rank: %d, Hash: %s\n",
918  name.c_str(), time, rank, hash.c_str());
919 
920  uint32_t num_values = 0;
921  if (DVS_NONE != plot->get_data(&num_values, nullptr, nullptr)) {
922  fprintf(stdout, "ERROR: Could not get plot number of values\n");
923  }
924 
925  if (num_values > 0) {
926  std::vector<float> x_values(num_values);
927  std::vector<float> y_values(num_values);
928 
929  if (DVS_NONE != plot->get_data(nullptr, x_values.data(), y_values.data())) {
930  fprintf(stdout, "ERROR: Could not get plot data values\n");
931  }
932 
933  fprintf(stdout, "X Values:");
934  for (uint32_t i = 0; i < num_values; i++) {
935  fprintf(stdout, " %f", x_values[i]);
936  }
937  fprintf(stdout, "\n");
938 
939  fprintf(stdout, "Y Values:");
940  for (uint32_t i = 0; i < num_values; i++) {
941  fprintf(stdout, " %f", y_values[i]);
942  }
943  fprintf(stdout, "\n");
944  }
945  }
946  }
947 
948  return 0;
949 }
Interface for datasets for the DVS Reader API.
virtual uint32_t get_num_ranks() const =0
Get the number of ranks for the dataset.
virtual const DVS::IObject * get_plot(uint32_t index) const =0
Get the plot object.
virtual uint32_t get_num_plots() const =0
Get the number of plots for this datasets.
virtual const DVS::IVar * get_var(uint32_t index) const =0
Get the var object.
virtual const char * get_unit_system() const =0
Get the unit system of the dataset.
virtual uint32_t get_num_chunks_per_rank() const =0
Get the size of the chunks_per_rank array for get_chunks_per_rank()
virtual uint32_t get_num_parts() const =0
Get the number of parts for this dataset.
virtual const DVS::IObject * get_part(uint32_t index) const =0
Get a part by index.
virtual dvs_ret get_ranks(uint32_t *ranks) const =0
Get an array of the ranks for this dataset query.
virtual uint32_t get_num_variables() const =0
Get the number of variables for this dataset.
virtual dvs_ret get_chunks_per_rank(uint32_t *chunks_per_rank) const =0
Get the number of chunks for each rank.
virtual dvs_ret get_hash(char *hash) const =0
Get the hash of the data.
virtual uint32_t get_hash_size() const =0
Get the size of the hash to use with IHash::get_hash()
Mesh Chunk Interface for DVS Reader API.
virtual dvs_ret get_coords_size(uint32_t &component_size)=0
Get the size of each coordinate component for unstructured meshes.
virtual float get_time() const =0
Get the time for this mesh chunk.
virtual dvs_ret get_coords_interleaved(float *coords)=0
Get the coords for a unstructured meshes interleaved in a single array.
virtual dvs_ret get_element_block_types(dvs_element_type *element_types) const =0
Get an array of the element block types for this mesh chunk.
virtual DVS::IElementBlock * get_element_block_by_type(dvs_element_type type)=0
Get the element block by element type.
virtual dvs_ret get_coords_curv_interleaved(float local_ijk_min[3], float local_ijk_max[3], float global_ijk_max[3], float *coords)=0
Get the coords for structured curvilinear meshes interleaved in a single array.
virtual dvs_ret get_num_element_blocks(uint32_t &num_elem_blocks) const =0
Get the number of element blocks for this mesh chunk.
virtual uint32_t get_chunk() const =0
Get the chunk for this mesh chunk.
virtual uint32_t get_rank() const =0
Get the rank for the mesh chunk.
virtual dvs_ret get_coords_curv_size(uint32_t &component_size)=0
Get the size of each coordinate component for structured curvilinear meshes.
virtual dvs_ret get_coords(float *x_coords, float *y_coords, float *z_coords)=0
Get the coordinates for an unstructured mesh.
virtual dvs_ret get_num_variables(uint32_t &num_vars) const =0
Get the number of nodal variables this mesh chunk has data for.
MeshType
The different mesh types allowed.
virtual dvs_ret get_coords_curv(float local_ijk_min[3], float local_ijk_max[3], float global_ijk_max[3], float *x_coords, float *y_coords, float *z_coords)=0
Get coordinate data for a structured curvilinear mesh.
virtual dvs_ret get_coords_parallele(float origin[3], float dir_vec_i[3], float dir_vec_j[3], float dir_vec_k[3], float local_ijk_min[3], float local_ijk_max[3], float global_ijk_max[3], float *i_vals, float *j_vals, float *k_vals)=0
Get the ijk mesh information for structured parallelepiped mesh chunks.
virtual MeshType get_type() const =0
Get the type of mesh chunk.
virtual dvs_ret get_variable_data(uint32_t index, uint32_t *num_values, float *array)=0
Get the variable data by index.
virtual dvs_ret get_coords_parallele_size(uint32_t &i_vals_size, uint32_t &j_vals_size, uint32_t &k_vals_size)=0
Get the size of each ijk component for structured parallelpiped meshes.
virtual const DVS::IObject * get_object() const =0
Get the object definiton this mesh chunk is associated with.
virtual const DVS::IVar * get_variable(uint32_t index) const =0
Get the variable definition associates with the nodal variable for this index.
Interface for part/plot objects for DVS Reader API.
virtual uint32_t get_num_metadata() const =0
Get the number of metadata objects.
virtual const char * get_metadata_key(uint32_t index) const =0
Get the metadata key by index.
virtual ObjectDefType get_type() const =0
Get the type of the object.
virtual const DVS::IDataset * get_dataset() const =0
Get the reference dataset for this object.
virtual const char * get_metadata_value(uint32_t index) const =0
Get the metadata value by index.
@ PART
Type for a part object.
@ PLOT
Type for a plot object.
virtual const char * get_name() const =0
Get the name of the object.
The query interface for the DVS Reader API.
virtual void release()=0
Release the memory of the query.
virtual void set_logger(DVS::ILogger *logger)=0
Set the logger object.
virtual dvs_ret get_var_hash(uint32_t index, char *hash) const =0
Get the hash of the variable data.
virtual uint32_t get_var_hash_size(uint32_t index) const =0
Get the size of the hash to use with IVarHash::get_var_hash()
Interface for variables for the DVS Reader API.
virtual const char * get_metadata_key(uint32_t index) const =0
Get a metadata key based on the index.
virtual uint32_t get_num_metadata() const =0
Get the num metadata values on this var.
virtual const DVS::IDataset * get_dataset() const =0
Get the reference dataset for this var.
virtual const char * get_unit_label() const =0
Get the unit label as string.
virtual dvs_var_location get_var_location() const =0
Get the var location.
virtual const char * get_metadata_value(uint32_t index) const =0
Get the metadata value base on the index.
virtual uint32_t get_float_count_per_value() const =0
Get the number of floats per value.
virtual const char * get_unit_dimension() const =0
Get the unit dimensions as string.
virtual dvs_var_type get_var_type() const =0
Get the type of var.
virtual const char * get_name() const =0
Get the name of the variable.
Logger class based on verbosity.
DVS Reader API Query Interface.
@ PARALLELEPIPED
Parallepiped.
@ CURVILINEAR
Curvilinear.
@ DVS_VERBOSE
Displays informational messages, warnings, errors.
@ PART
This is a variable for an entire part.
@ ELEMENT
This is a field variable per each element of a part.
@ NODE
This is a field variable per each node of a part's mesh.
@ CASE
This is a variable for an entire case (i.e. dataset)
int32_t dvs_ret
Return value of methods, TODO.
#define DVS_NONE
No detected error has occurred.
Verbosity based logger for DVS.
int main(int argc, char **argv)
Main method of test reader application.