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.

beg for a quick way to add material to each domain

Please login with a confirmed email address before reporting spam

Hello everyone,

I am using AC/DC module. The geometry has a lot of domains, which is shown in the attached file. Now, I want to add different materials with different relative permittivity to each domain. But it really takes a long time (my code in comsol with matlab is shown below). Is there a quick way to achieve this?

Thanks

parfor n2=1:4096 %no of grids
model.material.duplicate(strcat('mat', num2str(n2+3)), 'mat1');
model.material(strcat('mat', num2str(n2+3))).selection.set(n2+2);
model.material(strcat('mat', num2str(n2+3))).propertyGroup('def').set('relpermittivity', grid_permittivity(n2));
end


4 Replies Last Post Jun 30, 2016, 3:13 a.m. EDT
Lars Gregersen COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 8 years ago Jun 28, 2016, 5:01 a.m. EDT
Hi

You probably don't want 4096 distinct materials in your model. Are you refractive indices for each domain really unique?

You should keep the number of materials to a minimum and assign the domain numbers to each material.

Using parfor will most likely not give you any performance gain - and it may cause problems.


When making a lot of changes to your model you can speed up things by using the disableUpdates method. This is described in the LiveLink for Matlab User's Guide in the section titled "Improving Performance for Large Models".


--
Lars Gregersen
Comsol Denmark
Hi You probably don't want 4096 distinct materials in your model. Are you refractive indices for each domain really unique? You should keep the number of materials to a minimum and assign the domain numbers to each material. Using parfor will most likely not give you any performance gain - and it may cause problems. When making a lot of changes to your model you can speed up things by using the disableUpdates method. This is described in the LiveLink for Matlab User's Guide in the section titled "Improving Performance for Large Models". -- Lars Gregersen Comsol Denmark

Please login with a confirmed email address before reporting spam

Posted: 8 years ago Jun 28, 2016, 6:16 a.m. EDT
THANKS very much.

These 4096 domains do not have to use 4096 distinct materials. The difference is only in their relative permittivity. So do you have any suggestions to achieve this goal.

Thanks again.
THANKS very much. These 4096 domains do not have to use 4096 distinct materials. The difference is only in their relative permittivity. So do you have any suggestions to achieve this goal. Thanks again.

Lars Gregersen COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 8 years ago Jun 28, 2016, 9:11 a.m. EDT
Hi

If you only have a set of a few refractive indices to work with then I suggest you create these as materials and give them proper names. This makes it easier to follow your modelling later.

If you really have 4096 distinct values that depend on which domain you are in then I suggest you create an interpolation table (using the nearest neighbour method). Use the variable "dom" as the input and have the refractive index as a output.
Then you just need to find which domain number (dom) corresponds to each domain in your geometry. You can use the functions mphselectbox or mphselectcoords for this.

--
Lars Gregersen
Comsol Denmark


THANKS very much.

These 4096 domains do not have to use 4096 distinct materials. The difference is only in their relative permittivity. So do you have any suggestions to achieve this goal.

Thanks again.



Hi If you only have a set of a few refractive indices to work with then I suggest you create these as materials and give them proper names. This makes it easier to follow your modelling later. If you really have 4096 distinct values that depend on which domain you are in then I suggest you create an interpolation table (using the nearest neighbour method). Use the variable "dom" as the input and have the refractive index as a output. Then you just need to find which domain number (dom) corresponds to each domain in your geometry. You can use the functions mphselectbox or mphselectcoords for this. -- Lars Gregersen Comsol Denmark [QUOTE] THANKS very much. These 4096 domains do not have to use 4096 distinct materials. The difference is only in their relative permittivity. So do you have any suggestions to achieve this goal. Thanks again. [/QUOTE]

Please login with a confirmed email address before reporting spam

Posted: 8 years ago Jun 30, 2016, 3:13 a.m. EDT
THANK YOU VERY MUCH.

Following your instructions, finally I did it.
THANK YOU VERY MUCH. Following your instructions, finally I did it.

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.