WorkbenchClient#

class ansys.workbench.core.workbench_client.WorkbenchClient(local_workdir, server_host, server_port)#

Functions of a PyWorkbench client.

Parameters:
local_workdirstr

Local working directory for the client.

server_hoststr

Hostname or IP address of the server.

server_portint

Port number of the server.

Overview#

set_console_log_level

Set the log filter level for the client console.

set_log_file

Set a local log file for the Workbench server log.

reset_log_file

No longer use the current log file for the Workbench server log.

run_script_string

Run a script as given in the input string on the server.

run_script_file

Run a script file on the server.

upload_file

Upload one or more files from the client to the server.

upload_file_from_example_repo

Upload a file from the Ansys example-data repository to the server.

download_file

Download one or more files from the server.

download_project_archive

Create and download the project archive.

start_mechanical_server

Start the PyMechanical server for the given system in the Workbench project.

stop_mechanical_server

Stop the PyMechanical server for the given system in the Workbench project.

start_fluent_server

Start the PyFluent server for the given system in the Workbench project.

stop_fluent_server

Stop the Fluent server for the given system in the Workbench project.

start_sherlock_server

Start the PySherlock server for the given system in the Workbench project.

stop_sherlock_server

Stop the Sherlock server for the given system in the Workbench project.

__enter__

Connect to the server when entering a context.

__exit__

Disconnect from the server when exiting a context.

Import detail#

from ansys.workbench.core.workbench_client import WorkbenchClient

Attribute detail#

WorkbenchClient.workdir#

Method detail#

WorkbenchClient.__enter__()#

Connect to the server when entering a context.

WorkbenchClient.__exit__(exc_type, exc_value, traceback)#

Disconnect from the server when exiting a context.

WorkbenchClient.set_console_log_level(log_level)#

Set the log filter level for the client console.

Parameters:
log_levelstr, default: “error”

Level of logging. Options are “critical”, “debug”, “error”, “info”, and “warning”.

WorkbenchClient.set_log_file(log_file)#

Set a local log file for the Workbench server log.

Create a local log file if one does not exist and append it to the existing log file.

Parameters:
log_filestr

Path to a local file to use for logging.

WorkbenchClient.reset_log_file()#

No longer use the current log file for the Workbench server log.

WorkbenchClient.run_script_string(script_string, args=None, log_level='error')#

Run a script as given in the input string on the server.

Parameters:
script_stringstr

String containing the content of the script to run.

argsdictionary of script variable names and values

Variables in the script specified as $$varname%%50%% will be converted to variable values or use the default value - 50 in the example.

log_levelstr, default: “error”

Level of logging. Options are “critical”, “debug”, “error”, “info”, and “warning”.

Returns:
str

Output defined in the script.

Examples

Run a Workbench script, given in a string, that returns the name of a newly created system.

>>> wb.run_script_string(r'''import json
wb_script_result=json.dumps(GetTemplate(TemplateName="FLUENT").CreateSystem().Name)
''')
WorkbenchClient.run_script_file(script_file_name, args=None, log_level='error')#

Run a script file on the server.

Parameters:
script_file_namestr

Name of the script file to run. The script file should be located in the client working directory

argsdictionary of script variable names and values

Variables in the script specified as $$varname%%50%% will be converted to variable values or use the default value - 50 in the example.

log_levelstr, default: “error”

Level of logging. Options are “critical”, “debug”, “error”, “info”, and “warning”.

Returns:
str

Output defined in the script.

WorkbenchClient.upload_file(*file_list, show_progress=True)#

Upload one or more files from the client to the server.

Parameters:
file_listlist[str]

List of paths to the one or more local files to upload. The wildcard characters “?” and “*” are supported.

show_progressbool, default: True

Whether to show a progress bar during the upload.

Returns:
list[str]

Names of the uploaded files.

WorkbenchClient.upload_file_from_example_repo(relative_file_path, show_progress=True)#

Upload a file from the Ansys example-data repository to the server.

Parameters:
relative_file_pathstr

File path relative to the pyworkbench folder in the example-data repository.

show_progressbool, default: True

Whether to show a progress bar during the upload.

WorkbenchClient.download_file(file_name, show_progress=True, target_dir=None)#

Download one or more files from the server.

Parameters:
file_namestr

Name of the file. File must be located in the server’s working directory. The wildcard characters “?” and “*” are supported. A ZIP file is automatically generated and downloaded when multiple files are specified.

show_progressbool, default: True

Whether to show a progress bar during the download.

target_dirstr, default: None

Path to a local directory to download the files to. The default is None, in which case the client working directory is used.

Returns:
str

Name of the downloaded file.

WorkbenchClient.download_project_archive(archive_name, include_solution_result_files=True, show_progress=True)#

Create and download the project archive.

Parameters:
archive_namestr

Name of the project archive to use, without the file extension.

include_solution_result_filesbool, default: True

Whether to include solution and result files in the archive.

show_progressbool, default: True

Whether to show a progress bar during the download.

WorkbenchClient.start_mechanical_server(system_name, port=0)#

Start the PyMechanical server for the given system in the Workbench project.

Parameters:
system_namestr

Name of the system in the Workbench project.

portint, default: 0

Port to use for mechanical server if possible

Returns:
int

Port of the PyMechanical server to use to start the PyMechanical client.

Examples

Start a PyMechanical session for the given system.

>>> from ansys.mechanical.core import connect_to_mechanical
>>> server_port=wb.start_mechanical_server(system_name=mech_system_name)
>>> mechanical = connect_to_mechanical(port=server_port)
WorkbenchClient.stop_mechanical_server(system_name)#

Stop the PyMechanical server for the given system in the Workbench project.

Parameters:
system_namestr

Name of the system in the Workbench project.

Examples

Stop the PyMechanical session for the given system.

>>> wb.stop_mechanical_server(system_name=mech_system_name)
WorkbenchClient.start_fluent_server(system_name)#

Start the PyFluent server for the given system in the Workbench project.

Parameters:
system_namestr

Name of the system in the Workbench project.

Returns:
str

Path to the local file containing the PyFluent server information that can be used to start a PyFluent client.

Examples

Start a PyFluent session for the given system.

>>> import ansys.fluent.core as pyfluent
>>> server_info_file=wb.start_fluent_server(system_name=fluent_sys_name)
>>> fluent=pyfluent.connect_to_fluent(server_info_file_name=server_info_file)
WorkbenchClient.stop_fluent_server(system_name)#

Stop the Fluent server for the given system in the Workbench project.

Parameters:
system_namestr

Name of the system in the Workbench project.

Examples

Stop the Fluent session for the given system.

>>> wb.stop_fluent_server(system_name=mech_system_name)
WorkbenchClient.start_sherlock_server(system_name)#

Start the PySherlock server for the given system in the Workbench project.

Parameters:
system_namestr

Name of the system in the Workbench project.

Returns:
int

Port of the PySherlock server to use to start a PySherlock client.

Examples

Start a PySherlock session for the given system.

>>> from ansys.sherlock.core import pysherlock
>>> server_port=wb.start_sherlock_server(system_name=sherlock_system_name)
>>> sherlock = pysherlock.connect_grpc_channel(port=server_port)
>>> sherlock.common.check()
WorkbenchClient.stop_sherlock_server(system_name)#

Stop the Sherlock server for the given system in the Workbench project.

Parameters:
system_namestr

Name of the system in the Workbench project.

Examples

Stop the Sherlock session for the given system.

>>> wb.stop_sherlock_server(system_name=mech_system_name)