Merge meshes inside a mesh box

114 views
Skip to first unread message

gian...@gmail.com

unread,
Jun 14, 2017, 12:59:22 PM6/14/17
to iso2mesh-users
Hi all,

I am trying to create a mesh geometry composed of a sphere and two cylinders inside a cubic box, using iso2mesh.
I created the 3 inner volumes and the outer volume using the basic functions of iso2mesh, as following:

% Create mesh for a 3x3x3 cm cubic geometry:
[no0,fa0,el0]=meshabox([-15 -15 -15],[15 15 15],1,1);

% Create mesh for a 1 mm radius sphere:
[no1,fa1,el1]=meshasphere([0 0 0],1,1,2);

% Create mesh for a 2.5 mm radius cylinder:
[no2,fa2,el2]=meshacylinder([5 15 5],[5 -15 5],2.5,1,2);

% Create mesh for a 2.5 mm radius cylinder:
[no3,fa3,el3]=meshacylinder([-5 15 -5],[-5 -15 -5],2.5,1,2);


How do I incorporate the 3 inner volumes inside the box? 
I saw on the examples how to encase a sphere in a cube using surf2mesh, but I wonder how to extend this approach using multiple volumes. Or maybe is there a quicker way? 

Best regards,
Luca

Qianqian Fang

unread,
Jun 14, 2017, 7:19:54 PM6/14/17
to iso2mes...@googlegroups.com, gian...@gmail.com
hi Luca

it is not straightforward, but if you combine various features provided
in iso2mesh, this is indeed possible.

please see my below script:

% create individual objects

[no0,fa0,el0]=meshabox([-15 -15 -15],[15 15 15],1,1);
[no1,fa1,el1]=meshasphere([0 0 0],1,1,2);

% create the cylinders, extend beyond the box to facilitate boolean
[no2,fa2,el2]=meshacylinder([5 20.9 5],[5 -20.9 5],2.5,1,2); % use 20.9 to avoid coplanar structures
[no3,fa3,el3]=meshacylinder([-5 20.9 -5],[-5 -20.9 -5],2.5,1,2);

% extract and orient only the surfaces
fa0=volface(meshreorient(no0,el0(:,1:4)));
fa1=volface(meshreorient(no1,el1(:,1:4)));
fa2=volface(meshreorient(no2,el2(:,1:4)));
fa3=volface(meshreorient(no3,el3(:,1:4)));
[no0,fa0]=removeisolatednode(no0,fa0);
[no1,fa1]=removeisolatednode(no1,fa1);
[no2,fa2]=removeisolatednode(no2,fa2);
[no3,fa3]=removeisolatednode(no3,fa3);

% merge the box with the first cylinder use surfboolean
[n02,f02]=surfboolean(no0,fa0,'first',no2,fa2(:,[1 3 2]));
% [node,elem]=s2m(n02,f02,1,100,'tetgen',[0 0 0; 5 0 5]);

% then merge with the second cylinder use surfboolean
[n023,f023]=surfboolean(n02,f02,'first',no3,fa3(:,[1 3 2]));
% [node,elem]=s2m(n023,f023,1,100,'tetgen',[0 0 0; 5 0 5]);

% then merge the combined mesh with the sphere
[n0123,f0123]=surfboolean(n023,f023,'first',no1,fa1(:,[1 3 2]));

% run volumetric mesh generation
[node,elem]=s2m(n0123,f0123,1,100,'tetgen',[0 0 2; 0 0 0; 5 0 5; -5 0 -5]);

% plot the results
plotmesh(node,elem,'y>0')
hold on
plotmesh(node,elem(elem(:,end)>1,:))

the output mesh screenshot is attached. All objects are labeled with a unique
index, from 1 to 4.

let me know if this works for you.

Qianqian


Best regards,
Luca
--
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 post to this group, send email to iso2mes...@googlegroups.com.
Visit this group at https://groups.google.com/group/iso2mesh-users.
For more options, visit https://groups.google.com/d/optout.


two_cylinders_in_a_box.png

gian...@gmail.com

unread,
Jun 15, 2017, 9:21:35 AM6/15/17
to iso2mesh-users
Dear Dr. Fang,

Thank you for the response. 
The script you proposed works perfectly and gives me exactly the volume I wanted.

However, I have another issue now related to the above-mentioned volume, when I try to add a planar source to it in MMC.
I used the following script to create the source:

% Create planar source:
source=struct('srctype','planar','srcpos',[-10 -10 30],'srcdir',[0 0 -1 30],...
    'srcparam1',[20 0 0 0],'srcparam2',[0 20 0 0]);
[srcnode,srcelem]=mmcaddsrc(node,elem,source,'KeepShape',1);

But I get the following error: 

Index exceeds matrix dimensions.

Error in meshrefine (line 242)
    el2=map(el(:,1:4));

Error in mmcaddsrc (line 71)
[newnode,newelem]=meshrefine(node,elem,opt);

 Can you help me also with this issue?

Thanks again,
Luca
Reply all
Reply to author
Forward
0 new messages