How to Build an App from a COMSOL Multiphysics Model
Andrew Griesmer August 18, 2015
The Application Builder is an easy-to-use tool built into COMSOL Multiphysics. After watching the 10-minute video below, you will know how to build a functioning app from a model — and be on your way to building your own customized simulation apps.
Learning How to Use the Application Builder
As you are getting started building simulation apps in COMSOL Multiphysics, there are certain introductory-level things you should know how to do. To help you build up your base knowledge, we’re creating video tutorials that show you how to carry out specific tasks. The video featured here is Part 1 of a series of videos that teach you the basics of building apps in order to give you a base knowledge from which you may expand your apps by exploring the software yourself. We’ll continue to share each video on the blog over the next few weeks under the “Intro to Application Builder Videos” tag.
With the Application Builder, as with any other tool, the more time and effort you put into your apps, the more helpful they can be. For some of you, this video (and the accompanying videos in the series) may be enough to build an app that suits your needs. For others, this video series can be a springboard to eventually building more complex applications.
After watching this video, you will know how to do the following:
- Create a new form with the New Form wizard
- Modify the layout of your app
- Add a button
- Add data validation
Starting with the Busbar tutorial model, we create an app with the New Form wizard, wherein you can modify three parameters, run the simulation, and inspect the results. After creating this basic app, we make it more robust by modifying the layout to match the needs of the user. We add a second button to preview the geometry and limit the value of the input parameters that can be entered to prevent unrealistic inputs.
Video Tutorial: Build an App from a COMSOL Multiphysics Model
- Read a COMSOL Multiphysics user’s experience building an app from a model: Building an IR Microscope App at ZINK Imaging
Building an app from a model is simple and can be done in minutes, as will be shown in this video. We will go over the New Form wizard and the form objects that may be created with it. In future videos to be published, you will add more and more functionality to this app that is essential for any useful app. Furthermore, videos will be published on specific features used to produce the more complex industrial-grade apps seen in the Application Library.
I will begin by going to the File menu and opening up the Application Libraries and then going to COMSOL Multiphysics>Multiphysics>and then opening up the busbar model. This model may look familiar, as it is the introduction tutorial for COMSOL Multiphysics, and you could just as easily do this with one of your own models. Here, we have our fully functioning model with the geometry — the materials, the physics have all been added. We have our Mesh and our Results. Up in the Home tab, we have an Application section now and we can easily click on this Application Builder button, which will take us over to the Application Builder interface.
My app is empty right now, since I just created it, and to get things started I will click New Form to start the New Form wizard. Here, I have some of the different objects that I can add to a form: I have my inputs and outputs, and in this case I have all my input parameters, so I will add the Length and the Width and the Applied Voltage. These parameters are the ones that we are choosing to expose to the user. I can also add Graphics windows, so I will add the temperature graphics window, and I can add buttons, so I will add a button to compute the study. Now, over in this Preview section, as I am adding different objects, I get a preview of what they will look like when the form’s created. Clicking OK, you can see that the Form 1 has been created; I have this new form. And I can click on the different objects and drag them around. It is very easy to resize and I can test my application, as this should be a fully functioning app already. So, as you can see, I can change the length and the width and the applied voltage and then I can compute the study. And the model will solve and re-plot within this window and here we have our results. So, I can use the graphics window the same as in COMSOL Multiphysics.
Now, there are a few things that I would like to point out with this app that we can improve upon. First off, when I make the window bigger, the app isn’t responsive; it either leaves a lot of white space or gives us these scroll bars. So, I will show you how to improve upon that. I will also show how to add another button to preview the geometry, and set limits on the parameters that you can enter into the input fields.
Let’s start by changing the layout of our app. Right now we are in sketch mode, which is really easy to drag-and-drop items and move them around. However, there is not a lot of structure. I can switch to Grid mode, which adds a row and a column for each of the form objects that have been added. Now, I want to make the graphics window grow larger and smaller as the window of the app does, so what I can do is, I can right-click on this row and make it a Grow Row and similarly for the column, I can go to Column Settings in the ribbon and make this a Grow Column. And finally, I need to change the graphics window to fill horizontally and to fill vertically. Now, when I run my app, as I resize it, the graphics window will resize as well.
Before adding a new button, let’s take a look at the existing one. I have the settings window for my button. Here, we have the name of the object, the text that shows up, and I can also add a picture. There are several images that are preloaded that I can choose from. I will select compute_32, with the underscore 32 just meaning that it is 32-pixels-by-32-pixels, and this comes in handy if I want to make my button larger. So, now I have a compute button that is larger. I can also see here in the Commands to Run section that when I click the button, COMSOL Multiphysics will compute the study and then plot the temperature to the Graphics 1 object, which happens to be this graphics window. Now, as you can see, the layout of my app changed a little bit when I made my button bigger. To remedy this, I can split the cells of these two watt units and then merge the three cells here, so that the compute button takes up all three of those cells. Now, let’s add another button. I am going to insert a column to the left of my compute button and then merge the three cells to make room for another button.
Now, I will click the Insert Object button, and this shows all of the objects that I could add such as checkboxes, combo boxes, and table, but I am going to add a button. So, right now it is Button 2, and the text says Button 2, but I’m going to change this to Preview Geometry. Then, I am going to add another image, the geometry_32 image, and make this a large button. I have formatted the layout of my button, but now I need to actually make it do something. So, I will go into my model and then into the component, and click on the Geometry node. Then, all I have to do is click Run. That will build the geometry and then plot, to plot it in the graphics window. However, as you can see, there is no graphics window selected in the “Arguments”, so what I can do is click Edit Argument, which will show a list of the different arguments I can choose from. I want to choose my graphics windows here in Form 1, and here we are. When I created my Compute button with the New Form wizard, all of the commands to run were created automatically by the software, instead of having to create them manually.
Finally, let’s take a look at data validation. Data validation is important for making sure that the right parameters are entered into your model. To show you what I mean, I will test the application again. I can make the application window bigger, and the graphics window will resize with it. And then I can change around my geometry, let’s say 5 and 4, and preview the geometry. Now, the problem here is that I can enter a width of 1, let’s say, and then preview the geometry. And here you can see that this is an unrealistic looking busbar, really the width should not be any less than 3. So, what I can do is to go back into my app and here in the Width input field, I can scroll down to the Data Validation section and here the unit dimension is checked by appending the unit to the number. And the unit expression is centimeters (cm), and the filter is a double, so I can enter decimals into this input field. I can also check the Minimum and Maximum checkboxes and then enter in a value of 3 for the minimum and 15 for the maximum. Now, if the user tries to enter a value outside of that range, an error message will show up saying that that was an invalid input. I can change this as well to say: “Invalid input, enter width 3-15″ to let them know that they have to enter a specific width. I can also add something called a tooltip, so that when I hover over the button it will say “Width: 3-15″.
Let’s test our application again, now that we have added data validation and here I will enter a value of 2, preview the geometry, and, as you can see, that says “Invalid input, enter width 3-15″. Then, when I hover over the input field, you can see the tooltip. Now you know how to build your own app from a COMSOL Multiphysics model, format the layout of an app, add a button and format it, and add data validation to your input fields. Our next video is on “How to Add Save Options”.