John Reid pipe example#

This example is inspired by John Reid’s “Pipe” example on the LS-DYNA Knowledge Base site. It shows how to use PyDyna to create a keyword file for LS-DYNA and solve it within a Pythonic environment.

Perform required imports#

Import required packages, including those for the keywords, deck, and solver.

import os
import shutil
import tempfile

import pandas as pd

from ansys.dyna.core import Deck
from ansys.dyna.core import keywords as kwd
from ansys.dyna.core.pre.examples.download_utilities import EXAMPLES_PATH, DownloadManager
from ansys.dyna.core.run import run_dyna

mesh_file_name = "nodes.k"
mesh_file = DownloadManager().download_file(
    mesh_file_name, "ls-dyna", "John_Reid_Pipe", destination=os.path.join(EXAMPLES_PATH, "John_Reid_Pipe")
)

rundir = tempfile.TemporaryDirectory()

dynafile = "pipe.k"

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.

def write_deck(filepath):
    deck = Deck()

    # Append control keywords
    deck.extend(
        [
            kwd.ControlTermination(endtim=20.0),
            kwd.ControlEnergy(hgen=2, rwen=2, slnten=2),
            kwd.ControlOutput(npopt=1, neecho=3),
            kwd.ControlShell(istupd=1),
        ]
    )

    # 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.DatabaseJntforc(dt=0.10),
            kwd.DatabaseRbdout(dt=0.10),
            kwd.DatabaseRcforc(dt=0.10),
        ]
    )

    # Define contacts - sliding interfaces

    deck.extend(
        [
            kwd.ContactForceTransducerPenalty(surfa=1, surfatyp=3),
            kwd.ContactAutomaticSingleSurface(ssid=3, sstyp=2, fs=0.30, fd=0.30),
            kwd.SetPartList(sid=3, parts=[1, 2]),
        ]
    )

    # Define initial conditions

    deck.extend(
        [
            kwd.InitialVelocityGeneration(id=5, omega=-0.082, xc=-78.50, yc=-610.13, zc=5.69, nx=1.0),
            kwd.SetPartList(sid=5, parts=[1, 2]),
        ]
    )

    # Define pipe parts and materials

    pipe_parts = kwd.Part()
    pipe_parts.parts = pd.DataFrame(
        {
            "heading": ["Deformable-Pipe", "Pipe-End", "Rigid-Pipe"],
            "pid": [1, 2, 3],
            "secid": [1, 2, 2],
            "mid": [1, 2, 1],
        }
    )

    deck.extend(
        [
            pipe_parts,
            # Aluminium
            kwd.MatPlasticKinematic(mid=1, ro=7.86e-6, e=200.0, pr=0.30, sigy=0.250, etan=0.00689),
            kwd.MatRigid(mid=2, ro=7.86e-6, e=200.0, pr=0.30),
            # Sections
            kwd.SectionShell(secid=1, elfrom=2, nip=5, t1=11.0, t2=11.0, t3=11.0, t4=11.0),
            kwd.SectionShell(secid=2, elfrom=2, nip=3, t1=11.0, t2=11.0, t3=11.0, t4=11.0),
        ]
    )

    # Define bracket parts and materials
    bracket_parts = kwd.Part()
    bracket_parts.parts = pd.DataFrame({"heading": ["Bracket"], "pid": [4], "secid": [4], "mid": [4]})

    deck.extend(
        [
            bracket_parts,
            kwd.MatRigid(mid=4, ro=7.86e-6, e=200.0, pr=0.30, cmo=1, con1=7, con2=7),
            kwd.SectionSolid(secid=4),
        ]
    )

    # Define deformable switching
    deck.extend([kwd.DeformableToRigid(pid=1), kwd.DeformableToRigid(pid=2)])

    # Define nodes and elements
    deck.extend([kwd.Include(filename=mesh_file_name)])

    deck.export_file(filepath)
    return deck


def run_post(filepath):
    pass


shutil.copy(mesh_file, os.path.join(rundir.name, mesh_file_name))
deck = write_deck(os.path.join(rundir.name, dynafile))
deck.plot(cwd=rundir.name)
plot john pipe

Run the Dyna solver#

Run the Dyna solver.

run_dyna(dynafile, working_directory=rundir.name)
run_post(rundir.name)
 License option : check ansys licenses only


 ***************************************************************
 *            ANSYS LEGAL NOTICES                              *
 ***************************************************************
 *                                                             *
 * Copyright 1971-2023 ANSYS, Inc.  All rights reserved.       *
 * Unauthorized use, distribution or duplication is            *
 * prohibited.                                                 *
 *                                                             *
 * Ansys is a registered trademark of ANSYS, Inc. or its       *
 * subsidiaries in the United States or other countries.       *
 * See the ANSYS, Inc. online documentation or the ANSYS, Inc. *
 * documentation CD or online help for the complete Legal      *
 * Notice.                                                     *
 *                                                             *
 ***************************************************************
 *                                                             *
 * THIS ANSYS SOFTWARE PRODUCT AND PROGRAM DOCUMENTATION       *
 * INCLUDE TRADE SECRETS AND CONFIDENTIAL AND PROPRIETARY      *
 * PRODUCTS OF ANSYS, INC., ITS SUBSIDIARIES, OR LICENSORS.    *
 * The software products and documentation are furnished by    *
 * ANSYS, Inc. or its subsidiaries under a software license    *
 * agreement that contains provisions concerning               *
 * non-disclosure, copying, length and nature of use,          *
 * compliance with exporting laws, warranties, disclaimers,    *
 * limitations of liability, and remedies, and other           *
 * provisions.  The software products and documentation may be *
 * used, disclosed, transferred, or copied only in accordance  *
 * with the terms and conditions of that software license      *
 * agreement.                                                  *
 *                                                             *
 * ANSYS, Inc. is a UL registered                              *
 * ISO 9001:2015 company.                                      *
 *                                                             *
 ***************************************************************
 *                                                             *
 * This product is subject to U.S. laws governing export and   *
 * re-export.                                                  *
 *                                                             *
 * For U.S. Government users, except as specifically granted   *
 * by the ANSYS, Inc. software license agreement, the use,     *
 * duplication, or disclosure by the United States Government  *
 * is subject to restrictions stated in the ANSYS, Inc.        *
 * software license agreement and FAR 12.212 (for non-DOD      *
 * licenses).                                                  *
 *                                                             *
 ***************************************************************

      Date: 11/20/2024      Time: 10:21:05
      ___________________________________________________
     |                                                   |
     |  LS-DYNA, A Program for Nonlinear Dynamic         |
     |  Analysis of Structures in Three Dimensions       |
     |  Date    : 10/16/2023    Time: 19:29:09           |
     |  Version : smp d R14                              |
     |  Revision: R14.1-205-geb5348f751                  |
     |  AnLicVer: 2024 R1 (20231025+2752148)             |
     |                                                   |
     |  Features enabled in this version:                |
     |    Shared Memory Parallel                         |
     |    CESE CHEMISTRY EM ICFD STOCHASTIC_PARTICLES    |
     |    FFTW (multi-dimensional FFTW Library)          |
     |    ARPACK (nonsymmetric eigensolver library)      |
     |    ANSYSLIC enabled                               |
     |                                                   |
     |  Platform   : Xeon64 System                       |
     |  OS Level   : Linux 3.10.0 uum                    |
     |  Compiler   : Intel Fortran Compiler 19.0 SSE2    |
     |  Hostname   : d61618e92b67                        |
     |  Precision  : Double precision (I8R8)             |
     |                                                   |
     |  Unauthorized use infringes Ansys Inc. copyrights |
     |___________________________________________________|

 >ncpu=1 i=pipe.k memory=20m
[license/info] Successfully checked out 1 of "dyna_solver_core".
[license/info] --> Checkout ID: d61618e92b67-root-8-000004 (days left: 153)
[license/info] --> Customer ID: 0
[license/info] Successfully started "LSDYNA (Core-based License)".

 Executing with ANSYS license

 Command line options: ncpu=1
                       i=pipe.k
                       memory=20m

 Input file: pipe.k

 The native file format       : 64-bit small endian
 Memory size from command line:    20000000

 on UNIX computers note the following change:

 ctrl-c interrupts ls-dyna and prompts for a sense  switch.
 type the desired sense switch: sw1., sw2., etc. to continue
 the execution.  ls-dyna will respond as explained in the users manual

    type                      response
   -----   ------------------------------------------------------------
   quit    ls-dyna terminates.
   stop    ls-dyna terminates.
   sw1.    a restart file is written and ls-dyna terminates.
   sw2.    ls-dyna responds with time and cycle numbers.
   sw3.    a restart file is written and ls-dyna continues calculations.
   sw4.    a plot state is written and ls-dyna continues calculations.
   sw5.    ls-dyna enters interactive graphics phase.
   swa.    ls-dyna flushes all output i/o buffers.
   swb.    a dynain is written and ls-dyna continues calculations.
   swc.    a restart and dynain are written and ls-dyna continues calculations.
   swd.    a restart and dynain are written and ls-dyna terminates.
   swe.    stop dynamic relaxation just as though convergence
   endtime=time change the termination time
   lpri    toggle implicit lin. alg. solver output on/off.
   nlpr    toggle implicit nonlinear solver output on/off.
   iter    toggle implicit output to d3iter database on/off.
   prof    output timing data to messag and continue.
   conv    force implicit nonlinear convergence for current time step.
   ttrm    terminate implicit time step, reduce time step, retry time step.
   rtrm    terminate implicit at end of current time step.


 ********  notice  ********  notice  ********  notice  ********
 *                                                            *
 * This is the LS-DYNA Finite Element code.                   *
 *                                                            *
 * Neither LST nor the authors assume any responsibility for  *
 * the validity, accuracy, or applicability of any results    *
 * obtained from this system. Users must verify their own     *
 * results.                                                   *
 *                                                            *
 * LST endeavors to make the LS-DYNA code as complete,        *
 * accurate and easy to use as possible.                      *
 * Suggestions and comments are welcomed.  Please report any  *
 * errors encountered in either the documentation or results  *
 * immediately to LST through your site focus.                *
 *                                                            *
 * Copyright (C) 1990-2021                                    *
 * by Livermore Software Technology, LLC                      *
 * All rights reserved                                        *
 *                                                            *
 ********  notice  ********  notice  ********  notice  ********

 Beginning of keyword reader                                   11/20/24 10:21:08

                                                               11/20/24 10:21:08
 Open include file: nodes.k


 Memory required to process keyword     :     234893
 Additional dynamic memory required     :    2186821


 input of data is completed

 initial kinetic energy = 0.87041732E+05

 The LS-DYNA time step size should not exceed     8.500E-03
 to avoid contact instabilities.  If the step size is
 bigger then scale the penalty of the offending surface.

 Memory required to begin solution      :     235K
 Additional dynamically allocated memory:    2395K
                                   Total:    2630K

 initialization completed

 *** Warning 30308 (INI+308)
     Due to common shared node(s) it is necessary to merge
     rigid part ID: 2 with part ID: 1
       1 t 0.0000E+00 dt 4.18E-03 flush i/o buffers            11/20/24 10:21:08
       1 t 0.0000E+00 dt 4.18E-03 write d3plot file            11/20/24 10:21:08
 cpu time per zone cycle............       140 nanoseconds
 average cpu time per zone cycle....       304 nanoseconds
 average clock time per zone cycle..       489 nanoseconds

 estimated total cpu time          =         2 sec (       0 hrs  0 mins)
 estimated cpu time to complete    =         2 sec (       0 hrs  0 mins)
 estimated total clock time        =         5 sec (       0 hrs  0 mins)
 estimated clock time to complete  =         3 sec (       0 hrs  0 mins)
 termination time                  = 2.000E+01
     240 t 9.9899E-01 dt 4.18E-03 write d3plot file            11/20/24 10:21:08
     479 t 1.9980E+00 dt 4.18E-03 write d3plot file            11/20/24 10:21:08
     718 t 2.9970E+00 dt 4.18E-03 write d3plot file            11/20/24 10:21:08
     957 t 3.9960E+00 dt 4.18E-03 write d3plot file            11/20/24 10:21:08
    1197 t 4.9991E+00 dt 4.18E-03 write d3plot file            11/20/24 10:21:08
    1436 t 5.9981E+00 dt 4.18E-03 write d3plot file            11/20/24 10:21:08
    1675 t 6.9971E+00 dt 4.18E-03 write d3plot file            11/20/24 10:21:08
    1914 t 7.9961E+00 dt 4.18E-03 write d3plot file            11/20/24 10:21:08
    2154 t 8.9993E+00 dt 4.18E-03 write d3plot file            11/20/24 10:21:08
    2393 t 9.9983E+00 dt 4.18E-03 write d3plot file            11/20/24 10:21:09
    2632 t 1.0997E+01 dt 4.18E-03 write d3plot file            11/20/24 10:21:09
    2871 t 1.1996E+01 dt 4.18E-03 write d3plot file            11/20/24 10:21:09
    3111 t 1.2999E+01 dt 4.18E-03 write d3plot file            11/20/24 10:21:09
    3350 t 1.3998E+01 dt 4.18E-03 write d3plot file            11/20/24 10:21:09
    3589 t 1.4997E+01 dt 4.18E-03 write d3plot file            11/20/24 10:21:09
    3828 t 1.5996E+01 dt 4.18E-03 write d3plot file            11/20/24 10:21:09
    4068 t 1.7000E+01 dt 4.18E-03 write d3plot file            11/20/24 10:21:09
    4307 t 1.7999E+01 dt 4.18E-03 write d3plot file            11/20/24 10:21:09
    4546 t 1.8998E+01 dt 4.18E-03 write d3plot file            11/20/24 10:21:09
    4785 t 1.9997E+01 dt 4.18E-03 write d3plot file            11/20/24 10:21:09

 *** termination time reached ***
    4785 t 2.0001E+01 dt 4.18E-03 write d3dump01 file          11/20/24 10:21:09
    4785 t 2.0001E+01 dt 4.18E-03 write d3plot file            11/20/24 10:21:09

 N o r m a l    t e r m i n a t i o n                          11/20/24 10:21:09

 Memory required to complete solution   :     235K
 Additional dynamically allocated memory:    2395K
                                   Total:    2630K

 T i m i n g   i n f o r m a t i o n
                        CPU(seconds)   %CPU  Clock(seconds) %Clock
  ----------------------------------------------------------------
  Keyword Processing ... 1.5579E-02    1.19     1.5580E-02    0.43
    KW Reading ......... 7.1938E-03    0.55     7.1950E-03    0.20
    KW Writing ......... 1.9005E-03    0.15     1.9010E-03    0.05
  Initialization ....... 7.9925E-02    6.11     2.3873E+00   65.96
    Init Proc Phase 1 .. 6.8607E-03    0.52     8.2990E-03    0.23
    Init Proc Phase 2 .. 1.9091E-03    0.15     2.6050E-03    0.07
  Init solver .......... 8.5680E-05    0.01     8.7000E-05    0.00
  Element processing ... 7.2464E-01   55.37     7.2444E-01   20.01
    Solids ............. 9.7637E-03    0.75     9.5940E-03    0.27
    Shells ............. 6.7477E-01   51.56     6.7356E-01   18.61
    ISO Shells ......... 3.0848E-03    0.24     3.0930E-03    0.09
    E Other ............ 1.1801E-02    0.90     1.1972E-02    0.33
  Binary databases ..... 3.1113E-02    2.38     3.1138E-02    0.86
  ASCII database ....... 2.2400E-02    1.71     2.2302E-02    0.62
  Contact algorithm .... 1.1958E-01    9.14     1.1948E-01    3.30
    Interf. ID         1 9.0314E-03    0.69     9.3190E-03    0.26
    Interf. ID         2 6.2789E-02    4.80     6.2010E-02    1.71
  Rigid Bodies ......... 1.2370E-01    9.45     1.2304E-01    3.40
  Time step size ....... 4.3963E-03    0.34     4.4560E-03    0.12
  Group force file ..... 4.1044E-03    0.31     4.8370E-03    0.13
  Others ............... 1.1929E-02    0.91     1.2151E-02    0.34
  Misc. 1 .............. 8.9213E-02    6.82     9.3435E-02    2.58
    Scale Masses ....... 3.4658E-03    0.26     3.5180E-03    0.10
    Force Constraints .. 3.4869E-03    0.27     3.4990E-03    0.10
    Force to Accel ..... 1.7452E-02    1.33     1.7122E-02    0.47
    Update RB nodes .... 2.9914E-02    2.29     2.9456E-02    0.81
  Misc. 2 .............. 4.1165E-02    3.15     4.0400E-02    1.12
  Misc. 3 .............. 1.2006E-02    0.92     1.1963E-02    0.33
  Misc. 4 .............. 2.8910E-02    2.21     2.8962E-02    0.80
    Timestep Init ...... 1.6115E-02    1.23     1.5701E-02    0.43
    Apply Loads ........ 6.0508E-03    0.46     6.2510E-03    0.17
  ----------------------------------------------------------------
  T o t a l s            1.3087E+00  100.00     3.6195E+00  100.00

 Problem time       =    2.0001E+01
 Problem cycle      =      4785
 Total CPU time     =         1 seconds (   0 hours  0 minutes  1 seconds)
 CPU time per zone cycle  =        148.797 nanoseconds
 Clock time per zone cycle=        149.220 nanoseconds

 Number of CPU's    1
 NLQ used/max     192/  192
 Start time   11/20/2024 10:21:08
 End time     11/20/2024 10:21:09
 Elapsed time       1 second  for    4785 cycles using  1 SMP thread
             (      0 hour   0 minute   1 second )

 N o r m a l    t e r m i n a t i o n                          11/20/24 10:21:09

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

Gallery generated by Sphinx-Gallery