Mapdl module#

Mapdl methods and attributes#

class ansys.mapdl.core.mapdl.MapdlBase(loglevel='DEBUG', use_vtk=None, log_apdl=None, log_file=False, local=True, print_com=False, file_type_for_plots='PNG', **start_parm)#

Base MAPDL class shared across all MAPDL subclasses.

Warning

This class should NOT be imported by itself. You should always import a subclass of it like MapdlGrpc

Mapdl.add_file_handler(filepath[, append, level])

Add a file handler to the mapdl log.

Mapdl.allow_ignore

Invalid commands will be ignored rather than exceptions

Mapdl.busy

True when MAPDL gRPC server is executing a command.

Mapdl.chain_commands

Chain several mapdl commands.

Mapdl.check_parameter_names

Whether check if the name which is given to the parameter is allowed or not

Mapdl.default_file_type_for_plots

Default file type for plots.

Mapdl.directory

Current MAPDL directory.

Mapdl.exited

Return true if the MAPDL session exited

Mapdl.exiting

Returns true if the MAPDL instance is exiting.

Mapdl.file_type_for_plots

Returns the current file type for plotting.

Mapdl.finish_job_on_exit

Mapdl.force_output

Force text output globally by turning the Mapdl.mute attribute to False and activating text output (/GOPR)

Mapdl.get([par, entity, entnum, item1, ...])

Retrieves a value and stores it as a scalar parameter or part of an array parameter.

Mapdl.get_array([entity, entnum, item1, ...])

Uses the *VGET command to Return an array from ANSYS as a Python array.

Mapdl.get_esol([elem, node, item, comp, ...])

Get ESOL data.

Mapdl.get_nodal_constrains([label])

Get the applied nodal constrains:

Mapdl.get_nodal_loads([label])

Get the applied nodal loads.

Mapdl.get_nsol([node, item, comp, name, sector])

Get NSOL solutions

Mapdl.get_value([entity, entnum, item1, ...])

Runs the MAPDL GET command and returns a Python value.

Mapdl.get_variable([ir, tstrt, kcplx])

Obtain the variable values.

Mapdl.hostname

Return the hostname of the machine MAPDL is running in.

Mapdl.ignore_errors

Invalid commands will be ignored rather than exceptions

Mapdl.info

General information

Mapdl.input_strings(commands)

Run several commands as a single block.

Mapdl.is_alive

True when there is an active connect to the gRPC server

Mapdl.is_console

Return true if using console to connect to the MAPDL instance.

Mapdl.is_corba

Return true if using corba to connect to the MAPDL instance.

Mapdl.is_grpc

Return true if using grpc to connect to the MAPDL instance.

Mapdl.jobid

Returns the job id where the MAPDL is running in.

Mapdl.jobname

MAPDL job name.

Mapdl.kill_job(jobid)

Kill an HPC job

Mapdl.last_response

Returns the last response from MAPDL.

Mapdl.launched

Check if the MAPDL instance has been launched by PyMAPDL.

Mapdl.list_error_file()

Listing of errors written in JOBNAME.err

Mapdl.list_files([refresh_cache])

List the files in the working directory of MAPDL.

Mapdl.load_array(name, array)

Load an array from Python to MAPDL.

Mapdl.load_table(name, array[, var1, var2, ...])

Load a table from Python to into MAPDL.

Mapdl.locked

Instance is in use within a pool

Mapdl.logger

MAPDL Python-based logger

Mapdl.mapdl_on_hpc

Returns True if the MAPDL instance has been launched using an scheduler.

Mapdl.mute

Silence the response from all MAPDL functions unless explicitly set to True.

Mapdl.name

Instance unique identifier.

Mapdl.non_interactive

Non-interactive context manager.

Mapdl.on_docker

Check if MAPDL is running on docker.

Mapdl.open_apdl_log(filename[, mode])

Start writing all APDL commands to an MAPDL input file.

Mapdl.open_gui([include_result, inplace])

Save the existing database and open it up in the MAPDL GUI.

Mapdl.platform

Return the platform where MAPDL is running.

Mapdl.print_com

Whether to print or not to the console the mapdl.com ("/COM") calls.

Mapdl.process_is_alive

Check if the MAPDL process is alive

Mapdl.remove_file_handler()

Removes the filehander from the log

Mapdl.remove_temp_dir_on_exit

Mapdl.result

Binary interface to the result file using ansys.mapdl.reader.rst.Result.

Mapdl.result_file

Return the RST file path.

Mapdl.run(command[, write_to_log, mute])

Run single APDL command.

Mapdl.run_as_routine(routine)

Runs a command or commands at a routine and then revert to the prior routine.

Mapdl.run_multiline(commands)

Run several commands as a single block :rtype: str

Mapdl.save_selection

Save selection

Mapdl.scalar_param(pname)

Return a scalar parameter as a float.

Mapdl.screenshot([savefig])

Take an MAPDL screenshot and show it in a popup window.

Mapdl.set_log_level(loglevel)

Sets log level

Mapdl.thermal_result

The thermal result object

Mapdl.use_vtk

Returns if using VTK by default or not.

Mapdl.version

MAPDL build version.

Constants#

plotting.ALLOWED_TARGETS

Built-in mutable sequence.

plotting.BCS

Built-in mutable sequence.

mapdl_grpc.MapdlGrpc methods#

class ansys.mapdl.core.mapdl_grpc.MapdlGrpc(ip=None, port=None, timeout=15, loglevel='WARNING', log_file=False, cleanup_on_exit=False, log_apdl=None, set_no_abort=True, remove_temp_dir_on_exit=False, print_com=False, disable_run_at_connect=False, channel=None, remote_instance=None, **start_parm)#

This class connects to a GRPC MAPDL server and allows commands to be passed to a persistent session.

Parameters:
ipstr, optional

IP address to connect to the server. The default is ‘localhost’.

portint, optional

Port to connect to the MAPDL server. The default is 50052.

timeoutfloat, optional

Maximum allowable time to connect to the MAPDL server.

loglevelstr, optional

Sets which messages are printed to the console. Default ‘INFO’ prints out all ANSYS messages, ‘WARNING` prints only messages containing ANSYS warnings, and ‘ERROR’ prints only error messages.

cleanup_on_exitbool, optional

Exit MAPDL when Python exits or when this instance is garbage collected.

set_no_abortbool, optional

Sets MAPDL to not abort at the first error within /BATCH mode. The default is True.

remove_temp_dirbool, optional

When this parameter is True, the MAPDL working directory will be deleted when MAPDL is exited provided that it is within the temporary user directory. The default is False.

log_filebool, optional

Copy the log to a file called logs.log located where the python script is executed. The default is True.

print_combool, optional

Print the command /COM arguments to the standard output. The default is False.

disable_run_at_connect: bool, optional

Whether to disable the housekeeping commands when connecting. The default is False.

channelgrpc.Channel, optional

gRPC channel to use for the connection. This parameter can be used as an alternative to the ip and port parameters.

remote_instanceansys.platform.instancemanagement.Instance

The corresponding remote instance when MAPDL is launched through PyPIM. This instance will be deleted when calling Mapdl.exit.

file_type_for_plots: [“PNG”, “TIFF”, “PNG”, “VRML”, “TERM”], Optional

Change the default file type for plots using /SHOW, by default it is PNG.

Examples

Connect to an instance of MAPDL already running on locally on the default port 50052.

>>> from ansys.mapdl import core as pymapdl
>>> mapdl = pymapdl.Mapdl()

Connect to an instance of MAPDL running on the LAN on a default port.

>>> mapdl = pymapdl.Mapdl('192.168.1.101')

Connect to an instance of MAPDL running on the LAN on a non-default port.

>>> mapdl = pymapdl.Mapdl('192.168.1.101', port=60001)

If you wish to customize the channel, you can also directly connect directly to gRPC channels. For example, if you wanted to create an insecure channel with a maximum message length of 8 MB.

>>> import grpc
>>> channel = grpc.insecure_channel(
...     '127.0.0.1:50052',
...     options=[
...         ("grpc.max_receive_message_length", 8*1024**2),
...     ],
... )
>>> mapdl = pymapdl.Mapdl(channel=channel)

mapdl_grpc.MapdlGrpc.channel_state

Returns the gRPC channel state.

mapdl_grpc.MapdlGrpc.check_status

Return MAPDL status.

mapdl_grpc.MapdlGrpc.connection

Return the type of connection to the instance, namely: grpc, corba or console.

mapdl_grpc.MapdlGrpc.download(files[, ...])

Download files from the gRPC instance working directory :rtype: List[str]

mapdl_grpc.MapdlGrpc.download_project([...])

Download all the project files located in the MAPDL working directory.

mapdl_grpc.MapdlGrpc.download_result([path, ...])

Download remote result files to a local directory

mapdl_grpc.MapdlGrpc.file([fname, ext])

Specifies the data file where results are to be found.

mapdl_grpc.MapdlGrpc.ip

Return the MAPDL gRPC instance IP.

mapdl_grpc.MapdlGrpc.is_local

Check if the instance is running locally or remotely.

mapdl_grpc.MapdlGrpc.list_error_file()

Listing of errors written in JOBNAME.err

mapdl_grpc.MapdlGrpc.list_files([refresh_cache])

List the files in the working directory of MAPDL.

mapdl_grpc.MapdlGrpc.mute

Silence the response from all MAPDL functions unless explicitly set to True.

mapdl_grpc.MapdlGrpc.port

Returns the MAPDL gRPC instance port.

mapdl_grpc.MapdlGrpc.upload(file_name[, ...])

Upload a file to the grpc instance