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.

User defined function in post-processing (5.3)

Please login with a confirmed email address before reporting spam

Sorry if this has already been asked. I did try and search for this but couldn't find anything which is strange because it seems like a really obvious problem.

I have a working model of a thermal system, and a formula which depends on the average temperature of a certain component. I have defined a piecewise function (in Component 1) for this and would like to automatically apply this function to the temperature result in a results node table. If I "create plot" then COMSOL places a result node which plots the function and shows me that it exists as comp1.sr_vp as in this image. But if I try and apply this function to a result I get the error

Evaluation of result expression failed. Unknown function or operator. - Name: comp1.sr_vp

And the function is not visible in the list of functions defined under Component 1 in the "replace" menu.

I must be missing something obvious here but I don't know what. Any help is appreciated.


4 Replies Last Post 26 juil. 2018, 02:42 UTC−4

Please login with a confirmed email address before reporting spam

Posted: 6 years ago 25 juil. 2018, 06:59 UTC−4

Hi Matthew,

How did you define your function? Can you attach a screenshot?

Hi Matthew, How did you define your function? Can you attach a screenshot?

Please login with a confirmed email address before reporting spam

Posted: 6 years ago 25 juil. 2018, 08:53 UTC−4

Hi Matthew,

How did you define your function? Can you attach a screenshot?

Thanks for your reply Nichal, the function is defined as a piecewise combination of two analytic functions as in this screenshot and this one. Both the component functions are of similar form.

I have found a workaround which seems to work fine for now, which is to use probes instead of directly trying to operate on "Derived Values". If I put the function in the "Expression" box of a boundary probe, I get sensible results with no error.

>Hi Matthew, > >How did you define your function? Can you attach a screenshot? Thanks for your reply Nichal, the function is defined as a piecewise combination of two analytic functions as in [this screenshot](https://i.imgur.com/2pMfkgS.png) and [this one](https://i.imgur.com/rSNsLZd.png). Both the component functions are of similar form. I have found a workaround which seems to work fine for now, which is to use probes instead of directly trying to operate on "Derived Values". If I put the function in the ["Expression" box of a boundary probe](https://i.imgur.com/QFsudah.png), I get sensible results with no error.

Please login with a confirmed email address before reporting spam

Posted: 6 years ago 25 juil. 2018, 09:02 UTC−4

Hi Matthew,

That's odd. I tried to do a volume average with a expression of mine that was also time-dependent and I had no problem. Did you define that expression after computing your results? If so, you have to update your solution (right click on your study and select "Update Solution") in order to evaluate your expression

Hi Matthew, That's odd. I tried to do a volume average with a expression of mine that was also time-dependent and I had no problem. Did you define that expression after computing your results? If so, you have to update your solution (right click on your study and select "Update Solution") in order to evaluate your expression

Gunnar Andersson COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 6 years ago 26 juil. 2018, 02:42 UTC−4

Hi Matthew,

When postprocessing a solution you can only use the functions and operators that are defined in the solution. I suspect that you have done the following:

  1. Computed a study.
  2. Added a function.
  3. Used the function when computing a numerical value.

This doesn't work as the solution computed by the study doesn't contain the function. You can remedy this by doing

2.5. Study > Update Solution

Hi Matthew, When postprocessing a solution you can only use the functions and operators that are defined in the solution. I suspect that you have done the following: 1. Computed a study. 2. Added a function. 3. Used the function when computing a numerical value. This doesn't work as the solution computed by the study doesn't contain the function. You can remedy this by doing 2.5. Study > Update Solution

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.