3
$\begingroup$

I am quite new at FEM. I was trying to create a triangular mesh of a rectangular region. I wanted to do something very basic: Discretize the domain using squares and then subdivide each square into two rectangles. Here is the code:

Needs["NDSolve`FEM`"] 
Nx = 4;
Ny = Nx;
Dx = Subdivide[-2, 2, Nx]
Dy = Subdivide[-2, 2, Ny]
vertcoords = Tuples[{Dx, Reverse@Dy}]
LTidx = {(#1 - 1)*(Nx + 1) + #2, (#1)*(Nx + 1) + #2, (#1)*(Nx + 
         1) + #2 + 1} & @@@ Tuples[{Range[1, Nx], Range[1, Ny]}];
UTidx = {(#1 - 1)*(Nx + 1) + #2 + 
      1, (#1 - 1)*(Nx + 1) + #2, (#1)*(Nx + 1) + #2 + 1} & @@@ 
   Tuples[{Range[1, Nx], Range[1, Ny]}];
Tidx = Flatten[Transpose@{LTidx, UTidx}, 1]
\[CapitalOmega] = 
 ToElementMesh["Coordinates" -> vertcoords, 
  "MeshElements" -> {TriangleElement[Tidx]}]
\[CapitalOmega]["Wireframe"]

The plot looks fine to me, but then I get a warning:

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

I am not entirely sure what's wrong here.

Thanks

$\endgroup$

1 Answer 1

3
$\begingroup$

As the message suggests, the ordering of your incidents is wrong (but in your case consistent). So the fix is simple:

\[CapitalOmega] = 
 ToElementMesh["Coordinates" -> vertcoords, 
  "MeshElements" -> {TriangleElement[Reverse /@ Tidx]}]
\[CapitalOmega]["Wireframe"]
$\endgroup$
1
  • $\begingroup$ Thanks for your response, It took me a minute to see what was wrong. When I was writing the 'loop' for the vertex indexes, I was assuming the coordinates to be ordered 'row-wise' from the top left to the bottom right. So, another fix could be to apply ToElementMesh with the arguments "Coordinates" -> Reverse[Reverse /@ vertcoords], "MeshElements" -> {TriangleElement[Tidx]}. The double reverse seems nasty, would you have a fix for that?. $\endgroup$
    – NoobNoob
    Mar 8 at 19: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.