dowhile#
- Mapdl.dowhile(par, **kwargs)#
Context manager for an APDL
*DOWHILEloop.Mechanical APDL Command: *DOWHILE
The loop repeats as long as the
parparameter is truthy (greater than 0.0) in MAPDL. Because MAPDL, not Python, performs the looping,parmust be a parameter that already exists (or is set right before entering the loop) in MAPDL, and it must be updated from within thewithblock using APDL commands so MAPDL can re-evaluate it on every pass.This method automatically uses the
Mapdl.non_interactivecontext 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
*DOand*DOWHILE). Attempting to nest more loops than that raises aMapdlDoLoopLimitError.If an exception is raised inside the
withblock, the*ENDDOis 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 outernon_interactiveblock or an outerdo/dowhileloop.- Parameters:
- par
str Name of the scalar parameter checked before every pass. The loop terminates once
paris less than or equal to 0.0.
- par
- Returns:
contextlib.AbstractContextManagerContext manager that opens the
*DOWHILEloop on entry and closes it with*ENDDOon exit.
- Return type:
_DoLoop
Examples
Loop while the
contparameter 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")