Running COMSOL Batch with Databases
The COMSOL Multiphysics batch mode can be run with models and data stored in a Model Manager database — both when run via the command line and when run via a Study node in the COMSOL Desktop.
See also COMSOL Batch in the COMSOL Multiphysics Reference Manual.
Running COMSOL Batch via the Command-line
The COMSOL Multiphysics batch mode, when launched from a command-line interface, supports using models stored in a Model Manager database as both source input and target output for the simulation run. You specify a model version as input using the command-line argument -inputfile with a model version location as its value – see also Copying Model and File Locations. The output is specified using the command-line argument -outputfile and a second model version location. You can skip the output argument altogether, in which case it defaults to that of the input argument.
The output of the simulation run is saved as new versions for the same model item and branch that the model version specified by the -outputfile argument belongs to. The argument may refer to a model item that does not yet exist in the database, in which case the model item will be automatically created by the batch run.
During a batch run, various data such as status and log files are continuously written by the batch process. This batch data can also be stored in a database using the command-line arguments -outputdir and -batchlog with file version locations as values. A location may refer to a file item that does not yet exist in the database, in which case the file item will be automatically created by the batch run.
You can freely combine database and file system locations for the -inputfile, -outputfile, -outputdir, and -batchlog arguments. For example, a batch run could use a model version in a database as input, an MPH file on the file system as output, and the remaining batch data stored as file versions.
A batch run still produces temporary files in the batch directory set via the Batch directory field under Computing > Cluster in the Preferences dialog, even if you exclusively use model and file version locations for the command-line arguments. You may find these temporary files useful, for example, when troubleshooting failed batch runs.
You can generate location arguments for a model or file item that does not yet exist in the database using the Model Manager API. Run, for example, via the Java Shell window:
DatabaseApiUtil.api()
  .branchByLocationUri(
<input-argument>)
  .newModelLocationUri("My Output Model");
where <input-argument> is the model version location to be used as input argument for the batch run. The result is a location URI string for a model item to be created on the same branch as the input model version. For the batch log file, for example, run:
DatabaseApiUtil.api()
  .branchByLocationUri(<input-argument>)
  .newFileLocationUri("My Batch Log.txt");
When -outputdir refers to a file version location, the corresponding location URI string must represent a directory. You can obtain such a string by copying the file location of the target file version — see Copying Model and File Locations — pasting it in a text editor, and then removing the filename as a path argument from the URI. You can also generate such a location URI using the Model Manager API. Run, for example, via the Java Shell window:
DatabaseApiUtil.api()
  .branchByLocationUri(<
input-argument>)
  .newFileLocationUri(DatabaseApiUtil.param()     .forNewFileLocationUri()
    .withTitle("My Batch Data")
    .withFileResourcePath());
where <input-argument> is the model version location to be used as input argument for the batch run. The absence of any file path arguments passed to withFileResourcePath results in a “base directory” for the file version’s file resources.
See COMSOL Batch Commands (Windows) and COMSOL Batch Commands (Linux) in the COMSOL Multiphysics Reference Manual for general details on running batch from a command-line interface.
You can stop a batch run involving a model version by launching a new batch process using the same arguments as the first process but with an additional -stop argument. The batch run can be restarted using an additional -continue argument. For the case when the output is saved to a database, however, it becomes important to use the model version that was saved when the previous batch run was stopped as a new argument value for -inputfile. Otherwise, you will end up recomputing all solutions already obtained by the previous batch run. You would typically find the saved model version as the latest version of the model by browsing the corresponding branch in the Model Manager workspace, or via the Model Manager API using the -outputfile argument of the previous run as an “anchor” — see Navigating a Model Manager Database.
In case of a failure or otherwise interrupted run, and when the output target is a database, an attempt is first made to save the current run as a model version to be used later as a recovery. If this save fails, a recovery is instead saved on the file system. You can recover the batch run by launching a new batch process with the extra -recover argument in addition to the arguments used by the previously failed batch run.
You should not use the recovery model version for the -inputfile argument when recovering a failed batch run. That version will be automatically discovered by the recovering process.
Running COMSOL Batch from the COMSOL Desktop
The COMSOL Multiphysics batch mode, when launched from a batch feature under a Study node in the COMSOL Desktop, can be configured to store output in a Model Manager database. You may find this useful, for example, when the model used as input for the batch run is already stored in the same database.
In the Settings window for a batch feature, select either Database or Same as current model in the Model storage and Data storage lists. A requirement for both options is that the current model is already saved in a database. You can also use a hybrid storage mode by selecting File system in one of the lists.
See Running COMSOL Batch with Models and Data Storage in Databases in the COMSOL Multiphysics Reference Manual for details regarding the storage modes and supported batch features.
With batch settings configured, including the ones for Model storage and Data storage, click Compute on the Study node to start the batch job. You can track the progress in the The External Process Window — see also Batch for more details. Click the Detach job button in the External Process window to detach the job from the COMSOL Desktop. You can, for example, save a new version of the model opened in the desktop and continue working on something else. To return to the batch job, open the saved model from the database and click Attach job in the External Process window.
Once the batch run has completed, the Filename field in the Settings windows for the Batch Data (Subnode) and External Process (Subnode) features contain model version locations referring to saved model items. The Output directory fields refer to saved file items. Select Show Location in the menu next to these fields to access the corresponding item versions from The Versions Window in the Model Manager workspace.
The model and file versions saved as output from a batch run fall into three types — batch model, batch output, and batch data. Their version titles consist of Batch model, Batch output, and Batch data, followed by the saved timestamp, original model title, and any sweep parameters.
Batch output. An output model obtained by saving the batch model as a new model item. This model item will only be present if Save output model to file has been selected in the Settings window for the batch feature. A Batch Sweep will produce one output model for each simulated parameter value, which results in a corresponding number of batch output items being created.
After a batch run has completed, the generated items can be deleted on their branch by clicking the Clear All Data button in the Settings window for the Batch Data node, or from the External Process window. You can also delete them directly via the Model Manager workspace — see Deleting Models and Files. To permanently delete the items in the database, see Permanently Deleting Versions as a Maintenance Operation.