Using and Recording Methods to Create Custom Code for Simulation Apps
To create custom code for use in your simulation apps developed with the Application Builder in COMSOL Multiphysics, you can use methods. Writing, creating (via converting command sequences), and recording methods provides virtually unlimited levels of customization for your simulation apps. Activating the record code functionality in COMSOL Multiphysics creates Java code in the Application Builder that corresponds to the sequence of changes made in the Model Builder. Here, you will learn how to use this functionality. You will also see how to leverage the built-in code-recording functionality to help learn how to write methods.
Tutorial: Simulation App Customization Using Methods and Recording Code
The simplified thermal microactuator tutorial model is used for the model example, which a simulation app was developed for previously. Here, the simulation app is extended to enable users of the app to choose the mesh density level from a limited number of choices. A custom form object, Combo Box, is added to do this. Declarations are defined to enable proper operation of the newly added app functionality. Custom code used by the form object is generated with the help of the Record Method programming tool. Using Record Method to learn how to write Java code for customization is shown. Making changes to the app is done using the Settings window, Editor Tools window, and Method Editor. Topics covered in the tutorial video include the following:
- Creating a custom form object
- Adding the Combo Box form object
- Defining an integer variable under Declarations to use as the source
- Creating a Choice List in the settings
- Recording code
- Activating the Record Method option in the Developer ribbon tab of the Model Builder
- Performing operations in the Model Builder
- How to stop recording
- Returning to the Application Builder
- Opening the Method Editor window to review the Java method code generated
- Updating the code to incorporate use of the integer variable defined previously
- Renaming a method to reflect the action triggered
- Updating declarations
- Adding display names for options in the Choice List that are user-friendly and easily recognizable
- Updating associated form objects (such as Text Label form objects) to reflect changes
- Using Events to trigger an action when the value of the combo box is changed
- Updating the settings in the Events section
- Choosing a custom method created previously from the On data change menu
Further Learning
The COMSOL Documentation contains several examples of further customizations that can be made to simulation apps by creating user-defined methods. These can be found in the Application Programming Guide in the "Programming Examples" section. Additionally, there are several keyboard shortcuts for the Application Builder that are useful to know to more quickly develop and check your user-defined methods as well as general tips to improve simulation app design and structure.
请提交与此页面相关的反馈,或点击此处联系技术支持。