7
$\begingroup$

Bug introduced in 10.1 and persisting through 10.2 or later 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

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]

$\endgroup$
  • 2
    $\begingroup$ I can reproduce this on Windows in 10.1 but it has been fixed in 10.2. $\endgroup$ – RunnyKine Jul 26 '15 at 20:21
  • $\begingroup$ @RunnyKine thanks! Do you think it is the source of my problem in the linked question? Should I retag my question as bug? as 10.1? $\endgroup$ – chris Jul 26 '15 at 20:27
  • $\begingroup$ I don't think that's the source of the problem. If you can rewrite the ParametricRegion as an ImplicitRegion you may have better chances. For some reason, Mathematica doesn't know how to handle ParametricRegion properly. $\endgroup$ – RunnyKine Jul 26 '15 at 20:42
  • $\begingroup$ @RunnyKine would you know how to do this? $\endgroup$ – chris Jul 26 '15 at 21:13
  • 2
    $\begingroup$ Including the word "fixed" on the first line is going to make this post disappear from the bug-radar. $\endgroup$ – Szabolcs Jul 27 '15 at 20:14
4
$\begingroup$

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

$\endgroup$
  • 1
    $\begingroup$ 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. $\endgroup$ – chris Jul 27 '15 at 20:11
  • 1
    $\begingroup$ @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.) $\endgroup$ – Michael E2 Jul 27 '15 at 20:15
  • 2
    $\begingroup$ @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. $\endgroup$ – Michael E2 Jul 27 '15 at 20:45
  • 3
    $\begingroup$ @MichaelE2, yes this is quite an important point, For numerics ToElementMesh is preferable. $\endgroup$ – user21 Jul 28 '15 at 7:12
5
$\begingroup$

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

$\endgroup$
  • $\begingroup$ I thought the error with BoundaryDiscretizeRegion suggested a numerical issue. +1 $\endgroup$ – Michael E2 Jul 27 '15 at 20:06

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.