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.

Model couplings as inputs to functions

Please login with a confirmed email address before reporting spam

Hello All,

I am trying to put in a temperature average over a boundary into an analytical function. This isn't working and is producing an error. I was wondering whether anyone would have any suggestions on how to input an average temperature into a function?

Regards,
Josh

7 Replies Last Post Jan 16, 2013, 3:47 p.m. EST
Ivar KJELBERG COMSOL Multiphysics(r) fan, retired, former "Senior Expert" at CSEM SA (CH)

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Jan 16, 2013, 12:53 a.m. EST
Hi

you need to define a coupling average function over the boundary, then make a "Model - Definitions - Variable"
Tave = aveop1(T)

and call Tave in your "Model - Definition - Function".

But if you haven't solved your model once, or at least loaded the initial conditions, the Tave does not yet exist, so you cannot plot your function before Tave has got some value

--
Good luck
Ivar
Hi you need to define a coupling average function over the boundary, then make a "Model - Definitions - Variable" Tave = aveop1(T) and call Tave in your "Model - Definition - Function". But if you haven't solved your model once, or at least loaded the initial conditions, the Tave does not yet exist, so you cannot plot your function before Tave has got some value -- Good luck Ivar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Jan 16, 2013, 1:01 a.m. EST
Hey Ivar,

Thank you very much for your reply. I have tried setting the aveop(T) as a variable but I still couldn't get it to run.

Perhaps it was because I hadn't loaded the initial conditions. I am not familiar with loading the initial conditions before solving; how does one go about doing that? Is it a function in the solver?

Thanks Ivar,
Josh
Hey Ivar, Thank you very much for your reply. I have tried setting the aveop(T) as a variable but I still couldn't get it to run. Perhaps it was because I hadn't loaded the initial conditions. I am not familiar with loading the initial conditions before solving; how does one go about doing that? Is it a function in the solver? Thanks Ivar, Josh

Ivar KJELBERG COMSOL Multiphysics(r) fan, retired, former "Senior Expert" at CSEM SA (CH)

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Jan 16, 2013, 2:41 a.m. EST
Hi
In the last version it is back again (from 3.5 time) as a separate command when right clicking a Study node

in the previous versions (also possible in the latest) select the "Dependent Variables" node in the solver sequence and click "Compute to Selected" this fills in all matrices and loads the initial variables, and make the default plots if not already there, handy also to set the plot while solving to the desired plot entry

--
Good luck
Ivar
Hi In the last version it is back again (from 3.5 time) as a separate command when right clicking a Study node in the previous versions (also possible in the latest) select the "Dependent Variables" node in the solver sequence and click "Compute to Selected" this fills in all matrices and loads the initial variables, and make the default plots if not already there, handy also to set the plot while solving to the desired plot entry -- Good luck Ivar

Magnus Ringh COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Jan 16, 2013, 3:04 a.m. EST
Hi,

The analytic functions use "formal arguments" (default "x"), and you can use basically any suitable argument names. Then, when calling the function in the model you can use any valid (scalar) variable or value as an argument when calling the analytic function. For example, define an analytic function "myfcn" as:

Expression: x^2
Argument: x

which defines the analytic function myfcn(x) = x^2.

Then, if you have also created an Average operator "myavg" you can use, for example,

myfcn(myavg(T))

somewhere in a heat transfer model to use the average of the temperature T as argument to the analytic function (you may want to make sure that the units defined for the function and its argument are compatible with its use in the model).

Best regards,
Magnus Ringh, COMSOL
Hi, The analytic functions use "formal arguments" (default "x"), and you can use basically any suitable argument names. Then, when calling the function in the model you can use any valid (scalar) variable or value as an argument when calling the analytic function. For example, define an analytic function "myfcn" as: Expression: x^2 Argument: x which defines the analytic function myfcn(x) = x^2. Then, if you have also created an Average operator "myavg" you can use, for example, myfcn(myavg(T)) somewhere in a heat transfer model to use the average of the temperature T as argument to the analytic function (you may want to make sure that the units defined for the function and its argument are compatible with its use in the model). Best regards, Magnus Ringh, COMSOL

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Jan 16, 2013, 2:58 p.m. EST
Hello again Ivar,

I am finally back at work so am able to try out your suggestions (I am on the other side of the world).

I have tried both inputting the newly defined variable into the function and already having the variable in the function and neither of them work. If I try to have the variable in the function already then I get the error "undefined variable T_ave in function". If I try to input the variable I get an error saying "undefined value found in the stiffness matrix. There are 3 equations giving NaN/inf in the matrix rows....". All of these errors occur when I load the initial conditions too.

Do you have any ideas? Are there any other ways of inputting the average into a function?

Cheers,

Josh
Hello again Ivar, I am finally back at work so am able to try out your suggestions (I am on the other side of the world). I have tried both inputting the newly defined variable into the function and already having the variable in the function and neither of them work. If I try to have the variable in the function already then I get the error "undefined variable T_ave in function". If I try to input the variable I get an error saying "undefined value found in the stiffness matrix. There are 3 equations giving NaN/inf in the matrix rows....". All of these errors occur when I load the initial conditions too. Do you have any ideas? Are there any other ways of inputting the average into a function? Cheers, Josh

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Jan 16, 2013, 3:31 p.m. EST
Hello Magnus,

Thank you for clarifying this for me. It turns out that I have already done this a couple of times before. The problem this time was that I was inputting an average value that was too high for the function to work with.

Thank you very much for your clarification and your help.

Regards,

Josh
Hello Magnus, Thank you for clarifying this for me. It turns out that I have already done this a couple of times before. The problem this time was that I was inputting an average value that was too high for the function to work with. Thank you very much for your clarification and your help. Regards, Josh

Ivar KJELBERG COMSOL Multiphysics(r) fan, retired, former "Senior Expert" at CSEM SA (CH)

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Jan 16, 2013, 3:47 p.m. EST
Hi

where do you define the function ? in the Global function or the model Definition Function ? I would rather choose the second one

--
Good luck
Ivar
Hi where do you define the function ? in the Global function or the model Definition Function ? I would rather choose the second one -- Good luck Ivar

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.