WorkbenchClient
#
- class ansys.workbench.core.workbench_client.WorkbenchClient(local_workdir, server_host, server_port)#
Functions of a PyWorkbench client.
Overview#
Set the log filter level for the client console. |
|
Set a local log file for the Workbench server log. |
|
No longer use the current log file for the Workbench server log. |
|
Run a script as given in the input string on the server. |
|
Run a script file on the server. |
|
Upload one or more files from the client to the server. |
|
Upload a file from the Ansys |
|
Download one or more files from the server. |
|
Create and download the project archive. |
|
Start the PyMechanical server for the given system in the Workbench project. |
|
Stop the PyMechanical server for the given system in the Workbench project. |
|
Start the PyFluent server for the given system in the Workbench project. |
|
Stop the Fluent server for the given system in the Workbench project. |
|
Start the PySherlock server for the given system in the Workbench project. |
|
Stop the Sherlock server for the given system in the Workbench project. |
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_level
str
, default: “error” Level of logging. Options are “critical”, “debug”, “error”, “info”, and “warning”.
- log_level
- 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_file
str
Path to a local file to use for logging.
- log_file
- 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_string
str
String containing the content of the script to run.
- args
dictionary
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_level
str
, default: “error” Level of logging. Options are “critical”, “debug”, “error”, “info”, and “warning”.
- script_string
- 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_name
str
Name of the script file to run. The script file should be located in the client working directory
- args
dictionary
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_level
str
, default: “error” Level of logging. Options are “critical”, “debug”, “error”, “info”, and “warning”.
- script_file_name
- 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.
- WorkbenchClient.upload_file_from_example_repo(relative_file_path, show_progress=True)#
Upload a file from the Ansys
example-data
repository to the server.
- WorkbenchClient.download_file(file_name, show_progress=True, target_dir=None)#
Download one or more files from the server.
- Parameters:
- file_name
str
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_dir
str
, 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.
- file_name
- 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.
- WorkbenchClient.start_mechanical_server(system_name, port=0)#
Start the PyMechanical server for the given system in the Workbench project.
- Parameters:
- 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_name
str
Name of the system in the Workbench project.
- system_name
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_name
str
Name of the system in the Workbench project.
- system_name
- 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_name
str
Name of the system in the Workbench project.
- system_name
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_name
str
Name of the system in the Workbench project.
- system_name
- 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_name
str
Name of the system in the Workbench project.
- system_name
Examples
Stop the Sherlock session for the given system.
>>> wb.stop_sherlock_server(system_name=mech_system_name)