do#

Mapdl.do(par, ival='', fval='', inc='', **kwargs)#

Context manager for an APDL *DO loop.

Mechanical APDL Command: *DO

The block of commands issued inside the with block is sent to MAPDL once and executed repeatedly by MAPDL itself, similarly to how the *DO/*ENDDO commands work when typed directly into MAPDL. This is fundamentally different from a Python for loop: the body of the with block is only evaluated once by Python to build up the block of APDL commands, and MAPDL performs the actual looping.

This method automatically uses the Mapdl.non_interactive context manager (unless it is already active) so the whole loop is sent to MAPDL as a single block.

MAPDL allows a maximum of 20 levels of nested do-loops (shared between *DO and *DOWHILE). Attempting to nest more loops than that raises a MapdlDoLoopLimitError.

If an exception is raised inside the with block, the *ENDDO is never sent and the (incomplete) commands buffered by this loop are discarded, without affecting commands legitimately buffered before entering the loop, for example by an outer non_interactive block or an outer do/dowhile loop.

Parameters:
parstr

The name of the scalar parameter used as the loop index. Any existing parameter of the same name is redefined.

ivalstr, optional

Initial value assigned to par.

fvalstr, optional

Final value. If ival exceeds fval and inc is positive, the loop is not executed.

incstr, optional

Increment applied to par for each successive loop. Defaults to 1 in MAPDL. Negative increments and non-integer numbers are allowed.

Returns:
contextlib.AbstractContextManager

Context manager that opens the *DO loop on entry and closes it with *ENDDO on exit.

Return type:

_DoLoop

Examples

Create 10 nodes along the X axis.

>>> with mapdl.do("i", 1, 10):
...     mapdl.n("i", "i", 0, 0)