1
$\begingroup$

I am trying to use Mathematica's FEM capabilities, but I want to generate my own QuadElement mesh. (The key word in here is trying.)

Needs["NDSolve`FEM`"]
nx = ny = 5;
coordinates = 
  Flatten[ Table[{-Cos[(π/nx) i], -Cos[(π/ny) j]}, {i, 0, nx, 1}, {j, 0, ny, 1}], 1];
ToElementMesh[Rectangle[{-1, -1}, {1, 1}], 
  "Coordinates" -> coordinates, 
  "MeshElementType" -> QuadElement]["Wireframe"]

I am getting the error messages:

Unknown option Coordinates for ToElementMesh
Unknown option MeshElementsType for ToElementMesh

But both options are described in the Mathematica documentation.

Where is my mistake? Or worse, where are my mistakes? :)

Edit

While changing the code from "MeshElements" to "MeshElementType", I forget the "s" at the end and wrote "MeshElementsType".

$\endgroup$

closed as off-topic by Pinti, MarcoB, Alex Trounev, JungHwan Min, Bill Watts Feb 2 at 3:27

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Pinti, MarcoB, Alex Trounev, JungHwan Min, Bill Watts
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    $\begingroup$ I suggest that you read documentation (about possible syntax) for ToElementMesh carefully. You are mixing function syntax with region (Rectangle) and syntax with rules ("Coordinates"->... and "MeshElements"->...). $\endgroup$ – Pinti Jan 30 at 15:13
  • 1
    $\begingroup$ Also, it's "MeshElementType" not "MeshElementsType". Mind the "s". $\endgroup$ – Henrik Schumacher Jan 30 at 15:14
1
$\begingroup$

If you want to prescribe the points, you have to generate the mesh yourself. With the function getGridQuads below, you may try this:

nx = ny = 5;
R = ToElementMesh[
  "Coordinates" -> Tuples[-Cos[Subdivide[0., Pi , nx - 1]], 2],
  "MeshElements" -> {QuadElement[getGridQuads[nx, ny, False, False]]}
  ]

Code dump:

getGridQuads = 
  Compile[{{m, _Integer}, {n, _Integer}, {xclosed, True | False}, {yclosed, True | False}},
   Block[{a1, a2, a3, a4, b1, b2, quads, qq, mm, nn},
    b1 = Boole[xclosed];
    b2 = Boole[yclosed];
    mm = m - b1;
    nn = n - b2;

    quads = Flatten[Table[
       qq = Table[
         a1 = mm (j - 1) + i;
         a2 = mm (j - 1) + i + 1;
         a3 = mm j + i;
         a4 = mm j + i + 1;
         {a1, a2, a4, a3},
         {i, 1, mm - 1}];

       If[xclosed,
        Join[qq,
         a1 = mm (j - 1) + mm;
         a2 = mm (j - 1) + 1;
         a3 = mm (j) + 1;
         a4 = mm (j) + mm;
         {{a1, a2, a3, a4}}
         ],
        qq
        ]
       ,
       {j, 1, nn - 1}], 1];

    If[yclosed,
     qq = Table[
       a1 = mm (nn - 1) + i;
       a2 = mm (nn - 1) + i + 1;
       a3 = i;
       a4 = i + 1;
       {a1, a2, a4, a3},
       {i, 1, mm - 1}];
     If[xclosed,
      a1 = mm nn;
      a2 = mm (nn - 1) + 1;
      a3 = mm;
      a4 = 1;
      qq = Join[qq, {{a1, a2, a4, a3}}]
      ];
     Join[quads, qq],
     quads
     ]
    ],
   CompilationTarget -> "C",
   RuntimeOptions -> "Speed"
   ];
$\endgroup$

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