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.

Converting Parameters to Doubles

Nicholas Goldring Certified Consultant

Please login with a confirmed email address before reporting spam

Hello everyone,

This post is regarding an application that I'm creating with the application builder. I currently have an issue where I'm attempting to update a parameter value, say "length", in my application by setting it to the value of a different parameter, say "length_default". There is an input box for the user to update the value of "length" which works fine. The problem is that all of my attempts to update "length" with a button/method to the new value of "length_default" end up just displaying "length_default" in the input box instead of the numerical value.

I've tried to solve this by converting "length_default" to a double and an integer first - the parameter's value is set to something like 50.84. All of these attempts end up telling me that "length_default" is not an integer or a double. I'm pretty new to Java so any help here would be awesome. Thank you and please let me know if you need any more information.

--
Nick

4 Replies Last Post 17 mag 2017, 16:31 GMT-4
Jeff Hiller COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 8 years ago 17 mag 2017, 14:12 GMT-4
Hi Nicholas,

The Application Builder has a functionality called "Record Method" that allows you do perform operations in the COMSOL Desktop and have the software automatically write for you a method that performs those same operations.
Since you no doubt know how to assign the expression length_default to the parameter length in the GUI, just do the following:
In the App Builder, hit the "Record Method" button (A red frame will appear around the interface), go to the Model Builder and there set the Expression for length to length_default, then go back to the App Builder and hit "Stop Recording" (The red frame will disappear).
And there you have it, a method that contains the instruction to set length to length_default!

It typically does not generate the most compact code possible, but it is a convenient tool and a great way to learn some of the syntax and commands.

Hope this helps,
Jeff
Hi Nicholas, The Application Builder has a functionality called "Record Method" that allows you do perform operations in the COMSOL Desktop and have the software automatically write for you a method that performs those same operations. Since you no doubt know how to assign the expression length_default to the parameter length in the GUI, just do the following: In the App Builder, hit the "Record Method" button (A red frame will appear around the interface), go to the Model Builder and there set the Expression for length to length_default, then go back to the App Builder and hit "Stop Recording" (The red frame will disappear). And there you have it, a method that contains the instruction to set length to length_default! It typically does not generate the most compact code possible, but it is a convenient tool and a great way to learn some of the syntax and commands. Hope this helps, Jeff

Nicholas Goldring Certified Consultant

Please login with a confirmed email address before reporting spam

Posted: 8 years ago 17 mag 2017, 15:15 GMT-4
Updated: 8 years ago 17 mag 2017, 15:23 GMT-4
Hi Jeff, thanks so much for your quick reply! I have actually done that and written a handful of my own methods to try and solve the problem. The method you described outputs code that looks like:

with(model.param());
set("length", "length_default");
endwith();

This definitely works to set the value of "length" to the value of "length_default" behind the scenes. The problem that I'm having is that I have an input box with "length" as a source and when I run this method, "length_default" will show up in that input box instead of the numerical value that it represents. Furthermore, if I filter that input box to only accept doubles or integers, it will reject the "length_default" string value.

I'm not sure if it's related, but when I update a parameter value in an input box it is updated and I can see that in the plots and solutions however, other parameters don't seem to acknowledge that update. What I mean is that if I update "length" and I have a filter on another input box that has a filter limiting it to a maximum value of "length", it will be limited by the original value and not the updated one. Sorry for rambling, I hope it's just something I'm missing on my end but I think I've been pretty thorough.
--
Nick
Hi Jeff, thanks so much for your quick reply! I have actually done that and written a handful of my own methods to try and solve the problem. The method you described outputs code that looks like: with(model.param()); set("length", "length_default"); endwith(); This definitely works to set the value of "length" to the value of "length_default" behind the scenes. The problem that I'm having is that I have an input box with "length" as a source and when I run this method, "length_default" will show up in that input box instead of the numerical value that it represents. Furthermore, if I filter that input box to only accept doubles or integers, it will reject the "length_default" string value. I'm not sure if it's related, but when I update a parameter value in an input box it is updated and I can see that in the plots and solutions however, other parameters don't seem to acknowledge that update. What I mean is that if I update "length" and I have a filter on another input box that has a filter limiting it to a maximum value of "length", it will be limited by the original value and not the updated one. Sorry for rambling, I hope it's just something I'm missing on my end but I think I've been pretty thorough. -- Nick

Jeff Hiller COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 8 years ago 17 mag 2017, 16:15 GMT-4
Updated: 8 years ago 17 mag 2017, 16:16 GMT-4
I think I now see what you mean.
How about this?
with(model.param());
set("length", model.param().evaluate("length_default"));
endwith();

Jeff
I think I now see what you mean. How about this? with(model.param()); set("length", model.param().evaluate("length_default")); endwith(); Jeff

Nicholas Goldring Certified Consultant

Please login with a confirmed email address before reporting spam

Posted: 8 years ago 17 mag 2017, 16:31 GMT-4
Updated: 8 years ago 17 mag 2017, 16:42 GMT-4
Worked like a charm, I really appreciate it!

--
Nick
Worked like a charm, I really appreciate it! -- Nick

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.