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.
Parametric sweep and fuction definition
Posted 2011年8月12日 GMT-4 23:32 Materials, Parameters, Variables, & Functions Version 4.2 6 Replies
Please login with a confirmed email address before reporting spam
Hi all,
I'm having some problems in using parameter sweep for parameters that are inside a definition of a function.
I built a simple example in which the temperature of a boundary is defined to be tempInput(z). The function tempInput is defined to be sin(nodesIn*z*2*pi), and nodesIn is a global parameter. I then defined a study with a parametric sweep on the parameter nodesIn on, let's say, 4 different values. When I solve the model, the solver generates a solution for all the 4 parameters, but the solution is exactly the same (corresponding to the default value of nodesIn).
To be sure I didn't made stupid errors in the model, I then redefined the boundary temperature to be tempInput(nodesOut*z) (thus nodesOut plays an equivalent role as nodesIn, except that is used outside the function definition). I then defined another study with a parametric sweep over nodesOut, and this time the solutions generated for different values of nodeOut are indeed different (as expect).
So far, it seem to me that sweeping on parameters used inside a function definitions simply doesn't work. Is that true? Does anyone knows why? Possible workarounds?
However, that's not the end of the story. I do have a real model (that I think is too complicated to be posted here, but if you want...) in which I defined 4 different functions for 4 temperature profiles, let's say temp1... temp4. Then, I created another function defined as:
(n==1)*temp1+(n==2)*temp2+(n==3)*temp3+(n==4)*temp4
and assigned that as the temperature function in the boundary condition. I did that so I could easily switch between the 4 parameters by simply changing the value of the parameter n. Now, I DID USE that in a parametric sweep in that model, and it worked! I also set up different studies and added a "parametric" node to the solver to just select a particular value for n different from the default, and again it worked. That is strange, because it seems to contradict the above conclusion that parameters used inside a function definition can't be swept (well, they can, but the solution doesn't change!). Unfortunately, again, I tried to implement the same thing in the example model and... it doesn't work!
I'm really, really confused...
The model I'm attaching summarizes all these cases:
- in the study InnerParameter, I'm sweeping on the parameter used inside the function definition: no difference between the solutions
- in the study OuterParameter, I'm sweeping on the parameter used in the argument of the function (thus, outside the function definition): all the solutions are different, as expected
- in the study BooleanParameter, i tried the (n==?) trick described above, but it didn't work (although I repeat I have a model that is currently working with that trick... don't ask me how!)
- in the study ManualParametric, I try to add a parametric node directly to the solver (instead of using a parametric sweep to the study node) to simply select a value for the parameter n different from the default (the same technique I used in the model that works!), but it doesn't work.
I'll be grateful for any help...
Giacomo
I'm having some problems in using parameter sweep for parameters that are inside a definition of a function.
I built a simple example in which the temperature of a boundary is defined to be tempInput(z). The function tempInput is defined to be sin(nodesIn*z*2*pi), and nodesIn is a global parameter. I then defined a study with a parametric sweep on the parameter nodesIn on, let's say, 4 different values. When I solve the model, the solver generates a solution for all the 4 parameters, but the solution is exactly the same (corresponding to the default value of nodesIn).
To be sure I didn't made stupid errors in the model, I then redefined the boundary temperature to be tempInput(nodesOut*z) (thus nodesOut plays an equivalent role as nodesIn, except that is used outside the function definition). I then defined another study with a parametric sweep over nodesOut, and this time the solutions generated for different values of nodeOut are indeed different (as expect).
So far, it seem to me that sweeping on parameters used inside a function definitions simply doesn't work. Is that true? Does anyone knows why? Possible workarounds?
However, that's not the end of the story. I do have a real model (that I think is too complicated to be posted here, but if you want...) in which I defined 4 different functions for 4 temperature profiles, let's say temp1... temp4. Then, I created another function defined as:
(n==1)*temp1+(n==2)*temp2+(n==3)*temp3+(n==4)*temp4
and assigned that as the temperature function in the boundary condition. I did that so I could easily switch between the 4 parameters by simply changing the value of the parameter n. Now, I DID USE that in a parametric sweep in that model, and it worked! I also set up different studies and added a "parametric" node to the solver to just select a particular value for n different from the default, and again it worked. That is strange, because it seems to contradict the above conclusion that parameters used inside a function definition can't be swept (well, they can, but the solution doesn't change!). Unfortunately, again, I tried to implement the same thing in the example model and... it doesn't work!
I'm really, really confused...
The model I'm attaching summarizes all these cases:
- in the study InnerParameter, I'm sweeping on the parameter used inside the function definition: no difference between the solutions
- in the study OuterParameter, I'm sweeping on the parameter used in the argument of the function (thus, outside the function definition): all the solutions are different, as expected
- in the study BooleanParameter, i tried the (n==?) trick described above, but it didn't work (although I repeat I have a model that is currently working with that trick... don't ask me how!)
- in the study ManualParametric, I try to add a parametric node directly to the solver (instead of using a parametric sweep to the study node) to simply select a value for the parameter n different from the default (the same technique I used in the model that works!), but it doesn't work.
I'll be grateful for any help...
Giacomo
Attachments:
6 Replies Last Post 2011年8月25日 GMT-4 00:49