Sharing the Model Between the COMSOL Desktop® and the MATLAB® Prompt
It is possible to connect a COMSOL Desktop to the COMSOL Multiphysics Server that is already connected with MATLAB and then access the model from both client (the COMSOL Desktop and MATLAB). The change performed from either client are directly accessible from the other one; for instance, type a command at the MATLAB prompt and see the resulting modification in the Model Builder window, or extract data at the MATLAB prompt from a model set up in the COMSOL Desktop.
Connect the COMSOL Desktop to the COMSOL Multiphysics Server from the prompt
At the prompt call mphlaunch to start a COMSOL Desktop, connect it to the same COMSOL Multiphysics Server to which MATLAB is connected to, and import a model.
Run the command below:
mphlaunch
This starts a new COMSOL Desktop, connect it to the COMSOL Multiphysics Server that is already connected with MATLAB, and import the model available in the server. In case several model are available in the server you can specify which one to import by running the command below:
mphlaunch ModelTag
where ModelTag is the tag of the model to import.
You can also specify the MATLAB object name that is link to the application to be imported in the COMSOL Desktop, enter the command:
mphlaunch(model)
If a COMSOL Multiphysics client is already connected to the COMSOL Multiphysics Server you will be asked to disconnect the connected client and connect the new one or cancel the operation.
mphlaunch sets automatically a timeout to make MATLAB wait 0.5 second until the COMSOL server is free again. If you need to increase the timeout run the command below:
mphlaunch(model,<timeout>)
where <timeout> is the time in milliseconds to wait for the server to be free again.
Connect the COMSOL Desktop to the COMSOL Multiphysics Server
Connect the COMSOL Desktop to a COMSOL Multiphysics Server manually using the Connect to Server dialog box:
1
From the File (Windows users) or Options menu (Mac and Linux users), select COMSOL Multiphysics Server>Connect to Server ().
2
In the Connect to Server window, you specify the Server configuration and the user settings. In the Server section enter the COMSOL Multiphysics Server name (the default name is localhost) and the Port number (the default is 2036). This number corresponds to the port that the COMSOL Multiphysics Server is listening to, the number is displayed at the COMSOL Multiphysics Server window.
3
In the User section enter a Username and a Password (if they are empty); these are defined the first time you are connected to the COMSOL Multiphysics Server.
4
Import An application from the COMSOL Multiphysics Server to the COMSOL Desktop
Once you have the COMSOL Desktop connected to the COMSOL Multiphysics Server you can import the model in the GUI:
1
From the File (Windows users) or Options menu (Mac and Linux users), select COMSOL Multiphysics Server>Import Application from Server ().
2
In the Import Application from Server window, specify the application you want to import.
Import A Model from the COMSOL Multiphysics Server to MATLAB
To access a model stored in the COMSOL Multiphysics Server from the MATLAB prompt enter the command:
model = mphload(<ModelTag>)
where model is the variable in MATLAB used to access the model stored on the COMSOL server and <ModelTag> is the tag of the COMSOL Model.
You can get the list of the models stored in the COMSOL Multiphysics Server with the command:
mphtags -show
Set up a time-out in MATLAB
To prevent MATLAB sending command to the COMSOL Multiphysics Server while it is busy to update the COMSOL Desktop, you need to set up a time-out in MATLAB and specify how long to wait the COMSOL Multiphysics Server to be free again. Enter the command:
ModelUtil.setServerBusyHandler(ServerBusyHandler(<timeout>))
Where <timeout> is the time in millisecond to wait the server to be free again.