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

# How to generate edge-information from a pde mesh?

##### 2 Comments

### Accepted Answer

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

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

For more information on generateMesh function, please refer to

% 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 Comments

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!

### More Answers (0)

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!