学习中心

Course:

Getting Started with Building Simulation Apps

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

Thesimplified thermal microactuator tutorial modelis used for the model example, which a simulation app was developed forpreviously. 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 theRecord Methodprogramming tool. UsingRecord Methodto learn how to write Java code for customization is shown. Making changes to the app is done using theSettingswindow,Editor Tools, and theMethod Editor. Topics covered in the tutorial video include the following:

  • Creating a custom form object
    • Adding the form object –Combo Box
    • Defining an integer variable underDeclarationsto use as the source
    • Creating aChoice Listin the settings
  • Recording code
    • Activating theRecord Methodoption in theDeveloperribbon tab of the Model Builder
    • Performing operations in the Model Builder
    • How to stop recording
  • Returning to the Application Builder
    • Opening theMethod Editorwindow 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 theChoice Listthat are user-friendly and easily recognizable
  • Updating associated form objects (such asText Labelform objects) to reflect changes
  • UsingEventsto trigger an action when the value of the combo box is changed
    • Updating the setting forEventssection
    • Choosing a custom method created previously from theOn data changemenu

Further Learning

TheCOMSOL Documentationcontains several examples of further customizations that can be made to simulation apps by creating user-defined methods. These can be found in theApplication Programming Guidein the chapter onProgramming Examples. Additionally, there are severalkeyboard shortcuts for the Application Builderthat are useful to know to more quickly develop and check your user-defined methods as well as generaltips to improve simulation app design and structure.


请提交与此页面相关的反馈,或点击此处联系技术支持

Baidu
map