Note: This discussion is about an older version of the COMSOL Multiphysics® software. The information provided may be out of date.

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.

Keeping track of subdomains/boundaries in 4.0a

Please login with a confirmed email address before reporting spam

Hello,

I'm currently working on adapting my Matlab code from version 3.5 to 4.0a. In 3.5, I would use something like this:

[g,st] = geomcsg({object1, object2, ... objectN});
ctx = geomcsg({object1, object2, ... objectN},'Out','ctx');

I could then use st to figure out which subdomains in the resulting geometry belong to which objects that I drew. Similarly I could use geomcsg with the 'ctx' option to associate boundary numbers in the final geometry with the same set of individual objects.

I've been trying to figure out a way to do something similar in Comsol4.0a with the Matlab LiveLink, but have so far come up with nothing. I've drawn my geometry so that each "object" (as in my syntax above) is now a feature with an appropriate name, so what I would like to do, for example, is something like this:

model.physics('htgh').feature.create('temp1', 'TemperatureBoundary', 1);
model.physics('htgh').feature('temp1').selection.set({'spr_anchor_b', 'spr_anchor_t' ,'lev_anchor','actuator_anchor_l','actuator_anchor_r'});

I would expect this to set all of the boundaries of the listed features to the selection for the feature temp1. However, this does not seem to work. All of the examples I've seen in the documentation always have a hard coded list of boundary/subdomain numbers which will not work for me since the geometry changes quite dramatically and the numbering of subdomains/boundaries is not always the same.

Please let me know what solution(s) are available for solving this problem.

Thanks,
Mark Roy

5 Replies Last Post Feb 14, 2011, 5:59 p.m. EST

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Aug 25, 2010, 1:33 p.m. EDT
I've been trying to write my own Matlab function that goes through and analyzes the geometry to determine the domain and boundary numbering. So far, my code seems to be working for domains, but I'm having some problems with the boundaries.

The way I approached it was to iterate through the objects with model.geom('geom1').objectNames, and then use getEdge() and getVertex() to determine the edges and their coordinates. However, it seems that the information provided by these methods is not quite correct.

For example, if I draw a square anchor with a cantilever attached to the middle of one side, I would expect that the edge that the cantilever is connected to should be split into three boundaries; one for the edge above the cantilever, one for the edge below, and one for the portion that is shared by the cantilever and the anchor. With this example, getNBoundaries() on the square anchor reports only 4 boundaries when there should be 6 and likewise getEdge only reports 4 edges when there should be 6. When I import the same geometry from the Comsol server to the Comsol GUI, I can plainly see all 6 boundaries and their respective numbers.

I'm not sure why this topic is so overlooked in the documentation about the Matlab LiveLink and in the API docs. It seems to me that without knowing the boundary or domain numbering the usefulness of Matlab is severely crippled as I can not do an iterate over various geometrical parameters without manually assigning boundaries and subdomains.

Cheers.
Mark Roy
I've been trying to write my own Matlab function that goes through and analyzes the geometry to determine the domain and boundary numbering. So far, my code seems to be working for domains, but I'm having some problems with the boundaries. The way I approached it was to iterate through the objects with model.geom('geom1').objectNames, and then use getEdge() and getVertex() to determine the edges and their coordinates. However, it seems that the information provided by these methods is not quite correct. For example, if I draw a square anchor with a cantilever attached to the middle of one side, I would expect that the edge that the cantilever is connected to should be split into three boundaries; one for the edge above the cantilever, one for the edge below, and one for the portion that is shared by the cantilever and the anchor. With this example, getNBoundaries() on the square anchor reports only 4 boundaries when there should be 6 and likewise getEdge only reports 4 edges when there should be 6. When I import the same geometry from the Comsol server to the Comsol GUI, I can plainly see all 6 boundaries and their respective numbers. I'm not sure why this topic is so overlooked in the documentation about the Matlab LiveLink and in the API docs. It seems to me that without knowing the boundary or domain numbering the usefulness of Matlab is severely crippled as I can not do an iterate over various geometrical parameters without manually assigning boundaries and subdomains. Cheers. Mark Roy

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Aug 31, 2010, 12:07 p.m. EDT
I thought I would post an update so that hopefully other people wont have to go through the same trouble. I've attached the code that I wrote that analyzes a geometry and gives you an ordered list of domains, boundaries and a list of interior boundaries.

The code first sorts all domains found with geom.objectNames by getting the lowest leftmost vertex of each domain and then sorting all domains by the vertexes.

Next, I iterate through all of the domains and save a list of their edges'. Next, I create a new "all" feature which is the union of everything in the geometry; this is needed so that comsol figures out how to split up feature edges into boundaries (ie the example I gave in the previous reply). The next part of my code loops through all of the edges of the new "all" feature (conveniently, when you call getEdges, comsol gives them to you already ordered, so no sorting needed) and attempts to determine which feature they belong to by comparing it to the boundaries found earlier. Finally, if more than one of the feature edges matches to the boundary then it is flagged as interior. The last step is to delete the "all" feature so that the geometry is the same as the original.

The usage of the function is as follows:

[domains boundaries interiorBoundaries] = geomAnalyze(model.geom('geom1'));

domains and boundaries are both an ordered list of strings; ie domains(1) returns a string that corresponds to the feature name of the first domain. boundaries is also a list of domain names; ie the string in boundary(10) is the name of the domain that the 10th boundary belongs to. interiorBoundaries contains a 1 if the boundary is "interior" and a 0 otherwise; ie find (interiorBoundaries) will give a list of all interior boundaries.

The function works, but it is quite slow since it has to re-do a lot of work that Comsol has already done but doesnt make available through the live link. Hope that somebody else finds this useful.

Cheers.
Mark Roy
I thought I would post an update so that hopefully other people wont have to go through the same trouble. I've attached the code that I wrote that analyzes a geometry and gives you an ordered list of domains, boundaries and a list of interior boundaries. The code first sorts all domains found with geom.objectNames by getting the lowest leftmost vertex of each domain and then sorting all domains by the vertexes. Next, I iterate through all of the domains and save a list of their edges'. Next, I create a new "all" feature which is the union of everything in the geometry; this is needed so that comsol figures out how to split up feature edges into boundaries (ie the example I gave in the previous reply). The next part of my code loops through all of the edges of the new "all" feature (conveniently, when you call getEdges, comsol gives them to you already ordered, so no sorting needed) and attempts to determine which feature they belong to by comparing it to the boundaries found earlier. Finally, if more than one of the feature edges matches to the boundary then it is flagged as interior. The last step is to delete the "all" feature so that the geometry is the same as the original. The usage of the function is as follows: [domains boundaries interiorBoundaries] = geomAnalyze(model.geom('geom1')); domains and boundaries are both an ordered list of strings; ie domains(1) returns a string that corresponds to the feature name of the first domain. boundaries is also a list of domain names; ie the string in boundary(10) is the name of the domain that the 10th boundary belongs to. interiorBoundaries contains a 1 if the boundary is "interior" and a 0 otherwise; ie find (interiorBoundaries) will give a list of all interior boundaries. The function works, but it is quite slow since it has to re-do a lot of work that Comsol has already done but doesnt make available through the live link. Hope that somebody else finds this useful. Cheers. Mark Roy


Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Oct 18, 2010, 6:42 p.m. EDT
Mark, I was having exactly the same problem and found your script very handy!
Mark, I was having exactly the same problem and found your script very handy!

Remi Magnard COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Nov 23, 2010, 2:28 a.m. EST
Dear Mark,

This is nice functions you have implemented.
Just for your information there is in COMSOL 4.1 som wrapper functions that allow to get the entity (point,edge,boundary or domains) indexes just by entering spatial coordinates or by giving adjacement domain number.

These functions are :

- MPHSELECTBOX, returns the entity indexes included inside a selection box
- MPHSELECTCOORDS, returns the entity indexes that are close (within a certain search radius) of a point defined by spatial coordinates
- MPHGETADJ, returns the entity indexes that adjacent to a given entity.

These are listed in the reference guide at the end of the Livelink for MATLAB user's guide.
More examples are planned for the next release.

Best regards,

Remi Magnard
Dear Mark, This is nice functions you have implemented. Just for your information there is in COMSOL 4.1 som wrapper functions that allow to get the entity (point,edge,boundary or domains) indexes just by entering spatial coordinates or by giving adjacement domain number. These functions are : - MPHSELECTBOX, returns the entity indexes included inside a selection box - MPHSELECTCOORDS, returns the entity indexes that are close (within a certain search radius) of a point defined by spatial coordinates - MPHGETADJ, returns the entity indexes that adjacent to a given entity. These are listed in the reference guide at the end of the Livelink for MATLAB user's guide. More examples are planned for the next release. Best regards, Remi Magnard

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Feb 14, 2011, 5:59 p.m. EST
Hello,

I recently had to switch from automating COMSOL with Matlab to automation using Java and I really miss the new mphselectbox wrapper function. Does anyone know of a similar function that can be used, or have any thoughts as to how a similar function can be written, in Java?

Primarily, it's difficult to generate the domains and boundaries, since I'm presently defining some regions using large boxes (say, a rectangle spanning from (10, 20; 1, 5)) separated by lines (say, bezier polygons, single segment, (11, 11; 1, 5), then (12, 12; 1, 5), etc), since this is convenient for what I'm doing. I'm sure I could write an algorithm that figures out what the edges, domains, etc are, simply by looping through and numbering them, but I was curious of whether there was already some function out there than can do this in Java, especially since I plan to include non-rectangular features in my geometry at some point.

Thanks,
Jeremy

Hello, I recently had to switch from automating COMSOL with Matlab to automation using Java and I really miss the new mphselectbox wrapper function. Does anyone know of a similar function that can be used, or have any thoughts as to how a similar function can be written, in Java? Primarily, it's difficult to generate the domains and boundaries, since I'm presently defining some regions using large boxes (say, a rectangle spanning from (10, 20; 1, 5)) separated by lines (say, bezier polygons, single segment, (11, 11; 1, 5), then (12, 12; 1, 5), etc), since this is convenient for what I'm doing. I'm sure I could write an algorithm that figures out what the edges, domains, etc are, simply by looping through and numbering them, but I was curious of whether there was already some function out there than can do this in Java, especially since I plan to include non-rectangular features in my geometry at some point. Thanks, Jeremy

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.