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
Posted 18 nov. 2010, 07:03 UTC−5 RF & Microwave Engineering, Interfacing, Heat Transfer & Phase Change, Materials, Parameters, Variables, & Functions Version 4.0a, Version 4.1 11 Replies
Please login with a confirmed email address before reporting spam
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?
Please login with a confirmed email address before reporting spam
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
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
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
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
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
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 ?
Please login with a confirmed email address before reporting spam
Please login with a confirmed email address before reporting spam
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
Please login with a confirmed email address before reporting spam
Please login with a confirmed email address before reporting spam
Please login with a confirmed email address before reporting spam
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.
Suggested Content
- BLOG Using MATLAB® Functions in Your COMSOL Multiphysics® Models
- KNOWLEDGE BASE Modeling of Step Transitions
- FORUM Using interpolation functions to define material properties
- FORUM Using functions in functions for material definitions
-
KNOWLEDGE BASE
How can I see the equations COMSOL is defining?
How do I implement a user-defined Multiphysics coupling?