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.

Creating solution objects and assigning values from MATLAB in COMSOL 4 (similar to femsol)

Please login with a confirmed email address before reporting spam

Hello,

I am trying to adapt from COMSOL 3.5a to COMSOL 4, and so far, the biggest functionality that I miss while using the MATLAB connection is the following:

I want to be able to create solution objects and assign these solution objects to fem's, so that I can use COMSOL solvers to process the dataset I want, or more importantly, to be able to plot those datasets.

I was able to do this by using the following command in COMSOL 3.5:

fem.sol = femsol(u,'tlist',tlist)

where the solution data set I want to have in fem is present in u. In other words, I was able to manipulate the doffs by manipulating u. Is there a corresponding functionality in COMSOL 4?

Thanks in advance.

5 Replies Last Post Dec 12, 2013, 3:27 p.m. EST
Lars Gregersen COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Sep 12, 2011, 8:05 a.m. EDT
Hi

The LiveLink for Matlab contains a function mphgetu that you can use to extract the solution vector.

You can manipulate the solution vector and return it to Comsol using the methods described under setU() in the API Reference Guide.


Lars Gregersen
Comsol Denmark
Hi The LiveLink for Matlab contains a function mphgetu that you can use to extract the solution vector. You can manipulate the solution vector and return it to Comsol using the methods described under setU() in the API Reference Guide. Lars Gregersen Comsol Denmark

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Sep 13, 2011, 3:32 a.m. EDT
Thanks for your reply, I will look into those functions today.
Thanks for your reply, I will look into those functions today.

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Nov 16, 2011, 11:29 a.m. EST
I actually have the solution data saved to a mat file and I want to put it into a solution object and view it with the mphplot command, but I DO NOT want to run the solution again in COMSOL because it's a fairly lengthy solution. Here's what I'm trying to do...

Run the code until it gets to the model.sol('sol1').runAll command (to avoid running the solution). Then I run the lines

for i=1:1:length(tlist)
model.sol('sol1').setU(i,U(:,i));
end

model.sol('sol1').setPValues(tlist);

model.sol('sol1').createSolution;

everything but the createSolution method seems to work, but there's problems with createSolution (NullPointerException). Is this a good approach to doing this?

Thanks for any help,
-Matt
I actually have the solution data saved to a mat file and I want to put it into a solution object and view it with the mphplot command, but I DO NOT want to run the solution again in COMSOL because it's a fairly lengthy solution. Here's what I'm trying to do... Run the code until it gets to the model.sol('sol1').runAll command (to avoid running the solution). Then I run the lines for i=1:1:length(tlist) model.sol('sol1').setU(i,U(:,i)); end model.sol('sol1').setPValues(tlist); model.sol('sol1').createSolution; everything but the createSolution method seems to work, but there's problems with createSolution (NullPointerException). Is this a good approach to doing this? Thanks for any help, -Matt

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Nov 16, 2011, 1:23 p.m. EST
I can't tell if your approach will eventually work (I doubt it).

But I can tell you that plotting results in matlab from a .mat file is much faster than the mphplot command. It's better to work with the matlab plot command and your .mat file than trying to "upload" your .mat in a comsol model and working with the slow mphplot command.
I can't tell if your approach will eventually work (I doubt it). But I can tell you that plotting results in matlab from a .mat file is much faster than the mphplot command. It's better to work with the matlab plot command and your .mat file than trying to "upload" your .mat in a comsol model and working with the slow mphplot command.

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Dec 12, 2013, 3:27 p.m. EST
This thread is old, but I ll risk it anyway.
I want to be able to put data back into a solution object so i can use the integration methods from comsol on the mesh. I know I can also juggle with the numerical integration of matlab (trapz() for example), but it is more elegant to make comsol do it, since it has all the dimensions, geometry and mesh already there.
So, anybody found a solution on how to create a solution object with a given data?
( what I do is combine the data from two different datasets with matlab, then i want to integrate certain quantities on this new data set, it has the same number of everything than the original 2).
Thanks!
This thread is old, but I ll risk it anyway. I want to be able to put data back into a solution object so i can use the integration methods from comsol on the mesh. I know I can also juggle with the numerical integration of matlab (trapz() for example), but it is more elegant to make comsol do it, since it has all the dimensions, geometry and mesh already there. So, anybody found a solution on how to create a solution object with a given data? ( what I do is combine the data from two different datasets with matlab, then i want to integrate certain quantities on this new data set, it has the same number of everything than the original 2). Thanks!

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.