How to assign nodes to faces of a 3D tetrahedral mesh (pdetool)

11 visualizzazioni (ultimi 30 giorni)
Hi everybody,
I have a 3D tetrahedral mesh on a hollow cylinder, where the cavity has a tree-like form (with 7 branches, i.e. 7 faces after using the "importGeometry" command).
My goal is to find the coordinates and the indexes of the nodes at the boundary of this domain, especially the nodes laying on the tree-like structure.
The best thing would be to find a way to link a boundary node to the face it belongs to using a built-in MATLAB function, but I don't know if it's possible since the topic is quite new.
I found a way to overcome the problem using the function "freeBoundary", which identifies boundary nodes and returns a new 2D triangulation on the boundary, made by nodes of the original triangulation in a new order (it seems random).
Now, using "find" I can link the 2D nodes to the 3D ones, but I fear this is a terrible way to solve the problem!
So I was looking for something more direct, for example a MATLAB function to link the coordinates automatically.
Any help would be appreciated.
Thanks,
Claudio
  2 Commenti
claudio
claudio il 7 Nov 2016
Modificato: claudio il 8 Nov 2016
If someone else should be interested in this topic in the future, the right way to solve the problem uses the following lines:
[p,e,t] = model.Mesh.meshToPet();
A = e.getElementFaces(3);
The matrix A contains the indexes of the triangles which lie on face 3, and so on with other faces.
Luke Benham
Luke Benham il 29 Giu 2020
Is there a way to use the returned A matrix to determine the Label of each face and the coordinates of such faces? For example if I understand your model, is there a way to find which face has FaceLabel F1,F2,F3... etc as would be shown using;
pdeplot(model,'FaceLabels','on');
thanks!

Accedi per commentare.

Risposte (1)

Divyam
Divyam il 5 Nov 2024
Thanks for providing the solution for assigning nodes to faces of a 3D tetrahedral mesh. Generating a mesh for your model and then using the "meshToPet" function on your mesh will indeed help you get the faces of the 3D model.
Here is sample code with @claudio's solution being used on a simple cylinder:
model = createpde();
% Define the geometry: A simple cylinder
R = 1; % Radius of the cylinder
H = 5; % Height of the cylinder
% Create the cylinder using the built-in function
gm = multicylinder(R, H);
% Assign the geometry to the PDE model
model.Geometry = gm;
% Generate a mesh for the model
generateMesh(model, 'Hmax', 0.5);
% Assuming model is your PDE model
[p, e, t] = model.Mesh.meshToPet();
A = e.getElementFaces(3);
To answer @Luke Benham's query, yes, you can use the returned A matrix to determine the label of each face and the coordinates of such faces by querying over each face using the "getElementFaces" function and finding the unique node indices for the respective face. Here is a sample code which can be used for the same:
% Get the number of faces in the geometry
numFaces = model.Geometry.NumFaces;
% Iterate over each face
for faceID = 1:numFaces
% Get the elements (triangles) on the current face
faceElements = e.getElementFaces(faceID);
% Extract the unique node indices for the current face
faceNodeIndices = unique(faceElements(:));
% Get the coordinates of these nodes
faceCoordinates = p(:, faceNodeIndices);
% Display the face label and its coordinates
fprintf('Face Label: F%d\n', faceID);
disp('Coordinates:');
disp(faceCoordinates);
end
For more information regarding the "meshToPet" function, refer to this documentation: https://www.mathworks.com/help/pde/ug/pde.femesh.meshtopet.html
Note: The use of "meshToPet" has been deemed as a legacy workflow by MathWorks and the newer features (if any) might not be compatible with the "FEMesh" object. In such a scenario, you can try to use the "freeBoundary" function to find the boundary nodes and faces. For more information regarding the "freeBoundary" function, refer to this documentation: https://www.mathworks.com/help/matlab/ref/triangulation.freeboundary.html

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by