pymapdl: Did you publish this tutorial ? I'm having hard time running it at current time it keep failing
Sadly, MAPDL doesn’t directly support reading STEP files, but it turns out you can do it with gmsh!
I’m working on a tutorial right now, but the gist of it is:
import gmsh
import math
import os
gmsh.initialize()
gmsh.option.setNumber("General.Terminal", 1)
gmsh.model.add("t20")
# Load a STEP file (using `importShapes' instead of `merge' allows to directly
# retrieve the tags of the highest dimensional imported entities):
# path = os.path.dirname(os.path.abspath(__file__))
filename = 'pf_coil_case_1.stp'
v = gmsh.model.occ.importShapes(filename)
# Get the bounding box of the volume:
gmsh.model.occ.synchronize()
# Specify a global mesh size and mesh the partitioned model:
gmsh.option.setNumber("Mesh.CharacteristicLengthMin", 10)
gmsh.option.setNumber("Mesh.CharacteristicLengthMax", 10)
gmsh.model.mesh.generate(3)
gmsh.write("from_gmsh.msh")
# Show the result:
# gmsh.fltk.run()
gmsh.finalize()
That gives you your gmsh file. You can then convert it to MAPDL with:
import pyvista as pv
import pyansys
filename = '/home/alex/.local/lib/python3.7/site-packages/gmsh-4.6.0-Linux64-sdk/share/doc/gmsh/tutorial/python/t20.msh'
mesh = pv.read_meshio(filename)
# mesh.plot()
mesh.points /= 1000
pyansys.save_as_archive('archive.cdb', mesh)
mapdl = pyansys.launch_mapdl(exec_file='/ansys_inc/v194/ansys/bin/ansys194',
override=True, additional_switches='-smp')
filename = '/home/alex/Downloads/two_step_files/archive.cdb'
mapdl.cdread('db', filename)
I’m going to have to clean it up for an example, but it’s quite promising. Once you have the mesh, you can go ahead and analyze it in MAPDL. According to mesh.bounds
, it seems that the dimensions are in mm. You’ll have to scale it down and then copy it over to MAPDL with mesh.points /= 1000
prior to saving it.
I did a quick modal analysis because they make great gifs, but you’ll probably want to do a structural analysis.
# verify cells are valid
mapdl.prep7()
mapdl.shpp('SUMM')
# specify material properties
# using aprox values for AISI 5000 Series Steel
mapdl.units('SI')
mapdl.mp('EX', 1, 200E9) # Elastic moduli in Pa (kg/(m*s**2))
mapdl.mp('DENS', 1, 7700) # Density in kg/m3
mapdl.mp('NUXY', 1, 0.3) # Poissons Ratio
mapdl.emodif('ALL', 'MAT', 1)
# Run an unconstrained modal analysis
mapdl.run('/SOLU')
mapdl.antype('MODAL') # default NEW
mapdl.modopt('LANB', 20, 1) # First 6 modes above 1 Hz
mapdl.solve()
result = mapdl.result
# result.plot(cpos='xy')
cpos = [(0.0, 0.3074999999873, 2),
(0.0, 0.3074999999873, 0.5),
(0.0, 1.0, 0.0)]
result.animate_nodal_displacement(4,
cpos=cpos,
show_edges=False,
lighting=True,
loop=True,
add_text=False,
nangles=30,
movie_filename='tmp.gif')
_Originally posted by @akaszynski in https://github.com/pyansys/pymapdl/issues/234#issuecomment-649240031_
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 23
Commits related to this issue
- Added index. Added ex 01. Resolves #612 Resolves #567 — committed to ansys/pymapdl by germa89 3 years ago
- Feat/Adding extended examples library. (#613) * Added index. Added ex 01. Resolves #612 Resolves #567 * Fixing grammar * Fixing grammar * Fixing format * Format fixing. * Format... — committed to ansys/pymapdl by germa89 3 years ago
This is great work, and I’d like to add it as a static example (not one we compile each time) to the docs. Create a new directory in
doc/user_guide/extended-examples
and addindex.rst
along with a new example file (you pick the name). Describe the example as you’ve done above, but just in markdown.Reopening as another “TODO”. This shouldn’t be too bad since you’ve already done the hard work of writing the example.
Thank you so much guys, this example is definitely a great addition 😄
Just knowing it works on your end as well is great feedback. If you have sample code for other examples, post it here and we can add that too.
Thank you for your help, it works perfectly. i think this would be a really good example as well.
Let me know if I can be of any help
OK. I’m going to open another issue for adding static examples section and a new branch then.