dowhile#

Mapdl.dowhile(par, **kwargs)#

Context manager for an APDL *DOWHILE loop.

Mechanical APDL Command: *DOWHILE

The loop repeats as long as the par parameter is truthy (greater than 0.0) in MAPDL. Because MAPDL, not Python, performs the looping, par must be a parameter that already exists (or is set right before entering the loop) in MAPDL, and it must be updated from within the with block using APDL commands so MAPDL can re-evaluate it on every pass.

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

Name of the scalar parameter checked before every pass. The loop terminates once par is less than or equal to 0.0.

Returns:
contextlib.AbstractContextManager

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

Return type:

_DoLoop

Examples

Loop while the cont parameter is truthy, decrementing it on every pass.

>>> mapdl.parameters["cont"] = 5
>>> with mapdl.dowhile("cont"):
...     mapdl.n("cont", "cont", 0, 0)
...     mapdl.run("cont = cont - 1")