Discussion Forum

problem creating a model using a Matlab function (Comsol 4)

Thread index  |  Previous thread  |  Next thread  |  Start a new discussion

RSS FeedRSS feed   |   Email notificationsTurn on email notifications   |   6 Replies   Last post: February 1, 2012 4:33pm UTC
Chris Shor

Chris Shor

April 11, 2011 9:55am UTC

problem creating a model using a Matlab function (Comsol 4)

Hi,
i want to create a Comsol model using a Matlab function like:

function myFunction()

model = ModelUtil.create('Model');
...

return

When i call the function Matlab returns this error:
??? Undefined variable "ModelUtil" or class "ModelUtil.create".

I guess somehow i have to tell Matlab to use Comsol 4 because it seems not able to find ModelUtil from within a function.
What am i doing wrong?

Thank you for any advice.

Reply  |  Reply with Quote  |  Send private message  |  Report Abuse

Chris Shor

Chris Shor

April 11, 2011 10:08am UTC in response to Chris Shor

Re: problem creating a model using a Matlab function (Comsol 4)

Just solved it - should have read the LiveLink-manual more carefully :) It is neccessary to import the Comsol classes first:

function myFunction()

import com.comsol.model.*
import com.comsol.model.util.*

model = ModelUtil.create('Model');
...

return



Reply  |  Reply with Quote  |  Send private message  |  Report Abuse

Arye Nudelman

Arye Nudelman

May 10, 2011 9:36pm UTC in response to Chris Shor

Re: problem creating a model using a Matlab function (Comsol 4)

Hey i ask the same

thanks for your answer tomorrow i'll try it too

i want to make my model in comsol as a function in matlab and then i do sort of parametric
sweep on this model by using a for loop calling my model function and always with sweeping parameter

thanks a lot
and you think your advices here will work for me too?

Best regards,
Arye

Reply  |  Reply with Quote  |  Send private message  |  Report Abuse

Arye Nudelman

Arye Nudelman

May 11, 2011 5:35pm UTC in response to Arye Nudelman

Re: problem creating a model using a Matlab function (Comsol 4)

Thanks it worked you are awesome

Reply  |  Reply with Quote  |  Send private message  |  Report Abuse

xuesheng chen

xuesheng chen

November 2, 2011 8:39am UTC in response to Arye Nudelman

Re: (Comsol 4) Undefined variable "ModelUtil" or class "ModelUtil.create"

We need install LiveLink before using matlab combined with comsol v4?

Reply  |  Reply with Quote  |  Send private message  |  Report Abuse

Ivar Kjelberg

Ivar Kjelberg
Moderator

November 2, 2011 9:30am UTC in response to xuesheng chen

Re: (Comsol 4) Undefined variable "ModelUtil" or class "ModelUtil.create"

Hi

Indeed you need a corresponding Matlab installed, then COMSOL With the Matlab livelink for V4 to get everything running together. Cehck with your local rep, or on the KB for install details

--
Good luck
Ivar

Reply  |  Reply with Quote  |  Send private message  |  Report Abuse

ilgin

ilgin

February 1, 2012 4:33pm UTC in response to Chris Shor

COMSOL model implementation via LiveLink (ModelUtil.create)

Hello,

As an addition to the explanation from "Chris Shor"; it is also possible to run a LiveLink operation to start model implamentation without creating a MATLAB function file. That was especially helpful (and seems faster) in my case, since I have pre-processing of my data before starting model implementation.

To do so;

..._______________________________________________

%% PRE_PROCESSING

% constants
x = 1;
y = 2;
z = 3;
...

%% MODEL IMPLEMENTATION

mphstart % connect MATLAB to the COMSOL server (in default port)
import com.comsol.model.* % import the COMSOL classes
import com.comsol.model.util.*

model = ModelUtil.create('Model'); % start model implementation
model.name('xxx');

model.param.set('x', [num2str(x) 'unit'], 'explanation'); % define global model parameters (constants)
model.param.set('y', [num2str(y) 'unit'], 'explanation');
model.param.set('z', [num2str(z) 'unit'], 'explanation');
....

return
..._______________________________________________


Hopefully that will be helpful.
(LiveLink for MATLAB Users Guide - p.12-14)


--
-----
COMSOL 4.2a
Ubuntu 11.04
MATLAB R2010a

Reply  |  Reply with Quote  |  Send private message  |  Report Abuse


Rules and guidelines