start(cores=None, version=None, port=None)¶
Starts a local Comsol session.
This convenience function provides for the typical use case of running a Comsol session on the local machine, i.e. not have a client connect to a remote server elsewhere on the network.
import mph client = mph.start(cores=1) model = client.load('model.mph') model.solve() model.save() client.remove(model)
Depending on the platform, this may either be a stand-alone client (on Windows) or a thin client connected to a server running locally (on Linux and macOS). The reason for this disparity is that, while stand-alone clients are more lightweight and faster to start up, and therefore preferable, support for this mode of operation is somewhat limited on Unix-like operating systems, and thus not the default. Find more details in documentation chapter “Limitations”.
Due to limitations of the Java bridge, provided by the JPype library, only one client can be instantiated at a time. This is because JPype cannot manage more than one Java virtual machine within the same Python session. Therefore
start()can only be called once. Subsequent calls will raise
NotImplementedError. Separate Python processes would have to be started, or spawned, to work around this limitation. Refer to chapter “Demonstrations” in the documentation for an example of how to achieve this.
The number of
cores(threads) the Comsol instance uses can be restricted by specifying a number. Otherwise all available cores will be used.
A specific Comsol
versioncan be selected if several are installed, for example
version='5.3a'. Otherwise the latest version is used.
portcan be specified if client–server mode is used. If omitted, the port number is chosen automatically by the server. Hand-selecting a port is helpful when starting multiple processes in order to run sessions in parallel. Servers started at roughly the same time will all try to reserve the same network port, a collision that will usually produce run-time errors. In stand-alone mode this problem cannot occur and the argument is just ignored.