# Discussion Forum

## Expression, Function and how it must work correctly?

Dear Colleauges now I in the process of transfer from Ansys to Comsol and i have 20 years expirience for numerical simulations because now Comsol is really friendly and powerfull instrument.

I see the big possibilities for using Expression and Function for flexible define BC, matherial properties and etc, but with my huge expirience i have strange problem for my works with Espression in the Comsol. For example i want to define Piecewise function for radiative emisivity BC for walls, and i define hrad function with argument T is 0.1*sigma_const*(T^4 - 293^4) and interval for T. But Comsol not calculated the part of expression "-293^4" and results the same for "-293[K]^4" and etc, for example 0.1*sigma_const*(T^4)- 0.1*sigma_const*(293^4). The plot graph for this function calculated only for T argement and absolutely ignored all other. Where i can see the principles (algorithm) for correct defining of expresions? Please help me. As well, becasue Expression field absolutely don't has contects help (For example Ansys CFX preprocessor has a prefect help for all variables and etc in the field for formula), I'm as a user not understand what i may to do in the Expression field. The help of Comsol in laptop version is too small and i want to find the all list of operations, variables and etc (include from results solutions) which i can to use in the expression field. Please help me. Give me please the links to webinars,papers and other Comsol web helps, where i can see it clear.

My big respect for Comsol team, Evgeny

8 Replies Last Post 2023年2月2日 GMT-5 13:24

Posted: 2 months ago
Updated: 2 months ago

Hi, Evgeny!

But Comsol not calculated the part of expression...

You can see on the screenshot (Screenshot_1.png) that Peicewise function works correctly.

Expression field absolutely don't has contects help...

It's not exactly the case. With CTRL+Space shortcut you can open the list of parameters, variables, functions and operators that you can use in Expressions (see the Screenshot_2.png).

The help of Comsol in laptop version is too small...

Please check that help files are installed. Online version of the help system is available here: https://doc.comsol.com/6.1/docserver/#!/com.comsol.help.comsol/helpdesk/helpdesk.html

-------------------
Best regards,
Dmitry Lazarev

Posted: 2 months ago

Hello Dmitry

Thank you for you quick reply 1. Yes, context help is working by CTRL+SHIFT, but only for Expression field not for Function. 2. Please see the results of calculation fuction on my laptop... The both function gives a equal results. It is too strange, may be it my error and i'm a stupid. 3. Please help me and show (give) the direct link to paragraphs in your link ( https://doc.comsol.com/6.1/docserver/#!/com.comsol.help.comsol/helpdesk/helpdesk.html), where i can find the complete list of all variables, operators and etc which i can to implement in Expression and Function field.

Best regards, Evgeny

Posted: 2 months ago

Evgeny,

In the "with" screenshot, the plot is of a function called Myrad, not hrad. Could that be the issue?

Jeff

-------------------
Jeff Hiller

Posted: 2 months ago

Hello Jeff

"Myrad" it was previous function name before correction. I have change the name and at any case results the same - not correct. After your message i repeated few time to calculate - negave. I'm confused, the my version of Comsol is last - 6.1.0.282. This is a error of system i think, because the d(Enth(T),T) not working as well (my other forum topic). I'll thinking...

Best regards, Evgeny

Posted: 2 months ago

Hello Evgeny,

If I change the function definition to include `293[K]` in the piecewise function and click the Plot button, the values of the plotted function change as expected in the Function Plot window. I cannot really see any other reason than that you have not updated the function plot.

For lists of available mathematical and logical functions, user-defined functions, physical and mathematical constants, operators, and variables that you can use in expressions in your COMSOL Multiphysics models, see the Global and Local Definitions chapter in the COMSOL Multiphysics Reference Manual (also available in the Help and Documentation windows in the COMSOL Desktop where you can search for topics).

Note that some variables, such as the spatial coordinates, depend on the chosen space dimension in the model component, and that variables have a "scope" (that is, some of them are only available in a model component and depending on which physics interfaces you have added). There is also a "scope syntax" for accessing, for example, material properties during results evaluation. In the settings for plot nodes, for example, you can also use `Ctrl+Space` or the Insert Expression and Replace Expression buttons to choose from all available and applicable variables.

Best regards,

Magnus

Posted: 2 months ago
Updated: 2 months ago

Hello Evgeny,

If I change the function definition to include `293[K]` in the piecewise function and click the Plot button, the values of the plotted function change as expected in the Function Plot window. I cannot really see any other reason than that you have not updated the function plot.

For lists of available mathematical and logical functions, user-defined functions, physical and mathematical constants, operators, and variables that you can use in expressions in your COMSOL Multiphysics models, see the Global and Local Definitions chapter in the COMSOL Multiphysics Reference Manual (also available in the Help and Documentation windows in the COMSOL Desktop where you can search for topics).

Note that some variables, such as the spatial coordinates, depend on the chosen space dimension in the model component, and that variables have a "scope" (that is, some of them are only available in a model component and depending on which physics interfaces you have added). There is also a "scope syntax" for accessing, for example, material properties during results evaluation. In the settings for plot nodes, for example, you can also use `Ctrl+Space` or the Insert Expression and Replace Expression buttons to choose from all available and applicable variables.

Best regards,

Magnus

Hello Magnus Please see the record of screen. I'm reinstall the COMSOL 6.1.0.282, but the result the same. This is a system bag i think

Posted: 2 months ago
Updated: 2 months ago

Evgeny,

I see the plot change, albeit subtly, at 0:40 in your video.

Note that T^4-293^4 is not very different from T^4 when T>300 (T^4 grows very quickly and dominates 293^4). When T<300, the 0.1*sigma_const multiplying factor causes both expressions you're plotting to be essentially zero and therefore visually indistinguishable.

Jeff

-------------------
Jeff Hiller

Posted: 2 months ago
Updated: 2 months ago

Thank you Jeff

It is correct. The values is too big and "covered" the small "-293^4" addition. This issue is closed "d" operator not working on Win7, and I'm update to Win 10. Now all working.

Best regards, Evgeny