How to generate edge-information from a pde mesh?

12 次查看(过去 30 天)
Hi there,
My task is generating a list of all edges in mesh. (ps. I mean not edges of geometry, i saw some function there, which shows edges of a geometry, they are performed bases on interacting between mesh and geometry.)
For a mesh i can easily get access to elements (3d : tetraeder). I am considering break down each element into four faces. It's easy for me to get edges from faces (2nd step).
(elements -> faces -> edges)
now the problem is in 1st step. A 3d quadratic case, that means an element consists of ten nodes. I have no idea which node is vertices which is in middle of edges.
The way to create mesh :
cubic = [100, 50, 20];
model = createpde(thermal="transient");
geo = multicuboid(cubic(1), cubic(2),...
cubic(3), 'Zoffset', 0);
model.Geometry = geo;
generateMesh(model, GeometricOrder='quadratic');
pdemesh(model)
Is there any tips for me?
Thank you all.
Best regards
Kun
  2 个评论
Saurav
Saurav 2024-10-5
When dealing with quadratic elements in a finite element mesh, each 3D tetrahedral element typically consists of ten nodes: four corner nodes (vertices) and six mid-edge nodes. Identifying which nodes are vertices and which are mid-edge nodes is crucial for generating a list of edges.
In a quadratic tetrahedral element, the nodes are typically arranged as follows:
  • Nodes 1-4: The corner nodes (vertices) of the tetrahedron.
  • Nodes 5-10: The mid-edge nodes, positioned at the midpoints of the edges connecting the corner nodes.
For a quadratic tetrahedral element, you can extract four triangular faces. Each face is defined by three corner nodes and three mid-edge nodes.
Each triangular face has three edges. The edges can be extracted using combinations of the corner and mid-edge nodes.

请先登录,再进行评论。

采纳的回答

Umar
Umar 2024-10-6

Hi @Kun Cheng ,

To address your task of generating a list of all edges in a quadratic 3D mesh, I built upon the provided code and incorporate a method to differentiate between the vertices and mid-edge nodes in a tetrahedral element. In this context, each tetrahedral element consists of 10 nodes: 4 corner nodes, 6 edge midpoints, and 1 center node. Here is an updated MATLAB code snippet that generates the mesh and lists all edges correctly:

% Define the cubic dimensions
 cubic = [100, 50, 20];
% Create a PDE model for thermal transient analysis
model = createpde(thermal="transient");

Note: createpde requires Partial Differential Equation Toolbox.

% Create geometry using multicuboid
geo = multicuboid(cubic(1), cubic(2), cubic(3), 'Zoffset', 0);
model.Geometry = geo;

For more information on multicubiod function, please refer to

https://www.mathworks.com/help/pde/ug/multicuboid.html?searchHighlight=multicuboid&s_tid=srchtitle_support_results_1_multicuboid

% Generate a quadratic mesh
model = generateMesh(model, GeometricOrder='quadratic');

For more information on generateMesh function, please refer to

https://www.mathworks.com/help/pde/ug/pde.pdemodel.generatemesh.html?searchHighlight=generateMesh&s_tid=srchtitle_support_results_1_generateMesh

% Visualize the generated mesh
pdemesh(model);

For more information on pdemesh function, please refer to

https://www.mathworks.com/help/pde/ug/femodel.pdemesh.html?s_tid=doc_ta

% Get mesh information
mesh = model.Mesh;
% Initialize an array to hold edges
edges = [];
% Extract edge data from the mesh
for i = 1:size(mesh.Elements, 2) % Loop through each element
  % Get vertex indices for the current element (tetrahedron)
  vertexIndices = mesh.Elements(:, i);
    % Define edges for tetrahedron (6 unique edges)
    elementEdges = [
        vertexIndices(1), vertexIndices(2);
        vertexIndices(1), vertexIndices(3);
        vertexIndices(1), vertexIndices(4);
        vertexIndices(2), vertexIndices(3);
        vertexIndices(2), vertexIndices(4);
        vertexIndices(3), vertexIndices(4)
    ];
    % Append to edges array (removing duplicates)
    edges = [edges; unique(elementEdges, 'rows')];
  end
% Remove duplicate edges (if any)
edges = unique(sort(edges, 2), 'rows');
% Display all unique edges
disp('Unique Edges in the Mesh:');
disp(edges);

As you can see above in the code snippet, the cubic geometry is created using multicuboid. The generateMesh function creates a quadratic mesh with specified geometric order. The Edge Extraction loops through each tetrahedral element in mesh.Elements, where each column represents an element.For each tetrahedron, define its six edges based on its four vertices, collect these edges into an array while ensuring uniqueness by sorting and removing duplicates.

Each edge is represented by its two endpoint node indices. Sorting ensures that (A, B) is treated the same as (B, A). The approach uses MATLAB's built-in functions like unique to streamline the process of eliminating duplicate edges.

This code should fulfill your requirement to generate and list all unique edges from a quadratic tetrahedral mesh while maintaining clarity and efficiency.

If you have further questions or need additional modifications, feel free to ask!

  2 个评论
Kun Cheng
Kun Cheng 2024-10-6
Hi, Umar
i got it. It seems linear geometric order case. If im not get it wrong, the first 4 components of an element should be id for vertices right ? This information is useful.
Thank you sir.
Kun
Umar
Umar 2024-10-6

Hi @Kun Cheng ,

To address your query about the nature of tetrahedral elements in a quadratic 3D mesh and the identification of edges, it is essential to clarify how tetrahedral elements are structured and how they relate to the edges you’re interested in.

Understanding Tetrahedral Elements

A tetrahedron is defined by four corner vertices. In your context, each tetrahedral element has:

4 corner nodes (vertices) 6 edge midpoints 1 center node

This results in a total of 10 nodes per tetrahedron, which is typical for quadratic elements. The vertices are critical as they form the basis for defining the edges of the tetrahedron.

Edge Identification in Tetrahedra

As you correctly noted, the first four components of each element in mesh.Elements indeed represent the IDs of these corner vertices. The edges are formed by pairs of these vertices. Specifically, for a given tetrahedron defined by vertices (V_1, V_2, V_3)and (V_4), the edges can be enumerated as follows:

1. (V_1 - V_2) 2. (V_1 - V_3) 3. (V_1 - V_4) 4. (V_2 - V_3) 5. (V_2 - V_4) 6. (V_3 - V_4)

The provided MATLAB code effectively extracts these edges and ensures that duplicates are removed through sorting and using the unique function.

After glancing through the code, you probably noticed that using functions like pdemesh(model) not only helps visualize the generated mesh but can also assist in debugging by allowing you to visually verify that edges are correctly defined.

In case, if you’re looking to extend functionality, consider implementing methods to compute edge lengths or connectivity information between adjacent tetrahedra based on shared edges.

If you require further clarification on specific functions or additional features for your mesh generation tasks, feel free to reach out!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Geometry and Mesh 的更多信息

产品


版本

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by