Unable to solve .inp file using pymapdl

Options
Shailesh Kumar
Shailesh Kumar Member Posts: 10
First Comment
edited September 2023 in General Language Questions

Hi, I am trying to access a mechanical model and change the co-eff of friction for contact. But while doing so I am not able to solve the .inp file which I created from mechanical. Can anyone help me with this. The error says "SOLVE is not a recognized BEGIN command"

My code is as below:

from ansys.mapdl.core import launch_mapdl
import numpy as np
#import matplotlib.pyplot as plt
mapdl = launch_mapdl()
print(mapdl)
mapdl.input("D:\ACT\PyAnsys\PyAnsys_2021R2\X_Demo_Ansys_File\model1_input.inp")

# Change the friction coefficient for contact pair with ID 1 to 0.3
#mapdl.cmcoeff(1, "FRICTION", 0.3)

# Solve the model
#mapdl.slashsolu()
#mapdl.solve()
#mapdl.finish()

output = mapdl.solve()

print(output)

#result.plot_principal_nodal_stress(0,'seqv',background='w',show_edges=True,text_color='k',add_text=True)

mapdl.exit

Tagged:

Answers

  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 804
    First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member
    Options

    Hi @Shailesh Kumar . The issue is related to your last solve() command. As it is issued after finish() command, you're not in a processor where solve() command is recognized. You'll need to enter /solu before issuing that solve command. This is not really related to PyMAPDL, but more to MAPDL itself.

  • Shailesh Kumar
    Shailesh Kumar Member Posts: 10
    First Comment
    Options

    Hey, Thanks for the reply and sorry for the confusion but those lines are actually commented. Below is the complete code which is giving the error. It would be great if you could help!

    "from ansys.mapdl.core import launch_mapdl

    import numpy as np

    mapdl = launch_mapdl()

    print(mapdl)

    mapdl.input("D:\ACT\PyAnsys\PyAnsys_2023R1\X_Demo_Ansys_File\model1_input.inp")

    output = mapdl.solve()

    print(output)

    mapdl.exit"

  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 804
    First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member
    Options

    Can you check what is inside model1_input.inp ? Most probably it exits the /solu processor there and then when you try to solve you get this error.

  • Shailesh Kumar
    Shailesh Kumar Member Posts: 10
    First Comment
    Options

    I am getting this as error message - If you could find something with this, there is no /solu in my inp file

    CRITICAL - pymapdl_global - logging - handle_exception - Uncaught exception
    Traceback (most recent call last):
    File "d:\ACT\PyAnsys\PyAnsys_2023R1\dynCoF_2023-09-05_release0p7\dynCoF_2023-09-05_release0p7\Try.py", line 16, in
    output = mapdl.solve()
    File "D:\ACT\PyAnsys\PyAnsys_2023R1.venv\lib\site-packages\ansys\mapdl\core_commands\solution\analysis_options.py", line 3450, in solve
    return self.run(command, **kwargs)
    File "D:\ACT\PyAnsys\PyAnsys_2023R1.venv\lib\site-packages\ansys\mapdl\core\mapdl.py", line 3310, in run
    self._raise_errors(text)
    File "D:\ACT\PyAnsys\PyAnsys_2023R1.venv\lib\site-packages\ansys\mapdl\core\mapdl.py", line 4443, in _raise_errors
    raise MapdlInvalidRoutineError(text)
    ansys.mapdl.core.errors.MapdlInvalidRoutineError: *** WARNING *** CP = 0.781 TIME= 15:06:58
    SOLVE is not a recognized BEGIN command, abbreviation, or macro. This
    command will be ignored.

    Ignore these messages by setting 'ignore_errors'=True
    CRITICAL:pymapdl_global:Uncaught exception
    Traceback (most recent call last):
    File "d:\ACT\PyAnsys\PyAnsys_2023R1\dynCoF_2023-09-05_release0p7\dynCoF_2023-09-05_release0p7\Try.py", line 16, in
    output = mapdl.solve()
    File "D:\ACT\PyAnsys\PyAnsys_2023R1.venv\lib\site-packages\ansys\mapdl\core_commands\solution\analysis_options.py", line 3450, in solve
    return self.run(command, **kwargs)
    File "D:\ACT\PyAnsys\PyAnsys_2023R1.venv\lib\site-packages\ansys\mapdl\core\mapdl.py", line 3310, in run
    self._raise_errors(text)
    File "D:\ACT\PyAnsys\PyAnsys_2023R1.venv\lib\site-packages\ansys\mapdl\core\mapdl.py", line 4443, in _raise_errors
    raise MapdlInvalidRoutineError(text)
    ansys.mapdl.core.errors.MapdlInvalidRoutineError: *** WARNING *** CP = 0.781 TIME= 15:06:58
    SOLVE is not a recognized BEGIN command, abbreviation, or macro. This
    command will be ignored.

  • James Derrick
    James Derrick Administrator, Employee Posts: 248
    First Anniversary Solution Developer Community of Practice Member Ansys Employee 5 Up Votes
    admin
    Options

    Hi @Shailesh Kumar, welcome and thanks for posting! We use markdown on the forum, and I've formatted your first post to read a bit better as Python code. You can check more out about the forum here https://discuss.ansys.com/discussion/1848/welcome-please-read-before-posting#latest

  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 804
    First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member
    Options

    This is the problem - solve command is understood in /solu processor. So you need to enter it before issuing the solve command. At the moment when you are issuing the solve command you are still in the begin processor.

  • Shailesh Kumar
    Shailesh Kumar Member Posts: 10
    First Comment
    Options

    Hi, Thanks for help! its working now