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 model couplings inside functions (SOLVED)

Please login with a confirmed email address before reporting spam

Hi all,

don't bother reading the rather long post if you don't have this problem. I solved the issue: variables are our friends! :-)

Anyhow, I'm leaving here the original post in case you have a similar problem...

the super quick version is: can model couplings be used inside analytical functions? I guess not, but want to be sure...

Here the details for who is interested: I have two domains that are two coaxial cylinder one in front of the other. It is actually an optical system an the light propagates parallel to the cylinders' axis (let's call it Z). You can think of it as two lenses one in front of the other. The system is subject to thermal stress, that affects the phase of the transmitted light via different surface or bulk effect, depending on the position (X,Y) of the ray in the plane orthogonal to the optical axis.
Now, I want to plot every contribution, as well as the total effect. To do so, what I actually do is defining a plot on the front face, and using a series of extrusions and projections to have the relevant quatities calculated on the faces or domains of interest. More specifically:

- the optical path changes by a quatity (n-1)*w if a point of a face is displaced of a quantity w along Z (with the right sign, but this is not the point now). So, for example, for the back face I defined an extrusion "exBack" so that I can plot the quantity exBack(w) on the front face and actually obtain the displacement of the back face. Analogously for the other faces.

- the optical path also changes in the bulk as the index of refraction depends on the temperature, which requires an integration. Thus I defined a projection "proj1" so that proj1(T) evaluated on the front face gives the integral of T along lines parallel to Z passing for each point of the front face.

- In addition, as I'm only interested in the differences in optical path, I want to subtract from the value calculate in any point (X,Y) of the front face, the value calculated in (0,0). This is accomplished by defining another extrusion "centerValue" that maps to (0,0,Z) any point (X, Y, Z).

So far so good. and everything works. However, when I put all this together, and with some additional parameters and things, it becomes a pretty long and tedious expression to read, to copy and to maintain (I have to use it in multiple places). So I though I could simply define a function out of it, and go with that... but no! Apparently, when you use projections or extrusions inside and analytical function, the are not recognized. So what? Am I stuck with copy this mile-long expression by hand and going around correcting it in every place I used it? Do you have any alternative idea? Even just subtracting the center value requires me to copy the exact same expression twice in the same line, as if I try to define the function

diff(x) = x - centerValue(x)

it doesn't work, as centerValue is not recognized if used inside the function diff.

Many thanks!

Giacomo

0 Replies Last Post 16.09.2011, 15:03 GMT-4
COMSOL Moderator

Hello Giacomo Ciani

Your Discussion has gone 30 days without a reply. If you still need help with COMSOL and have an on-subscription license, please visit our Support Center for help.

If you do not hold an on-subscription license, you may find an answer in another Discussion or in the Knowledge Base.

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.