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.

How to determine domain number from a given block name.

Please login with a confirmed email address before reporting spam

Hi
I'm currently working with a project where I have to prepare a model to be illuminated in the RF module by microwawes and ultimately being able to determine the location of tumors in human tissue.

This model requires, among many other things, that the model of the illuminated medium can be altered between to different types of materials, essentially flesh and something other than flesh, water is used so far for convenience. All of this model is intended to be controllede via the LiveLink interface to COMSOL and the illuminated medium is created using matlab commands, given a 10x10x10 grid of squares where it was my intend that the changes in medium could be done simply by selecting between to materials, using the command:

>> model.material('mat2').selection(*insert numbers here*);

but in order to do so, I need the domain numbers of a given block, and clicking them manually is not an option, as the full solution should be capable of handling in excess of 10000 block.

Each block has been created with code below, in order to ease identification:

%Array creation
for x=1:10;
for y = 1:1;
for z = 1:1;
CellSize = 5;
s = strcat('blk_x',num2str(x),'_y',num2str(y),'_z',num2str(z));
model.geom('geom1').feature.create(s, 'Block');
model.geom('geom1').feature(s).setIndex('size', num2str(CellSize), 0);
model.geom('geom1').feature(s).setIndex('size', num2str(CellSize), 1);
model.geom('geom1').feature(s).setIndex('size', num2str(CellSize), 2);
model.geom('geom1').feature(s).setIndex('pos', num2str(CellSize*x), 0);
model.geom('geom1').feature(s).setIndex('pos', num2str(CellSize*y), 1);
model.geom('geom1').feature(s).setIndex('pos', num2str(CellSize*z), 2);
end
end
end

The name string is for example 'blk_x10_y1_z1'

Have a nice weekend. -Thomas

5 Replies Last Post Jul 12, 2017, 11:38 a.m. EDT

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago May 4, 2014, 6:11 p.m. EDT
Hi Thomas,

I have exactly the same problem. What I've used so far:

1. Rebuild geometry after addition of each block.
>> model.geom('geom1').run;

2. Get number of domains in geometry
>>blkDomainNumber = model.geom('geom1').getNDomains();

It should return the domain number of just added block.

But may be there is a better solution. If you find one, please let me know.

Thanks.
Hi Thomas, I have exactly the same problem. What I've used so far: 1. Rebuild geometry after addition of each block. >> model.geom('geom1').run; 2. Get number of domains in geometry >>blkDomainNumber = model.geom('geom1').getNDomains(); It should return the domain number of just added block. But may be there is a better solution. If you find one, please let me know. Thanks.

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago May 7, 2014, 4:25 a.m. EDT
Thanks, but I must admit that it seems like a really inefficient way to do it, especially when you have a large (more than 10000) amount of objects
Thanks, but I must admit that it seems like a really inefficient way to do it, especially when you have a large (more than 10000) amount of objects

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago May 7, 2014, 1:51 p.m. EDT
Hi Thomas,

yes it's inefficient and has a problem that domain numbers will be reassigned after you finalize geometry.
I've found another way to solve the problem:

activate auto creation of selections for each block (each grid block will create all possible selections)
>> blk.set('createselection', 'on');

after finalizing geometry
>> model.geom('geom1').run;

you can access to domain number for each block by selection name:
>> blkDomainSelectionEntities = model.selection('geomtag_blocktag_dom').entities(3);
where geomtag is your geometry tag (like geom1)
and block tag is you block tag.

See 'COMSOL API for use with Java Reference Manual' -> Selections of Geometric Entities -> Named selections

Hope this will help.
Hi Thomas, yes it's inefficient and has a problem that domain numbers will be reassigned after you finalize geometry. I've found another way to solve the problem: activate auto creation of selections for each block (each grid block will create all possible selections) >> blk.set('createselection', 'on'); after finalizing geometry >> model.geom('geom1').run; you can access to domain number for each block by selection name: >> blkDomainSelectionEntities = model.selection('geomtag_blocktag_dom').entities(3); where geomtag is your geometry tag (like geom1) and block tag is you block tag. See 'COMSOL API for use with Java Reference Manual' -> Selections of Geometric Entities -> Named selections Hope this will help.

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago May 14, 2014, 4:18 a.m. EDT
You just saved me half a day of coding, thank you :)
You just saved me half a day of coding, thank you :)

Please login with a confirmed email address before reporting spam

Posted: 7 years ago Jul 12, 2017, 11:38 a.m. EDT
You saved me a lot of time too - very helpful!

I am using this technique in Matlab LiveLink, where the syntax is slighty altered:
"model.geom('geom1').feature('feature1').set('createselection','on');" -> Create selections automatically
"model.geom('geom1').run;" -> Run the geometry after finalizing it
"model.selection.tags;" -> Show all selection tags
"mphgetselection(model.selection('geom1_feature1_dom'))" -> Get selection

Cheers
Frank
You saved me a lot of time too - very helpful! I am using this technique in Matlab LiveLink, where the syntax is slighty altered: "model.geom('geom1').feature('feature1').set('createselection','on');" -> Create selections automatically "model.geom('geom1').run;" -> Run the geometry after finalizing it "model.selection.tags;" -> Show all selection tags "mphgetselection(model.selection('geom1_feature1_dom'))" -> Get selection Cheers Frank

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.