Primitives

This example shows how you can use PyMAPDL to create basic geometry using Pythonic PREP7 volume commands.

import pyvista
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)

Out:

Product:             Ansys Mechanical Enterprise
MAPDL Version:       21.2
ansys.mapdl Version: 0.59.dev0

APDL Command: BLC4

Create a rectangular area or block volume by corner points.

Create a 0.5 x 0.5 rectangle starting at (0.25, 0.25)

mapdl.clear(); mapdl.prep7()

anum1 = mapdl.blc4(0.25, 0.25, 0.5, 0.5)
mapdl.aplot(show_lines=True, line_width=5, show_bounds=True, cpos='xy')
04 primitives

Out:

[(0.5, 0.5, 1.366025403784439),
 (0.5, 0.5, 0.0),
 (0.0, 1.0, 0.0)]

Create a block with dimensions 1 x 4 x 9 with one corner of the block at (0, 0) of the current working plane.

This method returns the volume number.

mapdl.clear(); mapdl.prep7()

vnum = mapdl.blc4(width=1, height=4, depth=9)
mapdl.vplot(show_lines=True)
04 primitives

Out:

[(11.541451884327385, 13.041451884327385, 15.541451884327387),
 (0.5, 2.0, 4.500000000000001),
 (0.0, 0.0, 1.0)]

APDL Command: BLC5

Create a rectangular area or block volume by center and corner points.

This differs from BLC4 since this describes the center rather than the corner points.

Create a square centered at (0, 0) with a width of 0.5 and a height of 0.5

mapdl.clear(); mapdl.prep7()

anum1 = mapdl.blc5(width=0.5, height=0.5)
mapdl.aplot(show_lines=True, line_width=5, show_bounds=True, cpos='xy')
04 primitives

Out:

[(0.0, 0.0, 1.3660254037844388),
 (0.0, 0.0, 0.0),
 (0.0, 1.0, 0.0)]

Create a block with dimensions 1 x 4 x 9 with the cetner at (0, 0) of the current working plane.

This method returns the volume number.

mapdl.clear(); mapdl.prep7()

vnum = mapdl.blc5(width=1, height=4, depth=9)
mapdl.vplot(show_lines=True, show_bounds=True)
04 primitives

Out:

[(11.041451884327385, 11.041451884327385, 15.541451884327387),
 (0.0, 0.0, 4.500000000000001),
 (0.0, 0.0, 1.0)]

APDL Command: BLOCK

Create a block volume based on working plane coordinates with the size (1 x 2 x 3)

mapdl.clear(); mapdl.prep7()

vnum = mapdl.block(0, 1, 0, 2, 1, 4)
mapdl.vplot(show_lines=False, show_bounds=True,
            color=(0.5, 0.5, 0.5),
            background=(0.8, 0.8, 0.8))
04 primitives

Out:

[(4.673276542716538, 5.173276542716538, 6.673276542716538),
 (0.5, 1.0, 2.5),
 (0.0, 0.0, 1.0)]

APDL Command: CON4

Create a conical volume anywhere on the working plane.

Create a cone with a bottom radius of 3 and a height of 10.

mapdl.clear(); mapdl.prep7()

vnum = mapdl.con4(rad1=3, rad2=0, depth=10)
mapdl.vplot(show_lines=False, quality=6, show_bounds=True)
04 primitives

Out:

[(14.627744630232042, 14.627744630232042, 19.627744630232044),
 (0.0, 2.220446049250313e-16, 5.0),
 (0.0, 0.0, 1.0)]

APDL Command: CONE

Create a conical volume centered about the working plane origin.

Create a quarter cone with a bottom radius of 3, top radius of 1 and a height of 10 centered at (0, 0).

mapdl.clear(); mapdl.prep7()

vnum = mapdl.cone(rbot=5, rtop=1, z1=0, z2=10, theta1=180, theta2=90)
mapdl.vplot(show_lines=False, quality=6, show_bounds=True)
04 primitives

Out:

[(11.160254037844393, 16.160254037844393, 18.660254037844393),
 (-2.5, 2.5, 5.000000000000001),
 (0.0, 0.0, 1.0)]

APDL Command: CYL4

Creates a circular area or cylindrical volume anywhere on the working plane.

Create a half arc centered at the origin with an outer radius of 2 and an inner radius of 1.

Note that the depth keyword argument is unset, which will generate an area rather than a volume. Setting depth to a value greater than 0 will generate a volume.

mapdl.clear(); mapdl.prep7()

anum = mapdl.cyl4(xcenter=0, ycenter=0, rad1=1, theta1=0, rad2=2, theta2=180)
mapdl.aplot(show_lines=True, line_width=5, show_bounds=True, cpos='xy')
04 primitives

Out:

[(0.0, 0.9997959600081615, 8.639150703161897),
 (0.0, 0.9997959600081615, 0.0),
 (0.0, 1.0, 0.0)]

Create a volumetric half arc centered at the origin with an outer radius of 2 and an inner radius of 1, and a thickness of 0.55.

mapdl.clear(); mapdl.prep7()

anum = mapdl.cyl4(xcenter=0, ycenter=0, rad1=1, theta1=0, rad2=2, theta2=180,
                  depth=0.55)
mapdl.vplot(show_bounds=True)
04 primitives

Out:

[(5.02546124453197, 6.025321252723083, 5.30046124453197),
 (0.0, 0.9998600081911138, 0.2750000000000001),
 (0.0, 0.0, 1.0)]

APDL Command: CYL5

Creates a circular area or cylindrical volume by end points.

Create a circular with one point of the circle at (1, 1) and the other point at (2, 2)

mapdl.clear(); mapdl.prep7()

anum = mapdl.cyl5(xedge1=1, yedge1=1, xedge2=2, yedge2=2)
mapdl.aplot(show_lines=True, line_width=5, show_bounds=True, cpos='xy')
04 primitives

Out:

[(1.5000000000015, 1.5000000000015, 3.8637033051669416),
 (1.5000000000015, 1.5000000000015, 0.0),
 (0.0, 1.0, 0.0)]

Create a cylinder with one point of the circle at (X, Y) == (1, 1) and the other point at (X, Y) == (2, 2) with a height of 3.

mapdl.clear(); mapdl.prep7()

vnum = mapdl.cyl5(xedge1=1, yedge1=1, xedge2=2, yedge2=2, depth=5)
mapdl.vplot(show_lines=False, quality=6, show_bounds=True)
04 primitives

Out:

[(7.506370879310776, 7.506370879310776, 8.506370879310776),
 (1.5, 1.5, 2.5000000000000004),
 (0.0, 0.0, 1.0)]

APDL Command: CYLIND

Create a cylindrical volume centered about the working plane origin.

Create a hollow cylinder with an inner radius of 0.9 and an outer radius of 1.0 with a height of 5

mapdl.clear(); mapdl.prep7()

vnum = mapdl.cylind(0.9, 1, z1=0, z2=5)
mapdl.vplot(show_lines=False, quality=4, show_bounds=True)
04 primitives

Out:

[(6.407227082229697, 6.407227082229697, 8.907227082229698),
 (0.0, 0.0, 2.5000000000000004),
 (0.0, 0.0, 1.0)]

APDL Command: PCIRC

Create a circular area centered about the working plane origin.

In this example a circular area with an inner radius of 0.95 and an outer radius of 1 is created.

mapdl.clear(); mapdl.prep7()

anum = mapdl.pcirc(0.95, 1)
mapdl.aplot(show_bounds=True)
04 primitives

Out:

[(3.1547005383792524, 3.1547005383792524, 3.1547005383792524),
 (0.0, 0.0, 0.0),
 (0.0, 0.0, 1.0)]

APDL Command: RECTNG

Create a rectangular area anywhere on the working plane.

In this example a rectangle with one corner at (0.5, 0.5) and another at (1.5, 2.5) is created.

mapdl.clear(); mapdl.prep7()

anum = mapdl.rectng(0.5, 1.5, 0.5, 2.5)
mapdl.aplot(show_bounds=True)
04 primitives

Out:

[(3.4940097592594674, 3.9940097592594674, 2.4940097592594674),
 (1.0, 1.5, 0.0),
 (0.0, 0.0, 1.0)]

APDL Command: SPH4

Create a spherical volume anywhere on the working plane.

This example creates a hollow sphere with an inner radius of 0.9 and an outer radius of 1.0 centered at (0, 0)

mapdl.clear(); mapdl.prep7()

vnum = mapdl.sph4(0, 0, rad1=0.9, rad2=1.0)
mapdl.vplot(show_lines=False, show_bounds=True, smooth_shading=True)
04 primitives

Out:

[(3.856674145489138, 3.8577638544590824, 3.856674145489138),
 (0.0, 0.0010897089699446472, 0.0),
 (0.0, 0.0, 1.0)]

APDL Command: SPHERE

Create a spherical volume anywhere on the working plane.

This example creates a half hollow sphere with an inner radius of 0.9 and an outer radius of 1.0.

mapdl.clear(); mapdl.prep7()

vnum = mapdl.sphere(rad1=0.95, rad2=1.0, theta1=90, theta2=270)
mapdl.vplot(show_lines=False, quality=4, show_bounds=True)
04 primitives

Out:

[(2.846065214951232, 3.346065214951232, 3.346065214951232),
 (-0.5, 0.0, 0.0),
 (0.0, 0.0, 1.0)]

APDL Command: SPH5

Create a spherical volume anywhere on the working plane.

This example creates a sphere with one point at (1, 1) and one point at (2, 2)

mapdl.clear(); mapdl.prep7()

vnum = mapdl.sph5(xedge1=1, yedge1=1, xedge2=2, yedge2=2)
mapdl.vplot(show_lines=False, show_bounds=True, smooth_shading=True)
04 primitives

Out:

[(4.227405710402886, 4.225472042976391, 2.727405710402886),
 (1.5, 1.4980663325735053, 0.0),
 (0.0, 0.0, 1.0)]

APDL Command: TORUS

Create a toroidal volume.

This example creates a torus with an inner minor radius of 1, an intermediate radii of 2, and a major radius of 5. The values 0 and 180 define the starting and ending angles of the torus.

mapdl.clear(); mapdl.prep7()

vnum = mapdl.torus(rad1=5, rad2=1, rad3=2, theta1=0, theta2=180)
mapdl.vplot(show_lines=False, show_bounds=True, smooth_shading=False)
04 primitives

Out:

[(18.01409334294718, 21.5088971675611, 18.01409334294718),
 (0.0, 3.494803824613917, 0.0),
 (0.0, 0.0, 1.0)]

Total running time of the script: ( 0 minutes 20.746 seconds)

Gallery generated by Sphinx-Gallery