Skip to main content

ls_toolbox

A collection of tools for working with LS-DYNA and LS-PrePost.

Installation

pip install ls_toolbox

Create environment variables named LSDYNA_PATH and LSPREPOST_PATH and set them to the paths of the LS-DYNA and LS-PrePost executables, respectively.
To do this, open the terminal and type:

For Windows:

setx LSDYNA_PATH "path\to\lsdyna\executable"
setx LSPREPOST_PATH "path\to\lsprepost\executable"

For Linux:

export LSDYNA_PATH="path/to/lsdyna/executable"
export LSPREPOST_PATH="path/to/lsprepost/executable"

Example usage

Copy/paste and run as it is:

import ls_toolbox as lst
import pyvista as pv
import os
import subprocess
import numpy as np

"""
Example using a beam 3D mesh .k file.
The mesh is first displayed using PyVista.
Then a finite element model is created by setting the boundary conditions (traction test) and material properties.
Finally, the simulation is run using LS-Dyna and the d3plot file is opened in LS-PrePost.
Simulation files are cleared at the end (except for the .K file of the FE model).
"""

# get ls_toolbox path
lst_path = os.path.dirname(lst.__file__)

# Path to the example keyfile
file_path = os.path.join(lst_path, "Example/Beam_3D_mesh_example.k")

# Read the keyfile
keyfile_lines = lst.read_keyfile.read_keyfile(file_path)

# Visualize the mesh with PyVista
mesh = lst.display.keyword2pvmesh(file_path)
mesh.plot(show_edges=True)

# Get the nodes from the keyfile
nodes = lst.read_keyfile.read_nodes(file_path)
ids = np.array(list(nodes.keys()))
coords = np.array(list(nodes.values()))

# Add a fixed displacement on the bottom nodes
# Get the nodes on the bottom face
bottom_nodes = ids[coords[:, 2] == min(coords[:, 2])]
lst.write_keyfile.add_spc(keyfile_lines, bottom_nodes)

# Add a prescribed motion on the top nodes
# Get the nodes on the top face
top_nodes = ids[coords[:, 2] == max(coords[:, 2])]
lst.write_keyfile.add_prescribed_motion_velocity(keyfile_lines, top_nodes, 1.)  # Only along the z axis

# Add a section
section_id = lst.write_keyfile.add_section_solid(keyfile_lines)

# Add a material elastic linear
material_data = np.array([1000, 1e6, 0.4999])  # rho, E, nu
material_id = lst.write_keyfile.add_mat_elastic(keyfile_lines, material_data)

# Modify the part to set the section and material data
part_id = 1
lst.write_keyfile.modify_part(keyfile_lines, part_id, section_id, material_id)

# Add an implicit solver
lst.write_keyfile.add_implicit_solver(keyfile_lines, dt0=0.5)

# Add termination time
lst.write_keyfile.add_termination(keyfile_lines, 30.)

# Add d3plot output
lst.write_keyfile.add_d3plot(keyfile_lines, dt=0.5)

# Write the new keyfile
new_file_path = file_path.replace(".k", "_model.k")
lst.write_keyfile.write_keyfile(keyfile_lines, new_file_path)

# Run LS-Dyna
print("Running LS-Dyna...")
lst.prepost_commands.run_lsdyna(new_file_path)
print("Done.")

# Open the d3plot file in PrePost
subprocess.check_call(
    f"\"{lst.prepost_commands.LS_PREPOST_PATH}\" {os.path.join(os.path.split(new_file_path)[0], 'd3plot')}", shell=True)

# Clear simulation files
lst.clear_sim_files.clear_sim_files(os.path.split(new_file_path)[0])

Metadata

Release files for ls-toolbox 0.1.9.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ls-toolbox 0.1.9.2
File Size Uploaded Provenance Actions
ls_toolbox-0.1.9.2.tar.gz 260.3 kB Without provenance Details for ls_toolbox-0.1.9.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ls-toolbox 0.1.9.2
File Interpreter ABI Platform Actions
ls_toolbox-0.1.9.2-py3-none-any.whl Python 3 none any Details for ls_toolbox-0.1.9.2-py3-none-any.whl

Total release size: 524.4 kB

Release files / ls_toolbox-0.1.9.2.tar.gz

Download URL ls_toolbox-0.1.9.2.tar.gz
Size 260.3 kB
Tags Source
SHA-256 checksum
How to use checksums
13cb2a4bf3afad19c9c9792d6fb51296087996176bf04cd46a18d832d28c7503
BLAKE2b-256 checksum
How to use checksums
59d4ac7ba11d452b1c055f8f3dbc33ea001f40c7d56deb0f1092794b785b595e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.7

Release files / ls_toolbox-0.1.9.2-py3-none-any.whl

Download URL ls_toolbox-0.1.9.2-py3-none-any.whl
Size 264.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1f4125ba2d4de1d63291684b5e4dec05f218c059116c57a97f6ae41d0cb8632f
BLAKE2b-256 checksum
How to use checksums
88defdbf7bf77d6d6c0fb56043dfa633fdf9c00b9e0b205a3184cd62681aa82a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.7

Security for ls-toolbox 0.1.9.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page