TAGGED: PyMAPDL
-
-
June 27, 2023 at 3:04 pmquanzSubscriber
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()
print(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
mapdl.clear()
mapdl.prep7()
# Elemente festlegen
mapdl.et(1, "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)
mapdl.cm("PIPE_PROFILE", "AREA")
# Materialparameter einstellen
mapdl.mp("EX", 1, e) # E-Modul
mapdl.mp("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
mapdl.amesh("ALL")
# Komponenten für Aufbringung von Lasten und Randbedingungen erstellen
mapdl.nsel("S", "LOC", "X", 0) # Knoten an der oberen linken Ecke auswählen
mapdl.cm("X_FIXED", "NODES") # Nodal component erstellen
mapdl.nsel("S", "LOC", "Y", 0) # Knoten an der unteren rechten Ecke auswählen
mapdl.cm("Y_FIXED", "NODES") # Nodal component erstellen
mapdl.allsel()
mapdl.lsel("S", "RADIUS", vmin=rad1) # Linie am inneren Radius auswählen
mapdl.cm("PRESSURE_EDGE", "LINE") # Linienkomponente erstellen
mapdl.allsel()
# 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
mapdl.csys(1)
# Aufbringen der gleichmäßigen Drucklast auf die ausgewähle Kante
mapdl.sfl("PRESSURE_EDGE", "PRES", press)
# Das Modell lösen
mapdl.allsel()
mapdl.solve()
mapdl.finish()
# Post-Prozessor starten
mapdl.post1()
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)
num_dof.append(dof)
max_stress.append(eqv_stress)
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.title('Netzkonvergenzstudie')
plt.xlabel('Number of DOF')
plt.ylabel('Maximum eqv. Stress (MPa)')
plt.show()
# Plotten des final genutzten Netzes
mapdl.allsel('ALL')
mapdl.eplot(
title='Element Plot', line_width=1, show_bounds=True, cpos="xy"
)
mapdl.post1()
mapdl.set(1, 1)
mapdl.post_processing.plot_nodal_displacement(
'NORM', cpos="xy", cmap="magma",
)
mapdl.post_processing.plot_nodal_eqv_stress(cpos="xy", cmap="magma")
mapdl.exit() -
June 27, 2023 at 7:02 pmmrifeAnsys 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.
Mike
-
June 28, 2023 at 7:04 amquanzSubscriber
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.csys(0)
mapdl.nsel('s','loc','z',0)
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)
mapdl.allsel('all')ÂAnd this are the error messages:CRITICAL - pymapdl_global - Â logging - handle_exception - Uncaught exception
Traceback (most recent call last):
 File "C:\Users\...\Skript.py", line 191, in
  mapdl.d('ALL', 'ROTX', 0)
 File "C:\Users\...\AppData\Roaming\Python\Python311\site-packages\ansys\mapdl\core\_commands\solution\fe_constraints.py", line 133, in d
  return self.run(command, **kwargs)
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^
 File "C:\Users\...\AppData\Roaming\Python\Python311\site-packages\ansys\mapdl\core\mapdl.py", line 3004, in run
  self._raise_errors(text)
 File "C:\Users\...\AppData\Roaming\Python\Python311\site-packages\ansys\mapdl\core\mapdl.py", 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     Â
 ignored.Ignore these messages by setting 'ignore_errors'=True
Process finished with exit code 1
Can you help me with this problem, too? -
June 28, 2023 at 1:43 pmmrifeAnsys 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 https://github.com/ansys/pymapdl/issues 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Â
-
- The topic ‘PyMAPDL Course Element Plot’ is closed to new replies.
-
1241
-
543
-
523
-
225
-
209
© 2024 Copyright ANSYS, Inc. All rights reserved.