diff --git a/doc/changelog.d/4579.fixed.md b/doc/changelog.d/4579.fixed.md new file mode 100644 index 000000000000..e5dd7a60da25 --- /dev/null +++ b/doc/changelog.d/4579.fixed.md @@ -0,0 +1 @@ +Example deprecation warnings and improvements diff --git a/doc/source/cheatsheet/cheat_sheet.qmd b/doc/source/cheatsheet/cheat_sheet.qmd index 3dc3d93f0fe9..30f4ac15323a 100644 --- a/doc/source/cheatsheet/cheat_sheet.qmd +++ b/doc/source/cheatsheet/cheat_sheet.qmd @@ -65,8 +65,8 @@ solver = pyfluent.launch_fluent( ```{python} fluent = pyfluent.connect_to_fluent( - ip="127.0.0.1", - port=50000, + ip="127.0.0.1", + port=50000, password="abcdefg") ``` @@ -392,7 +392,7 @@ solution.run_calculation.iterate(iter_count=100) from ansys.fluent.core import examples from ansys.fluent.core.filereader.case_file import CaseFile case_file_name = examples.download_file( - "Static_Mixer_Parameters.cas.h5", + "Static_Mixer_Parameters.cas.h5", "pyfluent/static_mixer") reader = CaseFile(case_file_name=case_file_name) reader.precision() @@ -432,7 +432,7 @@ from ansys.fluent.core.filereader.data_file import DataFile from ansys.fluent.core.filereader.case_file import CaseFile data_file_name = examples.download_file("elbow1.dat.h5", "pyfluent/file_session") reader = DataFile( - data_file_name=data_file_name, + data_file_name=data_file_name, case_file_handle=CaseFile(case_file_name)) reader.case_file reader.variables() @@ -461,10 +461,10 @@ fs.fields.field_info.get_scalar_fields_info() from ansys.fluent.core import examples from ansys.fluent.core.file_session import FileSession case_file_name = examples.download_file( - "mixing_elbow_mul_ph.cas.h5", + "mixing_elbow_mul_ph.cas.h5", "pyfluent/file_session") data_file_name = examples.download_file( - "mixing_elbow_mul_ph.dat.h5", + "mixing_elbow_mul_ph.dat.h5", "pyfluent/file_session") fs = FileSession() fs.read_case(case_file_name) @@ -525,11 +525,11 @@ velocity_vector.display("w3") import ansys.fluent.core as pyfluent from ansys.fluent.core import examples case_path = examples.download_file( - file_name="exhaust_system.cas.h5", + file_name="exhaust_system.cas.h5", directory="pyfluent/exhaust_system" ) data_path = examples.download_file( - file_name="exhaust_system.dat.h5", + file_name="exhaust_system.dat.h5", directory="pyfluent/exhaust_system" ) solver = pyfluent.launch_fluent( @@ -545,13 +545,13 @@ field_data = solver.fields.field_data ```{python} from ansys.fluent.core.services.field_data import SurfaceDataType data = field_data.get_surface_data( - surfaces=["inlet"], + surfaces=["inlet"], data_types=[SurfaceDataType.Vertices] ) data["inlet"][SurfaceDataType.Vertices].shape data["inlet"][SurfaceDataType.Vertices][5] faces_normal_and_centroid_data = field_data.get_surface_data( - data_types=[SurfaceDataType.FacesNormal, + data_types=[SurfaceDataType.FacesNormal, SurfaceDataType.FacesCentroid], surfaces=["inlet"] ) @@ -559,7 +559,7 @@ inlet = faces_normal_and_centroid_data["inlet"] inlet[SurfaceDataType.FacesNormal].shape inlet[SurfaceDataType.FacesCentroid][15] faces_connectivity_data = field_data.get_surface_data( - data_types=[SurfaceDataType.FacesConnectivity], + data_types=[SurfaceDataType.FacesConnectivity], surfaces=["inlet"] ) inlet = faces_connectivity_data["inlet"] @@ -570,7 +570,7 @@ inlet[SurfaceDataType.FacesConnectivity][5] ```{python} abs_press_data = field_data.get_scalar_field_data( - field_name="absolute-pressure", + field_name="absolute-pressure", surfaces=["inlet"] ) abs_press_data["inlet"].shape @@ -581,7 +581,7 @@ abs_press_data["inlet"][120] ```{python} velocity_vector_data = field_data.get_vector_field_data( - field_name="velocity", + field_name="velocity", surfaces=["inlet", "inlet1"] ) velocity_vector_data["inlet"].shape @@ -592,7 +592,7 @@ velocity_vector_data["inlet1"].shape ```{python} path_lines_data = field_data.get_pathlines_field_data( - field_name="velocity", + field_name="velocity", surfaces=["inlet"] ) path_lines_data["inlet"]["vertices"].shape @@ -638,10 +638,10 @@ solver1 = pyfluent.launch_fluent( mode=pyfluent.FluentMode.SOLVER ) case_path = download_file( - file_name="exhaust_system.cas.h5", + file_name="exhaust_system.cas.h5", directory="pyfluent/exhaust_system") data_path = download_file( - file_name="exhaust_system.dat.h5", + file_name="exhaust_system.dat.h5", directory="pyfluent/exhaust_system") solver1.settings.file.read_case_data( file_name=case_path @@ -651,11 +651,11 @@ solver2 = pyfluent.launch_fluent( mode=pyfluent.FluentMode.SOLVER ) case_path = download_file( - "elbow1.cas.h5", + "elbow1.cas.h5", "pyfluent/file_session" ) data_path = download_file( - "elbow1.dat.h5", + "elbow1.dat.h5", "pyfluent/file_session" ) solver2.settings.file.read_case_data( @@ -676,7 +676,7 @@ solver.fields.reduction.area( locations=[inlet["inlet1"]] ) solver.fields.reduction.area( - locations=["inlet1"], + locations=["inlet1"], ctxt=solver) ``` @@ -767,7 +767,7 @@ zone_info.zone_type ```{python} wall_fluid_info = solution_variable_info.get_variables_info( - zone_names=['wall' , "fluid"], + zone_names=['wall', "fluid"], domain_name="mixture") wall_fluid_info.solution_variables solution_variable_info_centroid = wall_fluid_info['SV_CENTROID'] @@ -782,7 +782,7 @@ solution_variable_info_centroid.field_type ```{python} sv_t_wall_fluid= solution_variable_data.get_data( variable_name="SV_T", - zone_names=["fluid", "wall"], + zone_names=["fluid", "wall"], domain_name="mixture") sv_t_wall_fluid.domain sv_t_wall_fluid.zones @@ -814,14 +814,14 @@ solution_variable_data.set_data( transaction = solver.fields.field_data.new_transaction() transaction.add_surfaces_request( - surfaces=[1], - data_types=[SurfaceDataType.Vertices, + surfaces=[1], + data_types=[SurfaceDataType.Vertices, SurfaceDataType.FacesCentroid] ) transaction.add_scalar_fields_request( - surfaces=[1, 2], - field_name="pressure", - node_value=True, + surfaces=[1, 2], + field_name="pressure", + node_value=True, boundary_value=True ) transaction.add_vector_fields_request( @@ -862,11 +862,11 @@ import_case = examples.download_file( import_data = examples.download_file( file_name="exhaust_system.dat.h5", directory="pyfluent/exhaust_system" ) -solver.file.read_case_data(file_name=import_case) +solver.settings.file.read_case_data(file_name=import_case) # check the active report plot monitors using the settings relevant object solver.settings.solution.monitor.report_plots() # initialize so that monitors object is usable -solver.solution.initialization.hybrid_initialize() +solver.settings.solution.initialization.hybrid_initialize() # check which monitors are available sorted(solver.monitors.get_monitor_set_names()) # create and register a callback function that will @@ -896,7 +896,7 @@ def display_monitor_table( register_id = solver.monitors.register_callback( display_monitor_table()) # run the solver and see the full tabulated monitor data on each iteration -solver.solution.run_calculation.iterate( +solver.settings.solution.run_calculation.iterate( iter_count=10) ``` @@ -969,21 +969,21 @@ from ansys.fluent.core import examples from ansys.fluent.core.utils.file_transfer_service import StandaloneFileTransferStrategy mesh_file_name = examples.download_file( - "mixing_elbow.msh.h5", + "mixing_elbow.msh.h5", "pyfluent/mixing_elbow") meshing_session = pyfluent.launch_fluent( - mode=pyfluent.FluentMode.MESHING, + mode=pyfluent.FluentMode.MESHING, file_transfer_service= StandaloneFileTransferStrategy()) meshing_session.upload( - file_name=mesh_file_name, + file_name=mesh_file_name, remote_file_name="elbow.msh.h5") meshing_session.meshing.File.ReadMesh( FileName="elbow.msh.h5") meshing_session.meshing.File.WriteMesh( FileName="write_elbow.msh.h5") meshing_session.download( - file_name="write_elbow.msh.h5", + file_name="write_elbow.msh.h5", local_directory="") ``` @@ -995,21 +995,21 @@ from ansys.fluent.core import examples from ansys.fluent.core.utils.file_transfer_service import ContainerFileTransferStrategy case_file_name = examples.download_file( - "mixing_elbow.cas.h5", + "mixing_elbow.cas.h5", "pyfluent/mixing_elbow") solver_session = pyfluent.launch_fluent( - mode=pyfluent.FluentMode.SOLVER, + mode=pyfluent.FluentMode.SOLVER, file_transfer_service= ContainerFileTransferStrategy()) solver_session.upload( - file_name=case_file_name, + file_name=case_file_name, remote_file_name="elbow.cas.h5") -solver_session.file.read_case( +solver_session.settings.file.read_case( file_name="elbow.cas.h5") -solver_session.file.write_case( +solver_session.settings.file.write_case( file_name="write_elbow.cas.h5") solver_session.download( - file_name="write_elbow.cas.h5", + file_name="write_elbow.cas.h5", local_directory="") ``` @@ -1044,7 +1044,7 @@ import ansys.fluent.core as pyfluent pyfluent.search("font") # Whole word search -pyfluent.search("ApplicationFontSize", +pyfluent.search("ApplicationFontSize", match_whole_word=True) # Wildcard pattern search @@ -1081,8 +1081,8 @@ import ansys.fluent.core as pyfluent os.environ["ANSYSLMD_LICENSE_FILE"] = "" custom_config = { - 'fluent_image': 'ansys_inc:latest', - 'mount_source': f"{os.getcwd()}", + 'fluent_image': 'ansys_inc:latest', + 'mount_source': f"{os.getcwd()}", 'auto_remove': False} solver = pyfluent.launch_fluent( diff --git a/doc/source/user_guide/fields/reduction.rst b/doc/source/user_guide/fields/reduction.rst index 054ef80d023e..ccb23e218a87 100644 --- a/doc/source/user_guide/fields/reduction.rst +++ b/doc/source/user_guide/fields/reduction.rst @@ -251,7 +251,7 @@ Functional: >>> reduction.area_average( ... expression=VariableCatalog.ABSOLUTE_PRESSURE, - ... locations=solver_session.setup.boundary_conditions.velocity_inlet, + ... locations=solver_session.settings.setup.boundary_conditions.velocity_inlet, ... ) 101957.2452989816 @@ -271,8 +271,8 @@ Object-Oriented: >>> reduction.minimum( ... expression=VariableCatalog.ABSOLUTE_PRESSURE, - ... locations=solver1.setup.boundary_conditions.pressure_outlet - ... + solver2.setup.boundary_conditions.pressure_outlet, + ... locations=solver1.settings.setup.boundary_conditions.pressure_outlet + ... + solver2.settings.setup.boundary_conditions.pressure_outlet, ... ) 101325.0 diff --git a/doc/source/user_guide/file_transfer.rst b/doc/source/user_guide/file_transfer.rst index de1ded3ac963..09b7dee8dcb7 100644 --- a/doc/source/user_guide/file_transfer.rst +++ b/doc/source/user_guide/file_transfer.rst @@ -3,15 +3,15 @@ File transfer ============= -PyFluent provides a file transfer service that manages how files are uploaded to and downloaded from the Fluent server. -This service allows file-based API methods like `read_case()` and `write_mesh()` to work seamlessly—even when Fluent is running remotely, +PyFluent provides a file transfer service that manages how files are uploaded to and downloaded from the Fluent server. +This service allows file-based API methods like `read_case()` and `write_mesh()` to work seamlessly—even when Fluent is running remotely, in a container, or in a PIM-managed environment. Depending on how Fluent is launched, different file transfer strategies are available: 1. **PIM file transfer service** - When launching Fluent through the `Product Instance Management (PIM) `_ file transfer is fully automated. + When launching Fluent through the `Product Instance Management (PIM) `_ file transfer is fully automated. You don’t need to call `upload()` or `download()`—files are transferred transparently when you use file-based API methods. Use this service when: @@ -29,13 +29,13 @@ Depending on how Fluent is launched, different file transfer strategies are avai >>> case_file = examples.download_file("mixing_elbow.cas.h5", "pyfluent/mixing_elbow") >>> session = pyfluent.launch_fluent() - >>> session.file.read_case(file_name=case_file) - >>> session.file.write_case(file_name="write_mixing_elbow.cas.h5") + >>> session.settings.file.read_case(file_name=case_file) + >>> session.settings.file.write_case(file_name="write_mixing_elbow.cas.h5") 2. **Container file transfer service** - When Fluent runs in a Docker container, files cannot be shared directly between client and server. + When Fluent runs in a Docker container, files cannot be shared directly between client and server. The remote file transfer service uses a gRPC-based mechanism to manage transfers. Use this service when: @@ -56,13 +56,13 @@ Depending on how Fluent is launched, different file transfer strategies are avai >>> file_transfer_service = ContainerFileTransferStrategy() >>> container_dict = {"mount_source": file_transfer_service.mount_source} >>> session = pyfluent.launch_fluent(file_transfer_service=file_transfer_service, container_dict=container_dict) - >>> session.file.read_case(file_name=case_file) - >>> session.file.write_case(file_name="write_mixing_elbow.cas.h5") + >>> session.settings.file.read_case(file_name=case_file) + >>> session.settings.file.write_case(file_name="write_mixing_elbow.cas.h5") 3. **Standalone file transfer service** - When Fluent is launched in standalone mode on the same machine as the Python client, files can be accessed directly from the local file system. + When Fluent is launched in standalone mode on the same machine as the Python client, files can be accessed directly from the local file system. In this case, the local file transfer service is used. Use this service when: diff --git a/doc/source/user_guide/monitors.rst b/doc/source/user_guide/monitors.rst index be24bfe55167..3fc8e66fb616 100644 --- a/doc/source/user_guide/monitors.rst +++ b/doc/source/user_guide/monitors.rst @@ -6,7 +6,7 @@ Using monitors Monitors in PyFluent allow you to dynamically observe the convergence of your solution by tracking the values of solution variables and residuals. They enable you to visualize the progress of the solver, helping ensure that -the solution is progressing as expected and allowing you to diagnose issues +the solution is progressing as expected and allowing you to diagnose issues early on. You can integrate PyFluent's monitor callback mechanism with visualization @@ -49,7 +49,7 @@ callback mechanism to perform a simple tabulation of monitored values per iterat >>> "point-vel-rplot", >>> "residual" >>> ] - >>> # create and register a callback function that will + >>> # create and register a callback function that will >>> def display_monitor_table(monitor_set_name="mass-bal-rplot"): >>> def display_table(): >>> data = solver_session.monitors.get_monitor_set_data(monitor_set_name=monitor_set_name) @@ -73,4 +73,4 @@ callback mechanism to perform a simple tabulation of monitored values per iterat >>> >>> register_id = solver_session.monitors.register_callback(display_monitor_table()) >>> # run the solver and see the full tabulated monitor data on each iteration - >>> solver_session.solution.run_calculation.iterate(iter_count=10) + >>> solver_session.settings.solution.run_calculation.iterate(iter_count=10) diff --git a/doc/source/user_guide/physical_variables.rst b/doc/source/user_guide/physical_variables.rst index 1b76da1efeb4..d5e52d740505 100644 --- a/doc/source/user_guide/physical_variables.rst +++ b/doc/source/user_guide/physical_variables.rst @@ -32,7 +32,7 @@ Here’s how to use ``VariableCatalog`` to read and reduce field data using unit solver_session = launch_fluent() case_path = examples.download_file("mixing_elbow.cas.h5", "pyfluent/mixing_elbow") - solver_session.file.read(file_type="case", file_name=case_path) + solver_session.settings.file.read(file_type="case", file_name=case_path) solver_session.settings.solution.initialization.hybrid_initialize() @@ -67,7 +67,7 @@ You can also use physical quantities in report definitions to improve clarity an surface_report.field = temperature # Note: using VariableCatalog, not a string surface_report.surface_names = locations - result = solver_session.solution.report_definitions.compute(report_defs=["avg_temp"]) + result = solver_session.settings.solution.report_definitions.compute(report_defs=["avg_temp"]) print(result[0]["avg_temp"][0]) Notes diff --git a/doc/source/user_guide/session/launching_ansys_fluent.rst b/doc/source/user_guide/session/launching_ansys_fluent.rst index 599ccb821b85..0861869446b8 100644 --- a/doc/source/user_guide/session/launching_ansys_fluent.rst +++ b/doc/source/user_guide/session/launching_ansys_fluent.rst @@ -3,15 +3,17 @@ Launching and connecting to Fluent ================================== -This document provides a comprehensive guide for launching and connecting to Ansys Fluent sessions using PyFluent, the Python interface for Fluent. -It covers multiple methods to start Fluent, including launching from a local installation, containerized environments (Docker or Podman), and connecting -to existing Fluent sessions. Detailed examples illustrate how to initialize Fluent in various modes such as meshing, solution, and pre/post processing. +This guide explains how to start and connect to Ansys Fluent sessions using PyFluent. It covers common workflows such as +:ref:`Launch from local installation `, :ref:`Launch in a container `, +or :ref:`Connect to an existing session `. Examples are provided for initializing Fluent in +meshing, solution, and post-processing modes. -Additionally, the guide explains advanced launching options such as setting precision, dimensions, and parallel execution configurations. -It also covers integration with job schedulers like Slurm, enabling efficient high-performance computing workflows. -Furthermore, instructions for launching Fluent within PIM environments and detailed procedures for cross-platform remote connections and file transfers between Windows, Linux, and WSL hosts are provided. +Advanced launch options, such as :ref:`selecting precision `, :ref:`dimensionality `, and +:ref:`parallel settings `, are also described. The document includes guidance for :ref:`running Fluent under job +schedulers like Slurm `, :ref:`using PyFluent in PIM environments `, and configuring remote connections +across Windows, Linux, and WSL systems. -This reference aims to equip users with the knowledge and tools required to flexibly and efficiently manage Fluent sessions in diverse computing environments. +.. _launch_from_local_installation: Launch from local installation ------------------------------ @@ -35,9 +37,11 @@ Use this method when: solver = pyfluent.Solver.from_install() solver_aero = pyfluent.SolverAero.from_install() solver_icing = pyfluent.SolverIcing.from_install() - pre_post = pyfluent.PrePost.from_install() + pre_post = pyfluent.PrePost.from_install() +.. _launch_in_container: + Launch in a container --------------------- @@ -69,6 +73,8 @@ Use this method when: pre_post = pyfluent.PrePost.from_container(container_dict=container_dict, product_version=pyfluent.FluentVersion.v252, use_podman_compose=True) +.. _connect_to_existing_session: + Connect to an existing session ------------------------------ @@ -121,6 +127,9 @@ Use this method when: A ``Meshing`` interface is not recommended for a **meshing-only** session, because ``switch_to_solver()`` would raise an error in that case. + +.. _connect_to_pim_session: + Launch in `PIM `_ mode ---------------------------------------------------------------------- @@ -140,7 +149,7 @@ Use this method when: solver = pyfluent.Solver.from_pim() solver_aero = pyfluent.SolverAero.from_pim() solver_icing = pyfluent.SolverIcing.from_pim() - pre_post = pyfluent.PrePost.from_pim() + pre_post = pyfluent.PrePost.from_pim() .. vale Google.Spacing = YES @@ -193,7 +202,7 @@ These two examples show equivalent ways to launch Fluent in solution mode: .. code:: python >>> solver_session = pyfluent.launch_fluent(mode=pyfluent.FluentMode.SOLVER) - + .. code:: python @@ -222,6 +231,8 @@ This example shows how to launch Fluent in Pre/Post mode: >>> pre_post_session = pyfluent.launch_fluent(mode=pyfluent.FluentMode.PRE_POST) +.. _select_precision: + Precision ~~~~~~~~~ This example shows how to launch Fluent in solution mode @@ -234,6 +245,8 @@ and set the floating point precision: >>> ) +.. _select_dimension: + Dimension ~~~~~~~~~ This example shows how to launch Fluent in solution mode and set the @@ -247,6 +260,8 @@ modeling dimension to two: >>> ) +.. _parallel_settings: + Local parallel ~~~~~~~~~~~~~~ This example shows how to launch Fluent in solution mode and set the @@ -288,6 +303,9 @@ This command enables logging: For more details, see :ref:`ref_logging_guide`. + +.. _scheduler_support: + Scheduler support ----------------- When PyFluent is used within a job scheduler environment, the :func:`launch_fluent() @@ -427,12 +445,14 @@ the ``-t`` and ``-cnf`` arguments must be passed to the :func:`launch_fluent() ` function using the ``additional_arguments`` parameter for distributed parallel processing. +.. _pypim_guide: + Launching a `PIM `_ session --------------------------------------------------------------------------- -When PyFluent is used within a `PIM `_ configured environment, -the :func:`launch_fluent() ` function automatically launches -Fluent session in `PIM `_ mode and in that same environment it -can be launched explicitly using :func:`create_launcher() ` as follows: +When PyFluent is used within a `PIM `_ configured environment, +:func:`launch_fluent() ` automatically launches Fluent in +`PIM `_ mode. In that same environment it can be launched explicitly +using :func:`create_launcher() ` as follows: .. code:: python @@ -478,7 +498,7 @@ Launch Fluent in container mode via PyFluent: >>> from ansys.fluent.core import examples >>> solver_session = pyfluent.launch_fluent(start_container=True, use_docker_compose=True) >>> case_file_name = examples.download_file("mixing_elbow.cas.h5", "pyfluent/mixing_elbow") - >>> solver_session.file.read(file_name=case_file_name, file_type="case") + >>> solver_session.settings.file.read(file_name=case_file_name, file_type="case") >>> solver_session.exit() @@ -523,7 +543,7 @@ Connecting to a Fluent container running inside Linux from a Windows host Connecting to Fluent on Windows from a Linux or WSL host -------------------------------------------------------- -This guide describes how to connect to an ANSYS Fluent instance running on a Windows machine from a Linux or WSL host. +This section outlines how to connect to Fluent running on Windows from a Linux or WSL host. It also includes steps to enable remote file transfer. Prerequisites: @@ -547,7 +567,7 @@ A. **Set Up Fluent and File Transfer Server on Windows** 2. **Retrieve Connection Details** - Get the IP address, port, and password from the `server_info.txt` file. + Get the IP address, port, and password from the `server_info.txt` file. Example: - IP: ``10.18.44.179`` - Port: ``51344`` @@ -589,16 +609,16 @@ Run the following Python code to connect to Fluent and transfer files: solver_session = connect_to_fluent(ip="10.18.44.179", port=51344, password="5scj6c8l", file_transfer_service=file_service) # `mixing_elbow.cas.h5` will be uploaded to remote Fluent working directory - solver_session.file.read_case(file_name="/home/user_name/mixing_elbow.cas.h5") + solver_session.settings.file.read_case(file_name="/home/user_name/mixing_elbow.cas.h5") # `elbow_remote.cas.h5` will be downloaded to local working directory - solver_session.file.write_case(file_name="elbow_remote.cas.h5") + solver_session.settings.file.write_case(file_name="elbow_remote.cas.h5") Connecting to Fluent on Linux or WSL from a Windows host -------------------------------------------------------- -This guide describes how to connect to an ANSYS Fluent instance running on a Linux or WSL machine from a Windows host. +This section outlines how to connect to an Fluent running on Linux or WSL from a Windows host. It also includes steps to enable remote file transfer. Prerequisites: @@ -622,7 +642,7 @@ A. **Set Up Fluent and File Transfer Server on Linux or WSL** 2. **Retrieve Connection Details** - Get the IP address, port, and password from the `server_info.txt` file. + Get the IP address, port, and password from the `server_info.txt` file. Example: - IP: ``10.18.19.150`` - Port: ``41429`` @@ -649,8 +669,7 @@ Run the following Python code to connect to Fluent and transfer files: solver_session = connect_to_fluent(ip="10.18.19.150", port=41429, password="u5s3iivh", file_transfer_service=file_service) # `mixing_elbow.cas.h5` will be uploaded to remote Fluent working directory - solver_session.file.read_case(file_name="D:\path_to_file\mixing_elbow.cas.h5") + solver_session.settings.file.read_case(file_name="D:\path_to_file\mixing_elbow.cas.h5") # `elbow_remote.cas.h5` will be downloaded to local working directory - solver_session.file.write_case(file_name="elbow_remote.cas.h5") - + solver_session.settings.file.write_case(file_name="elbow_remote.cas.h5") diff --git a/doc/source/user_guide/solver_settings/solver_settings_contents.rst b/doc/source/user_guide/solver_settings/solver_settings_contents.rst index d264019c024f..85de7e829d10 100644 --- a/doc/source/user_guide/solver_settings/solver_settings_contents.rst +++ b/doc/source/user_guide/solver_settings/solver_settings_contents.rst @@ -6,7 +6,7 @@ Solver settings objects .. vale Google.Spacing = NO Solver settings objects provide a natural way to access and modify Fluent solver -settings and issue commands to be executed in the Fluent solver. +settings and issue commands to be executed. An appropriate call to the :func:`~ansys.fluent.core.launcher.launcher.launch_fluent` function returns an object whose interface directly exposes the :ref:`ref_root` of the solver settings hierarchy. @@ -16,10 +16,10 @@ function returns an object whose interface directly exposes the :ref:`ref_root` New format for accessing solver settings objects ------------------------------------------------ -To simplify the usage of Fluent solver settings and improve readability, -you can now instantiate settings objects directly using a more intuitive syntax. -This new approach allows for straightforward access to various settings without -navigating through the hierarchical structure of the solver settings. +To simplify access to solver settings and improve readability, you can now +instantiate settings objects directly using a concise constructor-style syntax. +This avoids navigating the full hierarchy of solver settings while preserving +the same functional capabilities. Example usage ~~~~~~~~~~~~~ @@ -32,17 +32,17 @@ Example usage >>> inlet1 = VelocityInlet(settings_source=solver_session, name="inlet-1") -This format provides a more natural way to create and interact with settings objects, -making your code easier to read and maintain. By abstracting the underlying hierarchy, -users can focus on the specific settings they need without dealing with potential changes +This format provides a more natural way to create and interact with settings objects, +making your code easier to read and maintain. By abstracting the underlying hierarchy, +users can focus on the specific settings they need without dealing with potential changes in the Fluent API structure. +The traditional hierarchy-based API remains fully supported. The new syntax is an +additional, more convenient option and not a replacement. + Accessing solver settings ------------------------- -Following the introduction of the new format, the traditional method remains available for those -who prefer the existing hierarchy. - .. code-block:: python >>> file = solver_session.settings.file @@ -365,12 +365,12 @@ Also, when you have one or more velocity inlets with "inlet" in their names:: For string lists with allowed values, for instance:: - >>> solver_session.results.graphics.contour['contour-1'].surfaces_list = 'in*' + >>> solver_session.settings.results.graphics.contour['contour-1'].surfaces_list = 'in*' sets ``surfaces_list`` to all matches of surface names starting with ``in``, so when you prompt for the list of surfaces:: - >>> solver_session.results.graphics.contour['contour-1'].surfaces_list() + >>> solver_session.settings.results.graphics.contour['contour-1'].surfaces_list() ['in1', 'in2'] The following list summarizes common wildcards: diff --git a/doc/source/user_guide/usability.rst b/doc/source/user_guide/usability.rst index 6c93e4fc5714..230e56d2f720 100644 --- a/doc/source/user_guide/usability.rst +++ b/doc/source/user_guide/usability.rst @@ -116,7 +116,7 @@ Examples .tui.results.report.simulation_reports.read_simulation_report_template_file (Command) (similarity: 100.0%) >>> >>> # Whole word search - >>> pyfluent.search("iteration_at_creation_or_edit", match_whole_word=True) + >>> pyfluent.search("iteration_at_creation_or_edit", match_whole_word=True) .solution.monitor.convergence_conditions.convergence_reports[""].iteration_at_creation_or_edit (Parameter) >>> >>> # Whole word search within a specific API object @@ -144,7 +144,7 @@ Examples ... >>> >> # Wildcard pattern search within a specific API object - >>> pyfluent.search("iter*", api_path=".parallel.multidomain") + >>> pyfluent.search("iter*", api_path=".parallel.multidomain") .parallel.multidomain.conjugate_heat_transfer.set.coupling.iter_per_coupling_count (Parameter) .parallel.multidomain.conjugate_heat_transfer.set.coupling.single_session_coupling.iteration (Parameter) .parallel.multidomain.solve.dual_time_iterate (Command) diff --git a/examples/00-fluent/DOE_ML.py b/examples/00-fluent/DOE_ML.py index 1e43271863a2..02876c9778fe 100644 --- a/examples/00-fluent/DOE_ML.py +++ b/examples/00-fluent/DOE_ML.py @@ -1,3 +1,16 @@ +# /// script +# dependencies = [ +# "ansys-fluent-core", +# "matplotlib", +# "numpy", +# "pandas", +# "plotly", +# "scikit-learn", +# "seaborn", +# "tensorflow", +# ] +# /// + # Copyright (C) 2021 - 2026 ANSYS, Inc. and/or its affiliates. # SPDX-License-Identifier: MIT # @@ -32,7 +45,7 @@ # # Water enters a Mixing Elbow from two Inlets; Hot (313 K) and Cold (293 K) and exits # from Outlet. Using PyFluent in the background, this example runs Design of Experiments -# with Cold Inlet Velocity and Hot Inlet Velocity as Input Parameters and Outlet +# (DOE) with Cold Inlet Velocity and Hot Inlet Velocity as Input Parameters and Outlet # Temperature as an Output Parameter. # # Results can be visualized using a Response Surface. Finally, Supervised Machine @@ -84,8 +97,7 @@ solver_session = pyfluent.launch_fluent( precision="double", - processor_count=2, - version="3d", + processor_count=4, ) print(solver_session.get_fluent_version()) @@ -99,13 +111,15 @@ ############################################################################################## # Design of Experiments # ===================== -# * Define Manual DOE as numpy arrays -# * Run cases in sequence -# * Populate results (Mass Weighted Average of Temperature at Outlet) in resArr +# Specify inlet velocities for the cold and hot streams. +# Each pair of (coldVel, hotVel) will be used to run one Fluent case. coldVelArr = np.array([0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7]) -hotVelArr = np.array([0.8, 1, 1.2, 1.4, 1.6, 1.8, 2.0]) -resArr = np.zeros((coldVelArr.shape[0], hotVelArr.shape[0])) +hotVelArr = np.array([0.8, 1.0, 1.2, 1.4, 1.6, 1.8, 2.0]) + +# Allocate a results array. Entry (i, j) will hold the Mass‑Weighted +# Average Temperature at the outlet for coldVelArr[i] and hotVelArr[j]. +resArr = np.zeros((coldVelArr.size, hotVelArr.size)) for idx1, coldVel in np.ndenumerate(coldVelArr): for idx2, hotVel in np.ndenumerate(hotVelArr): @@ -236,12 +250,12 @@ # * Prediction on Unseen/Test Data (scikit-learn) # * Parity Plot (Matplotlib and Seaborn) -# from pprint import pprint +from sklearn.metrics import r2_score +from sklearn.model_selection import RepeatedKFold, cross_val_score +# optionally chose which model to use # from sklearn.ensemble import RandomForestRegressor # from sklearn.linear_model import LinearRegression -from sklearn.metrics import r2_score -from sklearn.model_selection import RepeatedKFold, cross_val_score from xgboost import XGBRegressor np.set_printoptions(precision=2) @@ -273,8 +287,6 @@ def fit_and_predict(model): print( "\n\nPredictions - Ground Truth (Kelvin): ", (test_predictions - y_test), "\n" ) - # print("\n\nModel Parameters:") - # pprint(model.get_params()) com_train_set = train_set com_test_set = test_set diff --git a/examples/00-fluent/ahmed_body_workflow.py b/examples/00-fluent/ahmed_body_workflow.py index a89aee4bfcfc..3ec6a9ba8ad2 100644 --- a/examples/00-fluent/ahmed_body_workflow.py +++ b/examples/00-fluent/ahmed_body_workflow.py @@ -1,3 +1,10 @@ +# /// script +# dependencies = [ +# "ansys-fluent-core", +# "ansys-fluent-visualization", +# ] +# /// + # Copyright (C) 2021 - 2026 ANSYS, Inc. and/or its affiliates. # SPDX-License-Identifier: MIT # @@ -302,8 +309,10 @@ "zones": ["wall_ahmed_body_main", "wall_ahmed_body_front", "wall_ahmed_body_rear"], "force_vector": [0, 0, 1], } -session.parameters.output_parameters.report_definitions.create(name="parameter-1") -session.parameters.output_parameters.report_definitions["parameter-1"] = { +session.settings.parameters.output_parameters.report_definitions.create( + name="parameter-1" +) +session.settings.parameters.output_parameters.report_definitions["parameter-1"] = { "report_definition": "cd-mon1" } @@ -322,9 +331,9 @@ ####################################################################################### # Post-Processing Workflow # ===================================================================================== -session.results.surfaces.iso_surface.create(name="xmid") -session.results.surfaces.iso_surface["xmid"].field = "x-coordinate" -session.results.surfaces.iso_surface["xmid"] = {"iso_values": [0]} +session.settings.results.surfaces.iso_surface.create(name="xmid") +session.settings.results.surfaces.iso_surface["xmid"].field = "x-coordinate" +session.settings.results.surfaces.iso_surface["xmid"] = {"iso_values": [0]} contour1 = Contour(solver=session, field="velocity-magnitude", surfaces=["xmid"]) disp1 = GraphicsWindow() diff --git a/examples/00-fluent/brake.py b/examples/00-fluent/brake.py index d46433812c10..3e09302017c5 100644 --- a/examples/00-fluent/brake.py +++ b/examples/00-fluent/brake.py @@ -1,3 +1,11 @@ +# /// script +# dependencies = [ +# "ansys-fluent-core", +# "ansys-fluent-visualization", +# "matplotlib", +# ] +# /// + # Copyright (C) 2021 - 2026 ANSYS, Inc. and/or its affiliates. # SPDX-License-Identifier: MIT # @@ -64,7 +72,7 @@ # Launch Fluent session with solver mode and print Fluent version # --------------------------------------------------------------- -session = pyfluent.launch_fluent(precision="double", processor_count=2, version="3d") +session = pyfluent.launch_fluent(precision="double", processor_count=2, dimension=3) print(session.get_fluent_version()) #################################################################################### diff --git a/examples/00-fluent/conjugate_heat_transfer.py b/examples/00-fluent/conjugate_heat_transfer.py index 3baca7bda8f9..3e216312e188 100644 --- a/examples/00-fluent/conjugate_heat_transfer.py +++ b/examples/00-fluent/conjugate_heat_transfer.py @@ -1,3 +1,12 @@ +# /// script +# dependencies = [ +# "ansys-fluent-core", +# "ansys-fluent-visualization", +# "matplotlib", +# "pyvista", +# ] +# /// + # Copyright (C) 2021 - 2026 ANSYS, Inc. and/or its affiliates. # SPDX-License-Identifier: MIT # @@ -86,7 +95,6 @@ meshing_session = pyfluent.launch_fluent( mode="meshing", - dimension=3, precision="double", processor_count=4, ) @@ -477,25 +485,19 @@ # Mesh Check; Review Fluent transcript for errors # =============================================== -solver_session.mesh.check() +solver_session.settings.mesh.check() ############################################################################# -# Create a few boundary list for display and post-processing -# ========================================================== +# Create boundary lists for display and post-processing +# ===================================================== mesh1 = Mesh(solver=solver_session) -wall_list = [] -periodic_list = [] -symmetry_list = [] - -for item in mesh1.surfaces.allowed_values: - if len(item.split("wall")) > 1: - wall_list.append(item) - if len(item.split("periodic")) > 1: - periodic_list.append(item) - if len(item.split("symmetry")) > 1: - symmetry_list.append(item) +wall_list = [ + boundary_name + for boundary_name in mesh1.surfaces.allowed_values + if "wall" in boundary_name +] ############################################################################# # Display Mesh @@ -521,66 +523,78 @@ # * Enable Energy Equation # * Enable Laminar Viscous Model -solver_session.setup.general.units.set_units( +solver_session.settings.setup.general.units.set_units( quantity="temperature", units_name="C", scale_factor=1.0, offset=273.15 ) -solver_session.setup.models.energy.enabled = True -solver_session.setup.models.viscous.model.set_state("laminar") +solver_session.settings.setup.models.energy.enabled = True +solver_session.settings.setup.models.viscous.model.set_state("laminar") ############################################################################# # Change a few material properties of default Air # =============================================== -air_dict = solver_session.setup.materials.fluid["air"].get_state() +air_dict = solver_session.settings.setup.materials.fluid["air"].get_state() air_dict["density"]["value"] = 1.2 air_dict["viscosity"]["value"] = 1.5e-5 air_dict["thermal_conductivity"]["value"] = 0.026 air_dict["specific_heat"]["value"] = 1006.0 -solver_session.setup.materials.fluid["air"].set_state(air_dict) +solver_session.settings.setup.materials.fluid["air"].set_state(air_dict) ############################################################################# # Change a few material properties of default Aluminum # ==================================================== -al_dict = solver_session.setup.materials.solid["aluminum"].get_state() +al_dict = solver_session.settings.setup.materials.solid["aluminum"].get_state() al_dict["density"]["value"] = 2719.0 al_dict["thermal_conductivity"]["value"] = 200.0 al_dict["specific_heat"]["value"] = 871.0 -solver_session.setup.materials.solid["aluminum"].set_state(al_dict) +solver_session.settings.setup.materials.solid["aluminum"].set_state(al_dict) ############################################################################# # Copy Copper and change a few material properties of default Copper # ================================================================== -solver_session.setup.materials.database.copy_by_name(type="solid", name="copper") -cu_dict = solver_session.setup.materials.solid["copper"].get_state() +solver_session.settings.setup.materials.database.copy_by_name( + type="solid", name="copper" +) +cu_dict = solver_session.settings.setup.materials.solid["copper"].get_state() cu_dict["density"]["value"] = 8978.0 cu_dict["thermal_conductivity"]["value"] = 340.0 cu_dict["specific_heat"]["value"] = 381.0 -solver_session.setup.materials.solid["copper"].set_state(cu_dict) +solver_session.settings.setup.materials.solid["copper"].set_state(cu_dict) ############################################################################# # Set Tube Cell Zone Material as Copper # ===================================== -tube_dict = solver_session.setup.cell_zone_conditions.solid["solid-tube-1"].get_state() +tube_dict = solver_session.settings.setup.cell_zone_conditions.solid[ + "solid-tube-1" +].get_state() tube_dict["material"] = "copper" -solver_session.setup.cell_zone_conditions.solid["solid-tube-1"].set_state(tube_dict) +solver_session.settings.setup.cell_zone_conditions.solid["solid-tube-1"].set_state( + tube_dict +) -tube_dict = solver_session.setup.cell_zone_conditions.solid["solid-tube-2"].get_state() +tube_dict = solver_session.settings.setup.cell_zone_conditions.solid[ + "solid-tube-2" +].get_state() tube_dict["material"] = "copper" -solver_session.setup.cell_zone_conditions.solid["solid-tube-2"].set_state(tube_dict) +solver_session.settings.setup.cell_zone_conditions.solid["solid-tube-2"].set_state( + tube_dict +) ############################################################################# # Set Boundary Condition for Inlet and Outlet # =========================================== -solver_session.setup.boundary_conditions.velocity_inlet["inlet"].momentum.velocity = 4.0 -solver_session.setup.boundary_conditions.velocity_inlet["inlet"].thermal.temperature = ( - 293.15 # Need to specify in Kelvin -) +solver_session.settings.setup.boundary_conditions.velocity_inlet[ + "inlet" +].momentum.velocity = 4.0 +solver_session.settings.setup.boundary_conditions.velocity_inlet[ + "inlet" +].thermal.temperature = 293.15 # Need to specify in Kelvin -solver_session.setup.boundary_conditions.pressure_outlet[ +solver_session.settings.setup.boundary_conditions.pressure_outlet[ "outlet" ].thermal.backflow_total_temperature = 293.15 @@ -588,17 +602,17 @@ # Set Thermal Boundary Condition for Wall Inner Tube # ================================================== -solver_session.setup.boundary_conditions.wall[ +solver_session.settings.setup.boundary_conditions.wall[ "wall-inner-tube-1" ].thermal.thermal_condition = "Convection" -solver_session.setup.boundary_conditions.wall[ +solver_session.settings.setup.boundary_conditions.wall[ "wall-inner-tube-1" ].thermal.heat_transfer_coeff = 1050.0 -solver_session.setup.boundary_conditions.wall[ +solver_session.settings.setup.boundary_conditions.wall[ "wall-inner-tube-1" ].thermal.free_stream_temp = 353.15 -solver_session.setup.boundary_conditions.copy( +solver_session.settings.setup.boundary_conditions.copy( from_="wall-inner-tube-1", to="wall-inner-tube-2" ) @@ -606,53 +620,55 @@ # Enable HOTR # =========== -solver_session.solution.methods.high_order_term_relaxation.enable = True +solver_session.settings.solution.methods.high_order_term_relaxation.enable = True ############################################################################# # Define Report Definitions # ========================= -solver_session.solution.report_definitions.surface["outlet-enthalpy-flow"] = {} -solver_session.solution.report_definitions.surface[ +solver_session.settings.solution.report_definitions.surface["outlet-enthalpy-flow"] = {} +solver_session.settings.solution.report_definitions.surface[ "outlet-enthalpy-flow" ].report_type = "surface-flowrate" -solver_session.solution.report_definitions.surface["outlet-enthalpy-flow"].field = ( - "enthalpy" -) -solver_session.solution.report_definitions.surface[ +solver_session.settings.solution.report_definitions.surface[ + "outlet-enthalpy-flow" +].field = "enthalpy" +solver_session.settings.solution.report_definitions.surface[ "outlet-enthalpy-flow" ].surface_names = ["outlet"] -solver_session.solution.report_definitions.surface["avg-pressure-inlet"] = {} -solver_session.solution.report_definitions.surface["avg-pressure-inlet"].report_type = ( - "surface-areaavg" -) -solver_session.solution.report_definitions.surface["avg-pressure-inlet"].field = ( - "pressure" -) -solver_session.solution.report_definitions.surface[ +solver_session.settings.solution.report_definitions.surface["avg-pressure-inlet"] = {} +solver_session.settings.solution.report_definitions.surface[ + "avg-pressure-inlet" +].report_type = "surface-areaavg" +solver_session.settings.solution.report_definitions.surface[ + "avg-pressure-inlet" +].field = "pressure" +solver_session.settings.solution.report_definitions.surface[ "avg-pressure-inlet" ].surface_names = ["inlet"] -solver_session.solution.report_definitions.volume["max-vel-louvers4"] = {} -solver_session.solution.report_definitions.volume["max-vel-louvers4"].report_type = ( - "volume-max" -) -solver_session.solution.report_definitions.volume["max-vel-louvers4"].field = ( +solver_session.settings.solution.report_definitions.volume["max-vel-louvers4"] = {} +solver_session.settings.solution.report_definitions.volume[ + "max-vel-louvers4" +].report_type = "volume-max" +solver_session.settings.solution.report_definitions.volume["max-vel-louvers4"].field = ( "velocity-magnitude" ) -solver_session.solution.report_definitions.volume["max-vel-louvers4"].cell_zones = [ - "fluid-tet-4" -] - -solver_session.solution.report_definitions.surface["wall-shear-int"] = {} -solver_session.solution.report_definitions.surface["wall-shear-int"].report_type = ( - "surface-integral" -) -solver_session.solution.report_definitions.surface["wall-shear-int"].field = ( +solver_session.settings.solution.report_definitions.volume[ + "max-vel-louvers4" +].cell_zones = ["fluid-tet-4"] + +solver_session.settings.solution.report_definitions.surface["wall-shear-int"] = {} +solver_session.settings.solution.report_definitions.surface[ + "wall-shear-int" +].report_type = "surface-integral" +solver_session.settings.solution.report_definitions.surface["wall-shear-int"].field = ( "wall-shear" ) -solver_session.solution.report_definitions.surface["wall-shear-int"].surface_names = [ +solver_session.settings.solution.report_definitions.surface[ + "wall-shear-int" +].surface_names = [ "wall-fluid-sweep-fin-solid-sweep-fin-shadow", "wall-fluid-tet-1-solid-tet-1", "wall-fluid-tet-2-solid-tet-2", @@ -660,46 +676,48 @@ "wall-fluid-tet-4-solid-tet-4", ] -solver_session.solution.monitor.report_plots.create(name="outlet-enthalpy-flow-plot") -solver_session.solution.monitor.report_plots[ +solver_session.settings.solution.monitor.report_plots.create( + name="outlet-enthalpy-flow-plot" +) +solver_session.settings.solution.monitor.report_plots[ "outlet-enthalpy-flow-plot" ].report_defs = "outlet-enthalpy-flow" -solver_session.solution.monitor.report_files["outlet-enthalpy-flow-file"] = {} -solver_session.solution.monitor.report_files["outlet-enthalpy-flow-file"] = { +solver_session.settings.solution.monitor.report_files["outlet-enthalpy-flow-file"] = {} +solver_session.settings.solution.monitor.report_files["outlet-enthalpy-flow-file"] = { "report_defs": ["outlet-enthalpy-flow"], "file_name": r"outlet-enthalpy-flow.out", } -solver_session.solution.monitor.report_plots["avg-pressure-inlet-plot"] = {} -solver_session.solution.monitor.report_plots["avg-pressure-inlet-plot"] = { +solver_session.settings.solution.monitor.report_plots["avg-pressure-inlet-plot"] = {} +solver_session.settings.solution.monitor.report_plots["avg-pressure-inlet-plot"] = { "report_defs": ["avg-pressure-inlet"] } -solver_session.solution.monitor.report_files["avg-pressure-inlet-file"] = {} -solver_session.solution.monitor.report_files["avg-pressure-inlet-file"] = { +solver_session.settings.solution.monitor.report_files["avg-pressure-inlet-file"] = {} +solver_session.settings.solution.monitor.report_files["avg-pressure-inlet-file"] = { "report_defs": ["avg-pressure-inlet"], "file_name": r"avg-pressure-inlet.out", } -solver_session.solution.monitor.report_plots["max-vel-louvers4-plot"] = {} -solver_session.solution.monitor.report_plots["max-vel-louvers4-plot"] = { +solver_session.settings.solution.monitor.report_plots["max-vel-louvers4-plot"] = {} +solver_session.settings.solution.monitor.report_plots["max-vel-louvers4-plot"] = { "report_defs": ["max-vel-louvers4"] } -solver_session.solution.monitor.report_files["max-vel-louvers4-file"] = {} -solver_session.solution.monitor.report_files["max-vel-louvers4-file"] = { +solver_session.settings.solution.monitor.report_files["max-vel-louvers4-file"] = {} +solver_session.settings.solution.monitor.report_files["max-vel-louvers4-file"] = { "report_defs": ["max-vel-louvers4"], "file_name": r"max-vel-louvers4.out", } -solver_session.solution.monitor.report_plots["wall-shear-int-plot"] = {} -solver_session.solution.monitor.report_plots["wall-shear-int-plot"] = { +solver_session.settings.solution.monitor.report_plots["wall-shear-int-plot"] = {} +solver_session.settings.solution.monitor.report_plots["wall-shear-int-plot"] = { "report_defs": ["wall-shear-int"] } -solver_session.solution.monitor.report_files["wall-shear-int-file"] = {} -solver_session.solution.monitor.report_files["wall-shear-int-file"] = { +solver_session.settings.solution.monitor.report_files["wall-shear-int-file"] = {} +solver_session.settings.solution.monitor.report_files["wall-shear-int-file"] = { "report_defs": ["wall-shear-int"], "file_name": r"wall-shear-int.out", } @@ -708,26 +726,26 @@ # Hybrid Initialization; Slit Interior between Solid Zones; Save Case # =================================================================== -solver_session.solution.initialization.initialization_type = "hybrid" -solver_session.solution.initialization.hybrid_initialize() +solver_session.settings.solution.initialization.initialization_type = "hybrid" +solver_session.settings.solution.initialization.hybrid_initialize() -solver_session.setup.boundary_conditions.slit_interior_between_diff_solids() -solver_session.file.write(file_type="case", file_name="hx-fin-2mm.cas.h5") +solver_session.settings.setup.boundary_conditions.slit_interior_between_diff_solids() +solver_session.settings.file.write(file_type="case", file_name="hx-fin-2mm.cas.h5") ############################################################################# # Set Aggressive Length Scale Method; Run Calculation & Save Data # =============================================================== -solver_session.solution.run_calculation.pseudo_time_settings.time_step_method.time_step_method = ( +solver_session.settings.solution.run_calculation.pseudo_time_settings.time_step_method.time_step_method = ( "automatic" ) -solver_session.solution.run_calculation.pseudo_time_settings.time_step_method.length_scale_methods = ( +solver_session.settings.solution.run_calculation.pseudo_time_settings.time_step_method.length_scale_methods = ( "aggressive" ) -solver_session.solution.run_calculation.iterate(iter_count=250) +solver_session.settings.solution.run_calculation.iterate(iter_count=250) -solver_session.file.write(file_type="case-data", file_name="hx-fin-2mm.dat.h5") +solver_session.settings.file.write(file_type="case-data", file_name="hx-fin-2mm.dat.h5") ############################################################################# # Post-Processing Mass Balance Report @@ -843,9 +861,13 @@ # Create Iso-Surface of X=0.012826 m # ================================== -solver_session.results.surfaces.iso_surface["x=0.012826"] = {} -solver_session.results.surfaces.iso_surface["x=0.012826"].field = "x-coordinate" -solver_session.results.surfaces.iso_surface["x=0.012826"] = {"iso_values": [0.012826]} +solver_session.settings.results.surfaces.iso_surface["x=0.012826"] = {} +solver_session.settings.results.surfaces.iso_surface["x=0.012826"].field = ( + "x-coordinate" +) +solver_session.settings.results.surfaces.iso_surface["x=0.012826"] = { + "iso_values": [0.012826] +} ############################################################################# # Vector Plot diff --git a/examples/00-fluent/exhaust_system_settings_api.py b/examples/00-fluent/exhaust_system_settings_api.py index a4a285f8c573..af5ff3a8eda8 100644 --- a/examples/00-fluent/exhaust_system_settings_api.py +++ b/examples/00-fluent/exhaust_system_settings_api.py @@ -1,3 +1,9 @@ +# /// script +# dependencies = [ +# "ansys-fluent-core", +# ] +# /// + # Copyright (C) 2021 - 2026 ANSYS, Inc. and/or its affiliates. # SPDX-License-Identifier: MIT # @@ -105,7 +111,6 @@ # Import the CAD geometry file (``exhaust_system.fmd``) and selectively manage some # parts. -meshing_session.upload(import_file_name) meshing_session.PartManagement.InputFileChanged( FilePath=import_file_name, IgnoreSolidNames=False, PartPerBody=False ) @@ -577,14 +582,14 @@ solver_session = meshing_session.switch_to_solver() -solver_session.mesh.check() +solver_session.settings.mesh.check() ############################################################################### # Select turbulence model # ~~~~~~~~~~~~~~~~~~~~~~~ # Select the kw sst turbulence model. -viscous = solver_session.setup.models.viscous +viscous = solver_session.settings.setup.models.viscous viscous.model = "k-omega" viscous.k_omega_model = "sst" @@ -595,7 +600,7 @@ # Set the velocity and turbulence boundary conditions for the first inlet # (``inlet-1``). -boundary_conditions = solver_session.setup.boundary_conditions +boundary_conditions = solver_session.settings.setup.boundary_conditions boundary_conditions.velocity_inlet["inlet-1"] = { "momentum": { @@ -623,13 +628,16 @@ # Set the boundary conditions at the outlet (``outlet-1``). boundary_conditions.pressure_outlet["outlet-1"].turbulence.turbulent_intensity = 0.05 +boundary_conditions.pressure_outlet[ + "outlet-1" +].turbulence.backflow_turbulent_intensity = 0.05 ############################################################################### # Initialize flow field # ~~~~~~~~~~~~~~~~~~~~~ # Initialize the flow field using hybrid initialization. -solver_session.solution.initialization.hybrid_initialize() +solver_session.settings.solution.initialization.hybrid_initialize() ############################################################################### # Start calculation @@ -641,13 +649,13 @@ # :width: 500pt # :align: center -solver_session.solution.run_calculation.iterate(iter_count=100) +solver_session.settings.solution.run_calculation.iterate(iter_count=100) ############################################################################### # Write the case and data files # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -solver_session.file.write( +solver_session.settings.file.write( file_type="case-data", file_name="exhaust_system.cas.h5", ) @@ -659,7 +667,7 @@ # picture files. Edit the picture settings to use a custom resolution so that # the images are large enough. -graphics = solver_session.results.graphics +graphics = solver_session.settings.results.graphics # use_window_resolution option not active inside containers or Ansys Lab environment if graphics.picture.use_window_resolution.is_active(): graphics.picture.use_window_resolution = False @@ -697,7 +705,7 @@ # ~~~~~~~~~~~~~~~~~~ # Create an iso-surface through the manifold geometry. -solver_session.results.surfaces.iso_surface["surf-x-coordinate"] = { +solver_session.settings.results.surfaces.iso_surface["surf-x-coordinate"] = { "field": "x-coordinate", "zones": ["fluid-region-1"], "iso_values": [0.38], @@ -745,15 +753,15 @@ # :width: 500pt # :align: center -solver_session.results.scene["scene-1"] = {} -scene1 = solver_session.results.scene["scene-1"] +solver_session.settings.results.scene["scene-1"] = {} +scene1 = solver_session.settings.results.scene["scene-1"] scene1.graphics_objects.add(name="mesh-1") scene1.graphics_objects["mesh-1"].transparency = 90 scene1.graphics_objects.add(name="contour-velocity") scene1.display() -graphics.views.camera.position(xyz=[1.70, 1.14, 0.29]) -graphics.views.camera.up_vector(xyz=[-0.66, 0.72, -0.20]) +graphics.views.camera.position = [1.70, 1.14, 0.29] +graphics.views.camera.up_vector = [-0.66, 0.72, -0.20] graphics.picture.save_picture(file_name="scene-1.png") ######################################################################### diff --git a/examples/00-fluent/external_compressible_flow.py b/examples/00-fluent/external_compressible_flow.py index fd969c195137..4cb142e3b88a 100644 --- a/examples/00-fluent/external_compressible_flow.py +++ b/examples/00-fluent/external_compressible_flow.py @@ -1,3 +1,9 @@ +# /// script +# dependencies = [ +# "ansys-fluent-core", +# ] +# /// + # Copyright (C) 2021 - 2026 ANSYS, Inc. and/or its affiliates. # SPDX-License-Identifier: MIT # @@ -117,7 +123,6 @@ } ) -meshing_session.upload(wing_intermediary_file) geo_import.Execute() ############################################################################### @@ -264,7 +269,7 @@ # reports a number of other mesh features that are checked. Any errors in the # mesh are reported. -solver_session.mesh.check() +solver_session.settings.mesh.check() ############################################################################### # Define model @@ -274,7 +279,7 @@ # model : k-omega # k-omega model : sst -viscous = solver_session.setup.models.viscous +viscous = solver_session.settings.setup.models.viscous viscous.model = "k-omega" viscous.k_omega_model = "sst" @@ -291,7 +296,7 @@ # reference temperature : 273.11 [K] # effective temperature : 110.56 [K] -air = solver_session.setup.materials.fluid["air"] +air = solver_session.settings.setup.materials.fluid["air"] air.density.option = "ideal-gas" @@ -318,9 +323,11 @@ # turbulent intensity : 5 [%] # turbulent viscosity ratio : 10 -pressure_farfield = solver_session.setup.boundary_conditions.pressure_far_field[ - "pressure_farfield" -] +pressure_farfield = ( + solver_session.settings.setup.boundary_conditions.pressure_far_field[ + "pressure_farfield" + ] +) pressure_farfield.momentum.gauge_pressure = 0 @@ -343,35 +350,39 @@ # operating pressure : 80600 [Pa] -solver_session.setup.general.operating_conditions.operating_pressure = 80600 +solver_session.settings.setup.general.operating_conditions.operating_pressure = 80600 ############################################################################### # Initialize flow field # ~~~~~~~~~~~~~~~~~~~~~ # Initialize the flow field using hybrid initialization. -solver_session.solution.initialization.hybrid_initialize() +solver_session.settings.solution.initialization.hybrid_initialize() ############################################################################### # Save case file # ~~~~~~~~~~~~~~ # Save the case file ``external_compressible1.cas.h5``. -solver_session.file.write(file_name="external_compressible.cas.h5", file_type="case") +solver_session.settings.file.write( + file_name="external_compressible.cas.h5", file_type="case" +) ############################################################################### # Solve for 25 iterations # ~~~~~~~~~~~~~~~~~~~~~~~~ # Solve for 25 iterations (100 iterations is recommended, however for this example 25 is sufficient). -solver_session.solution.run_calculation.iterate(iter_count=25) +solver_session.settings.solution.run_calculation.iterate(iter_count=25) ############################################################################### # Write final case file and data # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Write the final case file and the data. -solver_session.file.write(file_name="external_compressible1.cas.h5", file_type="case") +solver_session.settings.file.write( + file_name="external_compressible1.cas.h5", file_type="case" +) ############################################################################### # Close Fluent diff --git a/examples/00-fluent/frozen_rotor_workflow.py b/examples/00-fluent/frozen_rotor_workflow.py index 7d744cddff2b..a789437dc281 100644 --- a/examples/00-fluent/frozen_rotor_workflow.py +++ b/examples/00-fluent/frozen_rotor_workflow.py @@ -1,3 +1,9 @@ +# /// script +# dependencies = [ +# "ansys-fluent-core", +# ] +# /// + # Copyright (C) 2021 - 2026 ANSYS, Inc. and/or its affiliates. # SPDX-License-Identifier: MIT # @@ -50,9 +56,9 @@ ################################################################################################################ # Outline # ============================================================================================================== - +# # The example demonstrates the following: - +# # *Overview & Problem description # *Launching Fluent in solver mode. # *Downloading a mesh files from the examples repository. @@ -70,7 +76,6 @@ # *Saving the case file # *Closing the solver - ################################################################################################################ # Import required libraries/modules # ============================================================================================================== diff --git a/examples/00-fluent/lunar_lander_thermal.py b/examples/00-fluent/lunar_lander_thermal.py index 8d42bfd76684..ee93a571f902 100644 --- a/examples/00-fluent/lunar_lander_thermal.py +++ b/examples/00-fluent/lunar_lander_thermal.py @@ -1,3 +1,12 @@ +# /// script +# dependencies = [ +# "ansys-fluent-core", +# "matplotlib", +# "numpy", +# "pandas", +# ] +# /// + # Copyright (C) 2021 - 2026 ANSYS, Inc. and/or its affiliates. # SPDX-License-Identifier: MIT # @@ -265,7 +274,7 @@ def get_surf_mean_temp( # Load the mesh # ~~~~~~~~~~~~~ -solver_session.file.read_mesh(file_name=lander_mesh_file) +solver_session.settings.file.read_mesh(file_name=lander_mesh_file) ############################################################################### # Case Setup @@ -280,10 +289,10 @@ def get_surf_mean_temp( # 1. # Set solution to transient -solver_session.setup.general.solver.time = "unsteady-2nd-order" +solver_session.settings.setup.general.solver.time = "unsteady-2nd-order" # Set transient settings -trans_controls = solver_session.solution.run_calculation.transient_controls +trans_controls = solver_session.settings.solution.run_calculation.transient_controls trans_controls.type = "Fixed" trans_controls.max_iter_per_time_step = 20 trans_controls.time_step_count = 1 @@ -295,7 +304,7 @@ def get_surf_mean_temp( # Enable the energy model. Since fluid flow is not simulated, we will set the # viscosity model to laminar. -models = solver_session.setup.models +models = solver_session.settings.setup.models models.energy.enabled = True models.viscous.model = "laminar" @@ -345,7 +354,7 @@ def get_surf_mean_temp( # --- Properties of vacuum --- # Thermal conductivity: 0 -vacuum = solver_session.setup.materials.solid.create("vacuum") +vacuum = solver_session.settings.setup.materials.solid.create("vacuum") vacuum.chemical_formula = "" vacuum.thermal_conductivity.value = 0 vacuum.absorption_coefficient.value = 0 @@ -356,7 +365,7 @@ def get_surf_mean_temp( # Specific heat capacity: 1050 [J kg^-1 K^-1] # Thermal conductivity: 9.22e-4*(1 + 1.48*(temperature/350 K)^3) [W m^-1 K^-1] -fluff = solver_session.setup.materials.solid.create("fluff") +fluff = solver_session.settings.setup.materials.solid.create("fluff") fluff.chemical_formula = "" fluff.density.value = 1000 fluff.specific_heat.value = 1050 @@ -370,7 +379,7 @@ def get_surf_mean_temp( # Specific heat capacity: 1050 [J kg^-1 K^-1] # Thermal conductivity: 9.30e-4*(1 + 0.73*(temperature/350 K)^3) [W m^-1 K^-1] -regolith = solver_session.setup.materials.solid.create("regolith") +regolith = solver_session.settings.setup.materials.solid.create("regolith") regolith.chemical_formula = "" regolith.density.value = 2000 regolith.specific_heat.value = 1050 @@ -387,7 +396,7 @@ def get_surf_mean_temp( # lander. This cell zone must be set to be a solid so that the fluid equations # are not solved there, then it must be assigned to the vacuum material. -cellzones = solver_session.setup.cell_zone_conditions +cellzones = solver_session.settings.setup.cell_zone_conditions cellzones.set_zone_type( zone_list=["geom-2_domain"], new_type="solid", @@ -408,7 +417,7 @@ def get_surf_mean_temp( # Surface absorptivity: 0.87 # Surface emissivity: 0.97 -regolith_bc = solver_session.setup.boundary_conditions.wall["regolith"] +regolith_bc = solver_session.settings.setup.boundary_conditions.wall["regolith"] regolith_bc.thermal.q.value = 0.031 regolith_bc.thermal.planar_conduction = True @@ -448,7 +457,7 @@ def get_surf_mean_temp( # Absorptivity: 1 # Solar flux: 1414 [W m^-2] -space_bc = solver_session.setup.boundary_conditions.wall["space"] +space_bc = solver_session.settings.setup.boundary_conditions.wall["space"] space_bc.thermal.thermal_bc = "Temperature" space_bc.thermal.t.value = 3 @@ -473,7 +482,7 @@ def get_surf_mean_temp( # Absorptivity: 0.05 # Emissivity: 0.05 -sc_mli_bc = solver_session.setup.boundary_conditions.wall["sc-mli"] +sc_mli_bc = solver_session.settings.setup.boundary_conditions.wall["sc-mli"] sc_mli_bc.thermal.planar_conduction = True sc_mli_bc.thermal.shell_conduction = [ @@ -497,7 +506,7 @@ def get_surf_mean_temp( # Absorptivity: 0.17 # Emissivity: 0.09 below 273 K, 0.70 otherwise -sc_rad_bc = solver_session.setup.boundary_conditions.wall["sc-radiator"] +sc_rad_bc = solver_session.settings.setup.boundary_conditions.wall["sc-radiator"] sc_rad_bc.thermal.planar_conduction = True sc_rad_bc.thermal.shell_conduction = [ @@ -516,7 +525,7 @@ def get_surf_mean_temp( # definitions on them in the next step. The entire domain will be initialized # to a temperature of 230 K, or -43 °C. -sim_init = solver_session.solution.initialization +sim_init = solver_session.settings.solution.initialization sim_init.defaults["temperature"] = 230 sim_init.initialize() @@ -525,7 +534,7 @@ def get_surf_mean_temp( # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Create reports for the spacecraft's minimum, mean, and maximum temperatures. -surf_report_defs = solver_session.solution.report_definitions.surface +surf_report_defs = solver_session.settings.solution.report_definitions.surface sc_surfs = ["sc-radiator", "sc-mli"] @@ -551,7 +560,7 @@ def get_surf_mean_temp( # Create reports for the mean temperatures of each regolith layer. We will # store the report names for use later. -surf_report_defs = solver_session.solution.report_definitions.surface +surf_report_defs = solver_session.settings.solution.report_definitions.surface # Loop over all regolith reports to set common properties regolith_report_names = [] @@ -574,7 +583,7 @@ def get_surf_mean_temp( # ~~~~~~~~~~~~~~~~~~~~~~~~ # Create temperature report files for post-processing. -surf_report_files = solver_session.solution.monitor.report_files +surf_report_files = solver_session.settings.solution.monitor.report_files # Spacecraft temperatures surf_report_files["sc-temps-rfile"] = { @@ -591,7 +600,7 @@ def get_surf_mean_temp( # ~~~~~~~~ # Set the case to save only the data file at each timestep for post-processing. -autosave = solver_session.file.auto_save +autosave = solver_session.settings.file.auto_save autosave.case_frequency = "if-mesh-is-modified" autosave.data_frequency = 1 @@ -604,7 +613,7 @@ def get_surf_mean_temp( # Turn off the convergence criteria pertaining to fluid flow as there is no # fluid flow in this simulation. Keep only the energy convergence criterion. -residuals = solver_session.solution.monitor.residual.equations +residuals = solver_session.settings.solution.monitor.residual.equations for criterion in ["continuity", "x-velocity", "y-velocity", "z-velocity"]: residuals[criterion].check_convergence = False @@ -615,8 +624,8 @@ def get_surf_mean_temp( # ~~~~~~~~~~~~~~~ # Write the case file. Enable overwrite. -solver_session.file.batch_options.confirm_overwrite = True -solver_session.file.write( +solver_session.settings.file.batch_options.confirm_overwrite = True +solver_session.settings.file.write( file_name="lunar_lander_thermal.cas.h5", file_type="case", ) @@ -650,7 +659,7 @@ def get_surf_mean_temp( ) # Set beam direction - solver_session.setup.boundary_conditions.wall[ + solver_session.settings.setup.boundary_conditions.wall[ "space" ].radiation.direct_irradiation_settings.beam_direction = [ beam_x, @@ -665,7 +674,7 @@ def get_surf_mean_temp( ) # Simulate closing louvers below 273 K by changing emissivity - radiation_emission = solver_session.setup.boundary_conditions.wall[ + radiation_emission = solver_session.settings.setup.boundary_conditions.wall[ "sc-radiator" ].radiation.internal_emissivity_band["thermal-ir"] if rad_mean_temp < 273: @@ -674,7 +683,7 @@ def get_surf_mean_temp( radiation_emission.value = 0.70 # Run simulation for 1 timestep - solver_session.solution.run_calculation.calculate() + solver_session.settings.solution.run_calculation.calculate() ############################################################################### # Close Fluent @@ -783,7 +792,7 @@ def clean_col_names(df): regolith_df.plot( x="flow-time", - y=[f"regolith-layer-{i+1}-temp" for i in range(5)], + y=[f"regolith-layer-{i + 1}-temp" for i in range(5)], title="Regolith temperatures", ax=ax1, ) diff --git a/examples/00-fluent/mixing_elbow_settings_api.py b/examples/00-fluent/mixing_elbow_settings_api.py index 70b744ab4028..e29acaa5ac22 100644 --- a/examples/00-fluent/mixing_elbow_settings_api.py +++ b/examples/00-fluent/mixing_elbow_settings_api.py @@ -1,3 +1,9 @@ +# /// script +# dependencies = [ +# "ansys-fluent-core", +# ] +# /// + # Copyright (C) 2021 - 2026 ANSYS, Inc. and/or its affiliates. # SPDX-License-Identifier: MIT # @@ -81,22 +87,24 @@ # in the mesh are reported. Ensure that the minimum volume is not negative because # Fluent cannot begin a calculation when this is the case. -solver_session.file.read_case(file_name=import_file_name) -solver_session.mesh.check() +solver_session.settings.file.read_case(file_name=import_file_name) +solver_session.settings.mesh.check() ############################################################################### # Enable heat transfer # ~~~~~~~~~~~~~~~~~~~~ # Enable heat transfer by activating the energy equation. -solver_session.setup.models.energy.enabled = True +solver_session.settings.setup.models.energy.enabled = True ############################################################################### # Create material # ~~~~~~~~~~~~~~~ # Create a material named ``"water-liquid"``. -solver_session.setup.materials.database.copy_by_name(type="fluid", name="water-liquid") +solver_session.settings.setup.materials.database.copy_by_name( + type="fluid", name="water-liquid" +) ############################################################################### # Set up cell zone conditions @@ -104,9 +112,9 @@ # Set up the cell zone conditions for the fluid zone (``elbow-fluid``). Set ``material`` # to ``"water-liquid"``. -solver_session.setup.cell_zone_conditions.fluid["elbow-fluid"].general.material = ( - "water-liquid" -) +solver_session.settings.setup.cell_zone_conditions.fluid[ + "elbow-fluid" +].general.material = "water-liquid" ############################################################################### # Set up boundary conditions for CFD analysis @@ -121,7 +129,9 @@ # Turbulent Intensity: 5 [%] # Hydraulic Diameter: 4 [inch] # Temperature: 293.15 [K] -cold_inlet = solver_session.setup.boundary_conditions.velocity_inlet["cold-inlet"] +cold_inlet = solver_session.settings.setup.boundary_conditions.velocity_inlet[ + "cold-inlet" +] cold_inlet.momentum.velocity_magnitude.value = 0.4 cold_inlet.turbulence.turbulence_specification = "Intensity and Hydraulic Diameter" @@ -136,7 +146,9 @@ # Turbulent Intensity: 5 [%] # Hydraulic Diameter: 1 [inch] # Temperature: 313.15 [K] -hot_inlet = solver_session.setup.boundary_conditions.velocity_inlet["hot-inlet"] +hot_inlet = solver_session.settings.setup.boundary_conditions.velocity_inlet[ + "hot-inlet" +] hot_inlet.momentum.velocity_magnitude.value = 1.2 hot_inlet.turbulence.turbulence_specification = "Intensity and Hydraulic Diameter" @@ -147,23 +159,26 @@ # Backflow Turbulent Intensity: 5 [%] # Backflow Turbulent Viscosity Ratio: 4 -solver_session.setup.boundary_conditions.pressure_outlet[ +solver_session.settings.setup.boundary_conditions.pressure_outlet[ "outlet" ].turbulence.turbulent_viscosity_ratio = 4 +solver_session.settings.setup.boundary_conditions.pressure_outlet[ + "outlet" +].turbulence.backflow_turbulent_intensity = 0.05 ############################################################################### # Initialize flow field # ~~~~~~~~~~~~~~~~~~~~~ # Initialize the flow field using hybrid initialization. -solver_session.solution.initialization.hybrid_initialize() +solver_session.settings.solution.initialization.hybrid_initialize() ############################################################################### # Solve for 150 iterations # ~~~~~~~~~~~~~~~~~~~~~~~~ # Solve for 150 iterations. -solver_session.solution.run_calculation.iterate(iter_count=150) +solver_session.settings.solution.run_calculation.iterate(iter_count=150) ############################################################################### # Configure graphics picture export @@ -172,7 +187,7 @@ # picture files. Edit the picture settings to use a custom resolution so that # the images are large enough. -graphics = solver_session.results.graphics +graphics = solver_session.settings.results.graphics # use_window_resolution option not active inside containers or Ansys Lab environment if graphics.picture.use_window_resolution.is_active(): graphics.picture.use_window_resolution = False @@ -186,10 +201,12 @@ # Create and display velocity vectors on the ``symmetry-xyplane`` plane, then # export the image for inspection. -graphics = solver_session.results.graphics +graphics = solver_session.settings.results.graphics graphics.vector["velocity_vector_symmetry"] = {} -velocity_symmetry = solver_session.results.graphics.vector["velocity_vector_symmetry"] +velocity_symmetry = solver_session.settings.results.graphics.vector[ + "velocity_vector_symmetry" +] velocity_symmetry.print_state() velocity_symmetry.field = "velocity-magnitude" velocity_symmetry.surfaces_list = [ @@ -212,9 +229,11 @@ # Compute mass flow rate # ~~~~~~~~~~~~~~~~~~~~~~ # Compute the mass flow rate. -solver_session.solution.report_definitions.flux["mass_flow_rate"] = {} +solver_session.settings.solution.report_definitions.flux["mass_flow_rate"] = {} -mass_flow_rate = solver_session.solution.report_definitions.flux["mass_flow_rate"] +mass_flow_rate = solver_session.settings.solution.report_definitions.flux[ + "mass_flow_rate" +] mass_flow_rate.boundaries.allowed_values() mass_flow_rate.boundaries = [ "cold-inlet", @@ -222,7 +241,9 @@ "outlet", ] mass_flow_rate.print_state() -solver_session.solution.report_definitions.compute(report_defs=["mass_flow_rate"]) +solver_session.settings.solution.report_definitions.compute( + report_defs=["mass_flow_rate"] +) ######################################################################### # Close Fluent diff --git a/examples/00-fluent/mixing_tank_workflow.py b/examples/00-fluent/mixing_tank_workflow.py index dc08338e61db..7bf69dcc5185 100644 --- a/examples/00-fluent/mixing_tank_workflow.py +++ b/examples/00-fluent/mixing_tank_workflow.py @@ -1,3 +1,9 @@ +# /// script +# dependencies = [ +# "ansys-fluent-core", +# ] +# /// + # Copyright (C) 2021 - 2026 ANSYS, Inc. and/or its affiliates. # SPDX-License-Identifier: MIT # @@ -264,7 +270,7 @@ liquid_level_bc.momentum.shear_condition = "Specified Shear" # Change the Zone type for internal walls to interior -solver_session.setup.boundary_conditions.set_zone_type( +solver_session.settings.setup.boundary_conditions.set_zone_type( zone_list=["fluid_mrf_1-fluid_tank"], new_type="interior" ) diff --git a/examples/00-fluent/modeling_ablation.py b/examples/00-fluent/modeling_ablation.py index 960c8742846a..2ea3c8d213f6 100644 --- a/examples/00-fluent/modeling_ablation.py +++ b/examples/00-fluent/modeling_ablation.py @@ -1,3 +1,10 @@ +# /// script +# dependencies = [ +# "ansys-fluent-core", +# "ansys-fluent-visualization", +# ] +# /// + # Copyright (C) 2021 - 2026 ANSYS, Inc. and/or its affiliates. # SPDX-License-Identifier: MIT # @@ -98,7 +105,6 @@ # ================================================================================== solver_session = pyfluent.launch_fluent( - dimension=3, precision="double", processor_count=4, ) @@ -108,52 +114,54 @@ # Import mesh # ================================================================================== -solver_session.file.read_case(file_name=import_filename) +solver_session.settings.file.read_case(file_name=import_filename) #################################################################################### # Define models # ================================================================================== -solver_session.setup.general.solver.type = "density-based-implicit" -solver_session.setup.general.solver.time = "unsteady-1st-order" -solver_session.setup.general.operating_conditions.operating_pressure = 0.0 -solver_session.setup.models.energy = {"enabled": True} -solver_session.setup.models.ablation = {"enabled": True} +solver_session.settings.setup.general.solver.type = "density-based-implicit" +solver_session.settings.setup.general.solver.time = "unsteady-1st-order" +solver_session.settings.setup.general.operating_conditions.operating_pressure = 0.0 +solver_session.settings.setup.models.energy = {"enabled": True} +solver_session.settings.setup.models.ablation = {"enabled": True} ################################################################### # Define material # ================================================================= -solver_session.setup.materials.fluid["air"] = { +solver_session.settings.setup.materials.fluid["air"] = { "density": {"option": "ideal-gas"}, "molecular_weight": {"value": 28.966, "option": "constant"}, } -solver_session.setup.materials.fluid["air"] = {"density": {"option": "ideal-gas"}} +solver_session.settings.setup.materials.fluid["air"] = { + "density": {"option": "ideal-gas"} +} ############################ # Define boundary conditions # ========================== -solver_session.setup.boundary_conditions.set_zone_type( +solver_session.settings.setup.boundary_conditions.set_zone_type( zone_list=["inlet"], new_type="pressure-far-field" ) -solver_session.setup.boundary_conditions.pressure_far_field[ +solver_session.settings.setup.boundary_conditions.pressure_far_field[ "inlet" ].momentum.gauge_pressure = 13500 -solver_session.setup.boundary_conditions.pressure_far_field[ +solver_session.settings.setup.boundary_conditions.pressure_far_field[ "inlet" ].momentum.mach_number = 3 -solver_session.setup.boundary_conditions.pressure_far_field[ +solver_session.settings.setup.boundary_conditions.pressure_far_field[ "inlet" ].thermal.temperature = 4500 -solver_session.setup.boundary_conditions.pressure_far_field[ +solver_session.settings.setup.boundary_conditions.pressure_far_field[ "inlet" ].turbulence.turbulent_intensity = 0.001 -solver_session.setup.boundary_conditions.pressure_outlet[ +solver_session.settings.setup.boundary_conditions.pressure_outlet[ "outlet" ].momentum.gauge_pressure = 13500 -solver_session.setup.boundary_conditions.pressure_outlet[ +solver_session.settings.setup.boundary_conditions.pressure_outlet[ "outlet" ].momentum.prevent_reverse_flow = True @@ -165,13 +173,13 @@ # Remeshing options, #creates the wall-ablation dynamic mesh zone, and configure # appropriate dynamic mesh settings. -solver_session.setup.boundary_conditions.wall[ +solver_session.settings.setup.boundary_conditions.wall[ "wall_ablation" ].ablation.ablation_select_model = "Vielle's Model" -solver_session.setup.boundary_conditions.wall[ +solver_session.settings.setup.boundary_conditions.wall[ "wall_ablation" ].ablation.ablation_vielle_a = 5 -solver_session.setup.boundary_conditions.wall[ +solver_session.settings.setup.boundary_conditions.wall[ "wall_ablation" ].ablation.ablation_vielle_n = 0.1 @@ -278,9 +286,11 @@ # Define solver settings # ======================= -solver_session.setup.general.solver.time = "unsteady-2nd-order" -solver_session.solution.controls.limits = {"max_temperature": 25000} -solver_session.solution.monitor.residual.equations["energy"].absolute_criteria = 1e-06 +solver_session.settings.setup.general.solver.time = "unsteady-2nd-order" +solver_session.settings.solution.controls.limits = {"max_temperature": 25000} +solver_session.settings.solution.monitor.residual.equations[ + "energy" +].absolute_criteria = 1e-06 ############################################ # Create report definitions @@ -350,21 +360,23 @@ # Initialize and Save case # ======================== -solver_session.solution.initialization.compute_defaults( +solver_session.settings.solution.initialization.compute_defaults( from_zone_type="pressure-far-field", from_zone_name="inlet", phase="mixture" ) -solver_session.solution.initialization.initialization_type = "standard" -solver_session.solution.initialization.standard_initialize() -solver_session.solution.run_calculation.transient_controls.time_step_size = 1e-06 +solver_session.settings.solution.initialization.initialization_type = "standard" +solver_session.settings.solution.initialization.standard_initialize() +solver_session.settings.solution.run_calculation.transient_controls.time_step_size = ( + 1e-06 +) -solver_session.file.write(file_type="case", file_name="ablation.cas.h5") +solver_session.settings.file.write(file_type="case", file_name="ablation.cas.h5") ############################################ # Run the calculation # =================== # Note: It may take about half an hour to finish the calculation. -solver_session.solution.run_calculation.dual_time_iterate( +solver_session.settings.solution.run_calculation.dual_time_iterate( time_step_count=100, max_iter_per_step=20 ) @@ -372,7 +384,9 @@ # Save simulation data # ==================== # Write case and data files -solver_session.file.write(file_type="case-data", file_name="ablation_Solved.cas.h5") +solver_session.settings.file.write( + file_type="case-data", file_name="ablation_Solved.cas.h5" +) #################################################################################### # Post Processing @@ -419,22 +433,22 @@ # ================ # Following contours are displayed in the Fluent GUI: -solver_session.results.surfaces.plane_surface.create(name="mid_plane") -solver_session.results.surfaces.plane_surface["mid_plane"].method = "zx-plane" +solver_session.settings.results.surfaces.plane_surface.create(name="mid_plane") +solver_session.settings.results.surfaces.plane_surface["mid_plane"].method = "zx-plane" -solver_session.results.graphics.contour.create(name="contour_pressure") -solver_session.results.graphics.contour["contour_pressure"] = { +solver_session.settings.results.graphics.contour.create(name="contour_pressure") +solver_session.settings.results.graphics.contour["contour_pressure"] = { "field": "pressure", "surfaces_list": ["mid_plane"], } -solver_session.results.graphics.contour.display(object_name="contour_pressure") +solver_session.settings.results.graphics.contour.display(object_name="contour_pressure") -solver_session.results.graphics.contour.create(name="contour_mach") -solver_session.results.graphics.contour["contour_mach"] = { +solver_session.settings.results.graphics.contour.create(name="contour_mach") +solver_session.settings.results.graphics.contour["contour_mach"] = { "field": "mach-number", "surfaces_list": ["mid_plane"], } -solver_session.results.graphics.contour.display(object_name="contour_mach") +solver_session.settings.results.graphics.contour.display(object_name="contour_mach") ############################################### # Post processing with PyVista (3D visualization) diff --git a/examples/00-fluent/modeling_cavitation.py b/examples/00-fluent/modeling_cavitation.py index 62d6151d9e58..19f2dfea8025 100644 --- a/examples/00-fluent/modeling_cavitation.py +++ b/examples/00-fluent/modeling_cavitation.py @@ -1,3 +1,9 @@ +# /// script +# dependencies = [ +# "ansys-fluent-core", +# ] +# /// + # Copyright (C) 2021 - 2026 ANSYS, Inc. and/or its affiliates. # SPDX-License-Identifier: MIT # diff --git a/examples/00-fluent/parametric_static_mixer_1.py b/examples/00-fluent/parametric_static_mixer_1.py index 1d2b5d5e9106..586e6b3d92e9 100644 --- a/examples/00-fluent/parametric_static_mixer_1.py +++ b/examples/00-fluent/parametric_static_mixer_1.py @@ -1,3 +1,9 @@ +# /// script +# dependencies = [ +# "ansys-fluent-core", +# ] +# /// + # Copyright (C) 2021 - 2026 ANSYS, Inc. and/or its affiliates. # SPDX-License-Identifier: MIT # diff --git a/examples/00-fluent/radiation_headlamp.py b/examples/00-fluent/radiation_headlamp.py index ee936ed0adf2..7f21b538b36c 100644 --- a/examples/00-fluent/radiation_headlamp.py +++ b/examples/00-fluent/radiation_headlamp.py @@ -1,3 +1,9 @@ +# /// script +# dependencies = [ +# "ansys-fluent-core", +# ] +# /// + # Copyright (C) 2021 - 2026 ANSYS, Inc. and/or its affiliates. # SPDX-License-Identifier: MIT # @@ -484,7 +490,7 @@ # ~~~~~~~~~~~~~~~~~~~~~~~~ # Enable residual plots and set the convergence criteria to 'none'. -solver_session.solution.monitor.residual.options.criterion_type = "none" +solver_session.settings.solution.monitor.residual.options.criterion_type = "none" ########################################################################################################### # Define surface reports diff --git a/examples/00-fluent/single_battery_cell_workflow.py b/examples/00-fluent/single_battery_cell_workflow.py index 8fe4c89f2f11..6ec14aec460e 100644 --- a/examples/00-fluent/single_battery_cell_workflow.py +++ b/examples/00-fluent/single_battery_cell_workflow.py @@ -1,3 +1,9 @@ +# /// script +# dependencies = [ +# "ansys-fluent-core", +# ] +# /// + # Copyright (C) 2021 - 2026 ANSYS, Inc. and/or its affiliates. # SPDX-License-Identifier: MIT # diff --git a/examples/00-fluent/species_transport.py b/examples/00-fluent/species_transport.py index d35fd38c1e99..15633ecf5239 100644 --- a/examples/00-fluent/species_transport.py +++ b/examples/00-fluent/species_transport.py @@ -1,3 +1,9 @@ +# /// script +# dependencies = [ +# "ansys-fluent-core", +# ] +# /// + # Copyright (C) 2021 - 2026 ANSYS, Inc. and/or its affiliates. # SPDX-License-Identifier: MIT # diff --git a/examples/00-fluent/steady_vortex.py b/examples/00-fluent/steady_vortex.py index 831b9267b3ad..2f88d31ebaad 100644 --- a/examples/00-fluent/steady_vortex.py +++ b/examples/00-fluent/steady_vortex.py @@ -1,3 +1,10 @@ +# /// script +# dependencies = [ +# "imageio", +# "ansys-fluent-core", +# ] +# /// + # Copyright (C) 2021 - 2026 ANSYS, Inc. and/or its affiliates. # SPDX-License-Identifier: MIT # diff --git a/examples/00-fluent/tyler_sofrin_modes.py b/examples/00-fluent/tyler_sofrin_modes.py index bb4c63f9d41e..72cc4ca62fae 100644 --- a/examples/00-fluent/tyler_sofrin_modes.py +++ b/examples/00-fluent/tyler_sofrin_modes.py @@ -1,3 +1,11 @@ +# /// script +# dependencies = [ +# "matplotlib", +# "numpy", +# "ansys-fluent-core", +# ] +# /// + # Copyright (C) 2021 - 2026 ANSYS, Inc. and/or its affiliates. # SPDX-License-Identifier: MIT # @@ -101,10 +109,10 @@ # Post-Processing Implementation # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ####################################################################################### # Import required libraries/modules # ===================================================================================== +import csv import math import os from pathlib import Path @@ -146,7 +154,7 @@ # .. note:: # The dat file should correspond to the already completed DFT simulation. -session.file.read(file_type="case-data", file_name=import_filename) +session.settings.file.read(file_type="case-data", file_name=import_filename) ####################################################################################### # Define User constant/variables @@ -181,8 +189,8 @@ x = math.cos(math.radians(angle)) * r y = math.sin(math.radians(angle)) * r pt_name = "point-" + str(angle) - session.results.surfaces.point_surface[pt_name] = {} - session.results.surfaces.point_surface[pt_name].point = [x, y, z] + session.settings.results.surfaces.point_surface[pt_name] = {} + session.settings.results.surfaces.point_surface[pt_name].point = [x, y, z] ####################################################################################### # Compute Fourier coefficients at each monitor point (An, Bn) @@ -192,34 +200,34 @@ for angle_ind, angle in enumerate(range(0, 360, d_theta)): for n_ind, variable in enumerate(varname): - if len(variable) >= 4 and variable[:4] == "mean": - session.solution.report_definitions.surface["mag-report"] = { + if variable.startswith("mean"): + session.settings.solution.report_definitions.surface["mag-report"] = { "report_type": "surface-vertexavg", "surface_names": ["point-" + str(angle)], "field": str(variable), } - mag = session.solution.report_definitions.compute( + mag = session.settings.solution.report_definitions.compute( report_defs=["mag-report"] ) mag = mag[0]["mag-report"][0] An[n_ind][angle_ind] = mag Bn[n_ind][angle_ind] = 0 else: - session.solution.report_definitions.surface["mag-report"] = { + session.settings.solution.report_definitions.surface["mag-report"] = { "report_type": "surface-vertexavg", "surface_names": ["point-" + str(angle)], "field": str(variable) + "-mag", } - mag = session.solution.report_definitions.compute( + mag = session.settings.solution.report_definitions.compute( report_defs=["mag-report"] ) mag = mag[0]["mag-report"][0] - session.solution.report_definitions.surface["phase-report"] = { + session.settings.solution.report_definitions.surface["phase-report"] = { "report_type": "surface-vertexavg", "surface_names": ["point-" + str(angle)], "field": str(variable) + "-phase", } - phase = session.solution.report_definitions.compute( + phase = session.settings.solution.report_definitions.compute( report_defs=["phase-report"] ) phase = phase[0]["phase-report"][0] @@ -235,24 +243,16 @@ # This step is only required if data is to be processed with other standalone # tools. Update the path to the file accordingly. -fourier_coefficients_file = Path(os.getcwd(), "FourierCoefficients.txt") -with open(fourier_coefficients_file, "w") as f: - f.write("n theta An Bn \n") +with (Path.cwd() / "FourierCoefficients.csv").open("w") as f: + writer = csv.writer(f) + writer.writerow(["n", "theta", "An", "Bn"]) for n_ind, variable in enumerate(varname): - for ind, x in enumerate(An[n_ind, :]): - f.write( - str(n_mode[n_ind]) - + "," - + str(ind * d_theta) - + "," - + str(An[n_ind, ind]) - + "," - + str(Bn[n_ind, ind]) - + "\n" + for ind, _ in enumerate(An[n_ind, :]): + writer.writerow( + [n_mode[n_ind], ind * d_theta, An[n_ind, ind], Bn[n_ind, ind]] ) - ####################################################################################### # Calculate Resultant Pressure Field # ===================================================================================== diff --git a/src/ansys/fluent/core/launcher/standalone_launcher.py b/src/ansys/fluent/core/launcher/standalone_launcher.py index dbbdc66b2db1..7812a2534586 100644 --- a/src/ansys/fluent/core/launcher/standalone_launcher.py +++ b/src/ansys/fluent/core/launcher/standalone_launcher.py @@ -298,13 +298,13 @@ def __call__(self): elif self.argvals["lightweight_mode"]: session.read_case_lightweight(self.argvals["case_file_name"]) else: - session.file.read( + session.settings.file.read( file_type="case", file_name=self.argvals["case_file_name"], ) if self.argvals["case_data_file_name"]: if not FluentMode.is_meshing(self.argvals["mode"]): - session.file.read( + session.settings.file.read( file_type="case-data", file_name=self.argvals["case_data_file_name"], ) diff --git a/src/ansys/fluent/core/services/batch_ops.py b/src/ansys/fluent/core/services/batch_ops.py index 8f6b91ff24a2..d06d43da6047 100644 --- a/src/ansys/fluent/core/services/batch_ops.py +++ b/src/ansys/fluent/core/services/batch_ops.py @@ -68,7 +68,7 @@ class BatchOps: -------- >>> with pyfluent.BatchOps(solver): >>> solver.tui.file.read_case("mixing_elbow.cas.h5") - >>> solver.results.graphics.mesh["mesh-1"] = {} + >>> solver.settings.results.graphics.mesh["mesh-1"] = {} Above code will execute both operations through a single gRPC call upon exiting the ``with`` block. @@ -83,10 +83,10 @@ class BatchOps: >>> with pyfluent.BatchOps(solver): >>> solver.tui.file.read_case("mixing_elbow.cas.h5") - >>> solver.results.graphics.mesh["mesh-1"] = {} - >>> solver.results.graphics.mesh["mesh-1"].surfaces_list = ["wall-elbow"] + >>> solver.settings.results.graphics.mesh["mesh-1"] = {} + >>> solver.settings.results.graphics.mesh["mesh-1"].surfaces_list = ["wall-elbow"] - will throw a ``KeyError`` as ``solver.results.graphics.mesh["mesh-1"]`` attempts to + will throw a ``KeyError`` as ``solver.settings.results.graphics.mesh["mesh-1"]`` attempts to access the ``mesh-1`` mesh object which has not been created yet. """ diff --git a/src/ansys/fluent/core/session_solver.py b/src/ansys/fluent/core/session_solver.py index 6fbefa95354a..43811a9ae6c9 100644 --- a/src/ansys/fluent/core/session_solver.py +++ b/src/ansys/fluent/core/session_solver.py @@ -321,7 +321,9 @@ def read_case_lightweight(self, file_name: str): Case file name """ - self.file.read(file_type="case", file_name=file_name, lightweight_setup=True) + self.settings.file.read( + file_type="case", file_name=file_name, lightweight_setup=True + ) launcher_args = dict(self._launcher_args) launcher_args.pop("lightweight_mode", None) launcher_args["case_file_name"] = file_name diff --git a/src/ansys/fluent/core/solver/function/reduction.py b/src/ansys/fluent/core/solver/function/reduction.py index fd7ea378394e..a9980acff3c0 100644 --- a/src/ansys/fluent/core/solver/function/reduction.py +++ b/src/ansys/fluent/core/solver/function/reduction.py @@ -62,23 +62,24 @@ >>> # condition surfaces of the given solver >>> reduction.area_average( ... expr = "AbsolutePressure", -... locations = solver.setup.boundary_conditions.velocity_inlet +... locations = solver.settings.setup.boundary_conditions.velocity_inlet ... ) 10623.0 >>> from ansys.fluent.core.solver.function import reduction >>> # Compute the minimum of the square of velocity magnitude >>> # for all pressure outlets across two solvers ->>> named_exprs = solver1.setup.named_expressions +>>> named_exprs = solver1.settings.setup.named_expressions >>> vsquared = named_exprs["vsquared"] = {} >>> vsquared.definition = "VelocityMagnitude ** 2" >>> reduction.minimum( ... expr = vsquared, -... locations = solver1.setup.boundary_conditions.pressure_outlet -... + solver2.setup.boundary_conditions.pressure_outlet +... locations = solver1.settings.setup.boundary_conditions.pressure_outlet +... + solver2.settings.setup.boundary_conditions.pressure_outlet ... ) 19.28151 """ + from collections.abc import Iterable from enum import Enum diff --git a/src/ansys/fluent/core/utils/data_transfer.py b/src/ansys/fluent/core/utils/data_transfer.py index d5675192b97d..9d29988896d2 100644 --- a/src/ansys/fluent/core/utils/data_transfer.py +++ b/src/ansys/fluent/core/utils/data_transfer.py @@ -49,9 +49,11 @@ def _read_case_into(solver, file_type, file_name, full_file_name_container=None) except AttributeError: pass if full_file_name_container: - solver.file.read(file_name=full_file_name_container, file_type=file_type) + solver.settings.file.read( + file_name=full_file_name_container, file_type=file_type + ) else: - solver.file.read(file_name=file_name, file_type=file_type) + solver.settings.file.read(file_name=file_name, file_type=file_type) network_logger.info(f"Have read case: {file_name}") diff --git a/src/ansys/fluent/core/utils/file_transfer_service.py b/src/ansys/fluent/core/utils/file_transfer_service.py index b54caff069c8..83aefd6803c6 100644 --- a/src/ansys/fluent/core/utils/file_transfer_service.py +++ b/src/ansys/fluent/core/utils/file_transfer_service.py @@ -227,8 +227,8 @@ class ContainerFileTransferStrategy(FileTransferStrategy): >>> case_file_name = examples.download_file("mixing_elbow.cas.h5", "pyfluent/mixing_elbow") >>> solver_session = pyfluent.launch_fluent(file_transfer_service=ContainerFileTransferStrategy()) >>> solver_session.upload(file_name=case_file_name, remote_file_name="elbow.cas.h5") - >>> solver_session.file.read_case(file_name="elbow.cas.h5") - >>> solver_session.file.write_case(file_name="write_elbow.cas.h5") + >>> solver_session.settings.file.read_case(file_name="elbow.cas.h5") + >>> solver_session.settings.file.write_case(file_name="write_elbow.cas.h5") >>> solver_session.download(file_name="write_elbow.cas.h5", local_directory="") """ @@ -340,7 +340,7 @@ def upload(self, file_name: list[str] | str, remote_file_name: str | None = None >>> case_file_name = examples.download_file("mixing_elbow.cas.h5", "pyfluent/mixing_elbow") >>> solver_session = pyfluent.launch_fluent(file_transfer_service=ContainerFileTransferStrategy()) >>> solver_session.upload(file_name=case_file_name, remote_file_name="elbow.cas.h5") - >>> solver_session.file.read_case(file_name="elbow.cas.h5") + >>> solver_session.settings.file.read_case(file_name="elbow.cas.h5") """ files = _get_files(file_name) if self.client: @@ -380,7 +380,7 @@ def download(self, file_name: list[str] | str, local_directory: str | None = Non >>> from ansys.fluent.core.utils.file_transfer_service import ContainerFileTransferStrategy >>> case_file_name = examples.download_file("mixing_elbow.cas.h5", "pyfluent/mixing_elbow") >>> solver_session = pyfluent.launch_fluent(file_transfer_service=ContainerFileTransferStrategy()) - >>> solver_session.file.write_case(file_name="write_elbow.cas.h5") + >>> solver_session.settings.file.write_case(file_name="write_elbow.cas.h5") >>> solver_session.download(file_name="write_elbow.cas.h5", local_directory="") """ files = _get_files(file_name)