3
$\begingroup$

I would like to mesh the region below in order to use it for a calculation by means of NDSolve. Could anyone help me to discretize this region for NDSolve using. Thank you very much.

Needs["NDSolve`FEM`"];

Rwg=7.0; RLiner=8.0; RRib=8.5; RExt=9.0; Theta1=0.0227; Theta2=0.00916; 

Ω=ImplicitRegion[
    !(x^2 + y^2>RLiner^2 && x^2 + y^2< RRib^2 && 0<y<x*Tan[Theta2])&&
 (y>=0 && x^2 + y^2>=Rwg^2 && x^2 + y^2<=RExt^2 && y<=x Tan[Theta1]),{x, y}];


Show[ RegionPlot[Ω], ImageSize -> 300]

ToElementMesh[Ω,MaxCellMeasure -> 0.0001]["Wireframe"]
$\endgroup$
  • $\begingroup$ Welcome to the site, you've done well to post your code, and we'd love to help, but we can't really check the code without values for all those constants. $\endgroup$ – Jason B. Mar 15 '16 at 15:41
  • $\begingroup$ The constants values are: Rwg=7.0; RLiner=8.0; RRib=8.5; RExt=9.0; Theta1=Pi/4; Theta2=Pi/8; Thank you. I would be very grateful for your reply. $\endgroup$ – Antony Mar 15 '16 at 15:46
  • $\begingroup$ When I enter this code, I get this result, so I have no error with version 10.3.1. What version are you using? The mesh is extremely fine and I assume memory intensive, what happens if you change it to MaxCellMeasure -> 0.1? $\endgroup$ – Jason B. Mar 15 '16 at 15:56
  • $\begingroup$ Antony, please use the edit link right under your question to add those details in the question itself. $\endgroup$ – MarcoB Mar 15 '16 at 15:56
  • 1
    $\begingroup$ Don't you just hate it when the OP changes the problem! $\endgroup$ – Michael E2 Mar 16 '16 at 11:34
4
$\begingroup$

Look at the boundary mesh generated for the region:

Needs["NDSolve`FEM`"];
Rwg=7.0;RLiner=8.0;RRib=8.5;RExt=9.0;Theta1=0.0227;Theta2=0.00916;
\[CapitalOmega]=ImplicitRegion[!(x^2+y^2>RLiner^2&&x^2+y^2<RRib^2&&0<y<x*Tan[Theta2])&&(y>=0&&x^2+y^2>=Rwg^2&&x^2+y^2<=RExt^2&&y<=x Tan[Theta1]),{x,y}];
ToBoundaryMesh[\[CapitalOmega]]["Wireframe"]

enter image description here

You see there is a line at y==0 which should not be there.

\[CapitalOmega][[1]] /. {x -> 8.4, y -> 0}
True

If you reformulate the region to:

LOWER = -1;
\[CapitalOmega] = 
 ImplicitRegion[! (x^2 + y^2 > RLiner^2 && x^2 + y^2 < RRib^2 && 
      LOWER <= y < x*Tan[Theta2]) && y >= 0 && x^2 + y^2 >= 49.` && 
   x^2 + y^2 <= 81.` && y <= 0.022703899831486306` x, {x, y}]

This example works as expected:

ToElementMesh[\[CapitalOmega]]["Wireframe"]

enter image description here

Now, various version of Mathematica use different (default) algorithms to to discretize regions. Even more so DiscretizeRegion and ToElementMesh may use different algorithms in the same version. What I have shown here is version 10.4

$\endgroup$
  • $\begingroup$ Thanks - this method works for version 10.2 as well so it solves OP's problem. I knew it was a good idea to call in the artillery $\endgroup$ – Jason B. Mar 17 '16 at 9:39
  • 1
    $\begingroup$ @JasonB, I always thought of myself as being a little more subtle than the artillery ;-) $\endgroup$ – user21 Mar 17 '16 at 19:00
2
$\begingroup$

I believe this is a bug: for some reason changing the conditional y<x Tan[] to y/x<Tan[] makes it work:

Rwg = 7.0; RLiner = 8.0; RRib = 8.5; RExt = 9.0;
Theta1 = 0.0227
Theta2 = 0.0091
\[CapitalOmega] = 
  ImplicitRegion[! (x^2 + y^2 > RLiner^2 && x^2 + y^2 < RRib^2 && 
       0 < y/x < Tan[Theta2]) &&
    (y >= 0 && x^2 + y^2 >= Rwg^2 && x^2 + y^2 <= RExt^2 && 
      y/x <= Tan[Theta1]), {x, y}];
Show[RegionPlot[\[CapitalOmega]], ImageSize -> 300]
<< NDSolve`FEM`
ToElementMesh[\[CapitalOmega], MaxCellMeasure -> 0.0001]["Wireframe"]

note the mesh is so dense the wireframe image is just black.

enter image description here

here it is with MaxCellMeasure->0.0025

enter image description here

v10.1/Windows. Minimal example of the issue:

 GraphicsRow@Table[
  RLiner = 8.; RRib = 8.5; 
  o2 = ImplicitRegion[
    RLiner^2 <= x^2 + y^2 <= RRib^2 && 0 <= y <= x Tan[Theta2], {x, 
     y}];
  Show[{RegionPlot[o2, PlotStyle -> Red] , 
    Plot[{x Tan[Theta2]}, {x, 0, 9}]},
   PlotRange -> {0, .8}] , {Theta2, {.09, .075}}]

enter image description here

$\endgroup$
  • $\begingroup$ Thank you. But, unfourtunately, running your code I have back "The implicit region is not a valid region to plot". Moreover, the region discretizaed does not corresponds to the region I want actually discretized $\endgroup$ – Antony Mar 16 '16 at 8:19
  • 1
    $\begingroup$ @Antony, what version of Mathematica are you using? Please answer this, as it could have a great effect on which answer is right for you. Also, what about using DiscretizeRegion@Ω? $\endgroup$ – Jason B. Mar 16 '16 at 8:51
  • $\begingroup$ @george2079 - I can confirm the bug in your minimal example is there in 10.1 but fixed by 10.2. I can also say that the bug appears to be confined to RegionPlot. If you replace the first argument of your Show command with {Plot[{x Tan[Theta2]}, {x, 0, 9}], DiscretizeRegion@o2} then it seems to work just fine. $\endgroup$ – Jason B. Mar 16 '16 at 10:24
  • $\begingroup$ @JasonB: I am using the Mathematica 10.2. I never used DiscretizedRegion@Ω $\endgroup$ – Antony Mar 16 '16 at 10:29
  • $\begingroup$ @Antony - Excellent, I can confirm that the code in the original post gives me an error in version 10.2 - now I can try to find a workaround. I've never used the FEM capabilities for NDSolve, so I don't really know the difference between an ElementMesh and a MeshRegion $\endgroup$ – Jason B. Mar 16 '16 at 10:33
1
$\begingroup$

It can sometimes help out if you Reduce your implicit description of the region first.

ToElementMesh[
  ImplicitRegion[! (x^2 + y^2 > RLiner^2 && x^2 + y^2 < RRib^2 && 
         0 < y < x*Tan[Theta2]) && (y >= 0 && x^2 + y^2 >= Rwg^2 && 
        x^2 + y^2 <= RExt^2 && y <= x Tan[Theta1]) // Reduce // Evaluate,
   {x, y}], MaxCellMeasure -> 0.0001]["Wireframe"]

Mathematica graphics

As has been pointed out, it's a very fine mesh. Here it is with MaxCellMeasure commented out:

Mathematica graphics

$\endgroup$
  • $\begingroup$ the OP changed the angles in the question to ones that cause an error. Interestingly with these new angles, I get the error with the Reduce but it runs fine without: i.stack.imgur.com/QHboS.png $\endgroup$ – Jason B. Mar 16 '16 at 10:10
1
$\begingroup$

This is all very confusing, different versions of Mathematica seem to react differently to the different region functions involved here. What I'm going to write here is only really applicable to version 10.2, I may put a note at the bottom for other versions.

Here is the region,

With[{Rwg = 7.0, RLiner = 8.0, RRib = 8.5, RExt = 9.0, 
  Theta1 = 0.0227, Theta2 = 0.00916},
 region = ! (x^2 + y^2 > RLiner^2 && x^2 + y^2 < RRib^2 && 
       0 < y < x*Tan[Theta2]) && (y >= 0 && x^2 + y^2 >= Rwg^2 && 
      x^2 + y^2 <= RExt^2 && y <= x Tan[Theta1]);
 ]

We try to create an ElementMesh from this region,

Needs["NDSolve`FEM`"];
ToElementMesh[ImplicitRegion[
   region, {x, y}],
  MaxCellMeasure -> 0.0001]["Wireframe"]

During evaluation of In[22]:= ToElementMesh::fememins: The mesh elements are not valid. A set of valid mesh element incidents needs to be positive integers and be able to form a complete sequence starting from 1 to the largest incident present. There are missing incidents; a complete sequence cannot be formed. >>

During evaluation of In[22]:= ToElementMesh::femtemnm: A mesh could not be generated. >>

(* $Failed["Wireframe"] *)

We try MichaelE2's trick of simplifying the conditionals,

ToElementMesh[ImplicitRegion[
   Evaluate@Reduce@region, {x, y}],
  MaxCellMeasure -> 0.0001]["Wireframe"]

During evaluation of In[24]:= ToElementMesh::fememib: The input has or generated an intersecting boundary and cannot be processed. >>

During evaluation of In[24]:= ToElementMesh::femtemnm: A mesh could not be generated. >>

(* $Failed["Wireframe"] *)

Still no luck. But if we first create a MeshRegion and then convert it to an ElementMesh, then it does work, even though it still gives some errors.

dregion = DiscretizeRegion[
   ImplicitRegion[
    Evaluate@Reduce@region, {x, y}],
   Method -> "Continuation", PerformanceGoal -> "Quality"];
ToElementMesh[dregion, MaxCellMeasure -> 0.0001]["Wireframe"]

DiscretizeRegion::drcm: Method->Continuation not able to resolve all components of dimension less than the embedding dimension 2; these may be omitted from the result. >>

ToElementMesh::femimq: The element mesh has insufficient quality of -20.1137. A quality estimate below 0. may be caused by a wrong ordering of element incidents or self-intersecting elements. >>

enter image description here

Edit

As shown in this screenshot, I only get this error in version 10.2, not in 10.1 or 10.3

enter image description here

$\endgroup$

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.