Please login with a confirmed email address before reporting spam
Posted:
1 decade ago
25.08.2010, 13:33 GMT-4
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
31.08.2010, 12:07 GMT-4
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
18.10.2010, 18:42 GMT-4
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
23.11.2010, 02:28 GMT-5
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
14.02.2011, 17:59 GMT-5
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