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.

Data extraction in a regular grid using LiveLink for MATLAB

Please login with a confirmed email address before reporting spam

Hi everyone. I'm having some problems extracting the results of a model that runs in Livelink for Matlab. The model seems to work fine and I can see the results in a proper form in Comsol; they consist of values distributed over a plane (a cut plane, that doesn't coincides with any boundary) that contains both a laser source and detectors. I want to extract these results using some line like:

Res = mpheval(model, '(comp1.u)', 'dataset', 'dset2' , 'refine', 4); and Res =

I want to have these values in a regular (x, y) grid with dimensions 100 mm x 60 mm, for example. How can I do? Is there any function in Comsol that could make that form me? Any way to extract the results as an regular (x, y) grid?

Thanks in advance,

Demián.


2 Replies Last Post 2022年3月21日 GMT-4 05:18
Lars Gregersen COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 3 years ago 2022年3月21日 GMT-4 05:01

Hi

mpheval is for evaluating a solution in the node points of the mesh. Your cutplane is most likely interpolating your domain hence you need to use mphinterp.

E.g. something like this:

% Load the busbar model
mphopen busbar
% Create the cutplane
model.result.dataset.create('cpl1', 'CutPlane');
model.result.dataset('cpl1').set('quickplane', 'xy');
model.result.dataset('cpl1').set('quickz', 0.001);
% Extract the data (include x,y,z so the data can be plotted later)
[T,x,y,z]=mphinterp(model,{'T' 'x' 'y' 'z'},'dataset','cpl1');

If you want exact control over the coordinates you are probably better of using meshgrid (in Matlab) to define your coodinates before calling mphinterp:

[S1,S2]=meshgrid(0:0.01:0.09,0:-0.001:-0.05);
c=[S1(:) S2(:)];
[T,x,y,z,cpl1x,cpl1y]=mphinterp(model,{'T' 'x' 'y' 'z' 'cpl1x' 'cpl1y'},'dataset','cpl1','coord',c');
-------------------
Lars Gregersen
Comsol Denmark
Hi mpheval is for evaluating a solution in the node points of the mesh. Your cutplane is most likely interpolating your domain hence you need to use mphinterp. E.g. something like this: % Load the busbar model mphopen busbar % Create the cutplane model.result.dataset.create('cpl1', 'CutPlane'); model.result.dataset('cpl1').set('quickplane', 'xy'); model.result.dataset('cpl1').set('quickz', 0.001); % Extract the data (include x,y,z so the data can be plotted later) [T,x,y,z]=mphinterp(model,{'T' 'x' 'y' 'z'},'dataset','cpl1'); If you want exact control over the coordinates you are probably better of using meshgrid (in Matlab) to define your coodinates before calling mphinterp: [S1,S2]=meshgrid(0:0.01:0.09,0:-0.001:-0.05); c=[S1(:) S2(:)]; [T,x,y,z,cpl1x,cpl1y]=mphinterp(model,{'T' 'x' 'y' 'z' 'cpl1x' 'cpl1y'},'dataset','cpl1','coord',c');

Please login with a confirmed email address before reporting spam

Posted: 3 years ago 2022年3月21日 GMT-4 05:18

Hi

mpheval is for evaluating a solution in the node points of the mesh. Your cutplane is most likely interpolating your domain hence you need to use mphinterp.

E.g. something like this:

% Load the busbar model mphopen busbar % Create the cutplane model.result.dataset.create('cpl1', 'CutPlane'); model.result.dataset('cpl1').set('quickplane', 'xy'); model.result.dataset('cpl1').set('quickz', 0.001); % Extract the data (include x,y,z so the data can be plotted later) [T,x,y,z]=mphinterp(model,{'T' 'x' 'y' 'z'},'dataset','cpl1');
If you want exact control over the coordinates you are probably better of using meshgrid (in Matlab) to define your coodinates before calling mphinterp:

[S1,S2]=meshgrid(0:0.01:0.09,0:-0.001:-0.05); c=[S1(:) S2(:)]; [T,x,y,z,cpl1x,cpl1y]=mphinterp(model,{'T' 'x' 'y' 'z' 'cpl1x' 'cpl1y'},'dataset','cpl1','coord',c');

Hi, Lars. Thank you so much for your quick answer; I managed to use mpheval and then interpolating with the Matlab built-in function scatterInterpolant; finally I take only the slices in which I'm interested in. Now I'll try your method; thanks again.

>Hi > >mpheval is for evaluating a solution in the node points of the mesh. Your cutplane is most likely interpolating your domain hence you need to use mphinterp. > >E.g. something like this: > > % Load the busbar model > mphopen busbar > % Create the cutplane > model.result.dataset.create('cpl1', 'CutPlane'); > model.result.dataset('cpl1').set('quickplane', 'xy'); > model.result.dataset('cpl1').set('quickz', 0.001); > % Extract the data (include x,y,z so the data can be plotted later) > [T,x,y,z]=mphinterp(model,{'T' 'x' 'y' 'z'},'dataset','cpl1'); > >If you want exact control over the coordinates you are probably better of using meshgrid (in Matlab) to define your coodinates before calling mphinterp: > > [S1,S2]=meshgrid(0:0.01:0.09,0:-0.001:-0.05); > c=[S1(:) S2(:)]; > [T,x,y,z,cpl1x,cpl1y]=mphinterp(model,{'T' 'x' 'y' 'z' 'cpl1x' 'cpl1y'},'dataset','cpl1','coord',c'); Hi, Lars. Thank you so much for your quick answer; I managed to use mpheval and then interpolating with the Matlab built-in function scatterInterpolant; finally I take only the slices in which I'm interested in. Now I'll try your method; thanks again.

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.