lanl / LaGriT

Los Alamos Grid Toolbox (LaGriT) is a library of user callable tools that provide mesh generation, mesh optimization and dynamic mesh maintenance in two and three dimensions.
https://lanl.github.io/LaGriT/
Other
116 stars 48 forks source link

dump exodus memory error while reading faceset files #265

Open millerta opened 2 months ago

millerta commented 2 months ago

Example for testing from Jeffrey located in /project/meshing/demos/exo_bug_jeffrey/output_9frac/octree_dfm New code on branch tam-debug

 Enter a command
dump/exo/dfm_octree.exo/mo_dfm///facesets left.table right.table front.table bac
k.table facets_f1.table facets_f2.table facets_f3.table facets_f4.table facets_f
5.table facets_f6.table facets_f7.table facets_f8.table facets_f9.table facets_f
10.table facets_f11.table

 Found bndry elems and faces:                  2736
 auto_facesets  true
 auto_facesets false but output_facesets true
 mmgetblk sselemlist length:                  8208
 mmgetblk ssfacelist length:                  8208
 mmgetblk try:                 10944
 Exodus FACESETS imported from files.                    15

******** write to faceset arrays *******
 Total read from file:                  8158
 Set tag:                    14  nfaces:                   621
 Current offset to start write:                  7537
 Set new offset:                  8158
 ******** done writing to faceset arrays *******
 Warning: ncount may be greater than array size.
 iend:                  8779
 nouter1:                  2736
 nouter1*3:                  8208
 ******** write to faceset arrays *******
 Total read from file:                  8779
 Set tag:                    15  nfaces:                   621
 Current offset to start write:                  8158
 Set new offset:                  8779
 MMVERIFY: Array prolog overwritten
   Array ssfacelist                       in dumpexodusII
   Length=                 8208 , Address=       94911463699280
 MMVERIFY: Array epilog overwritten
   Array ssfacelist                       in dumpexodusII
   Length=                 8208 , Address=       94911463699280
 MMVERIFY: Array epilog overwritten
   Array sselemlist                       in dumpexodusII
   Length=                 8208 , Address=       94911463633504
--------
malloc(): unsorted double linked list corrupted

Program received signal SIGABRT: Process abort signal.
millerta commented 2 months ago

As Erica noticed, the arrays for ssfacelist etc are being overwritten. Then when excre is called for exodus to write file, there is a seg fault. Making the arrays larger helps, but excre exits with an error.

The memory allocations for facesets are all tangled up in the Automatic portion of the code. This was a very early iteration for writing facesets which automatically detects and creates facesets on boundary and base mmgetblk lengths on this number. This Automatic detection part of the code is why the memory allocation and failures vary depending on the mesh and parameters. For dfn octree meshes, there are many more facesets internal to the mesh, than on the boundary.

A major fix would be to skip the Automatic facesets part of code and allocate as each file is read. A less invasive fix would leave the auto-detect memory allocation in place, but reallocate if needed as files are read.

Better debug options need to be in place and should be based on the user setting ie cmo/setatt/moname/idebug 5 I also recommend adding call mmverify() before exodus exre command. This would look like:

 Found bndry elems and faces:                  2736
 auto_facesets  true
 auto_facesets false but output_facesets true
 mmgetblk sselemlist length:                  8208
 mmgetblk ssfacelist length:                  8208

******** write to faceset arrays *******
 Total read from file:                  8779
 Set tag:                    15  nfaces:                   621
 Current offset to start write:                  8158
 Set new offset:                  8779
 MMVERIFY: Array prolog overwritten
   Array ssfacelist                       in dumpexodusII
   Length=                 8208 , Address=       94911463699280
 MMVERIFY: Array epilog overwritten
   Array ssfacelist                       in dumpexodusII
   Length=                 8208 , Address=       94911463699280
 MMVERIFY: Array epilog overwritten
   Array sselemlist                       in dumpexodusII
   Length=                 8208 , Address=       94911463633504
--------
millerta commented 2 months ago

Currently, the default memory length for exodus side set arrays is 3nouter1 where nouter1 are the number of faces on the mesh boundary. This is fixed by allocating more memory for the arrays, we get another chunk of 3nouter1 size.

Other arrays should have the same check and increment if needed. For instance, there is a limit of 1000 for the number of facesets.

dumpexodusII.f

       call mmincblk
     &       ('sselemlist',isubname,ipsselemlist,ssinc,ierr)
        if (ierr.ne.0) print*,"mmincblk sselemlist err: ",ierr
        call mmgetlen(ipsselemlist,sslength,ierr)
        if (ierr.ne.0) print*,"mmgetlen sselemlist err: ",ierr

        call mmincblk
     &       ('ssfacelist',isubname,ipssfacelist,ssinc,ierr)
        if (ierr.ne.0) print*,"mmincblk ssfacelist err: ",ierr
        call mmgetlen(ipssfacelist,sslength,ierr)