This example shows how you can use PyMAPDL to create basic geometry using Pythonic PREP7 area commands.
import numpy as np from ansys.mapdl.core import launch_mapdl # start MAPDL and enter the pre-processing routine mapdl = launch_mapdl() mapdl.clear() mapdl.prep7() print(mapdl)
Product: Ansys Mechanical Enterprise MAPDL Version: 21.2 ansys.mapdl Version: 0.62.1
APDL Command: A#
Create a simple triangle in the XY plane using three keypoints.
APDL Command: AL#
Create an area from four lines.
mapdl.clear() mapdl.prep7() k0 = mapdl.k("", 0, 0, 0) k1 = mapdl.k("", 1, 0, 0) k2 = mapdl.k("", 1, 1, 0) k3 = mapdl.k("", 0, 1, 0) l0 = mapdl.l(k0, k1) l1 = mapdl.l(k1, k2) l2 = mapdl.l(k2, k3) l3 = mapdl.l(k3, k0) anum = mapdl.al(l0, l1, l2, l3) mapdl.aplot(show_lines=True, line_width=5, show_bounds=True, cpos="xy")
APDL Command: ADRAG#
Generate areas by dragging a line pattern along a path.
Drag a circle between two keypoints to create an area
APDL Command: ASBA#
0.5 x 0.5 rectangle from a
1 x 1 rectangle.
Return an array of the area IDs
Get the VTK
PolyData containing lines. This VTK mesh can be
saved or plotted. For more details, visit https://docs.pyvista.com
Note that this is a method so you can select the quality of the areas (mesh density), and if you would like a merged output or individual meshes.
[UnstructuredGrid (0x7f6c145b7ee0) N Cells: 12 N Points: 24 X Bounds: 0.000e+00, 1.000e+00 Y Bounds: 0.000e+00, 1.000e+00 Z Bounds: 0.000e+00, 0.000e+00 N Arrays: 3 ]
Merged Area Geometry#
There are two approaches for selecting areas, the old “legacy” style and the new style. The old style is valuable for those who are comfortable with the existing MAPDL commands, and new style is useful for selecting areas in a pythonic manner.
This example generates a series of random squares and selects them
[ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20]
Select every other area with the old style command.
mapdl.asel("S", "AREA", "", 1, 20, 2) print(mapdl.geometry.anum)
[ 1 3 5 7 9 11 13 15 17 19]
Select every other area with the new style command.
Note that the Area IDs are 1 based in MAPDL, while Python ranges are 0 based.
mapdl.geometry.area_select(range(1, 21, 2)) print(mapdl.geometry.anum)
[ 1 3 5 7 9 11 13 15 17 19]
Select areas from a list
Note that you can
return_selected if you want to see what you
have selected. This is helpful when reselecting from existing
[ 1 5 10 20]
APDL Command: APLOT#
This method uses VTK and pyvista to generate a dynamic 3D plot.
There are a variety of plotting options available for all the common
plotting methods. Here, we enable the bounds and show the lines of
the plot while increasing the plot quality with the
Note that the cpos keyword argument can be used to describe the camera direction from the following:
‘iso’ - Isometric view
‘xy’ - XY Plane view
‘xz’ - XZ Plane view
‘yx’ - YX Plane view
‘yz’ - YZ Plane view
‘zx’ - ZX Plane view
‘zy’ - ZY Plane view
mapdl.aplot(quality=1, show_bounds=True, cpos="iso", show_lines=True)
Total running time of the script: ( 0 minutes 3.099 seconds)