When using the Model Builder in the COMSOL Desktop interface, an embedded model with variable name model is automatically created. The embedded model has a special status. For example, the automatic code generation tools only consider the embedded model. In addition, when you save to or load from an MPH file, only the embedded model is saved or loaded. General tools include the
Save Application As command in the Application Builder and
File>Save As, from the
File menu of the COMSOL Desktop environment.
where My_model_1 is a unique tag. It is recommended that you do not use the names
Model1,
Model2,
Model3, and so on, since these names are used by the mechanism that automatically generates model tags for the embedded model when loading and saving MPH files.
For example in the Windows operating system, load a model my_model.mph from the folder
C:\COMSOL_Work, by using the built-in method
loadModel:
In this example, the tag My_Model_1 is important since it is used to retrieve the model from other methods. Once loaded, the model
extmodel exists in the work space of the current COMSOL Multiphysics or COMSOL Server session. Note that an MPH file can only contain one model object, so there is no ambiguity on which model you refer to when loading an MPH file.
Assume that you, in one method, have loaded the model extmodel with the tag
My_Model_1, such as in the example above. The model variable
extmodel is not available in other methods. In order to retrieve the model from another method use:
The contents of mymodel and
extmodel are the same, but these variables exist in the variable space of two different methods.
The tag My_Model_1 uniquely identified and retrieved the model object from the current COMSOL Multiphysics or COMSOL Server session.
In the File menu, this functionality is referred to as
Compact History.
If you use the loadModel method to load another model into your application, then the usual functionality for displaying the geometry, mesh, and results, for the loaded model, is not directly available in the application since that functionality is reserved for the embedded model. However, you can use the API to call geometry, mesh, study, and results functionality and extract numerical results from the loaded model. For example, you can change the value of parameters or variables of the loaded model, run a study, and extract numerical results.
In an application, you can display plots generated from models other than the embedded model by writing specific method code. First, you will need to use the loadModel method to load the desired model. Following this, the
useGraphics method can be used to display a particular plot group from the loaded model. Here is a simplified example to illustrate this process:
In this example, loadModel is used to load a model, and
useGraphics is used to display a plot group
"pg1" from the loaded model in the graphics component
"/form1/graphics1".
Note that useGraphics exclusively supports the display of plot groups. This method cannot be used for displaying other graphical elements like geometry or mesh. Furthermore, the toolbar accompanying these plots is limited compared to the one available for plots from the embedded model. This limitation exists as certain actions associated with the full toolbar are not supported in this scenario.
Note that the loadModel and
saveModel methods are not supported in standalone applications that have been compiled with COMSOL Compiler.