Inquiry Regarding Mesh Alignment Issue in v2m Output

27 views
Skip to first unread message

Kamran Ali Ahmed

unread,
Feb 22, 2024, 9:33:12 PM2/22/24
to iso2mesh-users
Dear Dr. Fang,

I am currently trying to modify the save2abaqus function to include node sets on various cross-sections along a direction and write to the Abaqus input file to be part of the model.  I have successfully amended the function to create a node set of all nodes at say X=0 location. However, I am facing challenges in generating aligned nodes at desired locations, such as X=0 or length L, within my model. The iso2mesh outputs nodes coordinate at (-0.45, 2.35, 1.44) which is not at the X=0 location. Similarly, there are nodes beyond the mesh dimensions (from 0 to L=10) defined in the code (nodes at X=10.44). 

I have experimented with adjusting various parameters in v2m, including the resolution and isovalue, in an attempt to generate nodes closer to the desired locations. However, despite these efforts, I have not achieved the precise alignment required for my model.

I suspect that there may be factors related to the coordinate system or scaling used by iso2mesh and its output that I may not fully understand. Additionally, I am uncertain whether any additional post-processing steps or coordinate transformations could be applied to address this alignment issue effectively.

I would greatly appreciate any insights, recommendations, or guidance you could give me to help me align the generated mesh with the desired cross-sections in my model.

Thanks,
Kamran

Qianqian Fang

unread,
Feb 22, 2024, 11:17:20 PM2/22/24
to iso2mes...@googlegroups.com, Kamran Ali Ahmed

it would be much easier to understand what you wanted to achieve if you attach a figure

I am not sure what type of "alignment" you wanted to see. if you call iso2mesh v2m with 'cgalmesh' as the meshing method, it does not give you the edge/corner features, instead, the surfaces near edges or corners are slightly rounded. you can set opt.distbound to a smaller value to make the sharper edges more prominent (see the built-in helloworld example)

if you want to mesh sharp features from the volume, you will need to use the surface-based meshing workflow, like we described in Fig. 3 of our brain2mesh paper https://doi.org/10.1117/1.NPh.7.1.015008

an example of meshing a multi-layered cube embedding a cylinder with sharp edge features, like shown in another of our papers

https://www.spiedigitallibrary.org/journals/journal-of-biomedical-optics/volume-27/issue-8/083014/BlenderPhotonics--an-integrated-open-source-software-environment-for-three/10.1117/1.JBO.27.8.083014.full#f7

can be created using the below commands

https://github.com/fangq/mmc/blob/master/mmclab/example/demo_mcxyz_skinvessel.m#L11-L25


using surfboolean.m and slice a mesh with a meshabox() created bounding box to create sharp/flat boundaries is another way to create meshes of precise dimensions.


but again, without seeing your plots, it is hard for me know for certain my above comments was relevant.

--
You received this message because you are subscribed to the Google Groups "iso2mesh-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to iso2mesh-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/iso2mesh-users/93e98ef7-7644-4db1-a988-5b1b8ce490acn%40googlegroups.com.

Kamran Ali Ahmed

unread,
Feb 25, 2024, 4:12:50 PM2/25/24
to iso2mesh-users
Hello Dr. Fang,

I appreciate your detailed response. 

I am trying to apply periodic boundary conditions on opposite faces of a cube, as a test case for my research problem. For this type of boundary conditions to be applied it is necessary to trace nodes on opposite faces to simulate periodicity. So my workflow includes creating a volume mesh in iso2mesh using the following mesh settings:

% Defining the size of the cube and mesh grid
L = 1;
N = 10;
% Create a grid of points along each axis
[x, y, z] = meshgrid(linspace(0, L, N), ...
linspace(0, L, N), ...
linspace(0, L, N));

% Initialize the volumetric image
cubeVolume = zeros(size(x));
% Define the coordinates of the vertices of the cube
cubeVertices = [0 0 0; L 0 0; L L 0; 0 L 0; ...
0 0 L; L 0 L; L L L; 0 L L];
% Define the faces of the cube
cubeFaces = [1 2 3 4; % Bottom face
5 6 7 8; % Top face
1 2 6 5; % Front face
2 3 7 6; % Right face
3 4 8 7; % Back face
4 1 5 8]; % Left face

% Loop through each face of the cube and set the corresponding voxels in the volumetric image to 1
for i = 1:size(cubeFaces, 1)
% Get the vertices of the current face
faceVertices = cubeVertices(cubeFaces(i, :), :);
% Define a normal vector for the current face
normal = cross(faceVertices(2,:) - faceVertices(1,:), faceVertices(3,:) - faceVertices(1,:));
normal = normal / norm(normal);
% Compute the distances of each voxel from the plane defined by the face
distances = (x - faceVertices(1,1)) * normal(1) + ...
(y - faceVertices(1,2)) * normal(2) + ...
(z - faceVertices(1,3)) * normal(3);
% Set the voxels inside the cube face to 1
cubeVolume(distances >= 0) = 1;
end

opt.radbound= 0.1;
opt.distbound=0.01;
[node, element, face] = v2m(cubeVolume, 0.05, opt, 2, 'cgalsurf');
element(:,[1,2,3,4])= element(:,[1,2,4,3]);

The generated mesh looks like this:
Matlab_1.PNG

Once the mesh is generated, the following code traces nodes on face X=Y=Z=0 and X=Y=Z=L to form a set of nodes to be written into the Abaqus input file. The inequality conditions are used to address an issue which is discussed later. 

% Define column ranges for X, Y, and Z faces
col_ranges = [1, 2, 3]; % for X, Y, and Z faces

% Define conditions for X, Y, and Z faces
conditions = {'>=', '<='}; % for X=L, X=0, Y=L, Y=0, Z=L, and Z=0

% Define corresponding values for conditions
values = {N, 0}; % for X=L, X=0, Y=L, Y=0, Z=L, and Z=0

% Define output file
output_file = 'selected_nodes_XYZL.inp';
entries_per_line = 16;
fid = fopen(output_file, 'w');

% Defining multiple sets of indices
set_names = {'Set_XN', 'Set_X0', 'Set_YN', 'Set_Y0', 'Set_ZN', 'Set_Z0'};
for col_idx = 1:length(col_ranges)
col = col_ranges(col_idx);
for cond_idx = 1:length(conditions)
condition = conditions{cond_idx};
value = values{cond_idx};
% Read specific column within the defined range and condition
if strcmp(condition, '>=')
indices = find(node(:, col) >= value);
elseif strcmp(condition, '<=')
indices = find(node(:, col) <= value);
else
error('Invalid condition specified.');
end

% Evaluate condition
selected_rows = node(indices, :);
selected_node = indices;
% Print node set to file
set_id = (col_idx - 1) * length(conditions) + cond_idx; % Unique ID for each node set
fprintf(fid, '*NSET, nset=%s, instance=Part-1-1\n', set_names{set_id}); % Use the corresponding name
for i = 1:length(indices)
fprintf(fid, '%d', indices(i));
% Check if it's not the last entry
if i < length(indices)
% Check if the number of entries printed is a multiple of entries per line
if mod(i, entries_per_line) == 0
fprintf(fid, '\n');
else
fprintf(fid, ', ');
end
else
fprintf(fid, '\n');
end
end
end
end

fprintf(fid, '*End Assembly\n');
fclose(fid);
plotmesh(node,element(:,1:4))

plotmesh(node,element(:,1:4))
mesh2abaqus(node,element,'output_cubetest.inp')

% Open the Abaqus input file in append mode
fid = fopen('output_cubetest.inp', 'a');

% Open the generated node sets file for reading
generated_node_sets_file = fopen(output_file, 'r');

% Read and append each line from the generated node sets file to the Abaqus input file
tline = fgetl(generated_node_sets_file);
while ischar(tline)
fprintf(fid, '%s\n', tline);
tline = fgetl(generated_node_sets_file);
end

% Close both files
fclose(fid);
fclose(generated_node_sets_file);

Doing so results in an Abaqus input file which when imported looks as follows (this image shows the selection of nodes at Z<=L). As it can be seen 6 node sets are created, one set at each face of the cube to apply the Periodic boundary condition. 

Abaqus_1.PNG

Now the issue is iso2mesh generates nodes beyond the specified mesh grid 0 to L. Some nodes have co-ordinates of less than zero and others have co-ordinates greater than L which forced me to use inequality conditions to trace all nodes at a face lying beyond the defined mesh grid. I want to create a mesh that exactly follows the mesh gird input and generates nodes at and between 0 and L which makes it easy to trace them later and avoid confusion.

Also, any other suggestion to trace nodes at a particular face 

Qianqian Fang

unread,
Feb 25, 2024, 4:19:26 PM2/25/24
to iso2mes...@googlegroups.com, Kamran Ali Ahmed

iso2mesh does not have the capability to create meshes that satisfy periodic condition, neither did it advertise it anywhere.

you will have to use specialized algorithms and tools, I am not aware of any other tool offers this capability except CGAL

https://doc.cgal.org/latest/Periodic_3_mesh_3/index.html


please redirect your future question to CGAL's mailing list

https://www.cgal.org/mailing_list.html

Kamran Ali Ahmed

unread,
Feb 25, 2024, 4:40:38 PM2/25/24
to iso2mesh-users
Thank you, Dr. Fang.
Reply all
Reply to author
Forward
0 new messages