3
$\begingroup$

This question is about functions ToBoundaryMesh and ToElementMesh. I use both functions successively because I need information about "Coordinates" and "MeshElements" as an input for function SMTAddMesh in AceFEM.

  << NDSolve`FEM`

    XIO = {{0.`, 0.`, 0.`}, {2.5`, 0.`, 0.`}, {2.5`, 2.5`, 0.`}, {0.`, 
        2.5`, 0.`}, {0.`, 0.`, 2.5`}, {2.5`, 0.`, 2.5`}, {2.5`, 2.5`, 
        2.5`}, {0.`, 2.5`, 2.5`}};
    disksdata = {{{1.25`, 1.25`, 1.25`}, 0.9069579196494525`}};

    {xmin, xmax, ymin, ymax, zmin, 
       zmax} = {Min[XIO[[All, 1]]], Max[XIO[[All, 1]]], 
        Min[XIO[[All, 2]]], Max[XIO[[All, 2]]], Min[XIO[[All, 3]]], 
        Max[XIO[[All, 3]]]} // N;

    disks = And @@ 
       Map[(x - #[[1, 1]])^2 + (y - #[[1, 2]])^2 + (z - #[[1, 
               3]])^2 >= #[[2]]^2 &, disksdata];

    n1 = Cross[XIO[[3]] - XIO[[4]], XIO[[1]] - XIO[[4]]];
    n2 = Cross[XIO[[2]] - XIO[[1]], XIO[[5]] - XIO[[1]]];
    n3 = Cross[XIO[[3]] - XIO[[2]], XIO[[6]] - XIO[[2]]];
    n4 = Cross[XIO[[4]] - XIO[[3]], XIO[[7]] - XIO[[3]]];
    n5 = Cross[XIO[[1]] - XIO[[4]], XIO[[8]] - XIO[[4]]];
    n6 = Cross[XIO[[6]] - XIO[[5]], XIO[[8]] - XIO[[5]]];

    regcond = 
      disks && n1.({x, y, z} - XIO[[4]]) <=  0 && 
       n2.({x, y, z} - XIO[[1]]) <=  0 && 
       n3.({x, y, z} - XIO[[2]]) <=  0 && 
       n4.({x, y, z} - XIO[[3]]) <=  0 && 
       n5.({x, y, z} - XIO[[4]]) <=  0 && n6.({x, y, z} - XIO[[5]]) <=  0;

    reg = ImplicitRegion[regcond, {x, y, z}];

    bmesh = ToBoundaryMesh[reg, "MeshElementType" -> TetrahedronElement,
       "MeshOrder" -> 1, 
       MaxCellMeasure -> {"Length" -> 
          Min[xmax - xmin, ymax - ymin, zmax - zmin]/2}]
    bmesh["MeshElements"]
    bmesh["Coordinates"] // Length

ToBoundaryMesh gives result for number of coordiantes 680. If I use ToElementMesh where input is result of ToBoundaryMeshused before and the same options as before I get different number of coordiantes 817. I would like to know why is that?

elementmesh = 
 ToElementMesh[bmesh, "MeshElementType" -> TetrahedronElement,
  "MeshOrder" -> 1, 
  MaxCellMeasure -> {"Length" -> 
     Min[xmax - xmin, ymax - ymin, zmax - zmin]/2}]
elementmesh["MeshElements"]
elementmesh["Coordinates"] // Length

I would also like to know if there is a way how to make the same mesh if I run the code again, because now mesh is generated randomly and I get different mesh every time I run it. I also wonder if there is possibility to get actual "MeshElements" directly from ToBoundaryMesh, now I get Automatic as an answer.

$\endgroup$
  • 1
    $\begingroup$ I would say that ToBoundaryMesh yields a triangle mesh, consisting solely of boundary vertices and boundary triangles while ToElementMesh` yields a fulldimensional tetrahedron mesh, containing both the boundary and the interior vertices. $\endgroup$ – Henrik Schumacher Dec 22 '17 at 15:31
  • 1
    $\begingroup$ You get the actual triangles of bmesh with bmesh["BoundaryElements"] and you can see the mesh with bmesh["Wireframe"] $\endgroup$ – Henrik Schumacher Dec 22 '17 at 15:41
  • $\begingroup$ Any idea how to persuade ToElementMesh to generte each time the same mesh? $\endgroup$ – NZupan Dec 27 '17 at 9:03
  • 1
    $\begingroup$ Why do need ToElementMesh to generate mesh with the same number of elements each time? As long as the approximation to the boundary is good, there should be no problem? What is it that you are trying to do? $\endgroup$ – user21 Dec 28 '17 at 10:44
  • $\begingroup$ Thanks for your answers everyone, it is all clear now. I needed the same mesh to rule out some randomly appearing bug. I found a way around it, with simply saving already generated mesh and using it again. $\endgroup$ – NZupan Dec 28 '17 at 11:42
2
$\begingroup$

I am not sure I understand your question 100%. The fact that the number of coordinates is different is because one is a boundary mesh (only the hull is meshed) and the other is a full mesh. This full mesh also has interior coordinates which the boundary mesh does not have. This is documented in the ElementMesh creation tutorial and the ref pages for ToBoundaryMesh and ToElementMesh

For the second question, the randomness comes from the underlying tetrahedralization software TetGen. There is no way to control this from outside of TetGen. I think it would be more robust if your algorithm did not depend on the meshing algorithm to return an exact number of elements.

$\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.