idaholab / moose

Multiphysics Object Oriented Simulation Environment
https://www.mooseframework.org
GNU Lesser General Public License v2.1
1.77k stars 1.05k forks source link

Moose::elementsIntersectedByLine can crash #12414

Open YaqiWang opened 6 years ago

YaqiWang commented 6 years ago

Rationale

I had a vector postprocessor calling this function and noticed that it can crash.

Description

I had a regular 2D mesh created by GeneratedMesh with xmin=0,xmax=80,nx=8 and ymin=0,ymax=80,ny=8. When I try to call the function with starting point '0 30 0' and end point '80 30 0', I get the crash. lldb shows that it is due to a recursive call at RayTracing.C:178. I know this line is just on the boundary of elements, so the behavior may not be well defined. But it should at least throw a meaningful error message.

Impact

A more robust function interface that could impact line sampling stuff.

permcody commented 6 years ago

Can you post your test input file? Also, do you have the crash message or stack trace handy? That would be useful to get started here.

FYI - @friedmud

YaqiWang commented 6 years ago
    frame #6686: 0x0000000103a8b07d libmoose-dbg.0.dylib`Moose::recursivelyFindElementsIntersectedByLine(line_segment=0x00007fff5fbfb110, current_elem=0x000000011025b100, incoming_side=3, incoming_point=0x00007fff5fbf8658, intersected_elems=size=1, segments=size=1) at RayTracing.C:178
    frame #6687: 0x0000000103a8b07d libmoose-dbg.0.dylib`Moose::recursivelyFindElementsIntersectedByLine(line_segment=0x00007fff5fbfb110, current_elem=0x000000011025afe0, incoming_side=3, incoming_point=0x00007fff5fbf8b38, intersected_elems=size=1, segments=size=1) at RayTracing.C:178
    frame #6688: 0x0000000103a8b07d libmoose-dbg.0.dylib`Moose::recursivelyFindElementsIntersectedByLine(line_segment=0x00007fff5fbfb110, current_elem=0x000000011025acb0, incoming_side=3, incoming_point=0x00007fff5fbf9018, intersected_elems=size=1, segments=size=1) at RayTracing.C:178
    frame #6689: 0x0000000103a8b07d libmoose-dbg.0.dylib`Moose::recursivelyFindElementsIntersectedByLine(line_segment=0x00007fff5fbfb110, current_elem=0x000000011025ab90, incoming_side=3, incoming_point=0x00007fff5fbf94f8, intersected_elems=size=1, segments=size=1) at RayTracing.C:178
    frame #6690: 0x0000000103a8b07d libmoose-dbg.0.dylib`Moose::recursivelyFindElementsIntersectedByLine(line_segment=0x00007fff5fbfb110, current_elem=0x000000011025a860, incoming_side=3, incoming_point=0x00007fff5fbf99d8, intersected_elems=size=1, segments=size=1) at RayTracing.C:178
    frame #6691: 0x0000000103a8b07d libmoose-dbg.0.dylib`Moose::recursivelyFindElementsIntersectedByLine(line_segment=0x00007fff5fbfb110, current_elem=0x000000011025a740, incoming_side=3, incoming_point=0x00007fff5fbf9eb8, intersected_elems=size=1, segments=size=1) at RayTracing.C:178
    frame #6692: 0x0000000103a8b07d libmoose-dbg.0.dylib`Moose::recursivelyFindElementsIntersectedByLine(line_segment=0x00007fff5fbfb110, current_elem=0x000000011025a410, incoming_side=3, incoming_point=0x00007fff5fbfa398, intersected_elems=size=1, segments=size=1) at RayTracing.C:178
    frame #6693: 0x0000000103a8b07d libmoose-dbg.0.dylib`Moose::recursivelyFindElementsIntersectedByLine(line_segment=0x00007fff5fbfb110, current_elem=0x000000011025a2f0, incoming_side=3, incoming_point=0x00007fff5fbfa878, intersected_elems=size=1, segments=size=1) at RayTracing.C:178
    frame #6694: 0x0000000103a8b07d libmoose-dbg.0.dylib`Moose::recursivelyFindElementsIntersectedByLine(line_segment=0x00007fff5fbfb110, current_elem=0x0000000110259fc0, incoming_side=3, incoming_point=0x00007fff5fbfad58, intersected_elems=size=1, segments=size=1) at RayTracing.C:178
    frame #6695: 0x0000000103a8b07d libmoose-dbg.0.dylib`Moose::recursivelyFindElementsIntersectedByLine(line_segment=0x00007fff5fbfb110, current_elem=0x0000000110259ea0, incoming_side=-1, incoming_point=0x00000001111542a8, intersected_elems=size=1, segments=size=1) at RayTracing.C:178
    frame #6696: 0x0000000103a8b8cf libmoose-dbg.0.dylib`Moose::elementsIntersectedByLine(p0=0x00000001111542a8, p1=0x00000001111542c0, (null)=0x0000000110258f70, point_locator=0x0000000117e250f0, intersected_elems=size=1, segments=size=1) at RayTracing.C:215
    frame #6697: 0x00000001010d09f6 librattlesnake-dbg.0.dylib`ElementVariableValuesAlongLine::execute(this=0x0000000111153c18) at ElementVariableValuesAlongLine.C:101
    frame #6698: 0x0000000103066cfc libmoose-dbg.0.dylib`FEProblemBase::computeUserObjects(this=0x0000000110807e18, type=0x0000000103d63838, group=0x00007fff5fbfc9e8) at FEProblemBase.C:3121
    frame #6699: 0x000000010306454c libmoose-dbg.0.dylib`FEProblemBase::execute(this=0x0000000110807e18, exec_type=0x0000000103d63838) at FEProblemBase.C:2974
    frame #6700: 0x0000000100f0d41f librattlesnake-dbg.0.dylib`SNFEProblem::execute(this=0x0000000110807e18, exec_type=0x0000000103d63838) at SNFEProblem.C:180
    frame #6701: 0x0000000103031cfc libmoose-dbg.0.dylib`FEProblemBase::initialSetup(this=0x0000000110807e18) at FEProblemBase.C:839
    frame #6702: 0x0000000102642b45 libmoose-dbg.0.dylib`Transient::init(this=0x0000000110806018) at Transient.C:296
    frame #6703: 0x00000001005df19b librattlesnake-dbg.0.dylib`IQS::init(this=0x0000000110806018) at IQS.C:230
    frame #6704: 0x00000001037ed63f libmoose-dbg.0.dylib`MooseApp::executeExecutioner(this=0x000000010f092a18) at MooseApp.C:824
    frame #6705: 0x00000001015f6b4e librattlesnake-dbg.0.dylib`OutputApp::executeExecutioner(this=0x000000010f092a18) at OutputApp.C:144
    frame #6706: 0x00000001037edf02 libmoose-dbg.0.dylib`MooseApp::run(this=0x000000010f092a18) at MooseApp.C:944
    frame #6707: 0x00000001015f7352 librattlesnake-dbg.0.dylib`OutputApp::run(this=0x000000010f092a18) at OutputApp.C:151
    frame #6708: 0x0000000100001fb1 rattlesnake-dbg`main(argc=4, argv=0x00007fff5fbfec00) at main.C:44
    frame #6709: 0x00007fffb7ab1235 libdyld.dylib`start + 1

My test is super large not suitable for solving this issue. I am pretty sure you can use one of line samplers that is calling the function to reproduce.

YaqiWang commented 6 years ago

I had Mesh/uniform_refine=1 that could be relevant.

permcody commented 6 years ago

The problem is that you are out of stack space! I only know this because I spent a lot of time fixing a different recursion issue that was in the ~5K depth range and it turned out that I just ran out of stack space!

Short term workaround: On the system you are running on you can increase the stack size to get this to run. There's not a universal way to do this. On linux it's easy:

ulimit -s <kbytes of space>

On Mac, you have to modify a plist somewhere and reboot. Then you'll lose that change later during a system update... sigh...

Long term fix: This utility will get re-written using Derek's RayTracing capability.

Medium term fix (optional): This method could be adapted to be non-recursive with about an hour or two worth of work. Instead of calling this method recursively, you create a queue or stack data structure and change the recursion to a while loop. I just did this in the GrainTracker recently to get around almost the exact same problem: https://github.com/idaholab/moose/commit/d22a759127787653becd1865a72ebdd357bbc5ea

YaqiWang commented 6 years ago

This is a simple mesh with only 16*16 elements. I am concerned with how the stack can be this deep. Maybe somewhere the return logic is not very right.

permcody commented 6 years ago

Oh! I thought you said this is a large example. You are correct. This shouldn't be happening on a mesh that small. It sounds like it's getting stuck.

friedmud commented 6 years ago

Agreed - if it's only 16x16 then it's getting stuck. Just move the line slightly or something.

This will all be done better once my ray-tracing stuff is in there.

Derek

On Thu, Nov 1, 2018 at 1:16 PM Cody Permann notifications@github.com wrote:

Oh! I thought you said this is a large example. You are correct. This shouldn't be happening on a mesh that small. It sounds like it's getting stuck.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/idaholab/moose/issues/12414#issuecomment-435152845, or mute the thread https://github.com/notifications/unsubscribe-auth/AA1JMTyDAdkOIfz4LypqIZQf9E9mLTqgks5uq0iEgaJpZM4YGp4m .

YaqiWang commented 6 years ago

Does the new ray-tracing support mesh adaptation? Looks like this function does not. But I made few small changes in the function by calling few different libMesh interface functions. I can make a small PR to push the changes if you'd like.

friedmud commented 6 years ago

Yes - it does.

Derek

On Sat, Nov 3, 2018 at 9:30 PM Yaqi notifications@github.com wrote:

Does the new ray-tracing support mesh adaptation? Looks like this function does not. But I made few small changes in the function by calling few different libMesh interface functions. I can make a small PR to push the changes if you'd like.

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/idaholab/moose/issues/12414#issuecomment-435639155, or mute the thread https://github.com/notifications/unsubscribe-auth/AA1JMTCXrT8DF0Bgn9iFWsSkfOSAI_erks5url9OgaJpZM4YGp4m .

-- Sent from my iPhone

YaqiWang commented 6 years ago

Can I send it a PR temporarily fix this and add support for adapted meshes? I know you have better plan, but I want this to be fixed so I can make few examples run fine otherwise have to comment out the line sampler.

permcody commented 6 years ago

I guess I don't see why not. I assume this means you understand what the issue is?