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.

Nesting functions within COMSOL

Please login with a confirmed email address before reporting spam

Hi there,

I was just curious whether it is possible to nest analytical functions within the COMSOL interface?

For example (my equations are a lot longer in reality):

Function 1: T = A^2+b+c (where a, b and c are parameters)
Function 2: A = x + y (where x and y are parameters)

eg. Final Function: F = T(A(x,y),b,c) + 5

Whenever I nest functions like this in COMSOL (mine are a fair bit longer!) I always get the error 'UNEXPECTED UNIT OF INPUT" and text becomes orange. While a solution still does arise when I compute everything the software clearly isn't too happy.

Am I doing something wrong?

Thanks in advance for all your help :)

4 Replies Last Post 2017年1月27日 GMT-5 03:25
Jeff Hiller COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 8 years ago 2017年1月26日 GMT-5 10:00
Hello Liam,

This is a warning that you are not consistent with dimensions. For instance, as far as the software is concerned, you may be adding a quantity that has units of length to one that has units of time.

Think of it this way: with pen and paper you may write that a point that moves at a constant speed of 1m/s has the x coordinate x= x0+t . A computer program seeing an expression like that has no way of knowing whether you intentionally left out the velocity or whether you made a mistake, so COMSOL produces a warning in the form of the orange text. If you know what you're doing, you can ignore this warning. To be on the safe side though, it's a good idea to type x0+1[m/s]*t or x0+v0*t where v0 has units consistent with a speed - The offending expression will return to black when it's "fixed".

Best,
Jeff

Hello Liam, This is a warning that you are not consistent with dimensions. For instance, as far as the software is concerned, you may be adding a quantity that has units of length to one that has units of time. Think of it this way: with pen and paper you may write that a point that moves at a constant speed of 1m/s has the x coordinate x= x0+t . A computer program seeing an expression like that has no way of knowing whether you intentionally left out the velocity or whether you made a mistake, so COMSOL produces a warning in the form of the orange text. If you know what you're doing, you can ignore this warning. To be on the safe side though, it's a good idea to type x0+1[m/s]*t or x0+v0*t where v0 has units consistent with a speed - The offending expression will return to black when it's "fixed". Best, Jeff

Please login with a confirmed email address before reporting spam

Posted: 8 years ago 2017年1月26日 GMT-5 12:24
Hi Jeff,

Firstly, thank you so much for your speedy reply! You are completely correct, including the units does seem to fix the issue of the orange text and now COMSOL is much happier :)

I have just one more question (also about nesting). In my project I am using a mixture of :

- Analytical Functions (under Global Definitions) to calculate values using empirical formulas
- Variables (under comp1 - Definitions) to calculate rates
- PDEs (under mathematics) to calculate mole fractions, pressure changes etc.

These are all interlinked and so the functions within the PDEs will call on Analytical Functions, which in turn will call on Variables to spit out the answer. This answer is then dropped into the following PDE, and so forth. This has begun causing issues for one of my PDEs (the one which spits out pressure) as its output is used as an input to all three types of functions listed above. I have tried to fix this by setting initial values for all variables required but the software is still having issues. I was curious if you think my setup (functions within functions etc.) is acceptable for COMSOL or if you would suggest a different route?

Kind regards,
Liam
Hi Jeff, Firstly, thank you so much for your speedy reply! You are completely correct, including the units does seem to fix the issue of the orange text and now COMSOL is much happier :) I have just one more question (also about nesting). In my project I am using a mixture of : - Analytical Functions (under Global Definitions) to calculate values using empirical formulas - Variables (under comp1 - Definitions) to calculate rates - PDEs (under mathematics) to calculate mole fractions, pressure changes etc. These are all interlinked and so the functions within the PDEs will call on Analytical Functions, which in turn will call on Variables to spit out the answer. This answer is then dropped into the following PDE, and so forth. This has begun causing issues for one of my PDEs (the one which spits out pressure) as its output is used as an input to all three types of functions listed above. I have tried to fix this by setting initial values for all variables required but the software is still having issues. I was curious if you think my setup (functions within functions etc.) is acceptable for COMSOL or if you would suggest a different route? Kind regards, Liam

Jeff Hiller COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 8 years ago 2017年1月26日 GMT-5 14:35
Nothing wrong with nesting functions, per se.
I am not sure I fully understand what specific problem you are facing, but I would check on scopes. With functions and variables calling each other, it's easy to unknowingly try to e.g. call a quantity where it is not properly defined.
Not sure if that helps. Feel free to contact support@comsol.com with more details if needed.
Best,
Jeff
Nothing wrong with nesting functions, per se. I am not sure I fully understand what specific problem you are facing, but I would check on scopes. With functions and variables calling each other, it's easy to unknowingly try to e.g. call a quantity where it is not properly defined. Not sure if that helps. Feel free to contact support@comsol.com with more details if needed. Best, Jeff

Please login with a confirmed email address before reporting spam

Posted: 8 years ago 2017年1月27日 GMT-5 03:25
Hi Jeff,

Thank you for clarifying that nesting functions is okay, this puts me at ease.

I will check the scopes now, let us see if that works out, otherwise I will pop you guys an email.

Kind regards,
Liam
Hi Jeff, Thank you for clarifying that nesting functions is okay, this puts me at ease. I will check the scopes now, let us see if that works out, otherwise I will pop you guys an email. Kind regards, Liam

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.