7

Bug introduced in 10.1 and fixed in 11.3


Context

In relation to this question I have would like to use splines to define a ParametricRegion and DiscretizeRegion

I proceed as follows:

pts = {{1, 0}, {1.8, 3}, {0, 2}};
 {xu, yu} = Transpose[pts]; 
n = 2;m = Length[pts]; 
knots = {ConstantArray[0, n + 1], Range[m - n - 1]/(m - n), 
         ConstantArray[1, n + 1]} // Flatten; 
fx[t_] = xu.Table[ BSplineBasis[{n, knots}, i - 1, t], {i, Length[pts]}]; 
fy[t_] = yu.Table[ BSplineBasis[{n, knots}, i - 1, t], {i, Length[pts]}]; 

So that

ParametricPlot[{fx[t], fy[t]}, {t, 0, 1}, Axes -> None, Frame -> True,
  Epilog -> {Directive[AbsolutePointSize[5], Red], Point[pts]}]

Mathematica graphics

Now I would like to Discretize this BSpline as follows:

  dpr = ParametricRegion[{{ fx[t], fy[t]}, 0 <= t <= 1}, t];
  δΩ = DiscretizeRegion[dpr, MaxCellMeasure -> 0.001];

This seems to produce a buggy region. Indeed

   Show[δΩ, Axes -> True]

Mathematica graphics

presents some defect in the triangulation. Note in particular the two points at the origin and at coordinate (0.9,-0.2).


Question

Is this a bug in DiscretizeRegion?

Can anyone reproduce this problem?

I am using mathematica 10.1 on macos X.

Thanks!

Update

In mathematica 10.2 is works better but not always. For instance let us define

 << NDSolve`FEM`

Jet0[pts_: {{1, 0}, {1.8, 1.8}, {0, 2}}] := Module[{xu, yu, n, m, knots, fx, fy, pr, mesh, t, r}, {xu, yu} = Transpose[pts]; n = 2; m = Length[pts]; knots = {ConstantArray[0, n + 1], Range[m - n - 1]/(m - n), ConstantArray[1, n + 1]} // Flatten; fx[t_] = xu.Table[BSplineBasis[{n, knots}, i - 1, t], {i, Length[pts]}]; fy[t_] = yu.Table[BSplineBasis[{n, knots}, i - 1, t], {i, Length[pts]}]; pr = ParametricRegion[{{r fx[t], r fy[t]}, 0 <= t <= 1 && 0 <= r <= 1}, {t, r}]; mesh = ToElementMesh[pr, "MaxBoundaryCellMeasure" -> 0.1]; mesh["Wireframe"]]

so that

Jet0[]

produces

Mathematica graphics

but on the other hand

Jet0[{{1, 0}, {1.8, 1.8}, {0, 3}}]

produces

$Failed[Wireframe]

user21
  • 39,710
  • 8
  • 110
  • 167
chris
  • 22,860
  • 5
  • 60
  • 149

2 Answers2

6

There is a workaround involving Rationalize.

Jet0[pts0_: {{1, 0}, {1.8, 1.8}, {0, 2}}] := 
 Module[{xu, yu, n, m, knots, fx, fy, pr, mesh, t, r},
   pts=Rationalize[pts0,0.001];
  {xu, yu} = Transpose[pts];
  n = 2; m = Length[pts];
  knots = {ConstantArray[0, n + 1], Range[m - n - 1]/(m - n), 
     ConstantArray[1, n + 1]} // Flatten;
  fx[t_] = 
   xu.Table[BSplineBasis[{n, knots}, i - 1, t], {i, Length[pts]}];
  fy[t_] = 
   yu.Table[BSplineBasis[{n, knots}, i - 1, t], {i, Length[pts]}];
  pr = ParametricRegion[{{r fx[t], r fy[t]}, -1 <= t <= 1 && 
      0 <= r <= 1}, {t, r}];
  mesh = ToElementMesh[pr, "MaxBoundaryCellMeasure" -> 0.1];
  mesh["Wireframe"]]

works as expected:

 Jet0[{{1, 0}, {1.8, 1.8}, {0, 3}}]

Mathematica graphics

chris
  • 22,860
  • 5
  • 60
  • 149
4

DiscretizeRegion will work in place of ToElementMesh:

Jet0[pts_: {{1, 0}, {1.8, 1.8}, {0, 2}}] := 
 Module[{xu, yu, n, m, knots, fx, fy, pr, t, r},
  {xu, yu} = Transpose[pts];
  n = 2; m = Length[pts];
  knots = {ConstantArray[0, n + 1], Range[m - n - 1]/(m - n), 
     ConstantArray[1, n + 1]} // Flatten;
  fx[t_] = xu.Table[BSplineBasis[{n, knots}, i - 1, t], {i, Length[pts]}];
  fy[t_] = yu.Table[BSplineBasis[{n, knots}, i - 1, t], {i, Length[pts]}];
  pr = ParametricRegion[{{r fx[t], r fy[t]}, 0 <= t <= 1 && 0 <= r <= 1},
        {t, r}];
  DiscretizeRegion[pr, MaxCellMeasure -> {"Length" -> 0.1}]]

Jet0[{{1, 0}, {1.8, 1.8}, {0, 3}}]

Mathematica graphics

Michael E2
  • 235,386
  • 17
  • 334
  • 747
  • 1
    your answer is useful for people who are happy with DiscretizeRegion. According to @user21 I need ToElementMesh in order to be able to solve a PDE on it. – chris Jul 27 '15 at 20:11
  • 1
    @chris ToElementMesh@Jet0[{{1, 0}, {1.8, 1.8}, {0, 3}}] generally converts a MeshRegion to an ElementMesh with no problem. NDSolve should convert a MeshRegion automatically, too, but often one wants to set up the ElementMesh first before calling NDSolve. (The problem here is getting from a parametric description to any sort of mesh.) – Michael E2 Jul 27 '15 at 20:15
  • 2
    @chris, Ayy, I forgot there is a difference: Along the boundary, the quadratic vertices in converting a MeshRegion are placed on the linear boundary elements; in converting a Region, they are placed on the Region's boundary and thus are more accurate for solving PDEs. – Michael E2 Jul 27 '15 at 20:45
  • 3
    @MichaelE2, yes this is quite an important point, For numerics ToElementMesh is preferable. – user21 Jul 28 '15 at 07:12