Ansys Innovation Courses

Ansys Innovation Courses

Provide feedback or ask questions related to the Ansys Innovation Courses content

PyMAPDL Course Element Plot


    • Markus Quanz

      Hello, I am currently learning PyMAPDL, so I took the course "Getting Started with Ansys PyMAPDL". I tried to code the example of lesson 2, the 2D pipe. I am using the MAPDL Version 22.1 and the ansys.mapdl Version 0.63.3. The problem is that the element plot and the other post processing plots do not work. Can someone help me? Here is my code:

      import numpy as np
      import matplotlib.pyplot as plt
      from ansys.mapdl.core import launch_mapdl

      # MAPDL starten
      mapdl = launch_mapdl()

      # Querschnitt Rohr erzeugen

      def pipe_plain_strain(e, nu, inn_radius, out_radius, press, AESIZE):

      # e = E-Modul, nu=Querkontraktionszahl, press=Drucklast, AESIZE = Elementgröße
      # mapdl zurücksetzen

      # Elemente festlegen, "PLANE182", kop3=2) # Quad 4 node 182 mit keyoption 3 = 2 (plain strain formulation)

      # Geometrie erstellen
      # Viertelrohr erstellen, plain strain analysis von 0-90°
      mapdl.pcirc(inn_radius, out_radius, theta1=0, theta2=90)"PIPE_PROFILE", "AREA")

      # Materialparameter einstellen"EX", 1, e) # E-Modul"PRXY", 1, nu) # Querkontraktionszahl

      # Mesh-Controls definieren
      mapdl.aesize("ALL", AESIZE)
      mapdl.mshape(0, "2D") # die Fläche mit 2D Quad Elementen meshen
      mapdl.mshkey(1) # mapped mesh
      mapdl.cmsel("S", "PIPE_PROFILE") # Fläche als Komponente festlegen, die vernetzt werden soll

      # Komponenten für Aufbringung von Lasten und Randbedingungen erstellen
      mapdl.nsel("S", "LOC", "X", 0) # Knoten an der oberen linken Ecke auswählen"X_FIXED", "NODES") # Nodal component erstellen

      mapdl.nsel("S", "LOC", "Y", 0) # Knoten an der unteren rechten Ecke auswählen"Y_FIXED", "NODES") # Nodal component erstellen

      mapdl.lsel("S", "RADIUS", vmin=rad1) # Linie am inneren Radius auswählen"PRESSURE_EDGE", "LINE") # Linienkomponente erstellen

      # Lösungsparameter erstellen
      mapdl.slashsolu() # Enter solution
      mapdl.antype("STATIC", "NEW") # Neue statische Analyse (optional)

      mapdl.d("X_FIXED", "UX", 0) # Ausgewählte Knoten in X-Richtung sperren
      mapdl.d("Y_FIXED", "UY", 0) # Ausgewählte Knoten in Y-Richtung sperren

      # Wechsel vom aktiven Kartesischen Koordinatensystem in Zylindrisches Koordinatensystem

      # Aufbringen der gleichmäßigen Drucklast auf die ausgewähle Kante
      mapdl.sfl("PRESSURE_EDGE", "PRES", press)

      # Das Modell lösen

      # Post-Prozessor starten
      mapdl.set(1, 1) # ersten Lastschritt auswählen

      max_eqv_stress = np.max(mapdl.post_processing.nodal_eqv_stress())
      all_dof = mapdl.mesh.nnum_all
      num_dof = 2*all_dof.size # Anzahl der Freiheitsgrade ist doppelt so groß wie die Knotenanzahl

      return num_dof, max_eqv_stress

      # Input-Parameter definieren
      rad1 = 175 # innerer Radius
      rad2 = 200 # äußerer Radius
      pressure = 100

      e = 2e5 # E-Modul
      nu = 0.3 # Querkontraktionszahl

      # mesh convergence parameters definieren
      num_dof = []
      max_stress = []

      # Elementgröße: log space verwenden, da Netz logarithmisch konvergiert
      esizes = np.logspace(1.4, 0, 20)

      # Netzkonvergenz und Ergebnisse ausgeben
      for esize in esizes:
      dof, eqv_stress = pipe_plain_strain(e, nu, rad1, rad2, pressure, esize)
      print(f'DOF: {dof:5d} #Stress: {eqv_stress:.2f} MPa')

      # Plotten der Netzkonvergenz-Ergebnisse
      plt.figure(figsize=(8, 6), dpi=80)
      plt.plot(num_dof, max_stress, 'b-o')
      plt.plot([num_dof[0], num_dof[-1]], [max_stress[-1], max_stress[-1]], 'r:')
      plt.xlabel('Number of DOF')
      plt.ylabel('Maximum eqv. Stress (MPa)')

      # Plotten des final genutzten Netzes

      title='Element Plot', line_width=1, show_bounds=True, cpos="xy"

      mapdl.set(1, 1)

      'NORM', cpos="xy", cmap="magma",

      mapdl.post_processing.plot_nodal_eqv_stress(cpos="xy", cmap="magma")

    • Mike Rife
      Ansys Employee

      Hi Markus

      What do you mean by the plots do not work?  Also please update your PyMAPDL installation as the latest version is 0.65.0.


    • Markus Quanz

      Hi Mike,

      switching to the newer version worked, thank you. But with the new version I am getting another error in a different code. This is the part of the other code, which worked with PyMAPDL 0.63.3, but does not work with PyMAPDL 0.65.0:

      # Fixierung Welle Stirnseite
      mapdl.d('ALL', 'UX', 0)
      mapdl.d('ALL', 'UY', 0)
      mapdl.d('ALL', 'UZ', 0)
      mapdl.d('ALL', 'ROTX', 0)
      mapdl.d('ALL', 'ROTY', 0)
      mapdl.d('ALL', 'ROTZ', 0)
      And this are the error messages:

      CRITICAL - pymapdl_global -  logging - handle_exception - Uncaught exception
      Traceback (most recent call last):
        File "C:\Users\...\", line 191, in
          mapdl.d('ALL', 'ROTX', 0)
        File "C:\Users\...\AppData\Roaming\Python\Python311\site-packages\ansys\mapdl\core\_commands\solution\", line 133, in d
          return, **kwargs)
        File "C:\Users\...\AppData\Roaming\Python\Python311\site-packages\ansys\mapdl\core\", line 3004, in run
        File "C:\Users\...\AppData\Roaming\Python\Python311\site-packages\ansys\mapdl\core\", line 4015, in _raise_errors
          raise MapdlCommandIgnoredError(text)
      ansys.mapdl.core.errors.MapdlCommandIgnoredError: *** WARNING ***                         CP =      49.125   TIME= 08:59:54
       An inactive degree of freedom label (ROTX) was found on the D command.  
       The current degree of freedom set is: UX UY UZ                          
        This degree of freedom will be ignored.                                

       *** WARNING ***                         CP =      49.125   TIME= 08:59:54
       No valid degree of freedom labels were input.  The D command is         

      Ignore these messages by setting 'ignore_errors'=True

      Process finished with exit code 1

      Can you help me with this problem, too?
    • Mike Rife
      Ansys Employee

      Hi Markus

      For now since the model does not have rotational degrees of freedom, do not define them.  Or use the ignore_errors as indicated.  Please report this issue to as the PyMAPDL developers would like to see this.  Possibly they can build in some error handling to bypass D commands that define values to DOFs that do not exist, and pop a warning.  Mike 

Viewing 3 reply threads
  • You must be logged in to reply to this topic.