su2code / SU2

SU2: An Open-Source Suite for Multiphysics Simulation and Design
https://su2code.github.io
Other
1.33k stars 838 forks source link

Infinite Loop When Running Grid Adaptivity on Hexahderons #487

Closed clarkpede closed 6 years ago

clarkpede commented 6 years ago

I've encountered a bug where SU2 will get stuck in an infinite loop. I've been trying out the grid adaptation code recently. Tets, rectangles, and triangles all worked fine, but hexahedra threw the code into an infinite loop. Basically, the code is missing the proper code for hexahedra in the CGridAdaptation::SetSensorElem function.

I've attached the offending lines 3640-3653 of Common/src/grid_adaptation_structure.cpp below:

/*--- Selection of the elements to be adapted ---*/
threshold = 0.999;
nElem_real = 0;
while (nElem_real <= max_elem) {
    for (iElem = 0; iElem < geometry->GetnElem(); iElem ++)
        if ( Sensor[iElem] >= threshold && !geometry->elem[iElem]->GetDivide() ) {
            if (geometry->elem[iElem]->GetVTK_Type() == TRIANGLE) nElem_real = nElem_real + 3;
            if (geometry->elem[iElem]->GetVTK_Type() == QUADRILATERAL) nElem_real = nElem_real + 3;
            if (geometry->elem[iElem]->GetVTK_Type() == TETRAHEDRON) nElem_real = nElem_real + 7;
            geometry->elem[iElem]->SetDivide(true);
            if (nElem_real >= max_elem) break;
        }   
    threshold = threshold - 0.001;
}

As you can see, if all of the elements are hexahedral, the threshold will keep decreasing but nElem_real will never increase, and the loop will never end.

This is an easy fix, and I've already fixed it on a local branch. But I'm also wondering why grid adaptation doesn't work for hexahedra. It's not just this section of code that doesn't work. There's other sections too. One of the biggest ones is at lines 2369-2386 of Common/src/grid_adaptation_structure.cpp. In that section, all hexahedra are explicitly removed from the grid adaptivity process.

This is rather confusing, because there is a lot of code in the CGridAdaptation class that is set up for adaptation of hexahedra. The AIAA paper from 2013 even dedicates a whole paragraph to explaining the hexahedral grid adaptation. I understand that a pure hex grid can be a poor case for adaptive grid refinement, but I would like to try the grid adaptivity on a hybrid mesh (with hexes and tets).

Is there some reason that grid adaptivity for hexahedra is "turned off"?

clarkpede commented 6 years ago

As for the question I raised, Dr. Alonso mentioned the problem in an email he sent me. He said, "We used [grid adaptation] successfully in tetrahedral meshes, but I do not believe the hexahedral adaptation was ever fully functional."

That matches my experience with a few tests I ran. After playing around a little, it seems like adaptivity for hexahedra was only partially finished. Many sections of the are implemented, but there seem to be both bugs and unfinished implementation.