ansys / pymapdl

Pythonic interface to MAPDL
https://mapdl.docs.pyansys.com
MIT License
426 stars 120 forks source link

Adding subplots to one of the examples #1825

Closed germa89 closed 1 year ago

germa89 commented 1 year ago

Thanks to #1822 I realised we can use pyvista subplots out-of-the-box.

I would like to see this in some of our examples.

For example, here you can find a modified version of the example 3D Stress Concentration Analysis for a Notched Plate

from ansys.mapdl.core import launch_mapdl
from ansys.mapdl.core.examples import vmfiles

import pyvista as pv

mapdl = launch_mapdl(start_instance=False, port=50052)

length = 0.4
width = 0.1

notch_depth = 0.04
notch_radius = 0.01

# create the half arcs
mapdl.prep7()

circ0_kp = mapdl.k(x=length / 2, y=width + notch_radius)
circ_line_num = mapdl.circle(circ0_kp, notch_radius)
circ_line_num = circ_line_num[2:]  # only concerned with the bottom arcs

# create a line and drag the top circle downward
circ0_kp = mapdl.k(x=0, y=0)
k1 = mapdl.k(x=0, y=-notch_depth)
l0 = mapdl.l(circ0_kp, k1)
mapdl.adrag(*circ_line_num, nlp1=l0)

# same thing for the bottom notch (except upwards
circ1_kp = mapdl.k(x=length / 2, y=-notch_radius)
circ_line_num = mapdl.circle(circ1_kp, notch_radius)
circ_line_num = circ_line_num[:2]  # only concerned with the top arcs

# create a line whereby the top circle will be dragged up
k0 = mapdl.k(x=0, y=0)
k1 = mapdl.k(x=0, y=notch_depth)
l0 = mapdl.l(k0, k1)
mapdl.adrag(*circ_line_num, nlp1=l0)

rect_anum = mapdl.blc4(width=length, height=width)

# Note how pyansys parses the output and returns the area numbers
# created by each command.  This can be used to execute a boolean
# operation on these areas to cut the circle out of the rectangle.
# plate_with_hole_anum = mapdl.asba(rect_anum, circ_anum)
cut_area = mapdl.asba(rect_anum, "ALL")  # cut all areas except the plate

# mapdl.aplot(vtk=True, show_line_numbering=True)
mapdl.lsla("S")

plotter = pv.Plotter(shape=(1,3))

plotter.subplot(0,0)
mapdl.lplot(vtk=True, show_keypoint_numbering=True, plotter=plotter, return_plotter=True)
mapdl.lsel("all")

# plot the area using vtk/pyvista
plotter.subplot(0,1)
mapdl.aplot(vtk=True, show_area_numbering=True, show_lines=True, cpos="xy", plotter=plotter, return_plotter=True)

# Next, extrude the area to create volume
thickness = 0.01
mapdl.vext(cut_area, dz=thickness)

# Checking volume plot
plotter.subplot(0,2)
mapdl.vplot(vtk=True, show_lines=True, show_axes=True, smooth_shading=True, plotter=plotter, return_plotter=True)
plotter.show()

Result:

image

germa89 commented 1 year ago

Please @clatapie, whenever you have time, can you do this?

Also, I believe a warning will raise when you issue those commands, make sure that warning exists and it makes sense.

Pinging @RobPasMue for visibility.

mikerife commented 1 year ago

@germa89 Shouldn't there be a

plotter.show()

at the end? Mike

akaszynski commented 1 year ago

Sharp eyes @mikerife, I added it.

germa89 commented 1 year ago

Damn... this guy is good @mikerife