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.

muliple geometries

Please login with a confirmed email address before reporting spam

I know that you assign properties by using the x,y,z coordinates, and directly to the elements.
My problem is this: I have a rectangle, that I want to dub divide into 500 triangles. Each triangle, I want it to have a different material property.

Is any way I could mesh this domain, and the triangles produced, used as different domains?

4 Replies Last Post Mar 7, 2013, 1:18 a.m. EST
Ivar KJELBERG COMSOL Multiphysics(r) fan, retired, former "Senior Expert" at CSEM SA (CH)

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Mar 6, 2013, 12:41 p.m. EST
Hi

by default the GUI is set up so that you define N domains, and attribute at most N material, one to each material. Now having one domain that is subdivided by "math" and not geoemtry is not the standard for the GUI interface (easier to tweak via programming).
But you have something similar if you look into how the models of auto adapting models, where the results changes the material property locally, via a new variable from solid to "void". See the model library loaded knee or adaptive bridge structure.
This might inspire you (it's all done from the GUI without external programming ;)

--
Good luck
Ivar
Hi by default the GUI is set up so that you define N domains, and attribute at most N material, one to each material. Now having one domain that is subdivided by "math" and not geoemtry is not the standard for the GUI interface (easier to tweak via programming). But you have something similar if you look into how the models of auto adapting models, where the results changes the material property locally, via a new variable from solid to "void". See the model library loaded knee or adaptive bridge structure. This might inspire you (it's all done from the GUI without external programming ;) -- Good luck Ivar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Mar 6, 2013, 6:53 p.m. EST
Hi Ivar,

Thanks for the reply. The way I tried to do it, was through a matlab function and the use of inpolygon command. But it is painfull slow.


For instance,

I extract the triangulation from comsol

[A1,B1]=mphmeshstats(model,'mesh1');
inv_mesh_tri=B1.elem{1,2}'+1; % Remember, Comsol is zero based
inv_mesh_coords=(round(1e5*[B1.vertex(1,:)' B1.vertex(2,:)'])/1e5);


and then make a function for the next run, where I define a matlab function find_tr2(x,y)



function ind=find_tr2(x,y)

load('inv_mesh_coords.mat');
load('inv_mesh_tri.mat');
load('dx.mat');


ind=zeros(length(x),1);

SI=zeros(length(x),1);
for i=1:length(inv_mesh_tri)

xv=[inv_mesh_coords(inv_mesh_tri(i,1),1) inv_mesh_coords(inv_mesh_tri(i,2),1) inv_mesh_coords(inv_mesh_tri(i,3),1) inv_mesh_coords(inv_mesh_tri(i,1),1)];
yv=[inv_mesh_coords(inv_mesh_tri(i,1),2) inv_mesh_coords(inv_mesh_tri(i,2),2) inv_mesh_coords(inv_mesh_tri(i,3),2) inv_mesh_coords(inv_mesh_tri(i,1),2)];

t=inpolygon(x,y,xv,yv);
SI(t==1)=i;

end

for i=1:length(dx)
ind(SI==i)=dx(i);
end

ind(SI==0)=mean(dx);



Hi Ivar, Thanks for the reply. The way I tried to do it, was through a matlab function and the use of inpolygon command. But it is painfull slow. For instance, I extract the triangulation from comsol [A1,B1]=mphmeshstats(model,'mesh1'); inv_mesh_tri=B1.elem{1,2}'+1; % Remember, Comsol is zero based inv_mesh_coords=(round(1e5*[B1.vertex(1,:)' B1.vertex(2,:)'])/1e5); and then make a function for the next run, where I define a matlab function find_tr2(x,y) function ind=find_tr2(x,y) load('inv_mesh_coords.mat'); load('inv_mesh_tri.mat'); load('dx.mat'); ind=zeros(length(x),1); SI=zeros(length(x),1); for i=1:length(inv_mesh_tri) xv=[inv_mesh_coords(inv_mesh_tri(i,1),1) inv_mesh_coords(inv_mesh_tri(i,2),1) inv_mesh_coords(inv_mesh_tri(i,3),1) inv_mesh_coords(inv_mesh_tri(i,1),1)]; yv=[inv_mesh_coords(inv_mesh_tri(i,1),2) inv_mesh_coords(inv_mesh_tri(i,2),2) inv_mesh_coords(inv_mesh_tri(i,3),2) inv_mesh_coords(inv_mesh_tri(i,1),2)]; t=inpolygon(x,y,xv,yv); SI(t==1)=i; end for i=1:length(dx) ind(SI==i)=dx(i); end ind(SI==0)=mean(dx);

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Mar 6, 2013, 7:25 p.m. EST
The problem is that comsol calls many times this functions (by providing x,y) and not just once.
The problem is that comsol calls many times this functions (by providing x,y) and not just once.

Ivar KJELBERG COMSOL Multiphysics(r) fan, retired, former "Senior Expert" at CSEM SA (CH)

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Mar 7, 2013, 1:18 a.m. EST
Hi

I would say, if you cannot implement a field variable to control locally your material values, then use matlab to create N domains, and N materials, but it's tedious I agree. I do not see of any other way.

But there are many others out here having a lot of good ideas ;)

--
Good luck
Ivar
Hi I would say, if you cannot implement a field variable to control locally your material values, then use matlab to create N domains, and N materials, but it's tedious I agree. I do not see of any other way. But there are many others out here having a lot of good ideas ;) -- Good luck Ivar

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.