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.

export current plot/particle tracing with comsol w/ matlab

Please login with a confirmed email address before reporting spam

Hi,

I'm working on polymer flow, through a canal, and I need to determine the temperature function of time, for some particles in the flow. But I don't know how to do that through Matlab.

I'm using the particle tracing plot of postprocessing of COMSOL, and more precisely the function "color expression" where I write "partt", it represents the time. I export the datas with "file/export/current plot + write script etc.".
I repeat the same operation writing "T" (for temperature) instead of partt in the color expression of particle tracing plot, and then export datas through the same way (file/export/...).

The problem is that I need to do this for a program which can't be runned with Comsol, but only with Matlab with comsol because of some loops in it.

I've no problem to do the particle tracing plot with matlab (using postplot), but I really don't know how to obtain the same datas than with "File/export current plot, ...".
I've been trying with postcrossplot (+ outtype with postdata) but didn't find how to call "partt"...

Does anyone have an idea ?
Thank you.

11 Replies Last Post 19 nov. 2010, 08:19 UTC−5

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 8 mars 2010, 10:35 UTC−5
I finally found the solution of my problem, maybe it could be useful for somebody.

Some codes seems to work with Comsol but not with Matlab. This is the one I use :

"VAR_PART=postplot(fem, ...
'outtype','postdataonly', ...
'partmasstype','massless', ...
'partstart',{[0.001],[eps]}, ...
'partcolordata','partt', ...
'partdata',{'u','v'}, ...
'partedgetol',0.001, ...
'parttvar','partt', ...
'partres',5, ...
'solnum','end', ...
'geom','off', ...
'axis',[-0.038658065092179075,0.08865806583723716,-0.005000000074505795,0.10500000156462193]);"

And the datas are contained in the workspace of Matlab, in VAR_PART, to access them, by example the time :
VAR_PART{1,1}.parttime

To plot the results, just change outtype in "postdata" or "handle".

I finally found the solution of my problem, maybe it could be useful for somebody. Some codes seems to work with Comsol but not with Matlab. This is the one I use : "VAR_PART=postplot(fem, ... 'outtype','postdataonly', ... 'partmasstype','massless', ... 'partstart',{[0.001],[eps]}, ... 'partcolordata','partt', ... 'partdata',{'u','v'}, ... 'partedgetol',0.001, ... 'parttvar','partt', ... 'partres',5, ... 'solnum','end', ... 'geom','off', ... 'axis',[-0.038658065092179075,0.08865806583723716,-0.005000000074505795,0.10500000156462193]);" And the datas are contained in the workspace of Matlab, in VAR_PART, to access them, by example the time : VAR_PART{1,1}.parttime To plot the results, just change outtype in "postdata" or "handle".

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 8 mars 2010, 11:31 UTC−5
Hi man!

Listen I have a problem...I'm able to plot streamlines in COMSOL+Matlab but not pathlines. Here is my code (just a part of it):

A = {0.24, -0.015}; % Single streamline/pathline as test case
figure
h = postplot(fem,...
'parttvar','partt','parttstar','auto',...
'partstart',A,'outtype','postdata');

grid on
xlabel('x-coordinate');
ylabel('y-coordinate');

Can you tell me why doesn't work? Thanks in advance for that!

J
Hi man! Listen I have a problem...I'm able to plot streamlines in COMSOL+Matlab but not pathlines. Here is my code (just a part of it): A = {0.24, -0.015}; % Single streamline/pathline as test case figure h = postplot(fem,... 'parttvar','partt','parttstar','auto',... 'partstart',A,'outtype','postdata'); grid on xlabel('x-coordinate'); ylabel('y-coordinate'); Can you tell me why doesn't work? Thanks in advance for that! J

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 9 mars 2010, 05:43 UTC−5
Hi,

I'm not sure for your code, but using the one I post below, it seems to work, with something like that :

A = {0.24, -0.015};
figure
h=postplot(fem, ...
'outtype','postdata', ...
'partstart',A, ...
'parttstar','auto', ...
'partdata',{'u','v'}, ...
'parttvar','partt', ...
'geom','off');
grid on
xlabel('x-coordinate');
ylabel('y-coordinate');


You can change 'geom' in 'on' to see your geometry with the particle.
I think the problem was the line 'partdata'

Hope it will help you,
JL
Hi, I'm not sure for your code, but using the one I post below, it seems to work, with something like that : A = {0.24, -0.015}; figure h=postplot(fem, ... 'outtype','postdata', ... 'partstart',A, ... 'parttstar','auto', ... 'partdata',{'u','v'}, ... 'parttvar','partt', ... 'geom','off'); grid on xlabel('x-coordinate'); ylabel('y-coordinate'); You can change 'geom' in 'on' to see your geometry with the particle. I think the problem was the line 'partdata' Hope it will help you, JL

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 9 mars 2010, 12:13 UTC−5
In my case partdata is giving error, I'm forced to use partvelvar. No idea why...
In my case partdata is giving error, I'm forced to use partvelvar. No idea why...

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 9 mars 2010, 12:14 UTC−5
Forgot this...and doesn't work anyway!
Forgot this...and doesn't work anyway!

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 16 nov. 2010, 10:50 UTC−5
Hi
Thank you for your kindness. but i have some question and i hope that you could help me. I used your code
and i got the results. for example the x and y dimension was 9097. and i get the amount of x, y through

cc=get(fem.mesh,'p');x=cc(1,:);y=cc(2,:);


and the dimension was1049 and the results were different? which of these is true? and this x and y are the x and y of each node or they are something else.

also, when i solve my comsol problem in matlab, i have to insert some new variables. how can i plot this new variable in matlab (over my previous mesh).?

any answer would be appriciated
Hi Thank you for your kindness. but i have some question and i hope that you could help me. I used your code and i got the results. for example the x and y dimension was 9097. and i get the amount of x, y through cc=get(fem.mesh,'p');x=cc(1,:);y=cc(2,:); and the dimension was1049 and the results were different? which of these is true? and this x and y are the x and y of each node or they are something else. also, when i solve my comsol problem in matlab, i have to insert some new variables. how can i plot this new variable in matlab (over my previous mesh).? any answer would be appriciated

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 17 nov. 2010, 04:12 UTC−5
Hi

I'm not sure I've understood your question but, the x and y you're talking about are the positions of your mesh elements. All informations about your mesh can be accessed with the simple command:

fem.mesh

During a particle tracing, comsol calculate the succesives positions of a particle at each time in fonction of the velocity. All positions are independent of your previous Comsol mesh. And through the command you use, you can only deal with mesh elements.



For your other question, to plot new variables, you need to create your own mesh in matlab with the command meshgrid and griddata.
You can find help on matlab forums, or directly in matlab typing "help griddata"



Hope I've correctly answered your questions,
JL
Hi I'm not sure I've understood your question but, the x and y you're talking about are the positions of your mesh elements. All informations about your mesh can be accessed with the simple command: fem.mesh During a particle tracing, comsol calculate the succesives positions of a particle at each time in fonction of the velocity. All positions are independent of your previous Comsol mesh. And through the command you use, you can only deal with mesh elements. For your other question, to plot new variables, you need to create your own mesh in matlab with the command meshgrid and griddata. You can find help on matlab forums, or directly in matlab typing "help griddata" Hope I've correctly answered your questions, JL

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 17 nov. 2010, 09:35 UTC−5
Dear LAUNAY,

Thank you very much for your attention. My domain is very complicated . how can i generate this complicated model in matlab? and i think (i'm not so sure) that i can't use the x , y (x and y data from fem.mesh) to generate my model in matlab, can i? ( if you know something please let me know)

so how can i generate this complecated model in matlab. I think there should be some command that i can use both previous comsol data and matlab data together. please tell me if you know sth about it.

Thank you very much in advance
With Best Regards,

Fatemeh Sharifi
Dear LAUNAY, Thank you very much for your attention. My domain is very complicated . how can i generate this complicated model in matlab? and i think (i'm not so sure) that i can't use the x , y (x and y data from fem.mesh) to generate my model in matlab, can i? ( if you know something please let me know) so how can i generate this complecated model in matlab. I think there should be some command that i can use both previous comsol data and matlab data together. please tell me if you know sth about it. Thank you very much in advance With Best Regards, Fatemeh Sharifi

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 17 nov. 2010, 11:28 UTC−5
Hi Fatemeh

I have complicated geometries too, sometimes in 2D or 3D. I don't know if there are functions in Matlab to use your comsol mesh, directly.

I use to make a new grid, larger than the entire geometry in comsol, in 2D or 3D, with the command meshgrid, and griddata enables to interpolate the values from comsol in the right place in my matlab mesh.

I just need to impose in my matlab's mesh, NaN on the cells located outside my geometry, in order to have the perfect representation of it. I assume that it does represent really complicated programs but I did'nt find other ways.

But you're right, maybe there's a possibility of using the fem.mesh. Did you try to get X and Y positions of the different elements :

AA=get(fem.mesh,'p');
Xpos=AA(1,:);
Ypos=AA(2,:);

MESH=[Xpos' Ypos'];

for i=1:length(MYMESH)
MYMESH(:,3)=0;
end

X1=MYMESH(:,1);
Y1=MYMESH(:,2);
Z1=MYMESH(:,3);

plot3(Z1,X1,Y1);

I just typed that, never test it before but these commands seems to work with my programs... Maybe a start ?

Best regards,
JL




Hi Fatemeh I have complicated geometries too, sometimes in 2D or 3D. I don't know if there are functions in Matlab to use your comsol mesh, directly. I use to make a new grid, larger than the entire geometry in comsol, in 2D or 3D, with the command meshgrid, and griddata enables to interpolate the values from comsol in the right place in my matlab mesh. I just need to impose in my matlab's mesh, NaN on the cells located outside my geometry, in order to have the perfect representation of it. I assume that it does represent really complicated programs but I did'nt find other ways. But you're right, maybe there's a possibility of using the fem.mesh. Did you try to get X and Y positions of the different elements : AA=get(fem.mesh,'p'); Xpos=AA(1,:); Ypos=AA(2,:); MESH=[Xpos' Ypos']; for i=1:length(MYMESH) MYMESH(:,3)=0; end X1=MYMESH(:,1); Y1=MYMESH(:,2); Z1=MYMESH(:,3); plot3(Z1,X1,Y1); I just typed that, never test it before but these commands seems to work with my programs... Maybe a start ? Best regards, JL

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 19 nov. 2010, 03:45 UTC−5
Dear LAUNAY,
Thank you very much. with this command that you gave me i just can see my domain (in very very bad shape with out any mesh) and i could'nt plot any countor of my new variables. how could you plot your new variables over your domain?


Thanks a lot.

With Best Regards,
Fatemeh Sharifi
Dear LAUNAY, Thank you very much. with this command that you gave me i just can see my domain (in very very bad shape with out any mesh) and i could'nt plot any countor of my new variables. how could you plot your new variables over your domain? Thanks a lot. With Best Regards, Fatemeh Sharifi

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 19 nov. 2010, 08:19 UTC−5
Hi Fatemeh

The rule to apply your datas on a new mesh is to create a new matlab mesh which must be regular. I mean that you have to create a rectangular mesh by the commands below :

with a vector X and a vector Y (coordinates of your particle track for example)

xi=linspace(min(X),max(X),100);
yi=linspace(min(Y),max(Y),100);

[XI,YI]=meshgrid(xi,yi);

These commands create a rectangular mesh of hundred coordinates in Y and X. Now, to apply your datas "DAT", depending of Xcoord and Ycoord, you can use the next command :

DAT_2=griddata(XI,YI,DAT,X,Y);


I repeat myself, but the only possibility I've found for complicated geometries is to create a surface larger that my comsol domain, (from min(X) to max(X) and from min(Y) to max(Y)) and just apply NaN on the cells outside of my comsol domain.

You can also create matrices before you use them as :
DAT_2=NaN(100,100);

That's just an example. You have to modify it for your own case.

Finally to see the result :
surf(DAT_2);
shading interp



Julien


Hi Fatemeh The rule to apply your datas on a new mesh is to create a new matlab mesh which must be regular. I mean that you have to create a rectangular mesh by the commands below : with a vector X and a vector Y (coordinates of your particle track for example) xi=linspace(min(X),max(X),100); yi=linspace(min(Y),max(Y),100); [XI,YI]=meshgrid(xi,yi); These commands create a rectangular mesh of hundred coordinates in Y and X. Now, to apply your datas "DAT", depending of Xcoord and Ycoord, you can use the next command : DAT_2=griddata(XI,YI,DAT,X,Y); I repeat myself, but the only possibility I've found for complicated geometries is to create a surface larger that my comsol domain, (from min(X) to max(X) and from min(Y) to max(Y)) and just apply NaN on the cells outside of my comsol domain. You can also create matrices before you use them as : DAT_2=NaN(100,100); That's just an example. You have to modify it for your own case. Finally to see the result : surf(DAT_2); shading interp Julien

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.