This repository has been archived by the owner on Oct 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
avtvisitESSIFileFormat.C
2009 lines (1627 loc) · 76.8 KB
/
avtvisitESSIFileFormat.C
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*****************************************************************************
*
* Copyright (c) 2000 - 2013, 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.
*
*****************************************************************************/
// ************************************************************************* //
// avtvisitESSIFileFormat.C //
// ************************************************************************* //
#include <avtvisitESSIFileFormat.h>
#include <string>
#include <limits>
#include <vtkFloatArray.h>
#include <vtkIntArray.h>
#include <vtkPoints.h>
#include <vtkRectilinearGrid.h>
#include <vtkStructuredGrid.h>
#include <vtkUnstructuredGrid.h>
#include <avtDatabaseMetaData.h>
#include <avtIntervalTree.h>
#include <DBOptionsAttributes.h>
#include <Expression.h>
#include <InvalidVariableException.h>
#include <InvalidDBTypeException.h>
using std::string;
#include <vtkCellType.h>
//For debugging (debug 4)
#include <DebugStream.h>
// My includes
#include <hdf5.h>
#define GO_HERE std::cout
// #define GO_HERE debug4
// ****************************************************************************
// Method: avtvisitESSIFileFormat constructor
//
// Programmer: jaabell -- generated by xml2avt
// Creation: Thu May 15 11:22:33 PDT 2014
//
// ****************************************************************************
avtvisitESSIFileFormat::avtvisitESSIFileFormat(const char *filename)
: avtMTMDFileFormat(filename)
{
// INITIALIZE DATA MEMBERS
filename_string = filename;
nnodes = 0;
ncells = 0;
nsteps = -1;
returned_gaussmesh_already = false;
returned_mainmesh_already = false;
m_mainmesh_data = NULL;
m_gaussmesh_data = NULL;
initialized = false;
}
// ****************************************************************************
// Method: avtvisitESSIFileFormat::FreeUpResources
//
// Purpose:
// When VisIt is done focusing on a particular timestep, it asks that
// timestep to free up any resources (memory, file descriptors) that
// it has associated with it. This method is the mechanism for doing
// that.
//
// Programmer: jaabell -- generated by xml2avt
// Creation: Thu May 15 11:22:33 PDT 2014
//
// ****************************************************************************
void
avtvisitESSIFileFormat::FreeUpResources(void)
{
// GO_HERE << "FREEEEE\n";
// H5close();
// if(m_gauss_to_element_tag[domain])
// {
// delete [] m_gauss_to_element_tag[domain];
// m_gauss_to_element_tag[domain] = 0;
// }
// if(m_number_of_gauss_points[domain])
// {
// delete [] m_number_of_gauss_points[domain];
// m_number_of_gauss_points[domain] = 0;
// }
// if(m_number_of_dofs[domain])
// {
// delete [] m_number_of_dofs[domain];
// m_number_of_dofs[domain] = 0;
// }
// if(m_tags2pointnumbers[domain])
// {
// delete [] m_tags2pointnumbers[domain];
// m_tags2pointnumbers[domain] = 0;
// }
// if(m_pointnumbers2tags[domain])
// {
// delete [] m_pointnumbers2tags[domain];
// m_pointnumbers2tags[domain] = 0;
// }
// if(m_tags2cellnumbers[domain])
// {
// delete [] m_tags2cellnumbers[domain];
// m_tags2cellnumbers[domain] = 0;
// }
// if(m_cellnumbers2tags[domain])
// {
// delete [] m_cellnumbers2tags[domain];
// m_cellnumbers2tags[domain] = 0;
// }
}
// ****************************************************************************
// Method: avtvisitESSIFileFormat::PopulateDatabaseMetaData
//
// Purpose:
// This database meta-data object is like a table of contents for the
// file. By populating it, you are telling the rest of VisIt what
// information it can request from you.
//
// Programmer: jaabell -- generated by xml2avt
// Creation: Thu May 15 11:22:33 PDT 2014
//
// ****************************************************************************
void
avtvisitESSIFileFormat::PopulateDatabaseMetaData(avtDatabaseMetaData *md, int timeState)
{
initialize();
//
// CODE TO ADD A MESH
//
//
// AVT_RECTILINEAR_MESH, AVT_CURVILINEAR_MESH, AVT_UNSTRUCTURED_MESH,
// AVT_POINT_MESH, AVT_SURFACE_MESH, AVT_UNKNOWN_MESH
// avtMeshType mt = AVT_UNSTRUCTURED_MESH;
// //
// int nblocks = 1;// <-- this must be 1 for MTSD
// int block_origin = 0;
// int spatial_dimension = 3;
// int topological_dimension = 3;
// double *extents = NULL;
// // Here's the call that tells the meta-data object that we have a mesh:
// //
// AddMeshToMetaData(md, meshname, mt, extents, nblocks, block_origin,
// spatial_dimension, topological_dimension);
//
mainmesh = "ESSI Domain Mesh";
avtMeshMetaData *mmd = new avtMeshMetaData;
mmd->name = mainmesh.c_str();
mmd->spatialDimension = 3;
mmd->topologicalDimension = 3;
mmd->meshType = AVT_UNSTRUCTURED_MESH;
mmd->numBlocks = number_of_processes > 1 ? number_of_processes - 1 : 1;
md->Add(mmd);
gaussmesh = "Gauss Points";
mmd = new avtMeshMetaData;
mmd->name = gaussmesh.c_str();
mmd->spatialDimension = 3;
mmd->topologicalDimension = 0;
mmd->meshType = AVT_POINT_MESH;
mmd->numBlocks = number_of_processes > 1 ? number_of_processes - 1 : 1;
md->Add(mmd);
GO_HERE << "ewmwecmwosmdcoiwemdeclkmsadlkmclkwqmdslkcmwdlksmcklds = " << number_of_processes << "\n";
ncells = new int [number_of_processes];
ngauss = new int [number_of_processes];
nnodes = new int [number_of_processes];
for (int i = 0; i < number_of_processes; i++)
{
ncells[i] = 0;
ngauss[i] = 0;
nnodes[i] = 0;
}
//
// CODE TO ADD A SCALAR VARIABLE
//
string varname = "Node Tag";
avtCentering cent = AVT_NODECENT;
AddScalarVarToMetaData(md, varname, mainmesh, cent);
varname = "Element Tag";
cent = AVT_ZONECENT;
AddScalarVarToMetaData(md, varname, mainmesh, cent);
varname = "Element Partition";
cent = AVT_ZONECENT;
AddScalarVarToMetaData(md, varname, mainmesh, cent);
varname = "Element Type";
cent = AVT_ZONECENT;
AddScalarVarToMetaData(md, varname, mainmesh, cent);
varname = "8 Node Brick Update Time";
cent = AVT_ZONECENT;
AddScalarVarToMetaData(md, varname, mainmesh, cent);
varname = "Shell_M11";
cent = AVT_ZONECENT;
AddScalarVarToMetaData(md, varname, mainmesh, cent);
varname = "Shell_M22";
cent = AVT_ZONECENT;
AddScalarVarToMetaData(md, varname, mainmesh, cent);
varname = "Shell_M12";
cent = AVT_ZONECENT;
AddScalarVarToMetaData(md, varname, mainmesh, cent);
//
// CODE TO ADD A VECTOR VARIABLE
//
varname = "Generalized Displacements";
int vector_dim = 3;
cent = AVT_NODECENT; // AVT_NODECENT, AVT_ZONECENT, AVT_UNKNOWN_CENT
AddVectorVarToMetaData(md, varname, mainmesh, cent, vector_dim);
//
// CODE TO ADD A VECTOR VARIABLE
//
varname = "Generalized Forces";
vector_dim = 3;
cent = AVT_NODECENT; // AVT_NODECENT, AVT_ZONECENT, AVT_UNKNOWN_CENT
AddVectorVarToMetaData(md, varname, mainmesh, cent, vector_dim);
//
// CODE TO ADD A TENSOR VARIABLE
//
varname = "Stress";
int tensor_dim = 9;
cent = AVT_NODECENT;
AddTensorVarToMetaData(md, varname, gaussmesh, cent, tensor_dim);
varname = "Strain";
AddTensorVarToMetaData(md, varname, gaussmesh, cent, tensor_dim);
varname = "Plastic Strain";
AddTensorVarToMetaData(md, varname, gaussmesh, cent, tensor_dim);
// CODE TO ADD A MATERIAL
//
// string mesh_for_mat = meshname; // ??? -- could be multiple meshes
// string matname = ...
// int nmats = ...;
// vector<string> mnames;
// for (int i = 0 ; i < nmats ; i++)
// {
// char str[32];
// sprintf(str, "mat%d", i);
// -- or --
// strcpy(str, "Aluminum");
// mnames.push_back(str);
// }
//
// Here's the call that tells the meta-data object that we have a mat:
//
// AddMaterialToMetaData(md, matname, mesh_for_mat, nmats, mnames);
//
//
// Here's the way to add expressions:
//Expression momentum_expr;
//momentum_expr.SetName("momentum");
//momentum_expr.SetDefinition("{u, v}");
//momentum_expr.SetType(Expression::VectorMeshVar);
//md->AddExpression(&momentum_expr);
//Expression KineticEnergy_expr;
//KineticEnergy_expr.SetName("KineticEnergy");
//KineticEnergy_expr.SetDefinition("0.5*(momentum*momentum)/(rho*rho)");
//KineticEnergy_expr.SetType(Expression::ScalarMeshVar);
//md->AddExpression(&KineticEnergy_expr);
//
Expression *e1 = new Expression;
e1->SetName("Sigma_X");
e1->SetDefinition("Stress[0][0]");
e1->SetType(Expression::ScalarMeshVar);
e1->SetHidden(false);
md->AddExpression(e1);
Expression *e2 = new Expression;
e2->SetName("Sigma_Y");
e2->SetDefinition("Stress[1][1]");
e2->SetType(Expression::ScalarMeshVar);
e2->SetHidden(false);
md->AddExpression(e2);
Expression *e3 = new Expression;
e3->SetName("Sigma_Z");
e3->SetDefinition("Stress[2][2]");
e3->SetType(Expression::ScalarMeshVar);
e3->SetHidden(false);
md->AddExpression(e3);
Expression *e4 = new Expression;
e4->SetName("Tau_XY");
e4->SetDefinition("Stress[0][1]");
e4->SetType(Expression::ScalarMeshVar);
e4->SetHidden(false);
md->AddExpression(e4);
Expression *e5 = new Expression;
e5->SetName("Tau_XZ");
e5->SetDefinition("Stress[0][2]");
e5->SetType(Expression::ScalarMeshVar);
e5->SetHidden(false);
md->AddExpression(e5);
Expression *e6 = new Expression;
e6->SetName("Tau_YZ");
e6->SetDefinition("Stress[1][2]");
e6->SetType(Expression::ScalarMeshVar);
e6->SetHidden(false);
md->AddExpression(e6);
Expression *e7 = new Expression;
e6->SetName("Relative_Generalized_Displacements");
e6->SetDefinition("<Generalized Displacements> - conn_cmfe(<[0]i:Generalized Displacements>, <ESSI Domain Mesh>)");
e6->SetType(Expression::VectorMeshVar);
e6->SetHidden(false);
md->AddExpression(e6);
}
// ****************************************************************************
// Method: avtvisitESSIFileFormat::GetMesh
//
// Purpose:
// Gets the mesh associated with this file. The mesh is returned as a
// derived type of vtkDataSet (ie vtkRectilinearGrid, vtkStructuredGrid,
// vtkUnstructuredGrid, etc).
//
// Arguments:
// timestate The index of the timestate. If GetNTimesteps returned
// 'N' time steps, this is guaranteed to be between 0 and N-1.
// domain The index of the domain. If there are NDomains, this
// value is guaranteed to be between 0 and NDomains-1,
// regardless of block origin.
// meshname The name of the mesh of interest. This can be ignored if
// there is only one mesh.
//
// Programmer: jaabell -- generated by xml2avt
// Creation: Thu May 15 11:22:33 PDT 2014
//
// ****************************************************************************
vtkDataSet *
avtvisitESSIFileFormat::GetMesh(int timestate, int domain, const char *meshname)
{
initialize();
GO_HERE << "visitESSI: Getting Mesh: -> " << meshname << ", domain = " << domain << "\n\n" ;
// GO_HERE << "visitESSI: Getting Mesh: -> " << meshname << " domain = " << domain << "\n\n" ;
// string mname = meshname;
// =============================================================================================
// =============================================================================================
// =============================================================================================
// =============================================================================================
// MAIN MESH
// =============================================================================================
// =============================================================================================
// =============================================================================================
// =============================================================================================
// =============================================================================================
// if (domain == 0)
// {
// return 0;
// }
openSubdomainNumber(domain);
if (strcmp(meshname, mainmesh.c_str()) == 0 )
{
// If this is the first time reading the mesh data -> load it into memory!!
if (m_mainmesh_data[domain] == NULL)
{
// nnodes[domain] = 0;
int ndims = 3;
int origin = 0;
// ncells[domain] = 0;
herr_t status;
// float *mainmesh_pts;
int *connectivity;
int *elements_nnodes;
hsize_t id_elements_nnodes_nvals;
//////////////////////////////////////////////////////////////////////////////////////////
// Nodes
//////////////////////////////////////////////////////////////////////////////////////////
GO_HERE << "visitESSI: Reading Node Info for domain " << domain << "\n\n";
//Get the number of defined nodes
// Read number of elements
hid_t id_num_elements = H5Dopen2(id_file, "/Number_of_Elements", H5P_DEFAULT);
hid_t id_num_elements_dataspace = H5Dget_space(id_num_elements);
H5Dread(id_num_elements, H5T_NATIVE_INT, H5S_ALL , id_num_elements_dataspace, H5P_DEFAULT,
&ncells[domain]);
H5Dclose(id_num_elements);
H5Sclose(id_num_elements_dataspace);
// Read number of nodes
int numero_de_nodos;
hid_t id_num_nodes = H5Dopen2(id_file, "/Number_of_Nodes", H5P_DEFAULT);
hid_t id_num_nodes_dataspace = H5Dget_space(id_num_nodes);
H5Dread(id_num_nodes, H5T_NATIVE_INT, H5S_ALL , id_num_nodes_dataspace, H5P_DEFAULT,
&(nnodes[domain]));
GO_HERE << "&nnodes[domain] = " << nnodes[domain] << endl;
H5Dclose(id_num_nodes);
H5Sclose(id_num_nodes_dataspace);
hid_t id_nodes_coordinates = H5Dopen2(id_file, "/Model/Nodes/Coordinates", H5P_DEFAULT);
hid_t id_coordinates_dataspace = H5Dget_space(id_nodes_coordinates);
hsize_t id_nodes_coordinates_nvals = H5Sget_simple_extent_npoints(id_coordinates_dataspace);
// nnodes[domain] = static_cast<int> (id_nodes_coordinates_nvals) / 3;
//Get number of maximum possibly defined tags :/
hid_t id_nodes_index_to_coordinates = H5Dopen2(id_file, "/Model/Nodes/Index_to_Coordinates", H5P_DEFAULT);
hid_t id_nodes_index_to_coordinates_dataspace = H5Dget_space(id_nodes_index_to_coordinates);
hsize_t nodes_number_of_tags_max = H5Sget_simple_extent_npoints(id_nodes_index_to_coordinates_dataspace);
//Get the index to coordinates
int *index_to_coordinates = new int[nodes_number_of_tags_max];
status = H5Dread(id_nodes_index_to_coordinates, H5T_NATIVE_INT, H5S_ALL , id_nodes_index_to_coordinates_dataspace, H5P_DEFAULT,
index_to_coordinates);
//Form an array that transforms node "tags" to connectivity indexes
m_tags2pointnumbers[domain] = new int[nodes_number_of_tags_max];
m_pointnumbers2tags[domain] = new int[nodes_number_of_tags_max];
int point_number = 0;
for (int tag = 0; tag < nodes_number_of_tags_max; tag++)
{
if (index_to_coordinates[tag] >= 0) // This condition checks that the node tag exists (else it has -1 in index to coord)
{
point_number = index_to_coordinates[tag] / 3;
m_tags2pointnumbers[domain][tag] = point_number;
m_pointnumbers2tags[domain][point_number] = tag;
// point_number++;
}
else // tag does not exist so no corresponding point number is generated
{
m_tags2pointnumbers[domain][tag] = -1;
}
}
//Get number of DOFS
hid_t id_nodes_number_of_dofs = H5Dopen2(id_file, "/Model/Nodes/Number_of_DOFs", H5P_DEFAULT);
hid_t id_nodes_number_of_dofs_dataspace = H5Dget_space(id_nodes_number_of_dofs);
//Get the index to coordinates
m_number_of_dofs[domain] = new int[nodes_number_of_tags_max];
status = H5Dread(id_nodes_number_of_dofs, H5T_NATIVE_INT, H5S_ALL , id_nodes_number_of_dofs_dataspace, H5P_DEFAULT,
m_number_of_dofs[domain]);
//
// Create the vtkPoints object and copy points into it.
//
vtkPoints *points = vtkPoints::New();
points->SetNumberOfPoints(nnodes[domain]);
float *pts = (float *) points->GetVoidPointer(0);
// mainmesh_pts = new float[nnodes * 3];
//Read values of coordinates from HDF5 directly into the VTK pts pointer
const hsize_t dims[1] = {nnodes[domain] * 3};
hid_t memspace = H5Screate_simple(1, dims, dims);
status = H5Dread(id_nodes_coordinates,
H5T_NATIVE_FLOAT,
memspace,
id_coordinates_dataspace,
H5P_DEFAULT,
pts);
// for (int nodenum = 0; nodenum < nnodes[domain]; nodenum++)
// {
// GO_HERE << "(" << pts[nodenum] << " " << pts[nodenum] << " " << pts[nodenum] << ") ";
// }
GO_HERE << "visitESSI: Done reading nodes. Read " << nnodes << " nodes values.\n\n";
//Free up memory.
delete [] index_to_coordinates;
H5Dclose(id_nodes_coordinates);
H5Sclose(id_coordinates_dataspace);
H5Dclose(id_nodes_index_to_coordinates);
H5Sclose(id_nodes_index_to_coordinates_dataspace);
//////////////////////////////////////////////////////////////////////////////////////////
// ELEMENTS
//////////////////////////////////////////////////////////////////////////////////////////
GO_HERE << "visitESSI: Reading Element Info\n\n";
//Get the class tags for the elements
hid_t id_elements_classtags = H5Dopen2(id_file, "/Model/Elements/Class_Tags", H5P_DEFAULT);
hid_t id_elements_classtags_dataspace = H5Dget_space(id_elements_classtags);
int id_elements_classtags_nvals = H5Sget_simple_extent_npoints(id_elements_classtags_dataspace);
id_elements_nnodes_nvals = id_elements_classtags_nvals;
max_ele_tag = id_elements_classtags;
int *elements_classtags = new int[id_elements_classtags_nvals];
status = H5Dread(id_elements_classtags, H5T_NATIVE_INT, H5S_ALL , id_elements_classtags_dataspace, H5P_DEFAULT,
elements_classtags);
//Read the descriptions
hid_t id_elements_descarray = H5Dopen2(id_file, "/Model/Elements/Element_Class_Desc", H5P_DEFAULT);
hid_t id_elements_descarray_dataspace = H5Dget_space(id_elements_descarray);
int id_elements_descarray_nvals = H5Sget_simple_extent_npoints(id_elements_descarray_dataspace);
max_ele_tag = id_elements_descarray;
int *Element_Desc_Array = new int[id_elements_descarray_nvals];
status = H5Dread(id_elements_descarray, H5T_NATIVE_INT, H5S_ALL , id_elements_descarray_dataspace, H5P_DEFAULT,
Element_Desc_Array);
//Get the number of elements (ncells[domain])
// hid_t id_elements_nnodes = H5Dopen2(id_file, "/Model/Elements/Number_of_Nodes", H5P_DEFAULT);
// hid_t id_elements_nnodes_dataspace = H5Dget_space(id_elements_nnodes);
// id_elements_nnodes_nvals = H5Sget_simple_extent_npoints(id_elements_nnodes_dataspace);
max_ele_tag = id_elements_nnodes_nvals;
elements_nnodes = new int[id_elements_nnodes_nvals + 1];
// status = H5Dread(id_elements_nnodes, H5T_NATIVE_INT, H5S_ALL , id_elements_nnodes_dataspace, H5P_DEFAULT,
// elements_nnodes);
for (int index = 0; index < id_elements_classtags_nvals; index++)
{
int class_tag = elements_classtags[index];
int class_desc = Element_Desc_Array[class_tag];
int nnodes = (class_desc / 1000000) % 100; // Number of element nodes
int ngauss = (class_desc % 100000) / 100; // Number of gauss nodes
if (class_tag != -1)
{
elements_nnodes[index] = nnodes;
}
else
{
elements_nnodes[index] = -1;
}
// cout << "class_tag = " << class_tag << endl;
// cout << "class_desc = " << class_desc << endl;
// cout << "nnodes = " << nnodes << endl;
// cout << "ngauss = " << ngauss << endl;
}
cout << "Here\n";
max_node_tag = id_elements_nnodes_nvals;
m_tags2cellnumbers[domain] = new int[id_elements_nnodes_nvals];
m_cellnumbers2tags[domain] = new int[id_elements_nnodes_nvals];
int cellnumber = 0;
for (int tag = 0; tag < id_elements_nnodes_nvals; tag++)
{
if (elements_nnodes[tag] >= 0) // This condition checks that the element tag exists (else it has -1 in number of nodes)
{
m_tags2cellnumbers[domain][tag] = cellnumber;
m_cellnumbers2tags[domain][cellnumber] = tag;
cellnumber++;
}
else // tag does not exist so no corresponding cell number is generated
{
m_tags2cellnumbers[domain][tag] = -1;
}
}
cout << "Here\n";
// H5Dclose(id_elements_nnodes);
// H5Sclose(id_elements_nnodes_dataspace);
GO_HERE << "visitESSI: Mesh has " << ncells[domain] << " elements. \n\n";
GO_HERE << "visitESSI: Reading connectivity \n\n";
//Get the connectivity
hid_t id_elements_connectivity = H5Dopen2(id_file, "/Model/Elements/Connectivity", H5P_DEFAULT);
hid_t id_elements_connectivity_dataspace = H5Dget_space(id_elements_connectivity);
hsize_t id_elements_connectivity_nvals = H5Sget_simple_extent_npoints(id_elements_connectivity_dataspace);
connectivity = new int[id_elements_connectivity_nvals];
status = H5Dread(id_elements_connectivity, H5T_NATIVE_INT, H5S_ALL , id_elements_connectivity_dataspace, H5P_DEFAULT,
connectivity);
H5Dclose(id_elements_connectivity);
H5Sclose(id_elements_connectivity_dataspace);
returned_mainmesh_already = true;
GO_HERE << "visitESSI: Done! \n\n";
GO_HERE << "visitESSI : Generating VTK nodes\n";
//
// Create a vtkUnstructuredGrid to contain the point cells.
//
m_mainmesh_data[domain] = vtkUnstructuredGrid::New();
m_mainmesh_data[domain] -> SetPoints(points);
points -> Delete();
m_mainmesh_data[domain] -> Allocate(ncells[domain]);
vtkIdType verts[27];
// Converters from ESSI node conventions to VTK
// 0 1 2 3 4 5 6 7
int essi_to_vtk_point[1] = { 0 };
int essi_to_vtk_beam[2] = { 0 , 1 };
int essi_to_vtk_4nodeandes[4] = { 0 , 1, 2, 3 };
int essi_to_vtk_8nodebrick[8] = {4, 5, 6, 7, 0, 1, 2, 3};
// 0 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
int essi_to_vtk_27nodebrick[27] = { 6, 5, 4, 7, 2, 1, 0, 3, 13, 12, 15, 14, 9, 8, 11, 10, 18, 17, 16, 19, 23, 21, 22, 24, 26, 25, 20 };
//Loop over elements and add them
int count = 0;
int number_of_added_elements = 0;
int *access_order;
bool found = false;
for (int tag = 0; tag < id_elements_nnodes_nvals; tag++)
{
int cellType = 0;
int nverts = 0;
found = false;
if (elements_nnodes[tag] > 0)
{
nverts = elements_nnodes[tag];
number_of_added_elements++;
if (nverts == 1)
{
// nverts = 1;
cellType = VTK_VERTEX;
access_order = essi_to_vtk_point;
found = true;
}
else if (nverts == 2)
{
// nverts = 2;
cellType = VTK_LINE;
access_order = essi_to_vtk_beam;
found = true;
}
else if (nverts == 4)
{
// nverts = 4;
cellType = VTK_QUAD;
access_order = essi_to_vtk_4nodeandes;
found = true;
}
else if (nverts == 8)
{
cellType = VTK_HEXAHEDRON;
access_order = essi_to_vtk_8nodebrick;
found = true;
}
else if (nverts == 27)
{
// nverts = 27;
cellType = VTK_TRIQUADRATIC_HEXAHEDRON;
access_order = essi_to_vtk_27nodebrick;
found = true;
}
if (found)
{
// Make a list of node indices that make up the cell..
int essi_node_number;
int visit_vertex_number;
for (int j = 0; j < nverts; j++)
{
essi_node_number = connectivity[count + access_order[j]];
visit_vertex_number = m_tags2pointnumbers[domain][essi_node_number];
if (visit_vertex_number >= 0)
{
verts[j] = visit_vertex_number;
}
else
{
//Something went wrong
GO_HERE << "!!!! visitESSI - something went wrong\n\n";
// EXCEPTION0(InvalidVariableException, meshname);
}
}
m_mainmesh_data[domain]->InsertNextCell(cellType, nverts, verts);
}
count += nverts;
}
}
// GO_HERE << "visitESSI: Added " << number_of_added_elements << " elements of " << ncells[domain] << " total available.\n\n";
GO_HERE << "visitESSI: Added " << number_of_added_elements << " elements of " << ncells[domain] << " total available.\n\n";
}
m_mainmesh_data[domain]->Register(NULL);
return m_mainmesh_data[domain];
} //Ends Brick Elements Mesh
// =============================================================================================
// =============================================================================================
// =============================================================================================
// =============================================================================================
// GAUSS POINT MESH
// =============================================================================================
// =============================================================================================
// =============================================================================================
// =============================================================================================
// =============================================================================================
else if (strcmp(meshname, gaussmesh.c_str()) == 0)
{
if (m_gaussmesh_data[domain] == NULL)
{
int ndims = 3;
int origin = 0;
herr_t status;
GO_HERE << "visitESSI: Reading GP Info\n\n";
//Get the number of defined gausspoints
hid_t id_gausspoints_coordinates = H5Dopen2(id_file, "/Model/Elements/Gauss_Point_Coordinates", H5P_DEFAULT);
hid_t id_coordinates_dataspace = H5Dget_space(id_gausspoints_coordinates);
hsize_t id_gausspoints_coordinates_nvals = H5Sget_simple_extent_npoints(id_coordinates_dataspace);
// ngauss = static_cast<int> (id_gausspoints_coordinates_nvals) / 3;
//Get number of maximum possibly defined tags :/
hid_t id_gausspoints_index_to_coordinates = H5Dopen2(id_file, "/Model/Elements/Index_to_Gauss_Point_Coordinates", H5P_DEFAULT);
hid_t id_gausspoints_index_to_coordinates_dataspace = H5Dget_space(id_gausspoints_index_to_coordinates);
hsize_t gausspoints_number_of_tags_max = H5Sget_simple_extent_npoints(id_gausspoints_index_to_coordinates_dataspace);
//Get the index to coordinates of GPS
int *index_to_coordinates = new int[gausspoints_number_of_tags_max];
status = H5Dread(id_gausspoints_index_to_coordinates, H5T_NATIVE_INT, H5S_ALL , id_gausspoints_index_to_coordinates_dataspace, H5P_DEFAULT,
index_to_coordinates);
//Get number of Gauss points per element
// hid_t id_number_of_gausspoints = H5Dopen2(id_file, "/Model/Elements/Number_of_Gauss_Points", H5P_DEFAULT);
// hid_t id_number_of_gausspoints_dataspace = H5Dget_space(id_number_of_gausspoints);
//Get the number of GPs
m_number_of_gauss_points[domain] = new int[gausspoints_number_of_tags_max];
// status = H5Dread(id_number_of_gausspoints, H5T_NATIVE_INT, H5S_ALL , id_number_of_gausspoints_dataspace, H5P_DEFAULT,
// m_number_of_gauss_points[domain]);
//////////////////////////???
//////////////////////////???
//////////////////////////???
//Get the class tags for the elements
hid_t id_elements_classtags = H5Dopen2(id_file, "/Model/Elements/Class_Tags", H5P_DEFAULT);
hid_t id_elements_classtags_dataspace = H5Dget_space(id_elements_classtags);
int id_elements_classtags_nvals = H5Sget_simple_extent_npoints(id_elements_classtags_dataspace);
int id_elements_nnodes_nvals = id_elements_classtags_nvals;
max_ele_tag = id_elements_classtags;
int *elements_classtags = new int[id_elements_classtags_nvals];
status = H5Dread(id_elements_classtags, H5T_NATIVE_INT, H5S_ALL , id_elements_classtags_dataspace, H5P_DEFAULT,
elements_classtags);
//Read the descriptions
hid_t id_elements_descarray = H5Dopen2(id_file, "/Model/Elements/Element_Class_Desc", H5P_DEFAULT);
hid_t id_elements_descarray_dataspace = H5Dget_space(id_elements_descarray);
int id_elements_descarray_nvals = H5Sget_simple_extent_npoints(id_elements_descarray_dataspace);
max_ele_tag = id_elements_descarray;
int *Element_Desc_Array = new int[id_elements_descarray_nvals];
status = H5Dread(id_elements_descarray, H5T_NATIVE_INT, H5S_ALL , id_elements_descarray_dataspace, H5P_DEFAULT,
Element_Desc_Array);
max_ele_tag = id_elements_nnodes_nvals;
for (int index = 0; index < id_elements_classtags_nvals; index++)
{
int class_tag = elements_classtags[index];
int class_desc = Element_Desc_Array[class_tag];
int nnodes = (class_desc / 1000000) % 100; // Number of element nodes
int ngauss = (class_desc % 100000) / 100; // Number of gauss nodes
if (class_tag != -1)
{
m_number_of_gauss_points[domain][index] = ngauss;
}
else
{
m_number_of_gauss_points[domain][index] = -1;
}
}
//////////////////////////???
//////////////////////////???
ngauss[domain] = 0;
for (int tag = 0; tag < gausspoints_number_of_tags_max; tag++)
{
if (index_to_coordinates[tag] >= 0)
{
ngauss[domain] += m_number_of_gauss_points[domain][tag];
}
}
GO_HERE << " Number of GPs on domain #" << domain << " = " << ngauss[domain] << endl;
//Build an index that relates number of a gauss point to the element it belongs to
// m_gauss_to_element_tag[domain] = new int[ngauss[domain]];
// int gaussnumber = 0;
// for (int tag = 0; tag < gausspoints_number_of_tags_max; tag++)
// {
// if (index_to_coordinates[tag] >= 0)
// {
// int number_of_gauss_points_for_this_element;
// number_of_gauss_points_for_this_element = m_number_of_gauss_points[domain][tag];
// for (int g = 0; g < number_of_gauss_points_for_this_element; g++)
// {
// m_gauss_to_element_tag[domain][gaussnumber] = tag;
// gaussnumber++;
// }
// }
// }
// Write the gausspoints
vtkPoints *points = vtkPoints::New();
points->SetNumberOfPoints(ngauss[domain]);
float *pts = (float *) points->GetVoidPointer(0);
//Read values of coordinates from HDF5 directly into the VTK pts pointer
const hsize_t dims[1] = {ngauss[domain] * 3 };
hid_t memspace = H5Screate_simple(1, dims, dims);
hsize_t start[1] = {0};
hsize_t stride[1] = {1};
hsize_t count[1] = {3 * ngauss[domain]};
hsize_t block[1] = {1};
status = H5Sselect_hyperslab(id_coordinates_dataspace, H5S_SELECT_SET, start, stride, count, block );
status = H5Dread(id_gausspoints_coordinates, H5T_NATIVE_FLOAT, memspace, id_coordinates_dataspace, H5P_DEFAULT,
pts);
GO_HERE << "visitESSI: Done reading Gauss Points. Read " << ngauss[domain] << " GP coordinate values.\n\n";
//Free up memory.
delete [] index_to_coordinates;
// delete [] m_number_of_gauss_points[domain];
H5Dclose(id_gausspoints_coordinates);
H5Sclose(id_coordinates_dataspace);
H5Dclose(id_gausspoints_index_to_coordinates);
H5Sclose(id_gausspoints_index_to_coordinates_dataspace);
// H5Dclose(id_number_of_gausspoints);
// H5Sclose(id_number_of_gausspoints_dataspace);
//
// Create a vtkUnstructuredGrid to contain the point cells.
//
m_gaussmesh_data[domain] = vtkUnstructuredGrid::New();
m_gaussmesh_data[domain]->SetPoints(points);
points->Delete();
m_gaussmesh_data[domain]->Allocate(ngauss[domain]);
vtkIdType onevertex;
for (int i = 0; i < ngauss[domain]; ++i)
{
onevertex = i;
m_gaussmesh_data[domain]->InsertNextCell(VTK_VERTEX, 1, &onevertex);
}
}
m_gaussmesh_data[domain]->Register(NULL);
return m_gaussmesh_data[domain];
}
return 0;
}
// ****************************************************************************
// Method: avtvisitESSIFileFormat::GetVar
//
// Purpose:
// Gets a scalar variable associated with this file. Although VTK has
// support for many different types, the best bet is vtkFloatArray, since
// that is supported everywhere through VisIt.
//
// Arguments:
// timestate The index of the timestate. If GetNTimesteps returned
// 'N' time steps, this is guaranteed to be between 0 and N-1.
// domain The index of the domain. If there are NDomains, this