Skip to content

Commit

Permalink
Added cross-references to API documenation.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-hen committed Jan 2, 2022
1 parent b2f373f commit 5b24fdd
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 32 deletions.
16 changes: 9 additions & 7 deletions mph/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def caching(self, state=None):
"""
Enables or disables caching of previously loaded models.
Caching means that the `load()` method will check if a model
Caching means that the {meth}`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.
Expand All @@ -348,7 +348,7 @@ def caching(self, state=None):

def create(self, name=None):
"""
Creates a new model and returns it as a `Model` instance.
Creates a new model and returns it as a {class}`Model` instance.
An optional `name` can be supplied. Otherwise the model will
retain its automatically generated name, like "Model 1".
Expand All @@ -363,7 +363,7 @@ def create(self, name=None):
return model

def remove(self, model):
"""Removes the given `model` from memory."""
"""Removes the given {class}`model <Model>` from memory."""
if isinstance(model, str):
if model not in self.names():
error = f'No model named "{model}" exists.'
Expand Down Expand Up @@ -407,8 +407,9 @@ def connect(self, port, host='localhost'):
client connections. The `host` address defaults to `'localhost'`,
but could be any domain name or IP address.
This will fail for stand-alone clients or if the client is already
connected to a server. In the latter case, `disconnect()` first.
This will fail for stand-alone clients or if the client is
already connected to a server. In the latter case, call
{meth}`disconnect` first.
"""
if self.standalone:
error = 'Stand-alone clients cannot connect to a server.'
Expand All @@ -427,8 +428,9 @@ def disconnect(self):
"""
Disconnects the client from the server.
Note that the server, unless started with the option `multi`
set to `'on'`, will shut down as soon as the client disconnects.
Note that the {class}`server <Server>`, unless started with
the option `multi` set to `'on'`, will shut down as soon as
the client disconnects.
"""
if self.port:
log.debug('Disconnecting from server.')
Expand Down
4 changes: 2 additions & 2 deletions mph/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def load(file=None):
If `file` is not given, looks for a configuration file named
`MPh.ini` in the current directory, or in the folder inside the
user profile as returned by `location()`, or in this library's
user profile as returned by {func}`location`, or in this library's
folder, in that order. If no such file is found, the hard-coded
default values are used.
"""
Expand Down Expand Up @@ -114,7 +114,7 @@ def save(file=None):
Saves the configuration in the given `.ini` file.
If `file` is not given, saves the configuration in `MPh.ini`
inside the default folder returned by `location()`.
inside the default folder returned by {func}`location`.
"""
if not file:
file = location()/'MPh.ini'
Expand Down
11 changes: 6 additions & 5 deletions mph/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class Model:
Represents a Comsol model.
The class is not intended to be instantiated directly. Rather, the
model would be loaded from a file by the client.
model would be loaded from a file by the [client](mph.Client.md).
Example usage:
```python
Expand All @@ -110,12 +110,12 @@ class Model:
model, then evaluate the results. The intention is not *per se*
to create the model from scratch or to extensively modify its
structure, though some such functionality is offered here, and
even more of it through the `Node` class.
even more of it through the {class}`Node` class.
This class is a wrapper around the [`com.comsol.model.Model`][1]
Java class, which itself is wrapped by JPype and can be accessed
directly via the `.java` attribute. The full Comsol functionality is
thus available if needed.
directly via the `.java` attribute. The full Comsol functionality
is thus available if needed.
The `parent` argument to the constructor is usually that internal
Java object. But in order to simplify extending the class with
Expand Down Expand Up @@ -438,7 +438,8 @@ def evaluate(self, expression, unit=None, dataset=None,
`unit` must be given correspondingly. If omitted, default
units are used. The expression may be a global one, or a scalar
field, or particle data. Results are returned as (lists of)
NumPy arrays, of whichever dimensionality they may then have.
[NumPy arrays](numpy:ndarray), of whichever dimensionality they
may then have.
A `dataset` may be specified. Otherwise the expression will
be evaluated on the default dataset. If the solution stored in
Expand Down
25 changes: 13 additions & 12 deletions mph/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ class Node:
on/off, creating child nodes, or "running" it.
Instances of this class reference a node in the model tree and work
similarly to `pathlib.Path` objects from Python's standard library.
They support string concatenation to the right with the division
operator in order to reference child nodes:
similarly to [`Path`](python:pathlib.Path) objects from Python's
standard library. They support string concatenation to the right
with the division operator in order to reference child nodes:
```python
>>> node = model/'functions'
>>> node
Expand All @@ -47,16 +47,17 @@ class Node:
Node('functions/step')
```
Note how the `model` object also supports the division operator in
order to generate node references. As mere references, nodes must
must not necessarily exist in the model tree:
Note how the {class}`model <Model>` object also supports the division
operator in order to generate node references. As mere references,
nodes must must not necessarily exist in the model tree:
```python
>>> (node/'new function').exists()
False
```
In interactive sessions, the convenience function `mph.tree()` may
prove useful to see the node's branch in the model tree at a glance:
In interactive sessions, the convenience function {func}`mph.tree`
may prove useful to see the node's branch in the model tree at a
glance:
```console
>>> mph.tree(model/'physics')
physics
Expand All @@ -76,8 +77,8 @@ class Node:
In rare cases, the node name itself might contain a forward slash,
such as the dataset `sweep/solution` that happens to exist in the
demo model from the Tutorial. These literal forward slashes can be
escaped by doubling the character:
demo model from the [Tutorial](../tutorial.md). These literal
forward slashes can be escaped by doubling the character:
```python
>>> node = model/'datasets/sweep//solution'
>>> node.name()
Expand All @@ -92,8 +93,8 @@ class Node:
[`com.comsol.model.ModelEntity`][1] interface. That Java object
can be accessed directly via the `.java` property. The full Comsol
functionality is thus available if needed. The convenience function
`mph.inspect()` is provided for introspection of the Java object in
an interactive session.
{func}`mph.inspect` is provided for introspection of the Java object
in an interactive session.
[1]: https://doc.comsol.com/5.6/doc/com.comsol.help.comsol/api\
/com/comsol/model/ModelEntity.html
Expand Down
13 changes: 7 additions & 6 deletions mph/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ def start(cores=None, version=None, port=0):
systems, and thus not the default. Find more details in documentation
chapter "Limitations".
Only one client can be instantiated at a time. This is a limitation
of the Comsol API. Subsequent calls to `start()` will return the
client instance created in the first call. In order to work around
this limitation, separate Python processes have to be started. Refer
to section "Multiple processes" in documentation chapter
"Demonstrations" for guidance.
Returns a {class}`Client` instance. Only one client can be
instantiated at a time. This is a limitation of the Comsol API.
Subsequent calls to `start()` will return the client instance
created in the first call. In order to work around this limitation,
separate Python processes have to be started. Refer to section
"[Multiple processes](demonstrations.md#multiple-processes)" for
guidance.
The number of `cores` (threads) the Comsol instance uses can be
restricted by specifying a number. Otherwise all available cores
Expand Down

0 comments on commit 5b24fdd

Please sign in to comment.