.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/John_Reid_Pendulum/plot_john_reid_pendulum.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_John_Reid_Pendulum_plot_john_reid_pendulum.py: John Reid pendulum example -------------------------- This example is inspired by John Reid’s “Pendulum” example on the `LS-DYNA Examples `_ site. It shows how to use DYNA-Lib to create a keyword file for LS-DYNA and solve it within a Pythonic environment. .. LINKS AND REFERENCES .. _ls_dyna_examples_site: https://www.dynaexamples.com/ .. GENERATED FROM PYTHON SOURCE LINES 13-16 Perform required imports ~~~~~~~~~~~~~~~~~~~~~~~~ Import required packages, including those for the keywords, deck, and solver. .. GENERATED FROM PYTHON SOURCE LINES 16-33 .. code-block:: default import os import pathlib import shutil import pandas as pd from ansys.dyna.keywords import Deck from ansys.dyna.keywords import keywords as kwd from ansys.dyna.run import run_dyna dynadir = "run" dynafile = "pendulum.k" p = pathlib.Path(dynadir) p.mkdir(parents=True, exist_ok=True) .. GENERATED FROM PYTHON SOURCE LINES 34-38 Create a deck and keywords ~~~~~~~~~~~~~~~~~~~~~~~~~~ Create a deck, which is the container for all the keywords. Then, create and append individual keywords to the deck. .. GENERATED FROM PYTHON SOURCE LINES 38-143 .. code-block:: default def write_deck(filepath): deck = Deck() # Append control keywords deck.extend( [ kwd.ControlTermination(endtim=11.0), kwd.ControlEnergy(hgen=2, rwen=2), kwd.ControlOutput(npopt=1, neecho=3), kwd.ControlShell(istupd=1, theory=2), ] ) # Append database keywords deck.extend( [ kwd.DatabaseBinaryD3Plot(dt=1.00), kwd.DatabaseExtentBinary(ieverp=1), kwd.DatabaseBinaryD3Thdt(dt=999999), kwd.DatabaseGlstat(dt=0.10), kwd.DatabaseMatsum(dt=0.10), kwd.DatabaseNodout(dt=0.10), kwd.DatabaseHistoryNode(id1=350, id2=374, id3=678, id4=713), kwd.DatabaseRbdout(dt=0.10), kwd.DatabaseRcforc(dt=0.10), ] ) # Define contacts deck.extend([kwd.ContactAutomaticSingleSurface(ssid=0, fs=0.08, fd=0.08), kwd.ControlContact(shlthk=2)]) # Define gravity curve1 = kwd.DefineCurve(lcid=1) curve1.curves = pd.DataFrame({"a1": [0.00, 10000.00], "o1": [1.000, 1.000]}) deck.extend([kwd.LoadBodyY(lcid=1, sf=0.00981), curve1]) # Define boundary conditions # BoundarySpcNode edited needs to redo code gen BoundarySpcNode = kwd.BoundarySpcNode() BoundarySpcNode.nodes = pd.DataFrame( { "nid": [45004, 45005, 45010, 45011], "cid": [0, 0, 0, 0], "dofx": [1, 1, 1, 1], "dofy": [1, 1, 1, 1], "dofz": [1, 1, 1, 1], "dofrx": [0, 0, 0, 0], "dofry": [0, 0, 0, 0], "dofrz": [0, 0, 0, 0], } ) deck.extend( [ BoundarySpcNode, kwd.InitialVelocity(boxid=5, vx=0.0, vy=-12.0, vz=0.0), kwd.DefineBox(boxid=5, xmn=-120.0, xmx=-80.0, ymn=80.0, ymx=120.0, zmn=-30.0, zmx=30.0), ] ) # Define parts and materials spherePart = kwd.Part() spherePart.parts = pd.DataFrame({"heading": ["sphere1", "sphere2"], "pid": [1, 2], "secid": [1, 2], "mid": [1, 1]}) beamPart = kwd.Part() beamPart.parts = pd.DataFrame( {"heading": ["Pendulum Wires - Elastic Beams"], "pid": [45], "secid": [45], "mid": [45]} ) deck.extend( [ spherePart, # Aluminium kwd.MatPlasticKinematic(mid=1, ro=2.7e-6, e=68.9, pr=0.330, sigy=0.286, etan=0.00689), # Sections kwd.SectionShell(secid=1, elfrom=2, t1=1.0, t2=1.0, t3=1.0, t4=1.0), kwd.SectionShell(secid=2, elfrom=2, t1=1.0, t2=1.0, t3=1.0, t4=1.0), # Pendu Wires beamPart, kwd.SectionBeam(secid=45, elform=3, shrf=1.00000, qr_irid=1.0, a=10.0), kwd.MatElastic(mid=45, ro=7.86e-6, e=210.0, pr=0.30), ] ) # Define deformable switching deck.extend([kwd.DeformableToRigid(pid=1), kwd.DeformableToRigid(pid=2)]) # Define nodes and elements deck.extend([kwd.Include(filename="nodes.k")]) deck.export_file(filepath) return deck def run_post(filepath): pass deck = write_deck(os.path.join(dynadir, dynafile)) shutil.copy("nodes.k", "run/nodes.k") .. rst-class:: sphx-glr-script-out .. code-block:: none 'run/nodes.k' .. GENERATED FROM PYTHON SOURCE LINES 144-148 View the model ~~~~~~~~~~~~~~ You can use the PyVista ``plot`` method in the ``deck`` class to view the model. .. GENERATED FROM PYTHON SOURCE LINES 148-151 .. code-block:: default out = deck.plot(cwd=dynadir) .. image-sg:: /auto_examples/John_Reid_Pendulum/images/sphx_glr_plot_john_reid_pendulum_001.png :alt: plot john reid pendulum :srcset: /auto_examples/John_Reid_Pendulum/images/sphx_glr_plot_john_reid_pendulum_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 152-155 Run the Dyna solver ~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 155-158 .. code-block:: default filepath = run_dyna(dynafile, working_directory=dynadir) run_post(filepath) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.015 seconds) .. _sphx_glr_download_auto_examples_John_Reid_Pendulum_plot_john_reid_pendulum.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_john_reid_pendulum.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_john_reid_pendulum.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_