Skip to content

Commit f3b86f4

Browse files
authored
Improve Examples and Testing (ansys#301)
* use rcParams default * use rcParams for default plotting * update for additional kwargs and dependencies * fixed load_table * using shallow copy for plotting
1 parent 31d0ca2 commit f3b86f4

File tree

17 files changed

+134
-59
lines changed

17 files changed

+134
-59
lines changed

docs/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
from sphinx_gallery.sorting import FileNameSortKey
100100

101101
sphinx_gallery_conf = {
102+
'pypandoc': True, # convert rst to md for ipynb
102103
# path to your examples scripts
103104
"examples_dirs": [
104105
"../examples/",

examples/02-mapdl-examples/2d_plate_with_a_hole.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import pyansys
1919

20-
# os.environ['I_MPI_SHM_LMT'] = 'shm' # necessary on Ubuntu without "smp"
2120
mapdl = pyansys.launch_mapdl(override=True, additional_switches='-smp',
2221
loglevel='ERROR')
2322

@@ -126,7 +125,7 @@
126125
mapdl.nsel('S', 'LOC', 'X', length)
127126

128127
# Verify that only the nodes at length have been selected:
129-
assert np.unique(mapdl.mesh.nodes[:, 0]) == length
128+
assert np.allclose(mapdl.mesh.nodes[:, 0], length)
130129

131130
# Next, couple the DOF for these nodes. This lets us provide a force
132131
# to one node that will be spread throughout all nodes in this coupled
@@ -148,7 +147,8 @@
148147
# Solve the static analysis
149148
mapdl.run('/SOLU')
150149
mapdl.antype('STATIC')
151-
mapdl.solve()
150+
output = mapdl.solve()
151+
print(output)
152152

153153
###############################################################################
154154
# Post-Processing
@@ -370,3 +370,10 @@ def compute_stress_con(ratio):
370370
plt.xlabel('Ratio of Hole Diameter to Width of Plate')
371371
plt.ylabel('Stress Concentration')
372372
plt.show()
373+
374+
375+
###############################################################################
376+
# Cleanup
377+
# ~~~~~~~
378+
# Close mapdl when complete
379+
mapdl.exit()

examples/02-mapdl-examples/3d_notch.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import numpy as np
1717
import pyansys
1818

19-
# os.environ['I_MPI_SHM_LMT'] = 'shm' # necessary on Ubuntu without "smp"
2019
mapdl = pyansys.launch_mapdl(override=True, additional_switches='-smp',
2120
loglevel='ERROR')
2221

@@ -305,3 +304,10 @@
305304
# plt.plot(ratios, k_t_exp, label=r'$K_t$ ANSYS')
306305
# plt.legend()
307306
# plt.show()
307+
308+
309+
###############################################################################
310+
# Cleanup
311+
# ~~~~~~~
312+
# Close mapdl when complete
313+
mapdl.exit()

examples/02-mapdl-examples/3d_plate_thermal.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import os
1616
import pyansys
1717

18-
os.environ['I_MPI_SHM_LMT'] = 'shm' # necessary on Ubuntu without "smp"
1918
mapdl = pyansys.launch_mapdl(loglevel='ERROR')
2019

2120
###############################################################################
@@ -67,6 +66,15 @@
6766
# Alternatively you could also use the result object that reads in the
6867
# result file using pyansys
6968

70-
nnum, temp = mapdl.result.nodal_temperature(0)
69+
result = mapdl.result
70+
nnum, temp = result.nodal_temperature(0)
7171
# this is the same as pyansys.read_binary(mapdl._result_file)
72+
print(nnum, temp)
73+
74+
75+
###############################################################################
76+
# Cleanup
77+
# ~~~~~~~
78+
# Close mapdl when complete
79+
mapdl.exit()
7280

examples/02-mapdl-examples/mapdl_3d_beam.py

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@
1010
1111
"""
1212

13-
import os
1413
from pyansys import examples
1514
import pyansys
1615

17-
os.environ['I_MPI_SHM_LMT'] = 'shm' # necessary on ubuntu
18-
mapdl = pyansys.launch_mapdl(override=True, additional_switches='-smp')
16+
17+
mapdl = pyansys.launch_mapdl(loglevel='ERROR')
1918

2019
mapdl.cdread('db', examples.hexarchivefile)
2120
mapdl.esel('s', 'ELEM', vmin=5, vmax=20)
@@ -40,9 +39,37 @@
4039

4140
mapdl.mxpand(elcalc='YES')
4241
mapdl.modal_analysis(nmode=6)
43-
mapdl.exit()
4442

45-
# view the results using pyansys's result viewer
43+
44+
###############################################################################
45+
# View the results using the pyansys result object
4646
result = mapdl.result
47-
result.animate_nodal_solution(0, show_edges=True, loop=False, displacement_factor=10,
48-
movie_filename='demo.gif')
47+
print(result)
48+
49+
50+
###############################################################################
51+
# Access nodal displacement values
52+
nnum, disp = result.nodal_displacement(0)
53+
54+
# print the nodes 50 - 59
55+
for i in range(49, 59):
56+
print(nnum[i], disp[i])
57+
58+
59+
###############################################################################
60+
# Plot a modal result
61+
result.plot_nodal_displacement(0, show_edges=True)
62+
63+
64+
###############################################################################
65+
# Animate a modal result
66+
# result.animate_nodal_solution(0, show_edges=True, loop=False, displacement_factor=10,
67+
# movie_filename='demo.gif')
68+
69+
70+
###############################################################################
71+
# Cleanup
72+
# ~~~~~~~
73+
# Close mapdl when complete
74+
mapdl.exit()
75+

examples/02-mapdl-examples/mapdl_beam.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
###############################################################################
1212
# Launch MAPDL with interactive plotting
1313
import pyansys
14-
mapdl = pyansys.launch_mapdl(override=True, loglevel='WARNING',
15-
interactive_plotting=True)
14+
mapdl = pyansys.launch_mapdl(interactive_plotting=True, loglevel='ERROR')
1615

1716
# reduce pixel count for larger font documentation plots
1817
mapdl.gfile(1200)

examples/02-mapdl-examples/path_operations.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
.. _ref_plane_stress_concentration:
2+
.. _ref_path_operation:
33
44
Path Operations within pyansys and MAPDL
55
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -19,7 +19,6 @@
1919

2020
import pyansys
2121

22-
os.environ['I_MPI_SHM_LMT'] = 'shm' # necessary on Ubuntu
2322
mapdl = pyansys.launch_mapdl(loglevel='ERROR')
2423

2524
###############################################################################

examples/02-mapdl-examples/pyvista_mesh.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
import pyansys
1515

1616
# launch MAPDL and run a modal analysis
17-
os.environ['I_MPI_SHM_LMT'] = 'shm' # necessary for Ubuntu
18-
mapdl = pyansys.launch_mapdl(loglevel='WARNING', override=True)
17+
mapdl = pyansys.launch_mapdl(loglevel='WARNING')
1918

2019
# Create a simple plane mesh centered at (0, 0, 0) on the XY plane
2120
mesh = pv.Plane(i_resolution=100, j_resolution=100)

examples/02-mapdl-examples/transient_thermal.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,12 @@
1616
"""
1717
# sphinx_gallery_thumbnail_number = 4
1818

19-
import os
2019
import numpy as np
2120

2221
import matplotlib.pyplot as plt
2322
import pyansys
2423

25-
os.environ['I_MPI_SHM_LMT'] = 'shm' # necessary on Ubuntu
26-
mapdl = pyansys.launch_mapdl()
24+
mapdl = pyansys.launch_mapdl(loglevel='ERROR')
2725

2826
mapdl.clear()
2927
mapdl.prep7()
@@ -234,3 +232,4 @@
234232
plt.xlabel('Time (seconds)')
235233
plt.ylabel('Temperature ($^\circ$F)')
236234
plt.show()
235+

pyansys/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
from pyansys.misc import Report, _configure_pyvista, _check_has_ansys
1515
from pyansys.examples.downloads import *
1616

17+
# optional www.pyansys.com feature
18+
if 'ANSJUPHUB_VER' in os.environ:
19+
try:
20+
from ansys.mapdl import launch_mapdl
21+
except ImportError:
22+
raise RuntimeError("you're not supposed to be here")
23+
1724

1825
_HAS_ANSYS = _check_has_ansys()
1926

0 commit comments

Comments
 (0)