Skip to main content
deleted 853 characters in body
Source Link
Kuba
  • 138.9k
  • 13
  • 297
  • 803

I'm trying to solve a very tricky bugissue in my program. It's tricky because it seems to be not working intermittently, and mostly not working when running with large data setsfunction. The code itself is kind of enormous but I think I know the crux offunction needs the problem, which I'll include here.

My program calculates many Point[]NDSolve`FEM` 's, a fairly large number (~10,000) framework. I then pass it to this function I've created that tries to find

Here is a concave hull for itminimal example:

GetBoundaryMesh[points_, alphaparameter_]Quit[] 
GetBoundaryMesh[obj_] := (Module[{bmesh}, (*<<NDSolve`FEM`;*)  Needs["NDSolve`FEM`"]; ashape bmesh = alphaShapes2DC[points,ToBoundaryMesh alphaparameter];@ obj; bmesh = ToBoundaryMesh@ashape; MeshPrimitives[MeshRegion @ Return@MeshPrimitives[MeshRegion@bmeshbmesh, 1]; )1] ] GetBoundaryMesh[pts,0.05]
GetBoundaryMesh[Disk[]]  
 MeshPrimitives[MeshRegion[Global`ToBoundaryMesh[Disk[{0,0}]]],1] 

So here's an exampleSomething went wrong, I was expecting a list of ptsLines, and what it looks like when which I show them with Graphics[]can get by executing this code manually:

ptsQuit[] {{0.31275,0.330298},{0.31301,0.330526},{0.313278,0.330762},{0.313553,0.331004},{0.313835,0.331251},{0.314123,0.331505},{0.314418,0.331764},{0.314718,0.332028},{0.315023,0.332296},
Needs["NDSolve`FEM`"]; bmesh \[CenterEllipsis]9983\[CenterEllipsis]= ,{0.334019,0.335577},{0.333671,0.335608},{0.333337,0.335646},{0.333018,0.33569},{0.332713,0.335741},{0.332421,0.335797},{0.332142,0.335859},{0.331876,0.335925}} ToBoundaryMesh @ obj; Graphics@Point[pts]MeshPrimitives[MeshRegion @ bmesh, 1] 

enter image description here

And here's what happens when I pass it to GetBoundaryMesh[] as in the code above:

enter image description here

{Line[{{1.,0.},{0.991575,0.129537}}],<<46>>,Line[{{<<19>>,-<<20>>},{<<1>>}}]} 

I'm not sure how to search for this, so that's why I'm kind of stumped. To me it seems like it isn't importing the NDSolve`FEM package correctly (in my GetBoundaryMesh function), so that's why ToBoundaryMesh isn't evaluating, but that's just my best guess. Also, ToBoundaryMesh is syntax highlighted in red in the function.


Loose thoughts

I'm trying to solve a very tricky bug in my program. It's tricky because it seems to be not working intermittently, and mostly not working when running with large data sets. The code itself is kind of enormous but I think I know the crux of the problem, which I'll include here.

My program calculates many Point[]'s, a fairly large number (~10,000). I then pass it to this function I've created that tries to find a concave hull for it:

GetBoundaryMesh[points_, alphaparameter_] := ( (*<<NDSolve`FEM`;*)  Needs["NDSolve`FEM`"]; ashape = alphaShapes2DC[points, alphaparameter]; bmesh = ToBoundaryMesh@ashape;  Return@MeshPrimitives[MeshRegion@bmesh, 1]; ) GetBoundaryMesh[pts,0.05] 

So here's an example of pts, and what it looks like when I show them with Graphics[]:

pts {{0.31275,0.330298},{0.31301,0.330526},{0.313278,0.330762},{0.313553,0.331004},{0.313835,0.331251},{0.314123,0.331505},{0.314418,0.331764},{0.314718,0.332028},{0.315023,0.332296}, \[CenterEllipsis]9983\[CenterEllipsis] ,{0.334019,0.335577},{0.333671,0.335608},{0.333337,0.335646},{0.333018,0.33569},{0.332713,0.335741},{0.332421,0.335797},{0.332142,0.335859},{0.331876,0.335925}}  Graphics@Point[pts] 

enter image description here

And here's what happens when I pass it to GetBoundaryMesh[] as in the code above:

enter image description here

I'm not sure how to search for this, so that's why I'm kind of stumped. To me it seems like it isn't importing the NDSolve`FEM package correctly (in my GetBoundaryMesh function), so that's why ToBoundaryMesh isn't evaluating, but that's just my best guess. Also, ToBoundaryMesh is syntax highlighted in red in the function.

I'm trying to solve a very tricky issue in my function. The function needs the NDSolve`FEM` framework.

Here is a minimal example:

Quit[] 
GetBoundaryMesh[obj_] := Module[{bmesh}, Needs["NDSolve`FEM`"];  bmesh = ToBoundaryMesh @ obj; MeshPrimitives[MeshRegion @ bmesh, 1] ] 
GetBoundaryMesh[Disk[]]  
 MeshPrimitives[MeshRegion[Global`ToBoundaryMesh[Disk[{0,0}]]],1] 

Something went wrong, I was expecting a list of Lines which I can get by executing this code manually:

Quit[] 
Needs["NDSolve`FEM`"]; bmesh = ToBoundaryMesh @ obj; MeshPrimitives[MeshRegion @ bmesh, 1] 
{Line[{{1.,0.},{0.991575,0.129537}}],<<46>>,Line[{{<<19>>,-<<20>>},{<<1>>}}]} 

To me it seems like it isn't importing the NDSolve`FEM package correctly, but that's just my best guess.


Loose thoughts

Tweeted twitter.com/StackMma/status/746059494388555776
added 13 characters in body; edited tags
Source Link
Kuba
  • 138.9k
  • 13
  • 297
  • 803

enter image description hereenter image description here

enter image description hereenter image description here

I'm not sure how to search for this, so that's why I'm kind of stumped. To me it seems like it isn't importing the NDSolveFEM package correctly (in my NDSolve`FEMGetBoundaryMesh package correctly (in my function), so that's whyGetBoundaryMeshToBoundaryMesh` function), so that's why ToBoundaryMesh isn't evaluating, but that's just my best guess. Also, ToBoundaryMeshToBoundaryMesh is syntax highlighted in red in the function.

When I close MMa and open my notebook again, if I do $Packages, FEMFEM`NDSolveNDSolve isn't there (as expected):

However, after I run the function once (and it gives its error), if I check $Packages$Packages, it is there! So it seems like it is loading it, but somehow the function isn't seeing that in time when it's called..?

enter image description here

enter image description here

I'm not sure how to search for this, so that's why I'm kind of stumped. To me it seems like it isn't importing the NDSolveFEM package correctly (in my GetBoundaryMeshfunction), so that's whyToBoundaryMesh` isn't evaluating, but that's just my best guess. Also, ToBoundaryMesh is syntax highlighted in red in the function.

When I close MMa and open my notebook again, if I do $Packages, FEMNDSolve isn't there (as expected):

However, after I run the function once (and it gives its error), if I check $Packages, it is there! So it seems like it is loading it, but somehow the function isn't seeing that in time when it's called..?

enter image description here

enter image description here

I'm not sure how to search for this, so that's why I'm kind of stumped. To me it seems like it isn't importing the NDSolve`FEM package correctly (in my GetBoundaryMesh function), so that's why ToBoundaryMesh isn't evaluating, but that's just my best guess. Also, ToBoundaryMesh is syntax highlighted in red in the function.

When I close MMa and open my notebook again, if I do $Packages, FEM`NDSolve isn't there (as expected):

However, after I run the function once (and it gives its error), if I check $Packages, it is there! So it seems like it is loading it, but somehow the function isn't seeing that in time when it's called..?

Source Link
YungHummmma
  • 3.1k
  • 16
  • 34

Where does a package have to be loaded?

I'm trying to solve a very tricky bug in my program. It's tricky because it seems to be not working intermittently, and mostly not working when running with large data sets. The code itself is kind of enormous but I think I know the crux of the problem, which I'll include here.

My program calculates many Point[]'s, a fairly large number (~10,000). I then pass it to this function I've created that tries to find a concave hull for it:

GetBoundaryMesh[points_, alphaparameter_] := ( (*<<NDSolve`FEM`;*) Needs["NDSolve`FEM`"]; ashape = alphaShapes2DC[points, alphaparameter]; bmesh = ToBoundaryMesh@ashape; Return@MeshPrimitives[MeshRegion@bmesh, 1]; ) GetBoundaryMesh[pts,0.05] 

So here's an example of pts, and what it looks like when I show them with Graphics[]:

pts {{0.31275,0.330298},{0.31301,0.330526},{0.313278,0.330762},{0.313553,0.331004},{0.313835,0.331251},{0.314123,0.331505},{0.314418,0.331764},{0.314718,0.332028},{0.315023,0.332296}, \[CenterEllipsis]9983\[CenterEllipsis] ,{0.334019,0.335577},{0.333671,0.335608},{0.333337,0.335646},{0.333018,0.33569},{0.332713,0.335741},{0.332421,0.335797},{0.332142,0.335859},{0.331876,0.335925}} Graphics@Point[pts] 

enter image description here

And here's what happens when I pass it to GetBoundaryMesh[] as in the code above:

enter image description here

I'm not sure how to search for this, so that's why I'm kind of stumped. To me it seems like it isn't importing the NDSolveFEM package correctly (in my GetBoundaryMeshfunction), so that's whyToBoundaryMesh` isn't evaluating, but that's just my best guess. Also, ToBoundaryMesh is syntax highlighted in red in the function.

When I close MMa and open my notebook again, if I do $Packages, FEMNDSolve isn't there (as expected):

{"GetFEKernelInit`", "StreamingLoader`", "IconizeLoader`", \ "CloudObjectLoader`", "ResourceLocator`", "PacletManager`", \ "System`", "Global`"} 

Even after I evaluate the cell that holds all my functions, it's still not in $Packages. At this point, if I run my function, it gives the same problem, because apparently it has not loaded the package (despite it being the first line in the function it runs...?).

However, after I run the function once (and it gives its error), if I check $Packages, it is there! So it seems like it is loading it, but somehow the function isn't seeing that in time when it's called..?

Okay, I managed to solve the problem kind of by explicitly calling ToBoundaryMesh this way:

NDSolve`FEM`ToBoundaryMesh@ashape; 

That seems to work on the first try, but why didn't it work without explicitly calling it? Why isn't it in the $Packages list for the function once Needs[] is called?

I was reading here about packages and context but I didn't really see the answer.