Managing components#

MAPDL components can be retrieved and set using Mapdl.components.

There are several ways to create a component in MAPDL.

You can use the Mapdl.cm method:

>>> from ansys.mapdl.core import launch_mapdl
>>> mapdl = launch_mapdl()
>>> mapdl.prep7()
>>> mapdl.block(0, 1, 0, 1, 0, 1)
>>> mapdl.vsel("s", "", "", 1)
>>> mapdl.cm("my_comp", "volu")

Or use higher level syntax. For instance, to set a component specifying the type and items:

>>> mapdl.components["mycomp3"] = "KP", [1, 2, 3]

Set a component without specifying the type, by default it is NODE:

>>> mapdl.components["mycomp4"] = (1, 2, 3)
/Users/german.ayuso/pymapdl/src/ansys/mapdl/core/component.py:347: UserWarning: Assuming   a KP selection.
It is recommended you use the following notation to avoid this warning:
> mapdl.components['mycomp4'] = 'KP' (1, 2, 3)
Alternatively, you disable this warning using:
> mapdl.components.default_entity_warning=False
warnings.warn(

You can change the default type by changing Mapdl.components.default_entity

>>> mapdl.components.default_entity = "KP"
>>> mapdl.components["mycomp"] = [1, 2, 3]
>>> mapdl.components["mycomp"].type
'KP'

You can also create a component from already selected entities:

>>> mapdl.lsel("S", 1, 2)
>>> mapdl.components["mylinecomp"] = "LINE"
>>> mapdl.components["mylinecomp"]
(1, 2)

Selecting a component and retrieving it:

>>> mapdl.cmsel("s", "mycomp3")
>>> mapdl.components["mycomp3"]
Component(type='KP', items=(1, 2, 3))

Note

Component selection To being able to access a component through Mapdl.components, the component needs to be selected using Mapdl.cmsel().

Component object#

The Component object <ansys.mapdl.core.component.Component> is the object returned by Mapdl.components when you query it with a component name. This object has two main attributes: type <Component.type> and items <Component.items>. The former returns the component type (“ELEM”, “NODE”, “KP”, etc) and the later returns a tuple with the index of the entities which belong to that component.

>>> comp = mapdl.components["mycomp3"]
>>> comp.type
'KP'
>>> comp.items
(1, 2, 3)

It should be noticed that the component object is not linked to the MAPDL component, so any change on it is not reflected in the MAPDL counterpart.