Discussion Closed This discussion was created more than 6 months ago and has been closed. To start a new discussion with a link back to this one, click here.

How to determine face numbers (using matlab livelink) associated with an object

Please login with a confirmed email address before reporting spam

Hello again,

I am trying to 'automatically' set my boundary conditions for a model generated in matlab with livelink. I know which objects need to have which boundary conditions based on a draw order that I specify but I don't know how to get COMSOL to tell me which boundaries (i.e. face numbers) are associated with which object. I can get a list of face numbers associated with objects by the following (which another user has kindly posted elsewhere on this forum):

upDown = model.geom('geom1').getUpDown;
domain = cell(1,max(upDown(:))+1);
for i = 1:length(upDown)
domain{upDown(1,i)+1}=[domain{upDown(1,i)+1},i];
domain{upDown(2,i)+1}=[domain{upDown(2,i)+1},i];
end

but I don't understand how to link the resulting lists of elements with their associated object since they aren't listed according to draw order.

5 Replies Last Post 13.08.2016, 11:12 GMT-4

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 07.02.2013, 11:19 GMT-5
Hi Daniel,

I'm not sure if I understood correctly your question, but I believe there are many different ways of doing that.

You may uses this line:

mphgeom(model,'geom1','Edgelabels','on')

to have a plot of the geometry with the numbering used by comsol.
Then with a simple 'input' matlab command you can specify which edge (or boundary) should have a determined boundary condition.

The mphgeom helps if your geometry changes within your applications. However, if that is not the case you better define selections to identify which edge has a particular set of boundary conditions.

Hope it helps,
Mattia

Hi Daniel, I'm not sure if I understood correctly your question, but I believe there are many different ways of doing that. You may uses this line: mphgeom(model,'geom1','Edgelabels','on') to have a plot of the geometry with the numbering used by comsol. Then with a simple 'input' matlab command you can specify which edge (or boundary) should have a determined boundary condition. The mphgeom helps if your geometry changes within your applications. However, if that is not the case you better define selections to identify which edge has a particular set of boundary conditions. Hope it helps, Mattia

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 07.02.2013, 14:17 GMT-5

The mphgeom helps if your geometry changes within your applications. However, if that is not the case you better define selections to identify which edge has a particular set of boundary conditions.


Yes this is the case. I am developing a pipeline where a text file with randomly generated coordinates is pulled up by matlab and used to define the geometry. There are over 100 objects whose boundary conditions need to be set. I know which objects need what boundary conditions based on draw order and I want to be able to automatically step through the objects and set boundary conditions without the user having to do it manually. However, I am not clear on how to associate the boundary/face numbers with a given object. They seem to be based on relative position within the geometry but I haven't been able to figure it out.
[QUOTE] The mphgeom helps if your geometry changes within your applications. However, if that is not the case you better define selections to identify which edge has a particular set of boundary conditions. [/QUOTE] Yes this is the case. I am developing a pipeline where a text file with randomly generated coordinates is pulled up by matlab and used to define the geometry. There are over 100 objects whose boundary conditions need to be set. I know which objects need what boundary conditions based on draw order and I want to be able to automatically step through the objects and set boundary conditions without the user having to do it manually. However, I am not clear on how to associate the boundary/face numbers with a given object. They seem to be based on relative position within the geometry but I haven't been able to figure it out.

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 07.02.2013, 17:43 GMT-5
Was able to figure out a round-about way of doing this for my particular geometry. Seems like comsol sets face numbers by stepping through the geometry starting in the lower left and proceeding through y, then taking one step in x, and proceeding through y again, etc. Once I've separated out the faces by which object they belong to, I can find out which object is which and what faces are associated with it, based on where it is in my model

oNames = model.geom('geom1').objectNames();
upDown = model.geom('geom1').getUpDown;
upDown = int32(upDown');

domain = cell(1,length(upDown));

for i = 1:length(domain)
domain{upDown(i,2)} = cat(2,domain{upDown(i,2)},i);
end

% posloc contains the x-y position data for objects on my plane of interest and cellpos is my 'odd man out'
% feature that needs a different BC. It's x position is at 75 with a radius of 7.5 so I can find the other features
% relative to it and less in x-value. Since the objects are added to my domain cell-array based on the same x-y
% position logic, I know which object is which.
cellpos = 75;
cellr = 7.5;
sortpos = sortrows(posloc);
xlessrows = find((sortpos(:,1)-r)<cellpos-cellr);

bndset = [];
for i = 2:(max(xlessrows)+1);
bndset = cat(2,bndset,domain{i});
end
for i = (max(xlessrows)+3):length(domain);
bndset = cat(2,bndset,domain{i});
end
Was able to figure out a round-about way of doing this for my particular geometry. Seems like comsol sets face numbers by stepping through the geometry starting in the lower left and proceeding through y, then taking one step in x, and proceeding through y again, etc. Once I've separated out the faces by which object they belong to, I can find out which object is which and what faces are associated with it, based on where it is in my model oNames = model.geom('geom1').objectNames(); upDown = model.geom('geom1').getUpDown; upDown = int32(upDown'); domain = cell(1,length(upDown)); for i = 1:length(domain) domain{upDown(i,2)} = cat(2,domain{upDown(i,2)},i); end % posloc contains the x-y position data for objects on my plane of interest and cellpos is my 'odd man out' % feature that needs a different BC. It's x position is at 75 with a radius of 7.5 so I can find the other features % relative to it and less in x-value. Since the objects are added to my domain cell-array based on the same x-y % position logic, I know which object is which. cellpos = 75; cellr = 7.5; sortpos = sortrows(posloc); xlessrows = find((sortpos(:,1)-r)

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 08.02.2013, 02:49 GMT-5
Hi Daniel,

my suggestion is to play more with comsol's command than with Matlab to identify these things. The API manual is a quite good reference (also the only one we have ;-) ).
Personally I'm using comsol 4,3, but you may find what you look for using:

model.mesh( 'mesh1' ).getElemEntity( 'edg' )

model.mesh( 'mesh1' ).getElem('edg' ) + 1

With these 2 lines you should be able to relate the boundaries of the geometry to the boundaries of the mesh.
While if you look for coordinates of any entity, than you shuold use the command xmeshinfo.

Another option might be to define selections while drawing your pipe. This shuold allow you to "keep track" of you 100 parameters!

Hope it helps,
Mattia
Hi Daniel, my suggestion is to play more with comsol's command than with Matlab to identify these things. The API manual is a quite good reference (also the only one we have ;-) ). Personally I'm using comsol 4,3, but you may find what you look for using: model.mesh( 'mesh1' ).getElemEntity( 'edg' ) model.mesh( 'mesh1' ).getElem('edg' ) + 1 With these 2 lines you should be able to relate the boundaries of the geometry to the boundaries of the mesh. While if you look for coordinates of any entity, than you shuold use the command xmeshinfo. Another option might be to define selections while drawing your pipe. This shuold allow you to "keep track" of you 100 parameters! Hope it helps, Mattia

Please login with a confirmed email address before reporting spam

Posted: 8 years ago 13.08.2016, 11:12 GMT-4
Hello,

I have a similar problem when using Comsol with Matlab.

I would like to export only the nodes associated with selected boundaries, that I know in the Comsol server.
The problem is that when I use "mphxmeshinfo" and "info.elements.edg.nodes" I get a different order of the boundaries with respect what I get by using "mphmesh(model,'mesh1','edgelabels','on')".

Is there any easy way to make the correct order?

Thanks in advance,
Simonetta
Hello, I have a similar problem when using Comsol with Matlab. I would like to export only the nodes associated with selected boundaries, that I know in the Comsol server. The problem is that when I use "mphxmeshinfo" and "info.elements.edg.nodes" I get a different order of the boundaries with respect what I get by using "mphmesh(model,'mesh1','edgelabels','on')". Is there any easy way to make the correct order? Thanks in advance, Simonetta

Note that while COMSOL employees may participate in the discussion forum, COMSOL® software users who are on-subscription should submit their questions via the Support Center for a more comprehensive response from the Technical Support team.