### start Source: https://github.com/mph-py/mph/blob/main/docs/api.md Starts a local Comsol session. ```APIDOC ## start ### Description Starts a local Comsol session. ### Method Not specified (assumed to be a function call) ### Endpoint Not applicable (SDK function) ### Parameters None explicitly documented. ### Request Example ```python import mph mph.start() ``` ### Response None explicitly documented. ``` -------------------------------- ### Initialize and Manage Comsol Server Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.Server.md Instantiate a Comsol server, print its listening port, and then stop it. This is a basic example of server lifecycle management. ```python import mph server = mph.Server(cores=1) print(f'Server listing on port {server.port}.') server.stop() ``` -------------------------------- ### Server Initialization Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.Server.md Initializes and starts a Comsol server process. Allows configuration of cores, version, port, multi-client support, timeout, and extra arguments. ```APIDOC ## Server Initialization ### Description Initializes and starts a Comsol server process. Allows configuration of cores, version, port, multi-client support, timeout, and extra arguments. ### Class `mph.Server` ### Parameters - **cores** (int, optional): Number of processor cores to use. Defaults to all available cores. - **version** (str, optional): Specific Comsol version to use (e.g., '6.0'). Defaults to the latest installed version. - **port** (int, optional): Network port for communication. If None, tries port 2036 or subsequent ports. If 0, selects a random free port. - **multi** (bool or str, optional): If True or 'on', the server accepts multiple client connections. If False, 'off', or None (default), the server shuts down when the first client disconnects. - **timeout** (int, optional): Timeout in seconds for server start-up. Defaults to 60. - **arguments** (list[str], optional): A list of extra command-line arguments to pass to the server process. ### Example Usage ```python import mph server = mph.Server(cores=1, version='6.0', port=2000, multi=True, timeout=30) ``` ``` -------------------------------- ### Start COMSOL Client Source: https://github.com/mph-py/mph/blob/main/docs/tutorial.md Initiates a connection to the COMSOL client. This operation may take approximately ten seconds to complete. You can optionally specify the number of processor cores to use. ```pycon >>> import mph >>> client = mph.start() ``` -------------------------------- ### mph.start Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.start.md Starts a local Comsol session. This function is used to create a Client instance for interacting with Comsol. It supports optional arguments for specifying the number of CPU cores, the Comsol version, and the server port. ```APIDOC ## mph.start ### Description Starts a local Comsol session. This convenience function is typically used for running a Comsol session on the local machine. ### Method Function call ### Signature `start(cores=None, version=None, port=0)` ### Parameters #### Function Parameters - **cores** (int, optional) - The number of CPU cores (threads) to be used by the Comsol instance. If not specified, all available cores will be used. - **version** (str, optional) - The specific Comsol version to select if multiple versions are installed (e.g., '6.0'). If not specified, the latest installed version is used. - **port** (int, optional) - The server port to be used if client-server mode is enabled. If omitted, the server chooses a random free port. ### Returns - [`Client`]() - An instance of the Client class representing the Comsol session. ### Notes - Only one client can be instantiated at a time. Subsequent calls to `start()` will return the existing client instance. - To work around the single-client limitation, separate Python processes must be started. - By default, communication is in client-server mode. To run a stand-alone client, set `mph.option('session', 'stand-alone')` beforehand. Stand-alone clients start faster and reduce call overhead but may have platform-specific limitations (e.g., out-of-the-box support on Windows only). ``` -------------------------------- ### Client Initialization Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.Client.md Initializes a Comsol client instance. It can connect to a running Comsol server or start a stand-alone session. Options include specifying the number of cores, Comsol version, port, and host. ```APIDOC ## Client Initialization ### Description Initializes a Comsol client instance. It can connect to a running Comsol server or start a stand-alone session. Options include specifying the number of cores, Comsol version, port, and host. ### Parameters #### Constructor Parameters - **cores** (int) - Optional - The number of processor cores (threads) the client instance uses. Defaults to all available cores. - **version** (str) - Optional - The Comsol version to select if several are installed (e.g., '6.0'). Defaults to the latest version. - **port** (int) - Optional - The port number to connect to a Comsol server. If not specified, initializes a stand-alone Comsol session. - **host** (str) - Optional - The host address of the Comsol server. Defaults to 'localhost'. If None, the client remains disconnected until `connect()` is called. ``` -------------------------------- ### Start Local COMSOL Session and Load Model Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.start.md Initiates a local COMSOL session with one core, loads a model, solves it, saves it, and then removes it from the session. This is a common workflow for local processing. ```python import mph client = mph.start(cores=1) model = client.load('model.mph') model.solve() model.save() client.remove(model) ``` -------------------------------- ### Load and Solve a COMSOL Model Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.Model.md This snippet demonstrates how to load a COMSOL model file, set parameters, solve the model, and evaluate a specific result. It requires the 'mph' library to be installed and a COMSOL model file (e.g., 'capacitor.mph'). ```python import mph client = mph.start() model = client.load('capacitor.mph') model.parameter('U', '1 [V]') model.parameter('d', '1 [mm]') model.solve() C = model.evaluate('2*es.intWe/U^2', 'pF') print(f'capacitance C = {C:.3f} pF') ``` -------------------------------- ### Install MPh Package Source: https://github.com/mph-py/mph/blob/main/docs/installation.md Install the MPh Python package using pip. This command also ensures that required dependencies like JPype and NumPy are installed. ```bash pip install MPh ``` -------------------------------- ### Start worker processes Source: https://github.com/mph-py/mph/blob/main/docs/demonstrations.md Launch multiple worker processes, each targeting the 'worker' function and sharing the 'jobs' and 'results' queues. It's recommended to store process objects to prevent garbage collection. ```python for _ in range(4): process = multiprocessing.Process(target=worker, args=(jobs, results)) process.start() ``` -------------------------------- ### Set LD_LIBRARY_PATH for Comsol Standalone Mode Source: https://github.com/mph-py/mph/blob/main/docs/limitations.md This example shows how to set the LD_LIBRARY_PATH environment variable to include Comsol shared libraries for standalone execution on Linux. Adjust the ComsolDir path based on your installation. ```bash ComsolDir=/usr/local/comsol63/multiphysics export LD_LIBRARY_PATH=\ $ComsolDir/lib/glnxa64:\ $ComsolDir/lib/glnxa64/gcc:\ $ComsolDir/ext/graphicsmagick/glnxa64:\ $ComsolDir/ext/cadimport/glnxa64:\ $LD_LIBRARY_PATH ``` -------------------------------- ### Referencing Model Nodes Using Division Operator Source: https://github.com/mph-py/mph/blob/main/docs/demonstrations.md Illustrates various ways to reference the same geometry element using the division operator with different starting points (client, model, geometries, geometry, block). ```python client/'block of ice'/'geometries'/'geometry'/'ice block' model/'geometries'/'geometry'/'ice block' geometries/'geometry'/'ice block' geometry/'ice block' block ``` -------------------------------- ### Getting Node Name Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.Node.md Retrieve the name of the node. ```python # Getting the node's name (example not directly runnable without context) # node.name() ``` -------------------------------- ### Get Time Step Values Source: https://github.com/mph-py/mph/blob/main/docs/tutorial.md Retrieve the actual time values corresponding to the 'first' and 'last' time steps in a time-dependent study. ```python (indices, values) = model.inner('time-dependent') >>> values[0] 0.0 >>> values[-1] 1.0 ``` -------------------------------- ### Getting Node Tag Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.Node.md Retrieve the tag of the node. ```python # Getting the node's tag (example not directly runnable without context) # node.tag() ``` -------------------------------- ### Install Older JPype Version Source: https://github.com/mph-py/mph/blob/main/docs/installation.md For Comsol versions 5.5 and 5.6, which use Java 8, you may need to downgrade JPype to a version compatible with Java 8. Newer JPype versions do not support Java 8. ```bash pip install "jpype1<1.6" ``` -------------------------------- ### Create a 3D Block Geometry in Comsol (Python) Source: https://github.com/mph-py/mph/blob/main/docs/demonstrations.md This Python code snippet achieves the same result as the Java example by creating a 3D block geometry in Comsol using MPh and JPype. It highlights the direct translation of Java API calls into Python, with minor adjustments for Python syntax, such as list representation. ```python import mph client = mph.start() pymodel = client.create('Model') model = pymodel.java model.modelNode().create("comp1"); model.geom().create("geom1", 3); model.geom("geom1").feature().create("blk1", "Block"); model.geom("geom1").feature("blk1").set("size", ["0.1", "0.2", "0.5"]); model.geom("geom1").run("fin"); ``` -------------------------------- ### Initialize and Use mph.Client Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.Client.md Demonstrates basic usage of the mph.Client to load, solve, save, and remove a model. Initializes a client with a specified number of cores. ```python import mph client = mph.Client(cores=1) model = client.load('model.mph') model.solve() model.save() client.remove(model) ``` -------------------------------- ### Getting Node Type Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.Node.md Retrieve the feature type of the node, which describes the type of model feature it represents. ```python # Getting the node's feature type (example not directly runnable without context) # node.type() ``` -------------------------------- ### mph.config.option Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.config.md Sets or returns the value of a configuration option. Can be used to get all options, a specific option, or set an option. ```APIDOC ## mph.config.option(name=None, value=None) ### Description Sets or returns the value of a configuration option. If called without arguments, returns all configuration options as a dictionary. Returns an option's value if only called with the option's `name`. Otherwise sets the option to the given `value`. ### Parameters #### Optional Parameters - **name** (string) - The name of the configuration option. - **value** (any) - The value to set for the configuration option. ### Returns - dict: All configuration options if no arguments are provided. - any: The value of the specified option if only `name` is provided. - None: If `value` is set. ``` -------------------------------- ### Render Documentation Source: https://github.com/mph-py/mph/blob/main/tools/ReadMe.md Renders project documentation using the render_docs.py script. ```shell uv run tools/render_docs.py ``` -------------------------------- ### Create and Configure Geometry by Name Source: https://github.com/mph-py/mph/blob/main/docs/demonstrations.md This snippet shows how to create a geometry node and set its properties using string-based node references. ```python import mph client = mph.start() model = client.create() model.create('geometries', 3) model.create('geometries/Geometry 1', 'Block') model.property('geometries/Geometry 1/Block 1', 'size', ('0.1', '0.2', '0.5')) model.build('Geometry 1') ``` -------------------------------- ### Enable Class Kit License Option Source: https://github.com/mph-py/mph/blob/main/docs/installation.md If using a 'Class Kit' Comsol license, set the 'classkit' option to True before calling mph.start() to pass the necessary '-ckl' argument. ```python mph.option('classkit', True) ``` -------------------------------- ### Get Model Geometries Source: https://github.com/mph-py/mph/blob/main/docs/tutorial.md Retrieve a list of geometry sequences defined within the model. This is useful for understanding the model's structure and dependencies. ```python >>> model.geometries() ['geometry'] ``` -------------------------------- ### Create Geometry with Custom Names Source: https://github.com/mph-py/mph/blob/main/docs/demonstrations.md Demonstrates creating geometry nodes with user-defined names, illustrating how 'model.create' handles non-existent parent nodes. ```python import mph client = mph.start() model = client.create('block of ice') model.create('geometries/geometry', 3) model.create('geometries/geometry/ice block', 'Block') model.property('geometries/geometry/ice block', 'size', ('0.1', '0.2', '0.5')) model.build('geometry') ``` -------------------------------- ### Model.solutions() Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.Model.md Returns the names of all solutions. ```APIDOC ## Model.solutions() ### Description Returns the names of all solutions. ### Method (Not specified, likely a getter method) ### Endpoint (Not applicable, SDK method) ### Parameters None ### Response #### Success Response - **solutions** (list of strings) - A list of solution names. ``` -------------------------------- ### Get Parameter Sweep Indices and Values Source: https://github.com/mph-py/mph/blob/main/docs/tutorial.md Retrieve the indices and corresponding parameter values for a parameter sweep study. This helps in mapping specific parameter settings to their results. ```python (indices, values) = model.outer('parametric sweep') >>> indices array([1, 2, 3], dtype=int32) >>> values array([1., 2., 3.] ``` -------------------------------- ### Build Wheel Package Source: https://github.com/mph-py/mph/blob/main/tools/ReadMe.md Builds the project's wheel package using the build_wheel.py script. ```shell uv run tools/build_wheel.py ``` -------------------------------- ### Print Model Parameters with Descriptions Source: https://github.com/mph-py/mph/blob/main/docs/tutorial.md Iterates through the model's parameters, fetching both the name/value and a description for each. It then prints this information in a formatted string. ```pycon >>> for (name, value) in model.parameters().items(): ... description = model.description(name) ... print(f'{description:20} {name} = {value}') ... applied voltage U = 1[V] electrode spacing d = 2[mm] plate length l = 10[mm] plate width w = 2[mm] ``` -------------------------------- ### Model.modules() Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.Model.md Returns the names of modules/products required to be licensed. ```APIDOC ## Model.modules() ### Description Returns the names of modules/products required to be licensed. ### Method (Not specified, likely a getter method) ### Endpoint (Not applicable, SDK method) ### Parameters None ### Response #### Success Response - **modules** (list of strings) - A list of required module names. ``` -------------------------------- ### Run Tests Source: https://github.com/mph-py/mph/blob/main/tools/ReadMe.md Executes the project's test suite using the run_tests.py script. ```shell uv run tools/run_tests.py ``` -------------------------------- ### Worker function for parallel processing Source: https://github.com/mph-py/mph/blob/main/docs/demonstrations.md This function is executed by each worker process. It starts a COMSOL session, loads a model, and processes jobs from a queue, returning results to another queue. It continues until the jobs queue is empty. ```python def worker(jobs, results): client = mph.start(cores=1) model = client.load('capacitor.mph') while True: try: d = jobs.get(block=False) except queue.Empty: break model.parameter('d', f'{d} [mm]') model.solve('static') C = model.evaluate('2*es.intWe/U^2', 'pF') results.put((d, C)) ``` -------------------------------- ### mph.config.load Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.config.md Loads configuration from a specified .ini file or a default file path. ```APIDOC ## mph.config.load(file=None) ### Description Loads the configuration from the given `.ini` file. If `file` is not given, it searches for `MPh.ini` in the current directory, the user profile directory, or the library's folder. If no file is found, default values are used. ### Parameters #### Optional Parameters - **file** (string) - The path to the configuration `.ini` file. ### Returns - None ``` -------------------------------- ### config Source: https://github.com/mph-py/mph/blob/main/docs/api.md Manages configuration options for the library. ```APIDOC ## config ### Description Manages configuration options for the library. ### Method Not specified (assumed to be a function or class) ### Endpoint Not applicable (SDK function/class) ### Parameters None explicitly documented. ### Request Example ```python import mph # Example: Accessing configuration (details not provided) # mph.config.some_option = 'value' ``` ### Response None explicitly documented. ``` -------------------------------- ### Model.materials() Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.Model.md Returns the names of all materials. ```APIDOC ## Model.materials() ### Description Returns the names of all materials. ### Method (Not specified, likely a getter method) ### Endpoint (Not applicable, SDK method) ### Parameters None ### Response #### Success Response - **materials** (list of strings) - A list of material names. ``` -------------------------------- ### Initialize job and results queues Source: https://github.com/mph-py/mph/blob/main/docs/demonstrations.md Create multiprocessing queues to manage tasks (jobs) and collect results from worker processes. Populate the jobs queue with parameter values. ```python jobs = multiprocessing.Queue() for d in values: jobs.put(d) ``` ```python results = multiprocessing.Queue() ``` -------------------------------- ### Setting LD_LIBRARY_PATH on Linux Source: https://github.com/mph-py/mph/blob/main/docs/limitations.md On Linux systems, to resolve 'UnsatisfiedLinkError' when running Comsol in stand-alone mode, you must add the paths to shared library folders to the LD_LIBRARY_PATH environment variable. This example shows how to append these paths to your .bashrc file. ```shell export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/comsol/plugins/run/bin/linux64:/path/to/comsol/multiphysics/bin/linux64 ``` -------------------------------- ### Switch to Main Branch and Update Source: https://github.com/mph-py/mph/blob/main/tools/ReadMe.md Switches to the main branch, pulls the latest changes, and forces updates for stable and version-specific branches. ```shell git switch main git pull git branch --force stable git branch --force 1.3 git push upstream stable git push upstream 1.3 ``` -------------------------------- ### backend Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.discovery.md Returns information about a specific Comsol back-end, or the latest version if none is specified. ```APIDOC ## backend(version=None) ### Description Returns information about the Comsol back-end. A specific Comsol `version` can be selected by name if several are installed, for example `version='6.0'`. Otherwise the latest version is used. ### Method N/A (Function call) ### Endpoint N/A ### Parameters - **version** (string) - Optional - The specific Comsol version name to retrieve information for (e.g., '6.0'). If not provided, the latest version is used. ``` -------------------------------- ### Import necessary modules Source: https://github.com/mph-py/mph/blob/main/docs/demonstrations.md Import the `mph`, `multiprocessing`, and `queue` modules for COMSOL interaction and parallel processing. ```python import mph import multiprocessing import queue ``` -------------------------------- ### Save Model with Solution Source: https://github.com/mph-py/mph/blob/main/docs/tutorial.md Save the current model, including its solution data. This will overwrite the existing file if no new filename is provided. ```python >>> model.save() ``` -------------------------------- ### Node.create(*arguments, name=None) Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.Node.md Creates a new child feature node. ```APIDOC ## Node.create(*arguments, name=None) ### Description Creates a new child feature node. ### Method N/A (Python method) ### Parameters - **arguments** (any) - Arguments required for creating the feature (e.g., feature type string). - **name** (str, optional) - The name/label for the new feature. If not given, a unique name is assigned automatically. ### Response - **new_node** (Node) - The instance of the newly created feature node. ``` -------------------------------- ### Node.run() Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.Node.md Performs the 'run' action if the node implements it. ```APIDOC ## Node.run() ### Description Performs the "run" action if the node implements it. ### Method N/A (Python method) ### Parameters None ### Response None (or specific return value if implemented by the node) ``` -------------------------------- ### List Available Datasets Source: https://github.com/mph-py/mph/blob/main/docs/tutorial.md Retrieve a list of all available datasets within the model, corresponding to different studies and solutions. ```python >>> model.datasets() ['electrostatic', 'time-dependent', 'parametric sweep', 'sweep//solution'] ``` -------------------------------- ### Model.physics() Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.Model.md Returns the names of all physics interfaces. ```APIDOC ## Model.physics() ### Description Returns the names of all physics interfaces. ### Method (Not specified, likely a getter method) ### Endpoint (Not applicable, SDK method) ### Parameters None ### Response #### Success Response - **physics** (list of strings) - A list of physics interface names. ``` -------------------------------- ### Server.running() Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.Server.md Checks if the Comsol server process is currently running. ```APIDOC ## Server.running() ### Description Returns whether the server process is still running. ### Method `Server.running()` ### Returns - **bool**: True if the server process is running, False otherwise. ``` -------------------------------- ### Model.build(geometry=None) Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.Model.md Builds the named geometry, or all of them if none given. ```APIDOC ## Model.build(geometry=None) ### Description Builds the named geometry, or all of them if none given. ### Method (Not specified, likely a method call) ### Endpoint (Not applicable, SDK method) ### Parameters #### Optional Parameters - **geometry** (string) - The name of the geometry sequence to build. If None, all geometries are built. ``` -------------------------------- ### Client Methods Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.Client.md Provides methods for managing models, client state, and connections. ```APIDOC ## Client Methods ### Description Provides methods for managing models, client state, and connections. ### Methods - **models()** - Returns all models currently held in memory. - **names()** - Returns the names of all loaded models. - **files()** - Returns the file-system paths of all loaded models. - **modules()** - Returns the names of available licensed modules/products. - **load(file)** - Loads a model from the given `file` and returns it. - **caching(state=None)** - Enables or disables caching of previously loaded models. Pass `True` to enable, `False` to disable. If no argument is passed, the current state is returned. - **create(name=None)** - Creates a new model and returns it as a `Model` instance. An optional `name` can be supplied. - **remove(model)** - Removes the given `model` from memory. - **clear()** - Removes all loaded models from memory. - **connect(port, host='localhost')** - Connects the client to a server listening at the given `port` and `host`. - **disconnect()** - Disconnects the client from the server. ``` -------------------------------- ### Model.components() Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.Model.md Returns the names of all model components. ```APIDOC ## Model.components() ### Description Returns the names of all model components. ### Method (Not specified, likely a getter method) ### Endpoint (Not applicable, SDK method) ### Parameters None ### Response #### Success Response - **components** (list of strings) - A list of component names. ``` -------------------------------- ### parse Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.discovery.md Parses version information as returned by the Comsol executable into a structured tuple. ```APIDOC ## parse(version) ### Description Parses version information as returned by Comsol executable. Returns `(name, major, minor, patch, build)` where `name` is a string and the rest are numbers. The name is a short-hand based on the major, minor, and patch version numbers, e.g. `'5.3a'`. Raises `ValueError` if the input string deviates from the expected format, i.e., the format in which the Comsol executable returns version information. ### Method N/A (Function call) ### Endpoint N/A ### Parameters - **version** (string) - Required - The version string to parse. ``` -------------------------------- ### Extract Max/Min Temperature from Busbar Model Source: https://github.com/mph-py/mph/blob/main/docs/demonstrations.md Loads a COMSOL busbar model, solves it, and programmatically extracts the maximum and minimum temperatures along with their coordinates. This is useful for analyzing simulation results without manual GUI interaction. ```python import mph client = mph.start() model = client.load('busbar.mph') model.solve() (x, y, z, T) = model.evaluate(['x', 'y', 'z', 'T']) (Tmax, Tmin) = (T.max(), T.min()) (imax, imin) = (T.argmax(), T.argmin()) print(f'Tmax = {T.max():.2f} K at ({x[imax]:5f}, {y[imax]:5f}, {z[imax]:5f})') print(f'Tmin = {T.min():.2f} K at ({x[imin]:5f}, {y[imin]:5f}, {z[imin]:5f})') ``` -------------------------------- ### List Physics Interfaces Source: https://github.com/mph-py/mph/blob/main/docs/tutorial.md Retrieves a list of names for all physics interfaces defined in the COMSOL model. ```pycon >>> model.physics() ['electrostatic', 'electric currents'] ``` -------------------------------- ### Model.descriptions Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.Model.md Retrieves all parameter descriptions as a dictionary. ```APIDOC ## Model.descriptions ### Description Returns all parameter descriptions as a dictionary. ### Method `descriptions()` ### Returns - dict: A dictionary where keys are parameter names (string) and values are their description texts (string). ``` -------------------------------- ### Model.mesh(mesh=None) Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.Model.md Runs the named mesh sequence, or all of them if none given. ```APIDOC ## Model.mesh(mesh=None) ### Description Runs the named mesh sequence, or all of them if none given. ### Method (Not specified, likely a method call) ### Endpoint (Not applicable, SDK method) ### Parameters #### Optional Parameters - **mesh** (string) - The name of the mesh sequence to run. If None, all mesh sequences are run. ``` -------------------------------- ### Client Source: https://github.com/mph-py/mph/blob/main/docs/api.md Manages the Comsol client instance. ```APIDOC ## Client ### Description Manages the Comsol client instance. ### Method Not specified (assumed to be a class) ### Endpoint Not applicable (SDK class) ### Parameters None explicitly documented. ### Request Example ```python import mph # Example: Instantiating the Client (details not provided) # client = mph.Client() ``` ### Response None explicitly documented. ``` -------------------------------- ### Create a 3D Block Geometry in Comsol (Java) Source: https://github.com/mph-py/mph/blob/main/docs/demonstrations.md This Java code snippet demonstrates the creation of a basic 3D block geometry within a Comsol model. It initializes a model, adds a geometry component, defines a block feature with specific dimensions, and runs the geometry. ```java import com.comsol.model.*; import com.comsol.model.util.*; public class HelloWorld { public static void main(String[] args) { run(); } public static Model run() { Model model = ModelUtil.create("Model"); model.modelNode().create("comp1"); model.geom().create("geom1", 3); model.geom("geom1").feature().create("blk1", "Block"); model.geom("geom1").feature("blk1").set("size", new String[]{"0.1", "0.2", "0.5"}); model.geom("geom1").run("fin"); return model; } } ``` -------------------------------- ### Run All Model Studies Source: https://github.com/mph-py/mph/blob/main/docs/tutorial.md Execute all simulation studies defined within the model. This is a convenient way to run all analyses at once. ```python >>> model.solve() ``` -------------------------------- ### Model.multiphysics() Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.Model.md Returns the names of all multiphysics interfaces. ```APIDOC ## Model.multiphysics() ### Description Returns the names of all multiphysics interfaces. ### Method (Not specified, likely a getter method) ### Endpoint (Not applicable, SDK method) ### Parameters None ### Response #### Success Response - **multiphysics** (list of strings) - A list of multiphysics interface names. ``` -------------------------------- ### Node Initialization Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.Node.md Initializes a Node object, representing a node in the model tree. It can be created with a model and an optional existing node. ```APIDOC ## Node Initialization ### Description Initializes a Node object, representing a node in the model tree. It can be created with a model and an optional existing node. ### Parameters * **model**: The model object this node refers to. * **node**: An optional existing node to reference. ``` -------------------------------- ### List Available Exports Source: https://github.com/mph-py/mph/blob/main/docs/tutorial.md View the names of all defined exports in the model. This helps in understanding what can be exported. ```python >>> model.exports() ['data', 'image'] ``` -------------------------------- ### Model.export Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.Model.md Executes an export node, optionally specifying an output file. If no arguments are provided, all export nodes are run with their default file names. ```APIDOC ## Model.export ### Description Runs the export node, either given by name or node reference. A file name can be specified; otherwise, the file name defined in the node's properties will be used. If called without arguments, all export nodes are run. ### Method `export(node=None, file=None)` ### Parameters - **node** (string or Node, optional) - The name or reference of the export node to run. If None, all export nodes are run. - **file** (string, optional) - The name of the file to export to. If None, the node's default file name is used. ### Returns None ``` -------------------------------- ### Compact COMSOL Model Files Source: https://github.com/mph-py/mph/blob/main/docs/demonstrations.md Iterates through all .mph files in the current directory, loads each model, clears its solution and mesh data, and saves it to reduce file size. This is useful for archiving models. ```python import mph from pathlib import Path client = mph.start() for file in Path.cwd().glob('*.mph'): print(f'{file}') model = client.load(file) model.clear() model.save() ``` -------------------------------- ### Model.file() Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.Model.md Returns the absolute path to the file the model was loaded from. ```APIDOC ## Model.file() ### Description Returns the absolute path to the file the model was loaded from. ### Method (Not specified, likely a getter method) ### Endpoint (Not applicable, SDK method) ### Parameters None ### Response #### Success Response - **file_path** (string) - The absolute path to the model file. ``` -------------------------------- ### Model.selections() Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.Model.md Returns the names of all selections. ```APIDOC ## Model.selections() ### Description Returns the names of all selections. ### Method (Not specified, likely a getter method) ### Endpoint (Not applicable, SDK method) ### Parameters None ### Response #### Success Response - **selections** (list of strings) - A list of selection names. ``` -------------------------------- ### Server Source: https://github.com/mph-py/mph/blob/main/docs/api.md Manages a Comsol server process. ```APIDOC ## Server ### Description Manages a Comsol server process. ### Method Not specified (assumed to be a class) ### Endpoint Not applicable (SDK class) ### Parameters None explicitly documented. ### Request Example ```python import mph # Example: Instantiating the Server (details not provided) # server = mph.Server() ``` ### Response None explicitly documented. ``` -------------------------------- ### Run Specific Simulation Studies Source: https://github.com/mph-py/mph/blob/main/docs/tutorial.md Execute a specific simulation study by its name. This allows for targeted analysis, such as electrostatic or relaxation studies. ```python >>> model.solve('static') >>> model.solve('relaxation') >>> model.solve('sweep') ``` -------------------------------- ### Navigating Model Nodes Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.Node.md Use the division operator to navigate the model tree and reference child nodes. Instances of Node work similarly to Python's Path objects. ```python >>> node = model/'functions' >>> node Node('functions') >>> node/'step' Node('functions/step') ``` -------------------------------- ### Generate Model Mesh Source: https://github.com/mph-py/mph/blob/main/docs/tutorial.md Create a mesh for the model. This is a prerequisite for running simulations and is often done automatically but can be explicitly called. ```python >>> model.mesh() ``` -------------------------------- ### search_disk Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.discovery.md Searches the file system for Comsol executables. ```APIDOC ## search_disk(architecture) ### Description Returns Comsol executables found on the file system. ### Method N/A (Function call) ### Endpoint N/A ### Parameters - **architecture** (string) - Required - The platform architecture to search for (e.g., 'win64'). ``` -------------------------------- ### find_backends Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.discovery.md Retrieves a list of all available Comsol back-ends discovered on the system. ```APIDOC ## find_backends() ### Description Returns the list of available Comsol back-ends. ### Method N/A (Function call) ### Endpoint N/A ### Parameters None ``` -------------------------------- ### Model.datasets() Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.Model.md Returns the names of all datasets. ```APIDOC ## Model.datasets() ### Description Returns the names of all datasets. ### Method (Not specified, likely a getter method) ### Endpoint (Not applicable, SDK method) ### Parameters None ### Response #### Success Response - **datasets** (list of strings) - A list of dataset names. ``` -------------------------------- ### search_path Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.discovery.md Searches the system's executable search path for the Comsol executable. ```APIDOC ## search_path() ### Description Returns Comsol executable if found on the system’s search path. ### Method N/A (Function call) ### Endpoint N/A ### Parameters None ``` -------------------------------- ### Node.toggle(action='flip') Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.Node.md Enables or disables the node. ```APIDOC ## Node.toggle(action='flip') ### Description Enables or disables the node. ### Method N/A (Python method) ### Parameters - **action** (str, optional) - The action to perform: 'flip' (default), 'enable', 'on', 'disable', 'off'. ### Response None ``` -------------------------------- ### search_registry Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.discovery.md Searches the Windows Registry for Comsol executables and returns their locations. ```APIDOC ## search_registry(architecture) ### Description Returns Comsol executables found in the Windows Registry. ### Method N/A (Function call) ### Endpoint N/A ### Parameters - **architecture** (string) - Required - The platform architecture to search for (e.g., 'win64'). ``` -------------------------------- ### List Custom Materials Source: https://github.com/mph-py/mph/blob/main/docs/tutorial.md Retrieves a list of names for all custom materials defined within the COMSOL model. ```pycon >>> model.materials() ['medium 1', 'medium 2'] ``` -------------------------------- ### Model.import_ Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.Model.md Imports external data from a file and assigns it to a specified node. Note the trailing underscore in the method name. ```APIDOC ## Model.import_ ### Description Imports external data from a file and assigns it to the node. The trailing underscore is necessary to avoid conflicts with Python's `import` statement. ### Method `import_(node, file)` ### Parameters - **node** (Node) - The node to which the data will be assigned. - **file** (string) - The path to the file containing the data to import. ### Returns None ``` -------------------------------- ### Model.meshes() Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.Model.md Returns the names of all mesh sequences. ```APIDOC ## Model.meshes() ### Description Returns the names of all mesh sequences. ### Method (Not specified, likely a getter method) ### Endpoint (Not applicable, SDK method) ### Parameters None ### Response #### Success Response - **meshes** (list of strings) - A list of mesh sequence names. ``` -------------------------------- ### mph.config.save Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.config.md Saves the current configuration to a specified .ini file or a default file path. ```APIDOC ## mph.config.save(file=None) ### Description Saves the configuration in the given `.ini` file. If `file` is not given, it saves the configuration in `MPh.ini` inside the default folder returned by [`location()`](). ### Parameters #### Optional Parameters - **file** (string) - The path to save the configuration `.ini` file. ### Returns - None ``` -------------------------------- ### Run Code Linting Source: https://github.com/mph-py/mph/blob/main/tools/ReadMe.md Lints the code for quality issues using the lint_code.py script. This is equivalent to running `uv run ruff check`. ```shell uv run tools/lint_code.py ``` -------------------------------- ### Model.exports() Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.Model.md Returns the names of all exports. ```APIDOC ## Model.exports() ### Description Returns the names of all exports. ### Method (Not specified, likely a getter method) ### Endpoint (Not applicable, SDK method) ### Parameters None ### Response #### Success Response - **exports** (list of strings) - A list of export names. ``` -------------------------------- ### Model.create Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.Model.md Creates a new feature node within the model. This is intended for COMSOL features and not all node types. ```APIDOC ## Model.create ### Description Creates a new feature node. This method is for COMSOL 'features' and may require specific arguments depending on the feature type. ### Method `create(node, *arguments)` ### Parameters - **node** (Node or string) - The parent node or node name under which to create the new feature. If the node does not exist, it will be created in its parent group. - **arguments** (any) - Arguments defining the feature to be created, often the feature type as a string (e.g., "Block"). Refer to COMSOL documentation for valid arguments. ### Returns - Node: The newly created child node instance. ``` -------------------------------- ### Visualizing the Model Tree Source: https://github.com/mph-py/mph/blob/main/docs/demonstrations.md Displays the structure of the created model using the mph.tree() function, showing automatically generated nodes and user-defined elements. ```pycon >>> mph.tree(model) block of ice ├─ parameters │ └─ Parameters 1 ├─ functions ├─ components │ └─ Component 1 ├─ geometries │ └─ geometry │ ├─ ice block │ └─ Form Union ├─ views │ └─ View 1 ├─ selections ├─ coordinates │ └─ Boundary System 1 ├─ variables ├─ couplings ├─ physics ├─ multiphysics ├─ materials ├─ meshes ├─ studies ├─ solutions ├─ batches ├─ datasets ├─ evaluations ├─ tables ├─ plots └─ exports ``` -------------------------------- ### Node.import_(file) Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.Node.md Imports external data from the specified file. ```APIDOC ## Node.import_(file) ### Description Imports external data from the given `file`. ### Method N/A (Python method) ### Parameters - **file** (str) - The path to the file to import. ### Response None ``` -------------------------------- ### detect_architecture Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.discovery.md Detects the platform architecture to determine the correct name for platform-specific Comsol binary sub-folders (e.g., 'win64', 'macarm64'). ```APIDOC ## detect_architecture ### Description Detects platform architecture to determine name of platform folder. Comsol binaries (executables and native libraries) are found in sub-folders with special names specific to the platform architecture, such as `win64` or `macarm64`. We return the correct folder name based on the detected platform (OS) and CPU architecture. ### Method N/A (Function call) ### Endpoint N/A ### Parameters None ``` -------------------------------- ### Model.name() Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.Model.md Returns the model's name. ```APIDOC ## Model.name() ### Description Returns the model's name. ### Method (Not specified, likely a getter method) ### Endpoint (Not applicable, SDK method) ### Parameters None ### Response #### Success Response - **name** (string) - The name of the model. ``` -------------------------------- ### Inspect Model Parameters Source: https://github.com/mph-py/mph/blob/main/docs/tutorial.md Retrieves a dictionary of all parameters defined within the loaded COMSOL model. Each parameter includes its name and value. ```pycon >>> model.parameters() {'U': '1[V]', 'd': '2[mm]', 'l': '10[mm]', 'w': '2[mm]'} ``` -------------------------------- ### Node.problems() Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.Node.md Retrieves problems (warnings and errors) reported by the node and its descendants. ```APIDOC ## Node.problems() ### Description Returns problems reported by the node and its descendants. ### Method N/A (Python method) ### Parameters None ### Response - **problems** (list[dict]) - A list of dictionaries, each containing 'message', 'category', 'node', and 'selection'. ``` -------------------------------- ### Export Result with Custom Filename Source: https://github.com/mph-py/mph/blob/main/docs/tutorial.md Export a specific result (e.g., 'image') and provide a custom filename and path. The '.png' extension is added automatically if not provided. ```python >>> model.export('image', 'static field.png') ``` -------------------------------- ### Model.parameters Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.Model.md Retrieves all global model parameters as a dictionary. Optionally evaluates them to numerical values. ```APIDOC ## Model.parameters ### Description Returns the global model parameters as a dictionary. Values can be returned as string expressions or evaluated numerical values. ### Method `parameters(evaluate=False)` ### Parameters - **evaluate** (boolean, optional) - If True, evaluates the parameter expressions to their numerical values. Defaults to False. ### Returns - dict: A dictionary where keys are parameter names (string) and values are parameter values (string expressions or numbers, depending on `evaluate`). ``` -------------------------------- ### Measure Code Coverage Source: https://github.com/mph-py/mph/blob/main/tools/ReadMe.md Measures the code coverage of the project using the measure_coverage.py script. ```shell uv run tools/measure_coverage.py ``` -------------------------------- ### Model.outer(dataset=None) Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.Model.md Returns the indices and values of outer solutions. ```APIDOC ## Model.outer(dataset=None) ### Description Returns the indices and values of outer solutions. These are the solution indices and values in parametric sweeps. ### Method (Not specified, likely a method call) ### Endpoint (Not applicable, SDK method) ### Parameters #### Optional Parameters - **dataset** (string) - The name of the dataset to use. If None, the default dataset is used. ### Response #### Success Response - **solution_data** (tuple) - A tuple containing an integer array of solution indices and a floating-point array of values. ``` -------------------------------- ### Display Model Tree Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.tree.md Visualize the branch of the model tree underneath a given node. Specify max_depth to limit the number of lower branches. This function performs poorly in client-server mode. ```python >>> mph.tree(model/'physics') ``` -------------------------------- ### Model.inner(dataset=None) Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.Model.md Returns the indices and values of inner solutions. ```APIDOC ## Model.inner(dataset=None) ### Description Returns the indices and values of inner solutions. These are the solution indices and time values in time-dependent studies. ### Method (Not specified, likely a method call) ### Endpoint (Not applicable, SDK method) ### Parameters #### Optional Parameters - **dataset** (string) - The name of the dataset to use. If None, the default dataset is used. ### Response #### Success Response - **solution_data** (tuple) - A tuple containing an integer array of solution indices and a floating-point array of time values. ``` -------------------------------- ### Node Navigation and Manipulation Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.Node.md Nodes support string concatenation to the right with the division operator to reference child nodes. They also provide methods to check existence and navigate the tree. ```APIDOC ## Node Navigation and Manipulation ### Description Nodes support string concatenation to the right with the division operator to reference child nodes. They also provide methods to check existence and navigate the tree. ### Example Usage ```python node = model / 'functions' child_node = node / 'step' print(child_node.exists()) ``` ### Methods * **exists()**: Checks if the node exists in the model tree. * **parent()**: Returns the parent node. * **name()**: Returns the node's name. * **tag()**: Returns the node's tag. * **type()**: Returns the node's feature type. ``` -------------------------------- ### Save Model with Custom Filename Source: https://github.com/mph-py/mph/blob/main/docs/tutorial.md Save the current model using a specified filename. The '.mph' extension is automatically appended if omitted. ```python >>> model.save('capacitor_solved') ``` -------------------------------- ### mph.config.location Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.config.md Returns the default location for the configuration file, which is platform-specific. ```APIDOC ## mph.config.location() ### Description Returns the default location of the configuration file. The folder returned by this function is platform-specific. ### Returns - string: The platform-specific default location for the configuration file. ``` -------------------------------- ### Model.save() Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.Model.md Saves the current model to a specified file path and format. If no path is provided, it uses the original file name or the current directory. The format can be explicitly set or inferred from the file extension. ```APIDOC ## Model.save(path=None, format=None) ### Description Saves the model at the given file-system path. If `path` is not given, the original file name is used. If the path contains no folder information, the current folder is used. If the path points to a folder, the model name is used to name the file inside that folder. A `format` can be specified as either "Comsol", "Java", "Matlab", or "VBA". If no format is given, it will be deduced from the file's ending. Imposes the correct file ending for the format. Overwrites existing files. ### Method `save(path=None, format=None)` ### Parameters #### Path Parameters * **path** (string) - Optional - The file-system path where the model will be saved. Defaults to the original file name or current directory. * **format** (string) - Optional - The format to save the model in (e.g., "Comsol", "Java", "Matlab", "VBA"). Defaults to format inferred from file extension or "Comsol" if no extension. ### Response None ``` -------------------------------- ### Model.problems() Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.Model.md Returns problems reported by nodes in the model. ```APIDOC ## Model.problems() ### Description Returns problems reported by nodes in the model. This method lets users check if any problems are reported throughout the model by testing `if model.problems():` in application code, to then act accordingly. ### Method (Not specified, likely a getter method) ### Endpoint (Not applicable, SDK method) ### Parameters None ### Response #### Success Response - **problems** (list) - A list of problems reported by nodes in the model. Each problem may contain error/warning messages and their origin. ``` -------------------------------- ### Model.version() Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.Model.md Returns the Comsol version the model was last saved with. ```APIDOC ## Model.version() ### Description Returns the Comsol version the model was last saved with. ### Method (Not specified, likely a getter method) ### Endpoint (Not applicable, SDK method) ### Parameters None ### Response #### Success Response - **version** (string) - The Comsol version. ``` -------------------------------- ### Model.properties Source: https://github.com/mph-py/mph/blob/main/docs/api/mph.Model.md Retrieves all properties of a given node as a dictionary. ```APIDOC ## Model.properties ### Description Returns names and values of all node properties as a dictionary. ### Method `properties(node)` ### Parameters - **node** (Node) - The node whose properties to retrieve. ### Returns - dict: A dictionary where keys are property names (string) and values are their corresponding values. ``` -------------------------------- ### Report Code Coverage Source: https://github.com/mph-py/mph/blob/main/tools/ReadMe.md Reports the code coverage, requiring an upload token to be set in the shell environment. ```shell # Add upload token in shell environment. uv run tools/report_coverage.py ```