Node

class Node(model, path=None)[source]

Represents a model node.

Nodes 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:

>>> node = model/'functions'
>>> node
Node('functions')
>>> node/'step'
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:

>>> (node/'new function').exists()
False

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:

>>> node = model/'datasets/sweep//solution'
>>> node.name()
'sweep//solution'
>>> node.parent()
Node('datasets')

This class allows inspecting a node, such as its properties and child nodes, as well as manipulating it to some extent, like toggling it on/off, creating child nodes, or “running” it. Not all actions made available by Comsol are exposed here. Those missing can however be triggered in the Java layer, which is accessible via the .java property.

property java

Returns the Java object this node maps to.

Note that this is a property, not an attribute. Internally, it is a function that performs a top-down search of the model tree in order to resolve the node reference. So it introduces a certain overhead every time it is accessed.

name()[source]

Returns the node’s name.

tag()[source]

Returns the node’s tag.

type()[source]

Returns the node’s feature type.

This a something like 'Block' for “a right-angled solid or surface block in 3D”. Refer to the Comsol documentation for details. Feature types are displayed in the Comsol GUI at the top of the Settings tab.

parent()[source]

Returns the parent node.

children()[source]

Returns all child nodes.

is_root()[source]

Checks if the node is the model’s root node.

is_group()[source]

Checks if the node refers to a built-in group.

exists()[source]

Checks if the node exists in the model tree.

rename(name)[source]

Renames the node.

retag(tag)[source]

Assigns a new tag to the node.

property(name, value=None)[source]

Returns or changes the value of the named property.

If no value is given, returns the value of property name. Otherwise sets the property to the given value.

properties()[source]

Returns names and values of all node properties as a dictionary.

toggle(action='flip')[source]

Enables or disables the node.

If action is 'flip' (the default), it enables the feature in the model tree if it is currently disabled or disables it if enabled. Pass 'enable' or 'on' to enable the feature regardless of its current state. Pass 'disable' or 'off' to disable it.

run()[source]

Performs the “run” action if the node implements it.

create(*arguments, name=None)[source]

Creates a new child node.

Refer to the Comsol documentation for the values of valid arguments. It is often just the feature type of the child node to be created, given as a string such as 'Block', but may also require different or more arguments.

If name is not given, a unique name/label will be assigned automatically.

remove()[source]

Removes the node from the model tree.