### Initialize Fluent Solver and Load Case Source: https://github.com/veeshy/fluent-docs/blob/gh-pages/version/stable/_sources/user_guide/solver_settings/set_up/models/models_contents.rst.txt Demonstrates how to import the `ansys.fluent.core` library, download an example case file, launch a Fluent solver session, and read the case file into the session. This setup is necessary before activating physics models. ```python >>> import ansys.fluent.core as pyfluent >>> from ansys.fluent.core import examples >>> file_name = examples.download_file("mixing_elbow.cas.h5", "pyfluent/mixing_elbow") >>> solver_session = pyfluent.launch_fluent() >>> solver_session.settings.file.read_case(file_name=file_name) ``` -------------------------------- ### Fluent setup and solution using settings objects (Python) Source: https://github.com/veeshy/fluent-docs/blob/gh-pages/version/stable/_sources/examples/index.rst.txt This example demonstrates the process of setting up and solving a simulation in Fluent using settings objects. It highlights a streamlined approach to Fluent configuration. ```python examples/00-fluent/mixing_elbow_settings_api.py ``` -------------------------------- ### Launch Fluent and Run Simulation with PyFluent Source: https://github.com/veeshy/fluent-docs/blob/gh-pages/version/stable/_sources/user_guide/user_guide_contents.rst.txt This example demonstrates launching Ansys Fluent in meshing mode, performing geometry import and meshing, switching to solver mode, setting up boundary conditions and cell zone conditions, initializing the solution, running calculations, and extracting vector field data. It requires the PyFluent library and Ansys Fluent installation. ```python >>> import ansys.fluent.core as pyfluent >>> meshing_session = pyfluent.launch_fluent(mode=pyfluent.FluentMode.MESHING, product_version=pyfluent.FluentVersion.v251) >>> watertight = meshing_session.watertight() >>> watertight.import_geometry.file_name = pyfluent.examples.download_file("mixing_elbow.pmdb","pyfluent/mixing_elbow") >>> watertight.import_geometry() >>> watertight.create_volume_mesh() >>> solver_session = meshing_session.switch_to_solver() >>> setup, solution = solver_session.settings.setup, solver_session.settings.solution >>> setup.boundary_conditions.set_zone_type(zone_list=["cold-inlet", "hot-inlet"], new_type="velocity-inlet") >>> setup.boundary_conditions.set_zone_type(zone_list=["outlet"], new_type="pressure-outlet") >>> setup.cell_zone_conditions.set_zone_type(zone_list="elbow-fluid", new_type="fluid") >>> solution.initialization.hybrid_initialize() >>> solution.run_calculation.iterate(iter_count=100) >>> velocity_data = solver_session.fields.field_data.get_vector_field_data(field_name="velocity", surfaces=["cold-inlet"]) ``` -------------------------------- ### PyFluent Energy Model Setup and Query Source: https://github.com/veeshy/fluent-docs/blob/gh-pages/version/stable/_sources/user_guide/solver_settings/set_up/models/energy.rst.txt Demonstrates initializing the energy model in Ansys Fluent using PyFluent. It shows how to read a case file, launch a Fluent session, create an Energy object, and then get and set the state of various energy model parameters like 'enabled' and 'viscous_dissipation'. ```python >>> import ansys.fluent.core as pyfluent >>> from ansys.fluent.core import examples >>> file_name = examples.download_file("mixing_elbow.cas.h5", "pyfluent/mixing_elbow") >>> solver_session = pyfluent.launch_fluent() >>> solver_session.settings.file.read_case(file_name=file_name) >>> energy = pyfluent.solver.Energy(settings_source=solver_session) >>> energy.enabled.get_state() True >>> from pprint import pprint >>> pprint(energy.get_state(), width=1) {'enabled': True, 'inlet_diffusion': True, 'kinetic_energy': False, 'pressure_work': False, 'viscous_dissipation': False} >>> energy.enabled.set_state(False) >>> pprint(energy.get_state(), width=1) {'enabled': False} >>> energy.enabled.set_state(True) >>> pprint(energy.get_state(), width=1) {'enabled': True, 'inlet_diffusion': True, 'viscous_dissipation': False, 'pressure_work': False, 'kinetic_energy': False} >>> energy.viscous_dissipation.set_state(True) >>> pprint(energy.get_state(), width=1) {'enabled': True, 'inlet_diffusion': True, 'viscous_dissipation': True} ``` -------------------------------- ### DataFile Usage Example Source: https://github.com/veeshy/fluent-docs/blob/gh-pages/version/stable/_sources/user_guide/offline/data_file.rst.txt Demonstrates initializing a DataFile object to read case and data files, and querying its interface for simulation data. It shows how to access variables, phases, face variables, cell variables, and field data. ```python >>> from ansys.fluent.core import examples >>> 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") >>> # Assuming 'case_file_name' is defined elsewhere or handled appropriately >>> # For demonstration, let's assume a placeholder or a valid path if available >>> # case_file_name = "path/to/your/elbow1.cas.h5" >>> # reader = DataFile(data_file_name=data_file_name, case_file_handle=CaseFile(case_file_name)) >>> # Placeholder for reader initialization if case_file_name is not provided or known >>> # In a real scenario, you would need a valid case file. >>> # For this example, we'll simulate the output based on the provided structure. >>> # Example of accessing attributes and methods: >>> # print(reader.case_file) >>> # print(reader.variables()) >>> # print(reader.get_phases()) >>> # print(reader.get_face_variables("phase-1")) >>> # print(reader.get_cell_variables("phase-1")) >>> # print(reader.get_face_scalar_field_data("phase-1", "SV_T", 4)) >>> # print(reader.get_face_vector_field_data("phase-1", 4)) >>> # Mocking output for demonstration purposes as actual file reading is not performed here: >>> print('elbow1.cas.h5') # Mock output for reader.case_file >>> print({'flow-time': 0.0, 'solvertime': 43.13454608435059, 'time-step': 0, 'vbm/trim': []}) # Mock output for reader.variables() >>> print(['phase-1']) # Mock output for reader.get_phases() >>> print(['SV_ARTIFICIAL_WALL_FLAG', 'SV_D', 'SV_DENSITY', 'SV_WALL_YPLUS_UTAU', '']) # Mock output for reader.get_face_variables("phase-1") >>> print(['SV_BF_V', 'SV_D', 'SV_DENSITY', 'SV_V', 'SV_W', '']) # Mock output for reader.get_cell_variables("phase-1") >>> print('array([293.14999, 293.14999, 293.14999, ..., 293.14999, 293.14999, 293.14999])') # Mock output for reader.get_face_scalar_field_data("phase-1", "SV_T", 4) >>> print('array([ 3.32643010e-01, 6.64311343e-03, 0.00000000e+00, ..., 4.56052223e-01, 2.45034248e-01, -1.24726618e-15])') # Mock output for reader.get_face_vector_field_data("phase-1", 4) ``` -------------------------------- ### Fluent: Workflow Tasks Example Source: https://github.com/veeshy/fluent-docs/blob/gh-pages/version/stable/_sources/examples/00-fluent/index.rst.txt This example showcases general workflow tasks in Ansys Fluent. It provides insights into common simulation setup and execution procedures. ```python pass # Reference to /examples/00-fluent/radiation_headlamp.py ``` -------------------------------- ### Documenting ansys.fluent.core.solver.tui.setup Class Source: https://github.com/veeshy/fluent-docs/blob/gh-pages/version/stable/_sources/api/solver/tui/setup/setup_contents.rst.txt This entry documents the 'setup' class from the ansys.fluent.core.generated.solver.tui_252.main_menu module. It includes all public members and the special __init__ method, excluding specific dunder attributes like __weakref__ and __dict__. ```APIDOC .. autoclass:: ansys.fluent.core.generated.solver.tui_252.main_menu.setup :members: :show-inheritance: :undoc-members: :exclude-members: __weakref__, __dict__ :special-members: __init__ :autosummary: :autosummary-members: ``` -------------------------------- ### Launch Fluent Solver Session Source: https://github.com/veeshy/fluent-docs/blob/gh-pages/version/stable/_sources/user_guide/session/session.rst.txt Demonstrates how to import the PyFluent library, download example files, and launch a Fluent solver session using a case file. ```python >>> import ansys.fluent.core as pyfluent >>> from ansys.fluent.core.examples import download_file >>> case_file_name = download_file("mixing_elbow.cas.h5", "pyfluent/mixing_elbow") >>> data_file_name = download_file("mixing_elbow.dat.h5", "pyfluent/mixing_elbow") >>> solver_session = pyfluent.launch_fluent(case_data_file_name=case_file_name) ``` -------------------------------- ### Ahmed Body External Aerodynamics Simulation (Python) Source: https://github.com/veeshy/fluent-docs/blob/gh-pages/version/stable/_sources/examples/index.rst.txt This example focuses on performing an Ahmed Body external aerodynamics simulation using PyFluent. It covers the typical workflow from setup to solution. ```python examples/00-fluent/ahmed_body_workflow.py ``` -------------------------------- ### Download and read files Source: https://github.com/veeshy/fluent-docs/blob/gh-pages/version/stable/_sources/examples/00-fluent/parametric_static_mixer_1.rst.txt Download the files for this example and read the case for the static mixer. ```Python import_filename = examples.download_file( "Static_Mixer_main.cas.h5", "pyfluent/static_mixer", save_path=os.getcwd(), ) solver_session.settings.file.read_case(file_name=import_filename) ``` -------------------------------- ### Design of Experiments and Machine Learning model building (Python) Source: https://github.com/veeshy/fluent-docs/blob/gh-pages/version/stable/_sources/examples/index.rst.txt This example demonstrates how to use PyFluent for Design of Experiments (DOE) and Machine Learning model building. It showcases advanced simulation setup and analysis capabilities. ```python examples/00-fluent/DOE_ML.py ``` -------------------------------- ### Download example file Source: https://github.com/veeshy/fluent-docs/blob/gh-pages/version/stable/_sources/examples/00-fluent/modeling_ablation.rst.txt Downloads the mesh file required for the ablation tutorial from the example repository to the current working directory. ```Python import_filename = examples.download_file( "ablation.msh.h5", "pyfluent/examples/Ablation-tutorial", save_path=os.getcwd(), ) ``` -------------------------------- ### Fault-tolerant meshing workflow using settings objects (Python) Source: https://github.com/veeshy/fluent-docs/blob/gh-pages/version/stable/_sources/examples/index.rst.txt This example utilizes the guided workflow for fault-tolerant meshing, suitable for geometries with imperfections like gaps and leakages. It showcases the use of settings objects for meshing configuration. ```python examples/00-fluent/exhaust_system_settings_api.py ``` -------------------------------- ### Set Up and Activate Python Virtual Environment Source: https://github.com/veeshy/fluent-docs/blob/gh-pages/version/stable/_sources/getting_started/faqs.rst.txt This snippet demonstrates how to create and activate a Python virtual environment using standard Python commands. It covers setup on Windows and activation on Linux (csh and bash). ```bash # Set up a local virtual environment python -m venv venv # Activate the virtual environment on Windows venv\Scripts\activate # Activate the virtual environment on Linux (csh) source venv/bin/activate.csh # Activate the virtual environment on Linux (bash) . venv/bin/activate ``` -------------------------------- ### PyFluent Field Data Streaming Example in Meshing Mode Source: https://github.com/veeshy/fluent-docs/blob/gh-pages/version/stable/_sources/user_guide/fields/field_data.rst.txt An example demonstrating how to launch Fluent in Meshing mode, set up a callback function to process streamed mesh data, register the callback, and start the field data streaming service. ```python >>> import ansys.fluent.core as pyfluent >>> from ansys.fluent.core import examples >>> # Download example geometry file >>> import_file_name = examples.download_file( >>> "mixing_elbow.pmdb", "pyfluent/mixing_elbow" >>> ) >>> # Launch Fluent in Meshing mode >>> meshing_session = pyfluent.launch_fluent(mode=pyfluent.FluentMode.MESHING) >>> # Dictionary to store mesh data >>> mesh_data = {} >>> # Define a callback function to process streamed field data >>> def plot_mesh(index, field_name, data): >>> if data is not None: >>> if index in mesh_data: >>> mesh_data[index].update({field_name: data}) >>> else: >>> mesh_data[index] = {field_name: data} >>> # Register the callback function >>> meshing_session.fields.field_data_streaming.register_callback(plot_mesh) >>> # Start field data streaming with byte stream and chunk size >>> meshing_session.fields.field_data_streaming.start(provideBytesStream=True, chunkSize=1024) >>> # Initialize the Meshing workflow >>> meshing_session.workflow.InitializeWorkflow(WorkflowType="Watertight Geometry") >>> # Import the geometry into the workflow >>> meshing_session.workflow.TaskObject["Import Geometry"].Arguments = { >>> "FileName": import_file_name, >>> "LengthUnit": "in", >>> } >>> meshing_session.workflow.TaskObject["Import Geometry"].Execute() ``` -------------------------------- ### lightweight_setup Class Documentation Source: https://github.com/veeshy/fluent-docs/blob/gh-pages/version/stable/_sources/api/solver/_autosummary/settings/lightweight_setup.rst.txt Provides documentation for the lightweight_setup class. This entry details the class's location within the Ansys Fluent Core library and its association with the 'read' command. ```APIDOC Class: lightweight_setup Module: ansys.fluent.core.generated.solver.settings_252 Description: Represents the lightweight_setup functionality in Ansys Fluent Core. Included in: - read command ``` -------------------------------- ### Switch to Solver Session Source: https://github.com/veeshy/fluent-docs/blob/gh-pages/version/stable/_sources/user_guide/meshing/new_meshing_workflows.rst.txt Transitions the current meshing session to a solver session. This is typically done after meshing is complete and before starting the simulation. ```python solver_session = meshing_session.switch_to_solver() ``` -------------------------------- ### Launch Fluent Source: https://github.com/veeshy/fluent-docs/blob/gh-pages/version/stable/_sources/examples/00-fluent/parametric_static_mixer_1.rst.txt Launch Fluent in 3D and double precision and print Fluent version. ```Python solver_session = pyfluent.launch_fluent( precision="double", processor_count=2, mode="solver" ) print(solver_session.get_fluent_version()) ``` -------------------------------- ### Iterate Through Task Objects Source: https://github.com/veeshy/fluent-docs/blob/gh-pages/version/stable/_sources/user_guide/meshing/meshing_workflows.rst.txt Provides an example of iterating through the TaskObject container using dictionary semantics. It prints the name and state of each task in the workflow. ```python >>> for name, object_dict in meshing_session.workflow.TaskObject.items(): >>> print(f"Task name: {name}, state: {object_dict}") ``` -------------------------------- ### Generate Surface Mesh Source: https://github.com/veeshy/fluent-docs/blob/gh-pages/version/stable/_sources/user_guide/meshing/meshing_workflows.rst.txt Executes the task responsible for generating the surface mesh in Fluent. This action typically follows geometry loading and region setup. ```python tasks["Generate the Surface Mesh"].Execute() ``` -------------------------------- ### Import necessary libraries and download mesh Source: https://github.com/veeshy/fluent-docs/blob/gh-pages/version/stable/_sources/examples/00-fluent/mixing_elbow_settings_api.rst.txt Imports the Ansys Fluent Core library and downloads the required mesh file for the simulation. ```Python import os import ansys.fluent.core as pyfluent from ansys.fluent.core import examples import_file_name = examples.download_file( "mixing_elbow.msh.h5", "pyfluent/mixing_elbow", save_path=os.getcwd(), ) ``` -------------------------------- ### Update Regions (Watertight) Source: https://github.com/veeshy/fluent-docs/blob/gh-pages/version/stable/_sources/user_guide/meshing/meshing_workflows.rst.txt Executes the task to update mesh regions in the watertight meshing workflow, ensuring proper region definitions for simulation setup. ```python >>> tasks["Update Regions"].Execute() ``` -------------------------------- ### Launch Fluent with Specific Configurations Source: https://github.com/veeshy/fluent-docs/blob/gh-pages/version/stable/_sources/getting_started/faqs.rst.txt Launches a Fluent session with specific configurations, such as double precision, multiple processors, and GUI mode enabled. This provides more control over the Fluent startup process. ```python session=pyfluent.launch_fluent(precision=pyfluent.Precision.DOUBLE, processor_count=2, ui_mode="gui") ``` -------------------------------- ### Launch Fluent and Read Case File Source: https://github.com/veeshy/fluent-docs/blob/gh-pages/version/stable/_sources/user_guide/fields/solution_data.rst.txt Demonstrates how to launch the Fluent solver and read a case file. This is a prerequisite for accessing solution variable data. It imports necessary libraries and downloads an example mesh file. ```python import ansys.fluent.core as pyfluent from ansys.fluent.core import examples import_filename = examples.download_file("mixing_elbow.msh.h5", "pyfluent/mixing_elbow") solver_session = pyfluent.launch_fluent() solver_session.settings.file.read(file_type="case", file_name=import_filename) ``` -------------------------------- ### Fluent Radiation Model Setup and Querying (Python) Source: https://github.com/veeshy/fluent-docs/blob/gh-pages/version/stable/_sources/user_guide/solver_settings/set_up/models/radiation.rst.txt Demonstrates initializing the Radiation object, retrieving its current state, listing allowed radiation models, setting the model to 'monte-carlo', configuring Monte Carlo specific parameters like `number_of_histories`, creating multiband definitions for solar and thermal-IR, and accessing solve frequency settings. This snippet showcases dynamic configuration and state management of the radiation model within a Fluent session. ```python >>> import ansys.fluent.core as pyfluent >>> radiation = pyfluent.solver.Radiation(settings_source=solver_session) >>> from pprint import pprint >>> pprint(radiation.get_state(), width=1) {'model': 'none', 'solar_load': {'solar_model': 'none', 'sun_direction_vector_definition': None}} >>> pprint(radiation.model.allowed_values(), width=1) ['none', 'p1', 's2s', 'discrete-ordinates', 'monte-carlo'] >>> radiation.model.set_state("monte-carlo") >>> pprint(radiation.get_state(), width=1) {'model': 'monte-carlo', 'monte_carlo': {'number_of_histories': 100000, 'target_cells_per_volume_cluster': 1, 'under_relaxation': 0.5}, 'multiband': None, 'solar_load': {'solar_model': 'none', 'sun_direction_vector_definition': None}, 'solve_frequency': {'iteration_interval': 10}} >>> radiation.monte_carlo.number_of_histories.set_state(1e7) >>> radiation.multiband.create("solar").set_state({ >>> "start": 0, >>> "end": 2.8, >>> }) >>> radiation.multiband.create("thermal-ir").set_state({ >>> "start": 2.8, >>> "end": 100, >>> }) >>> radiation_freq = radiation.solve_frequency >>> pprint(radiation_freq.get_state(), width=1) {'iteration_interval': 10} >>> pprint(radiation.get_state(), width=1) {'model': 'monte-carlo', 'monte_carlo': {'number_of_histories': 10000000.0, 'target_cells_per_volume_cluster': 1, 'under_relaxation': 0.5}, 'multiband': {'solar': {'end': 2.8, 'name': 'solar', 'start': 0}, 'thermal-ir': {'end': 100, 'name': 'thermal-ir', 'start': 2.8}}, 'solar_load': {'solar_model': 'none', 'sun_direction_vector_definition': None}, 'solve_frequency': {'iteration_interval': 10}} ``` -------------------------------- ### Manage Fluent Solver Settings Source: https://github.com/veeshy/fluent-docs/blob/gh-pages/version/stable/_sources/user_guide/session/session.rst.txt Provides examples of interacting with solver settings, including getting and setting model states, checking availability, and accessing numerical limits. ```python >>> viscous_model = settings.setup.models.viscous.model >>> viscous_model.get_state() 'k-omega' >>> from pprint import pprint >>> pprint(viscous_model.allowed_values()) ['inviscid', 'laminar', 'k-epsilon', 'k-omega', 'mixing-length', 'spalart-allmaras', 'k-kl-w', 'transition-sst', 'reynolds-stress', 'scale-adaptive-simulation', 'detached-eddy-simulation', 'large-eddy-simulation'] >>> viscous_model.set_state("laminar") >>> viscous_model.get_state() 'laminar' >>> discrete_phase = settings.setup.models.discrete_phase >>> discrete_phase.is_active() True >>> max_num_refinements = discrete_phase.numerics.tracking.accuracy_control.max_num_refinements >>> max_num_refinements.get_state() 20 >>> max_num_refinements.min(), max_num_refinements.max() (0, 1000000) ``` -------------------------------- ### Export Fluent 2D Mesh Source: https://github.com/veeshy/fluent-docs/blob/gh-pages/version/stable/_sources/user_guide/meshing/meshing_workflows.rst.txt Initiates the export of the generated mesh in Fluent 2D format. The code snippet is incomplete, but it shows the start of the export process. ```python >>> export_mesh = tasks["Export Fluent 2D Mesh"] >>> export_mesh.Arguments.set_state( >>> { >>> ```