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.

Using Matlab functions to define material properties

Please login with a confirmed email address before reporting spam

Hi

Im trying to calculate the modes in a step index fiber as a function of wavelength. Since the refractive index for fused silica depends on the the wavelength I'm using the sellmeier equation. I have this function in Matlab and it takes lambda as argument. I'm able to define and plot the function it in the global definitions, by first defining

Global Definitions:
MATLAB 2 (sellmeier)
Analytic 1 (N)

Where N is sellmeier(lambda) and lambda is defined from 200e-9 to 2.5e-6. However, I cant seem use N in the material properties.

I try to define the Refractive index "n" in the material properties as N(lambda0) but is doesnt work. If I plot emw.nxx it just shows some values close to 0 for the whole area.

The goal is then to do a parametric sweep of lambda0.


Where and how shall I use the matlab function sellmeier(lambda) in order to use the outupt of the function as refractive index of a material?

11 Replies Last Post 21.01.2011, 02:34 GMT-5

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 18.11.2010, 08:36 GMT-5
It seams as if I managed...

First I defined:

Global definitions:
-Parameter (lambda0=1550nm)
-MATLAB 2 (sellmeier)

then in Model 1:
Definitions
-Variables 1a

where Variables 1a contained n=sellmeier(lambda0)

and finally I defined variable {n11...n33} = n in
Materials
-Fused sillica
--Refractive index


Hope this helps someone;-)
It seams as if I managed... First I defined: Global definitions: -Parameter (lambda0=1550nm) -MATLAB 2 (sellmeier) then in Model 1: Definitions -Variables 1a where Variables 1a contained n=sellmeier(lambda0) and finally I defined variable {n11...n33} = n in Materials -Fused sillica --Refractive index Hope this helps someone;-)

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 10.01.2011, 11:32 GMT-5
Hello,
I just did not get the point.
What do you mean by
Variables 1a contained n=sellmeier(lambda0)?
In the variables, you can define name and expression. you mean to type n=sellmeier(lambda0) inside the expression?

you define the formula of sellmeier in .m file, right? or do you define in COMSOL interface?

Hello, I just did not get the point. What do you mean by Variables 1a contained n=sellmeier(lambda0)? In the variables, you can define name and expression. you mean to type n=sellmeier(lambda0) inside the expression? you define the formula of sellmeier in .m file, right? or do you define in COMSOL interface?

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 10.01.2011, 13:44 GMT-5
Yes sellmeier is defined in a .m file that is placed in a matlab path.

So if you type N= sellmeier(something) in a Variable for some specified domain you will get N=whatever value you would get in Matlab when you give "something" as an argument
Yes sellmeier is defined in a .m file that is placed in a matlab path. So if you type N= sellmeier(something) in a Variable for some specified domain you will get N=whatever value you would get in Matlab when you give "something" as an argument

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 12.01.2011, 12:19 GMT-5
Hi, Thanks a lot for your reply!
Unfortunately, I can not get it work.
I did the same step as you did.
1. I defined "wavelength=1.2e-6m" in the parameter setting.
2. I added Matlab function: epsilons(wavelength).
I type in Function: epsilons, Arguements: wavelength.
3. Then I added Variable1 in definitions. I type Name: epsilon_Ag_1 Expression: epsilons(wavelength).
But in this expression, it is always orange color. Only if I type in Expression: epsilons(1.2e-6) or epsilons(wavelength0) , the formula got back to normal black color.
Something wrong with the settings?

If I have several outputs in the function, in matlab it is defined like:
function [epsilon_Au,epsilon_SiO2,epsilon_Ag]=epsilons(wavelength), What should I type in Name of the Variable1 if I want to specify one of those outputs?

By the way, you mentioned
variable {n11...n33} = n is defined in Materials, is {n11...n33} different values corresponding to different wavelength or is it different outputs?
Hi, Thanks a lot for your reply! Unfortunately, I can not get it work. I did the same step as you did. 1. I defined "wavelength=1.2e-6m" in the parameter setting. 2. I added Matlab function: epsilons(wavelength). I type in Function: epsilons, Arguements: wavelength. 3. Then I added Variable1 in definitions. I type Name: epsilon_Ag_1 Expression: epsilons(wavelength). But in this expression, it is always orange color. Only if I type in Expression: epsilons(1.2e-6) or epsilons(wavelength0) , the formula got back to normal black color. Something wrong with the settings? If I have several outputs in the function, in matlab it is defined like: function [epsilon_Au,epsilon_SiO2,epsilon_Ag]=epsilons(wavelength), What should I type in Name of the Variable1 if I want to specify one of those outputs? By the way, you mentioned variable {n11...n33} = n is defined in Materials, is {n11...n33} different values corresponding to different wavelength or is it different outputs?

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 12.01.2011, 16:12 GMT-5
All functions in COMSOL gives back the same dimension that is in the argument. So you probably need to type:
epsilons(wavelength[1/m])

You can only have one output I think, and it should be a vector of same size as the argument.

{n11,... is for non-isotropic materials.
All functions in COMSOL gives back the same dimension that is in the argument. So you probably need to type: epsilons(wavelength[1/m]) You can only have one output I think, and it should be a vector of same size as the argument. {n11,... is for non-isotropic materials.

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 20.01.2011, 12:01 GMT-5

Yes sellmeier is defined in a .m file that is placed in a matlab path.

So if you type N= sellmeier(something) in a Variable for some specified domain you will get N=whatever value you would get in Matlab when you give "something" as an argument


Hi, I would like to do a similar thing to define non linear resistivity in a joule heating simulation. for now I try to make a very basic example to understand how things work, so I defined a matlab function toto.m, such as :

function [Q] = toto (T)

Q=coeff.*T

end

Which is placed in the same directory as the comsol file (test.mph).

In test.mph, I have a global definition MATLAB1, named toto with input T.

In the model, I set a variable Var1=toto(1)
and use this variable as a heat source on one of the domains.

One cannot dream simpler example, yet it fails because " function toto is not found"
or at least is it what comsol says. I tried both from comsol and from comsol-with-matlab using livelink, after having converted the test.mph in a test.m

Now comes my question : if the problem is indeed that comsol does not find the function, how do I explain where it is ?


[QUOTE] Yes sellmeier is defined in a .m file that is placed in a matlab path. So if you type N= sellmeier(something) in a Variable for some specified domain you will get N=whatever value you would get in Matlab when you give "something" as an argument [/QUOTE] Hi, I would like to do a similar thing to define non linear resistivity in a joule heating simulation. for now I try to make a very basic example to understand how things work, so I defined a matlab function toto.m, such as : function [Q] = toto (T) Q=coeff.*T end Which is placed in the same directory as the comsol file (test.mph). In test.mph, I have a global definition MATLAB1, named toto with input T. In the model, I set a variable Var1=toto(1) and use this variable as a heat source on one of the domains. One cannot dream simpler example, yet it fails because " function toto is not found" or at least is it what comsol says. I tried both from comsol and from comsol-with-matlab using livelink, after having converted the test.mph in a test.m Now comes my question : if the problem is indeed that comsol does not find the function, how do I explain where it is ?

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 20.01.2011, 14:46 GMT-5
the function should be placed in a directory that is in the matlab path. i.e. check editpath
the function should be placed in a directory that is in the matlab path. i.e. check editpath

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 20.01.2011, 14:49 GMT-5


Where N is sellmeier(lambda) and lambda is defined from 200e-9 to 2.5e-6. However, I cant seem use N in the material properties.

I try to define the Refractive index "n" in the material properties as N(lambda0) but is doesnt work. If I plot emw.nxx it just shows some values close to 0 for the whole area.



Hi,
1) I don't see why you need Matlab for this, just define a parameter called "par_lambda" (just in case comsol uses "lambda" for something else, you never know), gives the parameter any default value (it is later overwritten)

2.)then type in the refractive index

sqrt(1+B1*par_lambda^2/(par_lambda^2-C1)) (you could add more terms if you wish, don't forget to define B1 and C1 and more coefficients if needed)

3) then, just add a parametric study, and pick from the list of parameters "par_lambda". give the range you wish... it works out-of the box

cheers
john
[QUOTE] Where N is sellmeier(lambda) and lambda is defined from 200e-9 to 2.5e-6. However, I cant seem use N in the material properties. I try to define the Refractive index "n" in the material properties as N(lambda0) but is doesnt work. If I plot emw.nxx it just shows some values close to 0 for the whole area. [/QUOTE] Hi, 1) I don't see why you need Matlab for this, just define a parameter called "par_lambda" (just in case comsol uses "lambda" for something else, you never know), gives the parameter any default value (it is later overwritten) 2.)then type in the refractive index sqrt(1+B1*par_lambda^2/(par_lambda^2-C1)) (you could add more terms if you wish, don't forget to define B1 and C1 and more coefficients if needed) 3) then, just add a parametric study, and pick from the list of parameters "par_lambda". give the range you wish... it works out-of the box cheers john

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 20.01.2011, 14:51 GMT-5
Yes but if I already have the sellmeier function in matlab it's easier to call it than to reenter it in comsol...
Yes but if I already have the sellmeier function in matlab it's easier to call it than to reenter it in comsol...

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 20.01.2011, 15:07 GMT-5
it doesn't seem that easy, considering the fact that there are already 10 replies on this post.
it doesn't seem that easy, considering the fact that there are already 10 replies on this post.

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 21.01.2011, 02:34 GMT-5
true, but now I know how to do it...
true, but now I know how to do it...

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.