API

Ansys object

class pansys.Ansys(startcommand=None, startfolder=None, cleanup=False, host=None)

Ansys session class

Ansys class to create an interactive ansys session. You can interact with an ansys session with the help of this class.

Prerequisites:
  • Ansys should be installed in your computer.
  • Ansys should have a interactive commandline interface.

To initiate, create an instance of the class as shown below:

>>> ans = Ansys()

This will create an instance of ansys v.15 in a newly created folder. You can change the start command of ansys by setting the startcommand as shown below:

>>> ans = Ansys(startcommand="ansys130")

If you end up changing the startcommand everytime, you can as well set an environment variable, PANSYS_STARTCOMMAND to the command of your choice. If this environment variable is found, the value of this environment variable will be used for starting Ansys session. However, if you start the Ansys session with the startcommand specified, then the specified command will take precedence.

You can also change the folder where you want Ansys to start by setting the startfolder parameter.

Parameters:
  • startcommand (str) – Ansys start command. The linux command corresponding to the version of ansys you want to open. You can give the license type as well along with the ansys command.
  • startfolder (str) – The folder in which you want to start ansys. The folder should be existing already. If left blank, a new folder of the format YYYYMMDDHHSS will be started in the location where python is running and ansys will be started inside that.
  • cleanup (bool) – If true will delete the ansys working directory after the ansys has exited. Will not delete if an existing start folder was given.
  • host (str) – The system in which you want to start the Ansys session. You can pass in the format user@system where user is the username you want to use to connect to the system and system is the network name of the system or the ip-address of the system to which you want to connect to. You can omit the user part if you want to connect to the remote machine with the current login itself. It is expected that you have set up ssh-keys in the remote system for this to work.
__del__()

Destructor function for ansys exiting

__repr__()

Representation of the object

get(entity, entnum, item1, it1num='', item2='', it2num='')

Wrapper for ansys *GET command

Function to execute the *get command of ansys. Sequence of input data is same as in ansys.

Parameters:
  • entity (str) –
  • entnum (str) –
  • item1 (str) –
  • it1num (str) –
  • item2 (str) –
  • it2num (str) –

Note

All arguments are in the same order as per ansys *get documentation.

Returns:Output of *get. Can be int, float, exponential or string.
get_list(command_string, **kwargs)

Extract any list from ansys

Function to get any ansys list as a pandas.DataFrame.

Example

>>> a.get_list("nlist")

Note

The function assumes that the command_string will return a column data.

For example, instead of using a.get_list("elist") you should use a.get_list("elist,,,,1") For getting element list.

This function passess all keyword arguments directly to pandas.read_table() function. The default values of delim_whitespace is True and skiprows is 2.

Parameters:
  • command_string (str) – The Ansys command which will output a column data.
  • **kwargs – All keyword arguments for the read_table function in pandas is applicable for this function as well.
Returns:

A pandas.DataFrame with the data that

ansys returned when command_string was passed.

Return type:

pandas.Dataframe

get_output(command_string, persist=False)

Function to get ansys output as a file

The function uses /output command in ansys to redirect the output to a file. The path to this file will be returned from the command.

Parameters:
  • command_string (str) – The command(s) to be executed for which the output is sought.
  • persist (bool) – If True, will create a unique file which will not be overwritten because of subsequent call of this function. Default is False which will write the output to a file out.out in the ansys working directory.
Returns:

Path to a file which contains the output of the ansys command

call.

Return type:

str

get_queue()

Returns a generator with the commands in the current queue, submitted using the pansys.Ansys.queue() method.

Returns:A file object pointing to the command list
Return type:object
output

The output of the last executed Ansys command

plot(command_string)

Plot anything in ansys

Function to return an image with a plot from Anys.

Example

>>> ans.plot("eplot")
Parameters:command_string (str) – The command for plotting in ansys
Returns:The path to the image file.
Return type:str
queue(command_string)

Queue commands for delayed execution

When there is a large number of ansys commands that you want to pass, use this function to queue up them for execution. To execute the queue, use the pansys.Ansys.run_queue() method.

Parameters:command_string (str) – Required. The command that you want to add to the queue.
Returns:None
run_queue(**kwargs)

Runs all the commands in the queue

This method writes all the commands that are queued using the pansys.Ansys.queue() method to a file and execute them in one go by using the /input command of Ansys. This will be sent using the pansys.Ansys.send() method and hence will accept all keyword arguments of the same method.

Parameters:kwargs – Optional. See keyword args for pansys.Ansys.send()
Returns:None
send(command_string, **kwargs)

Sending a command to ansys

Function to send commands to interactive ansys session. Commands can be single line or multiline.

Example

>>> ans.send('/post1')
>>> ans.send('''
...     file,results,rst
...     set,last
...     esel,s,mat,,1
...     ''')

You can process the output from any ansys command using the output_function argument.

Example

>>> def parseout(line):
...     if "WARNING" in line:
...         print("Found a warning")
...     else:
...         pass
...
>>> ans.send("set, last", silent=False, output_function=parseout)

In the above scenario, “Found a warning” string will be printed for every occurance of a warning for the ansys command set,last. For other lines, no action will be taken.

Parameters:
  • command_string (str) – Required. The string containing ansys command silent (bool): Optional. Boolean value which when set true will print the output from ansys after executing command_string
  • output_function (function) – Optional. A function which will process the output from ansys. The output will be passed line by line to this function. silent option should be set to False for this to work.
Returns:

None

version

The version of ansys for the current active session.

wd

Current working directory where Ansys is running.