Manifold Geometry // Многообразная Геометрия

A note on NetGen

/ Просмотров: 1777

People use this famous open-sourced mesher as a cost-efficient (well, just free) tool for quality mesh generation. At some point we also felt the urge to have a fancy mesher instead of the low-poly faceter provided with OpenCascade.

NetGen rocks.

Here is the Tcl script that generates meshes for all STEP files in a folder:

#------------------------------------------------------------------------------
# This script generates facets for all CAD parts located in
# the specified target directory.
#------------------------------------------------------------------------------
  
set workdir "C:/work/data"
set targetExt "stp"
set filenames []
  
# Callback on visiting a certain file.
proc on_visit {path} {
  global filenames
#  puts "Next filename: $path"
  lappend filenames $path
}
  
# Recursive visiting procedure.
proc visit {base glob func} {
  foreach f [glob -nocomplain -types f -directory $base $glob] {
    if {[catch {eval $func [list [file join $base $f]]} err]} {
      puts stderr "error: $err"
    }
  }
  foreach d [glob -nocomplain -types d -directory $base *] {
    visit [file join $base $d] $glob $func
  }
}
  
# Procedure to find files of a certain type.
proc find_files {base ext} {
  visit $base *.$ext [list on_visit]
}
  
# Find files with a certain extension.
find_files [lindex $workdir 0] $targetExt
  
# Load each model and check.
foreach inFilename $filenames {
  puts "Next model to process: $inFilename"
  clear
  if { [catch {load-step $inFilename}] } {
    puts stderr "error: cannot read a STEP file."
    continue
  }
  
  poly-netgen
}
  
puts "Checked [llength $filenames] files."

This script iterates all STEP files in a directory and attempts to generate surface meshes for them. The idea behind this script was to pressure-test the mesher and see how reliable, fast and accurate it is. The result was not Okay: NetGet just hits jackpot. It is slow, unreliable, and not accurate. I don't know how folks from Salome and other teams handle it or if they apply some therapy on the vanilla NetGen. I'm almost convinced that this mesher is barely usable in industrial projects, at least in batch processes, where punctual success is nothing. Quite often NetGen stalls on moderate-size models or finishes with some fancy exceptions like this:

NetGen rocks all the time.

As for accuracy, the visually appealing meshes are not as perfect as they pretend to be. The precision loss is especially visible at round holes. For example, instead of sweeping a constant polygonal pattern along a bore, NetGen randomly distorts the corresponding cylinder, maybe for the sake of a better aspect ratio. The later property is kind of desired for finite element simulations. But, in less-demanding computer graphics it is the shape that dominates the party. Such issues might remain unnoticed until you start using such meshes for computations that require high accuracy (e.g., manufacturability tests).

NetGen accuracy is not perfect.

The batch job scripted above aims at checking the meshes analytically, without any visual assessment. That's where Analysis Situs CLI (Command Line Interface) can help: no UI, no 3D, just computation.

Analysis Situs CLI.

Batch processing is a headless thing. We can analytically verify if a mesh is good or broken by running check-facets command of Analysis Situs. A good mesh should not contain any dangling elements, like free edges or vertices. Neither it should expose any degenerated triangles or inconsistent normal fields.

Corrupted mesh.

Just to conclude on this topic: take care to get (buy) a good mesher. There are companies that ground their entire business on developing and maintaining quality grid generators. It would probably be wise to invest into a mesher to avoid surprises later on. Still, I do not really want to pick on NetGen as a product that much. It is open-sourced and it can work well in interactive workflows where you're working with a single part without much automation.

Want to discuss this? Jump in to our forum.