COMSOL Tips & Tricks v5.3: Model Methods Feature

New to version 5.3: Model Method Feature

To help save time and make analysis more streamlined it is common for us to set up physics with parameterized inputs. Unfortunately, this approach can also mean repeating commands multiple times that can be time consuming and may introduce mistakes. Now you can reduce the time that this process takes and ensure uniformity of implementation by using the Model Methods available in COMSOL Multiphysics® version 5.3. Model Methods allow recording and executing strings of commands, similar to a macro which you can then edit or create custom commands to add functionality to your Modeling.
Creating Model Methods in COMSOL is easy. When you click the “Record Code” button, the software records your commands and turns them into JavaScript. Quick Tip: be sure to change the Method type from “Application Method” to “Model Method” if you plan to run the code in the Model Builder window.  You can view, edit, and record additional code in the Application Builder window. You do not need to know Java to build or use Model Methods, but a little bit of programming basics can go a long way if you are interested in further developing robust and/or complex Methods.
Here’s a simple method we developed to create a heat transfer node with initialized temperature and convection coefficients, all in a few clicks. Check it out!
Step 1) Start a new method
Under the Task Ribbon, click "Developer>Record Method". Change the Method type from "Application method" to "Model method". A red box appears around the edge of the model window to indicate code is recording.
Record new method


Step 2) Create Default Parameters
Add a heat transfer physics node and create the following default parameters the same way you normally would. You can view code created at any time by going to the Application Builder Window.

Access and Edit Model Method Code
Step 3) Assign Parameter Values to Physics
Under Heat Transfer, create a heat flux node and change the type to “Convective heat flux.” Enter the parameters into the fields as shown. The following code is automatically generated. Click "Stop Recording".
image 6 TT v5.3
Image 4
Step 4) Run Model Method
Copy your code into any new or existing model file and click “Run Model Method.” The physics setup is automatically generated.
Run Code


Time Saving Summary
  Manual Method Model Method
Number of Entries 10 0
Number of Clicks 18 1
Total Time 90 seconds 1.5 seconds


And there you have it. Repetitive processes that once took up valuable time and introduced possible errors can now be accomplished quickly and easily. We hope this tip is helpful, and as always, we are here to address your modeling needs through our consulting services and/or training.
Happy COMSOLing!