mesh_finalize Subroutine

public subroutine mesh_finalize(m)

Safely deallocates all heap-allocated arrays in the mesh structure.

This routine should be called during solver shutdown or mesh reload to prevent memory leaks. It nullifies all counts after deallocation.

Arguments

Type IntentOptional Attributes Name
type(mesh_t), intent(inout) :: m

The mesh object to be cleared.


Source Code

   subroutine mesh_finalize(m)
      type(mesh_t), intent(inout) :: m

      integer :: p

      if (allocated(m%points)) deallocate(m%points)
      if (allocated(m%cells)) deallocate(m%cells)
      if (allocated(m%faces)) deallocate(m%faces)
      if (allocated(m%ncell_faces)) deallocate(m%ncell_faces)
      if (allocated(m%cell_faces)) deallocate(m%cell_faces)

      if (allocated(m%patches)) then
         do p = 1, size(m%patches)
            if (allocated(m%patches(p)%face_ids)) deallocate(m%patches(p)%face_ids)
         end do
         deallocate(m%patches)
      end if

      m%npoints = 0
      m%ncells = 0
      m%nfaces = 0
      m%npatches = 0
   end subroutine mesh_finalize