4
$\begingroup$

Original text

My need is simple: I have many non-overlapping regions that I will need to use as plotting domains and integration domains. The new region type operations in Mathematica 10 has made my life so much easier until 10.0.2 came out. When I first started with regions I asked the following question: RegionUnion issues with many Regions which was if I'm using RegionUnion[] on many regions the CPU would run full tilt until the kernel quit. The answer was to simply use DiscretizeRegion[] on my regions before I used RegionUnion[]. This worked very well so I wrapped it up deep in one of my packages and went on to my real work. I have since upgraded to version 10.0.2 but now my package will not work.

Here is a simple function to make a region with a flag to return either the region as is or to apply DiscretizeRegion[] first:

 r1[x_, ds_, r_: 1] := If[ds,
  DiscretizeRegion@Disk[{x, 0}, r],
  Disk[{x, 0}, r]
  ]

Lets use it to do some simple operations with two flags to easily try the different cases.

 d = 2.1;
 ds = False;
 OuterDS = False;
 If[OuterDS,
  DR = DiscretizeRegion,
  DR = Identity
 ];
R = RegionDifference[
       DR@RegionUnion[r1[0, ds], r1[d, ds]],
       DR@r1[d/2, ds, .5]
   ]
 Area[R]
 Head[R]
 Integrate[x^2 + y^2, {x, y} \[Element] R]

If I use ds=False and OuterDS = False everything works and I can use R in my integration. But I then quickly run into my old problem of the kernel crashing when there are lots of regions. If I use ds=True then it no longer works with either value for OuterDS. Remember I'm using 10.0.2 and this did work on 10.0 and I think it also worked on 10.0.1. I also tried this on the Mathematica online where it works for all cases!

It comes down to the following difference between versions. When I use RegionUnion[] on a list of DiscretizeRegion[] I get an object with the head BoundaryMeshRegion when I used to get MeshRegion. I cannot use RegionDifference[] on a BoundaryMeshRegion and a MeshRegion using 10.0.2 but this does work on the Mathematica online.

Is there a way to force region operations on MeshRegion to return a MeshRegion and not a BoundaryMeshRegion? Has anyone else run into this problem? If you have 10.0.1 can you try this code and tell me if it works for you?

Edit 1 I may close this. I have tried testing on another computer also with 10.0.2 and everything works. I then tried my real code and package and now it works?! But what was causing the problems in my simple code below? Some how with kernel history I got to a point where I could not use RegionUnion[] on BoundaryMeshRegion and a MeshRegion. So if you read this take it with a bit of skepticism. If I find out I was doing something stupid I'll remove this if I find a subtle order of events that caused this odd behavior I'll edit to point it out.

Edit 2 This is bad. I can now run the same code and get different results. I even use the Quit[] and re-evaluate in the same order and I seem to randomly get different results!?

What I get when it does not work: Dose not work

What I get when it does work: enter image description here

Edit 3 I have taken my full package and have run it on 10.0.1 with no problem. However, I have not found small clean example that shows the difference between 10.0.2 and 10.0.1 yet.

$\endgroup$
  • 2
    $\begingroup$ DiscretizeRegion appears to be bugged. This could easily be related. $\endgroup$ – Mr.Wizard Feb 8 '15 at 19:53
  • 1
    $\begingroup$ I'd suggest to send that in to the tech support for someone to look at. $\endgroup$ – user21 Feb 9 '15 at 11:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.