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 because it is used to reference the model from other methods. Once loaded, the model object
extmodel exists in the workspace of the current COMSOL Multiphysics or COMSOL Server session.
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.
Note: When using the Record Code or
Record Method options, additional code may be generated automatically. In the examples above, any unnecessary or extraneous code has been removed for clarity.
In the File menu, this action is referred to as
Compact History.
Repeated create operations for features in the Model Builder can become slow when you add many of them. Different feature types vary in complexity—for example, the TemperatureBoundary boundary condition is relatively simple, while, for example, a
Thermal Contact boundary condition performs more advanced operations. Although certain optimizations are possible, identifying and resolving bottlenecks can be time-consuming.
Disabling model updates can lead to unexpected side effects. For example, parameters in a physics feature, such as model inputs ending in _src, may remain invalid until the model is updated. Attempting to set any of these parameters while updates are disabled can produce errors. In addition, generated variables may be unavailable to the unit evaluator, and the equation view may show incomplete data. As soon as updates are re-enabled, the program performs a full variable refresh and returns the model to a fully functional state.
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.
However, 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
Note that useGraphics exclusively supports the display of plot groups. This method cannot be used for displaying other graphical elements like geometry or mesh. Note, however, that functionality for plotting the CAD model as well as the mesh is possible also from plot groups. For example, by plotting a constant expression or a fixed color for a surface or volume plot. Or, by using a dedicated mesh plot.
Note that the loadModel and
saveModel methods are not supported in standalone applications that have been compiled with COMSOL Compiler.