11/*------------ -------------- -------- --- ----- --- -- - -
22 * feenox's mesh-related gmsh routines
33 *
4- * Copyright (C) 2014--2024 Jeremy Theler
4+ * Copyright (C) 2014--2025 Jeremy Theler
55 *
66 * This file is part of feenox.
77 *
@@ -399,9 +399,7 @@ int feenox_mesh_read_gmsh(mesh_t *this) {
399399 }
400400
401401 // en msh2 si no es sparse, los tags son indices pero si es sparse es otro cantar
402- if (j + 1 != tag ) {
403- this -> sparse = 1 ;
404- }
402+ this -> sparse |= (j + 1 != tag );
405403
406404 this -> node [j ].tag = tag ;
407405 if (tag < tag_min ) {
@@ -416,6 +414,7 @@ int feenox_mesh_read_gmsh(mesh_t *this) {
416414
417415 // finished reading the node data, check if they are sparse
418416 // if they are, build tag2index
417+ // TODO: use the vtk hashmap
419418 if (this -> sparse ) {
420419 if (tag_max < this -> n_nodes ) {
421420 feenox_push_error_message ("maximum node tag %d is less that number of nodes %d" , tag_max , this -> n_nodes );
@@ -433,9 +432,19 @@ int feenox_mesh_read_gmsh(mesh_t *this) {
433432
434433 } else if (version_maj == 4 ) {
435434 // number of blocks and nodes
436- size_t num_blocks ;
435+ size_t num_blocks = 0 ;
437436 if (version_min == 0 ) {
438- // in 4.0 there is no min/ max
437+ // in 4.0 there's no min/max, I asked for this in
438+ // https://onelab.info/pipermail/gmsh/2018/012432.html
439+ //
440+ // > I would need to know the biggest tag of the nodes or elements before
441+ // > readuing them, not just the number of non-zero elements. Otherwise I
442+ // > need to either double-parse the file or reallocate the array each time.
443+ //
444+ // we could indeed add min/max vertex/element tags in the section header
445+ // in a future revision of the format
446+ //
447+ // see also https://gitlab.onelab.info/gmsh/gmsh/-/issues/444
439448 size_t data [2 ] = {0 ,0 };
440449 feenox_call (feenox_gmsh_read_data_size_t (this , 2 , data , binary ));
441450 num_blocks = data [0 ];
@@ -457,7 +466,8 @@ int feenox_mesh_read_gmsh(mesh_t *this) {
457466 feenox_check_alloc (this -> node = calloc (this -> n_nodes , sizeof (node_t )));
458467
459468 if (tag_max != 0 ) {
460- // we can do this as a one single pass because we have tag_max (I asked for this in v4.1)
469+ // we can do this as a one single pass because we have tag_max
470+ // (I asked for this in v4.1, see links above)
461471 if (tag_max < this -> n_nodes ) {
462472 feenox_push_error_message ("maximum node tag %d is less that number of nodes %d" , tag_max , this -> n_nodes );
463473 }
@@ -496,12 +506,15 @@ int feenox_mesh_read_gmsh(mesh_t *this) {
496506 return FEENOX_ERROR ;
497507 }
498508
509+ if (this -> node [node_index ].tag < tag_min ) {
510+ tag_min = this -> node [node_index ].tag ;
511+ }
499512 if (this -> node [node_index ].tag > tag_max ) {
500513 tag_max = this -> node [node_index ].tag ;
501514 }
502-
503- // in msh4 the tags are the indices of the global mesh
504515 this -> node [node_index ].index_mesh = node_index ;
516+ // we don't have tag2index yet, but we can check if it is sparse
517+ this -> sparse |= (this -> node [node_index ].tag != node_index + 1 );
505518 node_index ++ ;
506519 }
507520 } else {
@@ -530,14 +543,18 @@ int feenox_mesh_read_gmsh(mesh_t *this) {
530543 return FEENOX_ERROR ;
531544 }
532545 this -> tag2index_from_tag_min [this -> node [node_index ].tag ] = node_index ;
546+ this -> sparse |= (this -> node [node_index ].tag != node_index + 1 );
533547 node_index ++ ;
534548 }
535549 feenox_free (node_coords );
536550 }
537551 }
538552
553+ this -> node_tag_min = tag_min ;
554+ this -> node_tag_max = tag_max ;
539555 if (version_min == 0 ) {
540- // for v4.0 we need an extra loop because we did not have the actual tag_max
556+ // for v4.0 we need an extra loop because we did not have
557+ // the actual tag_min/tag_max before reading
541558 feenox_mesh_tag2index_alloc (this , tag_min , tag_max );
542559
543560 for (size_t j = 0 ; j < this -> n_nodes ; j ++ ) {
@@ -668,7 +685,6 @@ int feenox_mesh_read_gmsh(mesh_t *this) {
668685 } else if (version_maj == 4 ) {
669686 size_t num_blocks ;
670687 if (version_min == 0 ) {
671- // in 4.0 there's no min/max (I asked for this)
672688 tag_min = 0 ;
673689 tag_max = 0 ;
674690 if (fscanf (fp , "%lu %lu" , & num_blocks , & this -> n_elements ) < 2 ) {
0 commit comments