ansys.dyna.core.solver.dynasolver#

Module for defining the PyDNYA solver service.

Exceptions#

RunningError

Documentation missing.

NotFound

Documentation missing.

UnexpectedResponse

Documentation missing.

Classes#

DynaSolver

Provides the gRPC client-side of Ansys LS-DYNA.

Module Contents#

exception ansys.dyna.core.solver.dynasolver.RunningError[source]#

Bases: Exception

Documentation missing.

exception ansys.dyna.core.solver.dynasolver.NotFound[source]#

Bases: Exception

Documentation missing.

exception ansys.dyna.core.solver.dynasolver.UnexpectedResponse[source]#

Bases: Exception

Documentation missing.

class ansys.dyna.core.solver.dynasolver.DynaSolver(hostname='localhost', port='5000', channel=None, server_path='')[source]#

Provides the gRPC client-side of Ansys LS-DYNA.

Parameters:
hostnamestr

Host name or IP address to connect to.

portstr

Port the gRPC server is to listen on.

Returns:
An instance of the client, which can be used to communicate
with the gRPC server running at the given host name and port.
The client can then interact with LS-DYNA via gRPC.
hostname[source]#
port[source]#
pim_client = None[source]#
remote_instance = None[source]#
stub[source]#
logger[source]#
static get_appdata_path()[source]#
static downloadfile(url: str, fname: str)[source]#
static grpc_local_server_on() bool[source]#

Check if the server is launched locally.

Returns:
bool

True when successful, False when failed.

list_files(subname=None)[source]#

Get size information about one or more files in the LS-DYNA working directory.

Parameters:
subnamestr, defaultNone

If given, only files whose names contain subname as a substring are returned. This check is case insensitive.

Returns:
Array of (filename, size in bytes) pairs.
node(n)[source]#

Get size information about a node in the model’s working directory.

Parameters:
ninteger

User ID of a node in the model.

Returns:
A pair of 3-tuples are returned, giving the (x, y, z) coordinates and
velocities of the node. If the node number given does not exist
in the model, then (None, None) is returned.
pause()[source]#

Pause LS-DYNA execution.

Execution stops until told to resume or quit. Most switch” commands result in one cycle being executed so that the switch can be handled, and then LS-DYNA pauses again.

pull(fname)[source]#

Provide an alias for the download method for backward compatibility.

download(fname)[source]#

Download a file from the gRPC server.

Parameters:
fnamestr

Name of the file to download. The file is downloaded to the current working directory of the calling process. The file name should not begin with a leading /. The file is interpreted relative to the LS-DYNA working directory.

Returns:
int

Number of bytes received.

push(fname)[source]#

Provide an alias for the ``upload` method for backward compatibility.

upload(fname)[source]#

Upload a file to the LS-DYNA working directory.

Parameters:
fnamestr

Name of the local file to upload. The contents of this file are copied into the LS-DYNA working directory in a file of the same name, but with any path components removed.

Returns:
int

Number of bytes sent.

quit()[source]#

Terminate the gRPC server program. This does not terminate LS-DYNA.

If the server is running inside a container, it ignore this command and continues running.

resume(cycle=None, time=None)[source]#

Resume execution.

Parameters:
cycleinteger, optional

Cycle to pause execution on. The default is None.

timefloat, optional

Ssimulation time to pause execution at. The default is None.

This command can be given whether LS-DYNA is paused or running.
LS-DYNA runs until the given cycle number or simulation time. If
both are given, it stops based on whichever occurs first. If
neither are given, it runs until termination or until paused.
run(args)[source]#

Begin execution with the given string as the command-line arguments.

Parameters:
argsstr

Command line to pass to LS-DYNA.

setlc(lc, value)[source]#

Set a load curve to a constant value.

Parameters:
lcint

User ID of the load curve to set.

valuefloat

Value to set the load curve to.

start(nproc)[source]#

Start LS-DYNA.

The program starts and awaits further input. To begin a simulation, the run command must used to send the command line arguments.

After starting but before running, a resume command can be sent to set a pause time or cycle.

Parameters:
nprocint

Number of cores (MPI ranks) to run.

start_locally(preset='MPP', input='', nproc=1, memory=20)[source]#

Begin execution with the given string as the command-line arguments.

Parameters:
argsstr

Command line to pass to LS-DYNA.

switch(args)[source]#

Send a “sense switch” to LS-DYNA.

Parameters:
argsstr

Sense switch string.

Returns:
If the switch sent is sw2., a str is returned with the
usual status update information that a switch generates. Otherwise,
an empty str is returned.
tail(which=1, how=2, queuesize=0)[source]#

Monitor the stdout or stderr of the running job.

Parameters:
whichint, optional

Which stream to monitor. The default is 1, in which case stdout is used. Otherwise, stderr is used.

howint, optional

How to handle the file data. The default is 2. Options are:

  • 0: The file contents are printed to stdout, and this method does not return until LS-DYNA terminates.

  • 1: A Queue instance is returned. The queue holds raw blocks of text as returned by the server.

  • 2: A Queue instance is returned.The queue holds individual lines of text.

queuesizeint, optional

Size to use for the Queue instance if the how parameter is set to a value greater than 0.

Returns:
If the value for the how parameter is greater than 0, a Queue instance
is returned. When a call to the q.get() method returns None, all data
has been returned.
time()[source]#

Get the current cycle count and simulation time.

Returns:
A (cycle_count, simulation_time) pair.
send(cmdin)[source]#

Send one request to LS-DYNA using the command-line interface.

Parameters:
cmdinstr

Command to send.

Returns:
None

There is no data returned. Data that is returned from the underlying method call is just printed to the screen. This method is used to support the sample interactive client.py program.

Description

Example

“list” then optional file name

list d3plot

“list” then optional file name

list d3plot

“node” user node number

node 43444

“pause” (no arguments)

pause

“download” then file name

download glstat

“upload” then file name

upload input.k

“quit” (no arguments)

quit

“resume” optional cycle and/or time

resume 5000 0.25

“run” then the command line

run i=input.k jobid=xx

“setlc” user load curve number and value

setlc 1075 0.245

“start” number of processors

start 5

“switch” then switch text

switch sw2

“tail” then 1 for stdout, 2 for stderr

tail 1

“time” (no arguments)

time.

runfile(fname)[source]#

Read command lines from a file and execute them.

Each line is read from the file and echoed to the screen. You must hit the enter key to trigger execution of the command.

Parameters:
fnamestr

File to read commands from.