Mathematica Asked by S.B.MD.Khaja Moinuddin on December 29, 2020
I want to create a mesh with the following
The rows and columns control. For example, a mesh of 6 by 3. But the code shown below has no control over rows and columns. Instead, it has some MaxCellMeasure
option.
The node numbering starting from the bottom and going left to right and elements also numbered left to right starting from the bottom left corner element. But the code below has no control over node numbering and element numbering.
Please help me.
<<NDSolve`FEM`
m2 =
ToElementMesh[
Rectangle[{0, 0}, {254, 101.6}],
"MeshElementType" -> QuadElement,
MaxCellMeasure -> {"Area" -> 2000/4},
"MeshOrder"->1];
Show[
m2["Wireframe"],
m2["Wireframe"["MeshElement" -> "PointElements", "MeshElementIDStyle" -> Red]]]
For FEM the node and/or element numbering is not relevant as long as the nodes and incidents return a valid mesh. There are similar examples of what you want in the documentation here. Here is a way to do it.
Needs["NDSolve`FEM`"]
nx = 6;
ny = 3;
{xStart, xStop} = {0, 1};
{yStart, yStop} = {1, 3/2};
coordinates =
Flatten[ Table[{x, y}, {y, yStart, yStop, (yStop - yStart)/ny}, {x,
xStart, xStop, (xStop - xStart)/nx}], 1];
incidents = Flatten[Table[
{(j - 1)*(nx + 1) + i, (j - 1)*(nx + 1) + i + 1,
j*(nx + 1) + i + 1, j*(nx + 1) + i}
, {j, 1, ny}, {i, 1, nx}], 1];
m2 = ToElementMesh["Coordinates" -> coordinates,
"MeshElements" -> {QuadElement[incidents]}];
Show[
m2["Wireframe"["MeshElement" -> "PointElements",
"MeshElementIDStyle" -> Red]],
m2["Wireframe"["MeshElement" -> "MeshElements",
"MeshElementIDStyle" -> Blue]]]
Answered by user21 on December 29, 2020
MeshTools package contains some functions useful for such tasks (e.g. structured mesh with element number control).
Get["MeshTools`"]
(* Structured mesh on Rectangle with specified number of elements per edge. *)
mesh = RectangleMesh[{0, 0}, {254, 101.6}, {12, 5}]
(* Utility function to display mesh with node and element numbering. *)
showMeshNumbering[mesh_ElementMesh] := Show[
mesh["Wireframe"[
"MeshElement" -> "MeshElements",
"MeshElementIDStyle" -> Blue,
Axes -> True
]],
Graphics[
{Point[mesh["Coordinates"]],
MapIndexed[
Text[Style[First@#2, Red], #1, {-1, -1}] &,
mesh["Coordinates"]
]}
]
]
showMeshNumbering[mesh]
Apparently default node and element numbering of RectangleMesh
is not the one you want, so we define it in other direction and reflect it over y==x
diagonal line.
mesh = TransformMesh[
RectangleMesh[{0, 0}, Reverse@{254, 101.6}, Reverse@{12, 5}],
ReflectionTransform[{-1, 1}, {0, 0}]
]
showMeshNumbering[mesh]
Answered by Pinti on December 29, 2020
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP