Modify multiple node positions in PyMAPDL

Samukham Member Posts: 35
First Anniversary First Comment Name Dropper
edited September 2023 in Structures

I need to modify multiple node positions for a particular model. For this currently, I'm using the command mapdl.n() (also tried mapdl.ngen()) in a loop. This works fine but takes a longer time appx. 70 seconds (since the number of nodes to be modified is large). Whereas when I perform the same task through corresponding commands directly in the APDL, it takes only 6-8 seconds. I don't understand why this time discrepancy arises. Also, is there any way to perform this task in an effective way?

P.S: I'm performing the task in a way similar to the following script:


for id in range(1,10000):

APDL Script:



  • German Martinez
    German Martinez Member, Employee Posts: 6
    First Anniversary Name Dropper First Comment Ansys Employee


    Sending multiple commands in interactive mode (default) can be slow because the amount of extra processing (pre-processing, sending, waiting, post-processing) associated for each command.

    If you want to speed up the process, use non-interactive context manager.
    This will group all the command in one single MAPDL call, send it and wait for its full response, hence less gRPC overhead.

    There is an interesting discussion about this in GitHub:


  • Samukham
    Samukham Member Posts: 35
    First Anniversary First Comment Name Dropper

    Thanks a lot @German Martinez, the suggestion seems logical. I'll experiment with the non-interactive context manager.

  • Mike.Thompson
    Mike.Thompson Member, Employee Posts: 280
    First Anniversary First Comment 5 Likes Ansys Employee

    You can also always send APDL commands as text if there is some thing you want to do strictly by APDL input. This is useful when you may have APDL snippets and sections you don’t yet want to migrate to python implementation.

  • Samukham
    Samukham Member Posts: 35
    First Anniversary First Comment Name Dropper

    Hi @German Martinez,
    I tried out the non-interactive context manager you suggested, and it did make things faster. I also looked into the discussion on GitHub that you shared I tested various ways to run APDL commands with PyMAPDL and found that the PyMAPDL input method is much quicker. The non-interactive context manager does speed things up, but not as much (it's about 50% faster than interactive PyMAPDL).

    However, when I checked the GitHub discussion, they reported that there's not much difference between PyMAPDL's non-interactive context manager and the PyMAPDL input method. This is different from what I found. On my computer, the times were:

    PyMAPDL (interactive): 51 seconds
    PyMAPDL (non-interactive): 19 seconds
    PyMAPDL (Input): 0.4 seconds

    So, to double-check, I ran the same code from GitHub and got these results:

    === Results ===
    APDL Real Batch is the reference.
    Number of averages is 10
    APDL (Single batch) - Time spent: 0.092188 s - Relative: 100.000 %
    APDL (Multi Batch) - Time spent: 15.425698 s - Relative: 16732.961 %
    APDL (Single Input) - Time spent: 0.092188 s - Relative: 100.000 %
    APDL (Multi Input) - Time spent: 15.226078 s - Relative: 16516.423 %
    PyMAPDL (Interactive) - Time spent: 51.226841 s - Relative: 55568.099 %
    PyMAPDL (Interactive-No Output) - Time spent: 23.698389 s - Relative: 25706.727 %
    PyMADPL (Non-interactive) - Time spent: 20.281215 s - Relative: 21999.962 %
    PyMAPDL (Input) - Time spent: 0.205457 s - Relative: 222.869 %

    As you can see, there's a big difference between PyMAPDL (Input) and PyMAPDL (non-interactive) methods, which doesn't match what was discussed on GitHub.

    I'm curious to know why there is such a big difference in performance for PyMAPDL (non-interactive) on my computer compared to the results on GitHub. Is it because of the version issues or any other?

  • Mike Rife
    Mike Rife Member, Employee Posts: 35
    First Answer 5 Likes First Anniversary First Comment

    Hi @Samukham which PyMAPDL and MAPDL versions are you using? The PyMAPDL 'input' command is not the MAPDL 'input' command. It is a new implementation that recreates the functionality (of MAPDL input) along with adding some features. It's possible that this new PyMAPDL input is faster than the old.

    Also if you want to measure speed try testing out the new(ish) Db nodes push method.

    PyMAPDL DB Nodes Push

    My understanding, which may be very wrong!, is that this method is a direct grpc access to the MAPDL database and does not rely on MAPDL being an command interpreter. So it should be faster (in my technical support mind) to create/modify a node than the standard N command. The looping though throughs the whole thought experiment for a loop (ha!). So, let's test and find out.