model
Model object methods that set up basic parts of a model object such as the model history and saving model files.
Syntax
model is a model object that you can create, for example, using ModelUtil.create(<tag>).
model.baseSystem(<system>): The baseSystem methods sets the unit system for the entire model to the given system. The default is the SI system, which has the tag SI. Other supported unit systems are bft (British engineering units), cgs, mpa, emu, esu, fps, ips, and psi.
model.clearThumbnail(): The clearThumbnail method clears the model thumbnail image.
model.dateModified(): The dateModified method returns the modification date of the model.
Use model.description(description) and description = model.description() to set and retrieve the model’s description.
model.disableUpdates(): The disableUpdates method returns the current status of the disable state for the model object.
model.disableUpdates(boolean) Temporarily disables and reenables the update of variables in entities that automatically generates other entities (for example, physics or coordSystem). Disable updates to speed up the evaluation of long execution sequences. Leaving this flag disabled can cause strange side effects during modeling. For example, some parameter values in a feature of a physics interface might not be valid until an update has been made. The model inputs are such parameters, which end with the suffix _src. Trying to set a value to any of these parameters with updates disabled might give an error message. Other effects are that the generated variables are unknown to the unit evaluator and equation view readings can be incomplete. When the disabled state goes from true to false, the program performs a full update of the variables, so the model is in a fully functional state.
Use model.excludeComputedDataInMph(boolean exclude) to control whether to exclude the built, computed, and plotted data when saving model files. Use model.excludeComputedDataInMph() to return the current value.
Use model.excludeComputedDataInDrafts(boolean exclude) to control whether to exclude built, computed, and plotted data when saving the model as a draft version to a database. Use model.excludeComputedDataInDrafts() to return whether to exclude such data when saving the model as a draft version to a database.
Use model.excludeComputedDataInRegular(boolean exclude) to control whether to exclude built, computed, and plotted data when saving the model as a regular version to a database. Use model.excludeComputedDataInRegular() to return whether to exclude such data when saving the model as a regular version to a database.
model.fontFamily(<family>): The fontFamily method sets the font family to be used in plots. The font default is always available. If using Windows, most system fonts can also be used.
model.fontSize(<size>): The fontSize method sets the font size to be used in plots.
model.getComsolVersion(): The getComsolVersion method returns the COMSOL Multiphysics version used to save the model or the current version if the model has never been saved. There is also a ModelUtil.getComsolVersion() method, which returns the current version as a string.
model.getFilePath() returns the absolute path of the model or an empty string if the model has not been saved or if the model is loaded from a database.
model.getLastComputationTime(String time_format): The getLastComputationTime method returns the last computation time for the model or application as a string. Use model.getLastComputationTime() to get the time measured in ms, which you can then use as an input to model.setLastComputationTime. Other supported time formats are "hr:min:sec", "h:min:s", and "detailed", which returns the time in seconds and also includes more readable units for longer times.
model.getUsedProducts(): The getUsedProducts method returns the products that this model uses.
model.isReadOnly(): The isReadOnly method returns whether the file where the model is saved is read-only and cannot be overwritten or not. The file can be read-only for two reasons:
If the model has not been saved, this method returns false.
model.lastModifiedBy(): The lastModifiedBy method returns the last user to modify the model.
model.location(): The location method returns a string that contains the location of the saved model. For a model saved on the file system, the value is the absolute path of the model file. For a model saved in a Model Manager database, the return value is the model’s database location URI. If the model has never been saved, the location method returns null. The return value of the location method is what can be provided as-is to, for example, ModelUtil.load(String tag, String modelLocation) to load a model from either the file system or a database.
model.locationUri(): The locationUri method returns a database location URI for the save location of the model. If the model has never been saved, the location method returns null.
model.modelPath(<path>): The modelPath method sets the model path. The model path is used for reading files required by the model, if no path is provided to the file. <path> is a list of directories separated by semicolon. When reading an external file, COMSOL Multiphysics attempts to find a file in the following locations:
1
The absolute path as given in the filename. If the path given in the filename is relative, it is resolved relative to the following directories.
2
3
4
5
The directories defined by model.modelPath (ordered and semicolon separated).
6
The directories in the cs.path setting (ordered and semicolon separated).
7
The current directory, which is given by the Java system property user.dir and is the directory where you launch COMSOL Multiphysics, unless you have changed the value of user.dir.
The model directory is used for saving and exporting files if you do not provide an absolute path to the file.
model.modelPath() returns the path <path> set in a call to model.modelPath(<path>).
model.resetLabelsToDefault() resets all node labels to their default values.
model.save(<filename>). The save method saves the model as a multiphysics model file in <filename>. If you do not provide a path, the model is saved in the directory from where you have launched COMSOL Multiphysics or is automatically saved, if loaded from a database, as a draft version to that database.
model.save(<filename>,<type>) saves the multiphysics model in <filename>. If the type is java, a model file for use with Java® is saved. If the type is m, this command saves a model file as an M-file for use with the LiveLink™ for MATLAB®. If the type is vba, this command saves a model file as a VBA-file for use with VBA (Visual Basic for Applications) in Microsoft Excel®.
model.save(<path>,<saveCopy>) saves a copy of the model, if the boolean argument <saveCopy> is true. If it is set to false, this call results in a normal save operation. When saving as a copy, the location of that copy is not remembered, so the previous location for saving models is retained.
model.setLastComputationTime(long time): The setLastComputationTime method sets the last computation time for the model or application as the measured computation time (in ms) that you provide as the input.
model.setThumbnail(<image_filename>): The setThumbnail method imports the image file at the given path and sets it as the model’s thumbnail image.
Use model.title(title) and title = model.title() to set and retrieve the model’s title.
Methods for Compact History
model.hist().complete(bool) enables or disables history logging for methods where the arguments typically are very large objects. This setting affects some methods of model.sol("sol"). All methods with a name beginning with setU are affected by the model.hist().complete(bool) setting. The default for the completeness is false. The compact history operation is not affected by the completeness setting.
model.hist().isComplete() returns true if history logging is enabled for methods where the arguments typically are very large objects.
model.hist().disable() Disables logging of top-level API calls to the history. Use this method sparingly; the default is that the history is logged.
model.hist().enable() Removes the most recent disabling of top-level API calls to the history. Calling enable() can be viewed as removing an entry from a stack of disabled records; logging only occurs if the stack is empty. If you call disable() twice, you then have to call enable() twice to enable history generation.
model.resetHist(): Compact History. The resetHist() method reconstructs the model history from scratch to generate a compacted model’s Java- or M-file history (that is, creating a compact history). If the model has errors or invalid property values, the method fails and the old history is kept.
See Also
model.modelNode(), model.unitSystem()