13
$\begingroup$

In the DiscretizeRegion documentation:

The region reg can be anything that is ConstantRegionQ and RegionEmbeddingDimension less than or equal to 3.

With DiscretizeRegion there could be an easy way to check volume calculations. First, I do it with a test region:

reg3D = ImplicitRegion[x - 2 < y < x - 1 && 0 < z < (x + y)/(x - y),
                       {{x, 0, 2}, {y, -2, 0}, {z, 0, 3}}];
{RegionEmbeddingDimension @ reg3D, ConstantRegionQ @ reg3D}
{3, True}

{Volume @ reg3D // N, Volume @ DiscretizeRegion[reg3D]}
{0.375, 0.373509}

Now my problem region:

reg3D = ImplicitRegion[x - 2 < y < x - 1 && 0 < z < Exp[(x + y)/(x - y)],
                       {{x, 0, 2}, {y, -2, 0}, {z, 0, 3}}];
{RegionEmbeddingDimension @ reg3D, ConstantRegionQ @ reg3D}
{3, True}

{vol = Volume @ reg3D, vol // N}
{(3 (-1 + E^2))/(4 E), 1.7628}

Volume @ DiscretizeRegion[reg3D];

DiscretizeRegion::drf: DiscretizeRegion was unable to discretize the region ImplicitRegion[<<2>>]. >>

Error; yet another method:

g = RegionPlot3D[reg3D, PlotPoints -> 100]

region

discreteReg = DiscretizeGraphics[g // Normal] // Quiet;
{RegionDimension @ discreteReg, RegionEmbeddingDimension @ discreteReg}
{2, 3}

I am now able to obtain the area:

Area @ discreteReg
12.5795

but not the volume, it fails once again.

<< NDSolve`FEM`
ToElementMesh @ discreteReg

MeshRegion::dgcell: The cell Polygon[{41,11121,408,403}] is degenerate. >> ToBoundaryMesh::femtemnm: A mesh could not be generated. >>

I didn't get much further! What can I do?

$\endgroup$
11
$\begingroup$

Based on a discussion with the developers, the new default "MarchingCells" method (in version 10.2 or later) should be able to handle this, but is running into exception handling problems related to the singularity at x == y.

This may be improved in a future version, for now some possible workarounds are below. It is not necessary to fill the interior to compute the volume, so for a crude approximation we may use the "Legacy" method to get a boundary representation

reg0 = ImplicitRegion[x - 2 < y < x - 1 && 0 < z < Exp[(x + y)/(x - y)],
           {{x, 0, 2}, {y, -2, 0}, {z, 0, 3}}];

{bmr0 = BoundaryDiscretizeRegion[reg0, Method -> "Legacy"], Volume[bmr0]}

Mathematica graphics

which is not a great estimate.

This is an improvement, suggested by user21, which does fill the interior with 300000 or so tetrahedra.

em = NDSolve`FEM`ToElementMesh[reg0, 
        "BoundaryMeshGenerator" -> {"RegionPlot", "SamplePoints" -> 35}];
NIntegrate[1, {x, y, z} ∈ em]

(* 1.74563 *)

The following avoids the singularity and uses a finer mesh for a better estimate

ϵ = $MachineEpsilon/2; 
reg = ImplicitRegion[x - 2 < y < x - 1 && 0 < z < Exp[(x + y)/(x - y)], 
          {{x, ϵ, 2}, {y, -2, ϵ}, {z, 0, 3}}];
{bmr = BoundaryDiscretizeRegion[reg, MaxCellMeasure -> 0.001], Volume[bmr]}

Mathematica graphics

$\endgroup$
  • 3
    $\begingroup$ I hope that the "may", in be improved, is just there as a formality... because there are still a lot of exceptions in these regions related additions, and the potential is big. I'm hopping for fast boolean operations between the different types of regions (discretized, implicit, etc) before release 11... $\endgroup$ – P. Fonseca Sep 3 '15 at 19:31
  • $\begingroup$ Given the "MarchingCells" method you mention, does this have an easy solution in Mathematica? $\endgroup$ – Szabolcs Oct 4 '15 at 13:15

Your Answer

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