Import mesh from Matlab to Ansys with additional properties of each element

I have obtained a finite element mesh of an image using im2mesh file by JieXian Ma. I want to export it to Ansys, but I need not to just export a mesh (it's already implemented in this file), but first I have to assign Modulus of Elasticity value to each of the node.
From the image I have I've also obtained color intensity matrix (in grayscale). I multiplied it by Elasticity Modulus I have (it represents the non-homogeneity of a bone) and then I need to somehow assign this matrix's values to the mesh.
Mesh consists of verticies (n-by-2) (x and y coordinates) and triangles (m-by-3) (numbers of verticies building up a triangle) vectors. The matrix is a square one.
Also I consider removing zeros from the matrix, as it's not needed in the mesh creation, but then it transforms into a long vector, longer than previous ones and I don't know how to do it normally.
So, maybe someone knows how to assign values to the mesh?
Below are the images of the mesh, bone image and vectors and a color matrix I have.

10 Comments

Also I consider removing zeros from the matrix, as it's not needed in the mesh creation, but then it transforms into a long vector, longer than previous ones and I don't know how to do it normally.
You probably did not index into matrix properly.
The way you could tackle the problem, the fastest - create a simple model in ANSYS with triangular mesh with few elements. Export it to the .bdf or whichever NASTRAN format. Open it with text editor and find the points, material and elements definition so you can replace with your data. You are looking for CTRIA3, here is some documentation. https://help.autodesk.com/view/NINCAD/2022/DEU/?guid=GUID-F14EFBCD-CF81-4F42-A459-0B1B8D871A6C
I checked the data about CTRIA, thanks for this.
And exported bdf from ANSYS, but it created its own elements instead of CTRIA
I found a code exporting the mesh from MATLAB to ANSYS (also in this large program, thanks JieXian Ma), made some small corrections and managed to import it into ASYS. Now I need to understand how to apply different material to each node/element (it's the same bone material, but with different Elastic Modulus value)
Sorry for complete re-editing of the answer, I just made it too quickly before I completely understood how to import mesh from MATLAB to ANSYS
Okay, I would suggest to take a step back and try to understand your problem and how to get to the end goal - which is your question.
MATLAB - do MATLAB Onramp first, your institution may have access to courses on MATLAB Academy, they are useful too.
FEA - Try to understand the concepts first and the usual workflow of simulation: geometry, material definition, meshing, boundary conditions. You only need first three for now.
At least I don't understand how material definition is connected with GRID points. It's not, because it's the geometry definition. I see that you have defined the material, you should mesh it too, with triangular elements. Once you do that, and export the file you will find CTRIA section. From there it will be obvious where material properties are assigned.
Then comes the MATLAB part, where you use your data to write an input file that adheres to NASTRAN format. Maybe your supervisor imagined it different way, consult him.
Yes, I found the column containing material data for each element (I assigned 4 materials to different parts of a mesh and exported a bdf file).
As I understand, in Matlab I need to match values of matrix with corresponding node at the same pixel of an image, then calculate average between 3 nodes of an element and apply the resulting value to the element.
But I don't understand the part where I need to match a matrix with nodes, including separation non-zero matrix elements from zero elements (representing white color, i.e. air, which I don't need).
Regarding matrix indexing, I was using a(a==0) = [] to remove zeros (white color) and then it became a n-by-1 vector.
Let's split this into tasks:
  1. Obtain mesh - you have vert and tria, tria describes the vertices that form one triangle.
  2. Identify mesh to be removed - removing the parts that represent air. So, you have an RGB (I assume) image and it has 3 channels - one pixel in the image is described by 3 elements in a 3D array that share the same row and column. If the node represents air then all three of those are equal to 0. How do you code that? Do the courses please or figure it out by yourself.
  3. Remove identified nodes and elements - You will get indices of nodes that correspond to air and you have to remove triangles that consist of these identified nodes, nodes too afterwards. You should have the mesh now, but maybe it will need some tuning/fixing.
  4. Applying stiffness to element - find color intensities of nodes that form each triangle, average them and you have the number.
I think my explanation was hard to understand: the mesh is okay, I already have it built only on the "bone", without "air" (I chose all the phases except the last one of segmented image)
I mean the color matrix, which I get by the functions
imread
rgb2gray
As a result I have following matrix in grayscale (1D array) attached here. Now I want to match the values of this matrix with the nodes of the mesh.
I kind of understand how to write it into bdf input file, but don't know how to code a loop, which goes through nodes and then checks if the position of a node (x and y) matches the position of corresponding pixel on the matrix (row and column)
I hope I explained it better
I get it now, this could be interesting for people with image processing knowledge, as I don't know a lot about it. I think you should post another question that focuses only on that aspect of your task.
When you don't remove the "air", what's the output of below code? It could be that each pixel is represented by a grid that has evenly spaced points by 1.
numel(unique(vert(:,1)))
numel(unique(vert(:,2)))
If it's related to the size of gray_matrix, then it's great.
Maybe you can use scatteredInterpolant for this purpose, however, not sure if it's appropriate in this case.
Okay, I will try to use this code and tell about results later. And will post a new question 🫡
For now thanks a lot for help with file export and other things!
I created a mesh without removing "air" and I still got less nodes than elements in a matrix, so it seems there should be some other way. Or I don't undestand something
numel(unique(vert(:,1))) gave 8743
numel(unique(vert(:,2))) gave 9250

Sign in to comment.

Answers (1)

Hi Maksim,
In the new version of Im2mesh package, the mesh can be exported as msh file. You can open the msh file in Gmsh (free software) and save the mesh as other file format (see below).
inp (Abaqus), key (LSDYNA),
celum, cgns, diff (Diffpack 3D),
unv (I-deas Universal), ir3 (Iridum), med,
mesh (INRIA Medit), mail (CEA Triangulation),
m (Matlab), bdf (Nastran Bulk Data File),
off (Object File Format), p3d (Plot3D Structured Mesh),
stl (STL surface), wrl (VRML surface), vtk (VTK),
dat (Tochnog), ply2 (PLY2 Surface), su2,
neu (GAMBIT Neutral File), x3d, _0000.rad (RADIOSS BLOCK)
I'm not sure which format is better for ANSYS. Good luck!

Categories

Asked:

on 6 May 2024

Answered:

on 6 Apr 2025

Community Treasure Hunt

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

Start Hunting!