- class Client(cores=None, version=None, port=None, host='localhost')¶
Manages the Comsol client instance.
A client can either be a stand-alone instance or it could connect to a Comsol server instance started independently, possibly on a different machine on the network.
import mph client = mph.Client(cores=1) model = client.load('model.mph') model.solve() model.save() client.remove(model)
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. Separate Python processes would have to be started, or spawned, to work around this limitation.
NotImplementedErroris therefore raised if another client is already running.
The number of
cores(threads) the client instance uses can be restricted by specifying a number. Otherwise all available cores are used.
A specific Comsol
versioncan be selected if several are installed, for example
version='5.3a'. Otherwise the latest version is used, and reported via the
Initializes a stand-alone Comsol session if no
portnumber is specified. Otherwise tries to connect to the Comsol server listening at the given port for client connections. The
hostaddress defaults to
'localhost', but could be any domain name or IP address.
Internally, the client is a wrapper around the
ModelUtilobject provided by Comsol’s Java API, which may also be accessed directly via the instance attribute
Returns all models currently held in memory.
Returns the names of all loaded models.
Returns the file-system paths of all loaded models.
Loads a model from the given
fileand returns it.
Enables or disables caching of previously loaded models.
Caching means that the
load()method will check if a model has been previously loaded from the same file-system path and, if so, return the in-memory model object instead of reloading it from disk. By default (at start-up) caching is disabled.
Trueto enable caching,
Falseto disable it. If no argument is passed, the current state is returned.
Creates a new model and returns it as a
namecan be supplied. Otherwise the model will retain its automatically generated name, like “Model 1”.
Removes the given
Removes all loaded models from memory.
Disconnects the client from the server.