Model Methods and Application Methods
Methods called from the Model Builder are referred to as model methods, while those called from an application are referred to as application methods. When the context is clear, this distinction is often omitted, and they are simply called methods. Model methods directly modify the model object represented in the Model Builder during the current session and are typically used to automate modeling tasks that would otherwise involve several manual steps. Application methods, on the other hand, modify the embedded model within the application. When you click Test Application, the methods executed by the application do not modify the model currently seen in the Model Builder, but instead operate on a copy of the model—the embedded model of the application.
For example, a typical use of a model method is to solve multiple studies in sequence. In a model with several studies, you can record code that first computes Study 1, then Study 2, which may depend on the results of Study 1, and so on. This recorded method can then be called to automate the entire process.
To organize a customized workflow in the Model Builder you can create an add-in based on methods by using a Method Call, Settings Form, or a ribbon tab. For an introductory example of using methods from the Model Builder and for information on how to create add-ins, see Introduction to the Application Builder.
You can learn how to write methods to manipulate the model object by reading the method code in the add-ins that are available in the Add-in Libraries. To load an MPH file from these libraries, browse to the addins folder in the installation folder. This is typically located at:
C:\Program Files\COMSOL\COMSOL64\COMSOL_Multiphysics\addins
In these examples you can learn how to identify a model component, how to check the spatial dimension of a model component, how to work with selections, and more.