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.
Matlab functions in Comsol - limited compared to 3.5?
Posted 2011年5月6日 GMT-4 04:37 Interfacing, Materials Version 4.1, Version 4.3a 5 Replies
Please login with a confirmed email address before reporting spam
Dear All,
I'm running Comsol 4.1 via the LifeLink from Matlab. Basically it works fine but I encountered a limitation, which was not present in the version 3.5.
I have a Matlab function which sets up the Comsol model object based on an input image. This is realized with the following way:
- Matlab reads in image information from an image data file
- Matlab sets up the Comsol model geometry (via Lifelink) based on this image
- mesh, physics, solvers, etc are also set by Matlab
- a Matlab function is defined, which is giving back the material property at a location (x,y,z) based on the image information. This function should be called from Comsol during runtime for each element, but this function should still be connected to Matlab (from which the Lifelink was started) as the image information is read and stored there and this function should access this image-based information during execution of the Comsol solution.
In the old (3.5) version it was possible to have a such a Matlab function in the material definition fields of Comsol.
In the new (4.1) version I cannot make it work.
What I could do is to define a Matlab function within the Comsol model object, like this:
% MATLAB CODE
extm1=model.func.create('extm1', 'MATLAB');
extm1.setIndex('funcs', 'simple_function', 0, 0);
extm1.setIndex('funcs', 'x', 0, 1);
% END MATLAB CODE
This way Comsol will be able to recognize the function 'simple_function(x)' (if it's in the Matlab path) and I can then use it to define material properties as a function of 'x', e.g. like this (just a dummy example):
% MATLAB CODE
mName='MYmat';
model.material.create(mName);
model.material(mName).name(mName);
model.material(mName).materialModel.create('Orthotropic', 'Orthotropic');
Ex = '100001';
Ey = '100002';
Ez = 'simple_function(x)';
...
... definitions of nu_ii and G_ii are done here
...
model.material(mName).materialModel('Orthotropic').set('Evector', {Ex, Ey, Ez});
model.material(mName).materialModel('Orthotropic').set('nuvector', {nuxy, nuyz, nuxz});
model.material(mName).materialModel('Orthotropic').set('Gvector', {Gxy, Gyz, Gxz});
model.material(mName).selection.set('1');
% END MATLAB CODE
This way 'Ez' will be defined by 'simple_function(x)'.
BUT. The problem is that - as far as I have understood - Comsol calls a 'new' Matlab to evaluate the function 'simple_function(x)'. This 'new' Matlab cannot communicate with the 'original' Matlab (I mean from which Comsol Lifelink was started and where the image data is stored a global variable).
Therefore 'simple_function(x)' will not have access to the image data from which it should read the material property information
Could you please help me with this issue?
Thanks a lot in advance,
Peter
I'm running Comsol 4.1 via the LifeLink from Matlab. Basically it works fine but I encountered a limitation, which was not present in the version 3.5.
I have a Matlab function which sets up the Comsol model object based on an input image. This is realized with the following way:
- Matlab reads in image information from an image data file
- Matlab sets up the Comsol model geometry (via Lifelink) based on this image
- mesh, physics, solvers, etc are also set by Matlab
- a Matlab function is defined, which is giving back the material property at a location (x,y,z) based on the image information. This function should be called from Comsol during runtime for each element, but this function should still be connected to Matlab (from which the Lifelink was started) as the image information is read and stored there and this function should access this image-based information during execution of the Comsol solution.
In the old (3.5) version it was possible to have a such a Matlab function in the material definition fields of Comsol.
In the new (4.1) version I cannot make it work.
What I could do is to define a Matlab function within the Comsol model object, like this:
% MATLAB CODE
extm1=model.func.create('extm1', 'MATLAB');
extm1.setIndex('funcs', 'simple_function', 0, 0);
extm1.setIndex('funcs', 'x', 0, 1);
% END MATLAB CODE
This way Comsol will be able to recognize the function 'simple_function(x)' (if it's in the Matlab path) and I can then use it to define material properties as a function of 'x', e.g. like this (just a dummy example):
% MATLAB CODE
mName='MYmat';
model.material.create(mName);
model.material(mName).name(mName);
model.material(mName).materialModel.create('Orthotropic', 'Orthotropic');
Ex = '100001';
Ey = '100002';
Ez = 'simple_function(x)';
...
... definitions of nu_ii and G_ii are done here
...
model.material(mName).materialModel('Orthotropic').set('Evector', {Ex, Ey, Ez});
model.material(mName).materialModel('Orthotropic').set('nuvector', {nuxy, nuyz, nuxz});
model.material(mName).materialModel('Orthotropic').set('Gvector', {Gxy, Gyz, Gxz});
model.material(mName).selection.set('1');
% END MATLAB CODE
This way 'Ez' will be defined by 'simple_function(x)'.
BUT. The problem is that - as far as I have understood - Comsol calls a 'new' Matlab to evaluate the function 'simple_function(x)'. This 'new' Matlab cannot communicate with the 'original' Matlab (I mean from which Comsol Lifelink was started and where the image data is stored a global variable).
Therefore 'simple_function(x)' will not have access to the image data from which it should read the material property information
Could you please help me with this issue?
Thanks a lot in advance,
Peter
5 Replies Last Post 2013年3月4日 GMT-5 14:48