### Install PyDPF-Post in Development Mode Source: https://github.com/ansys/pydpf-post/blob/main/doc/source/contributing.rst Clone the repository and install PyDPF-Post using pip with the -e flag for development. ```bash git clone https://github.com/ansys/pydpf-post cd pydpf-post pip install -e . ``` -------------------------------- ### Install PyDPF-Post Source: https://context7.com/ansys/pydpf-post/llms.txt Install PyDPF-Post using pip. Include the `[graphics]` extra for PyVista plotting support. Development installations can be done from source. ```bash # Standard installation pip install ansys-dpf-post # With optional PyVista plotting support pip install ansys-dpf-post[graphics] # Development install from source git clone https://github.com/ansys/pydpf-post cd pydpf-post pip install -e .[graphics] # Verify the installation python -c " from ansys.dpf import post from ansys.dpf.post import examples simulation = post.load_simulation(examples.simple_bar) print(simulation) " ``` -------------------------------- ### Verify PyDPF-Post Installation Source: https://github.com/ansys/pydpf-post/blob/main/doc/source/getting_started/install.rst Run this Python code to confirm that PyDPF-Post is installed correctly and can load a sample simulation. ```python from ansys.dpf import post from ansys.dpf.post import examples simulation = post.load_simulation(examples.simple_bar) print(simulation) ``` -------------------------------- ### Install PyDPF-Post with Graphics Capabilities Source: https://github.com/ansys/pydpf-post/blob/main/doc/source/getting_started/install.rst Install PyDPF-Post along with its optional plotting functionalities, which require PyVista. Use the 'graphics' target for current and future installations. ```bash pip install ansys-dpf-post[graphics] ``` -------------------------------- ### Install PyDPF-Post from GitHub in Development Mode Source: https://github.com/ansys/pydpf-post/blob/main/doc/source/getting_started/install.rst Clone the PyDPF-Post repository from GitHub and install it in development mode. This is useful for contributing to the project or testing the latest unreleased features. ```bash git clone https://github.com/ansys/pydpf-post cd pydpf-post pip install -e .[graphics] ``` -------------------------------- ### Install PyDPF-Post Offline using Wheel File Source: https://github.com/ansys/pydpf-post/blob/main/doc/source/getting_started/install.rst Install PyDPF-Post on a machine without internet access by downloading the wheel file. Ensure you are in the directory containing the unzipped wheel file when running the command. ```bash pip install --no-index --find-links=. ansys-dpf-post ``` -------------------------------- ### Install PyDPF-Post using pip Source: https://github.com/ansys/pydpf-post/blob/main/doc/source/getting_started/install.rst Install the latest version of PyDPF-Post for use with Ansys 2021 R1 or later. This is the standard installation method. ```bash pip install ansys-dpf-post ``` -------------------------------- ### Load Solution and Get Strain Results Source: https://github.com/ansys/pydpf-post/blob/main/doc/source/user_guide/accessing_results.rst Instantiate the legacy `Solution` object and then the `ElasticStrain` and `PlasticStrain` result objects. This is specific to structural analysis result files (RST). ```python >>> from ansys.dpf import post >>> from ansys.dpf.post import examples >>> solution = post.load_solution(examples.multishells_rst) >>> elastic_strain = solution.elastic_strain() >>> plastic_strain = solution.plastic_strain() ``` -------------------------------- ### Load Simulation and Get Displacement Source: https://github.com/ansys/pydpf-post/blob/main/doc/source/user_guide/accessing_results.rst Instantiate the `Simulation` object and extract displacement data. This method is suitable for general result access. ```python >>> from ansys.dpf import post >>> from ansys.dpf.post import examples >>> simulation = post.load_simulation(examples.multishells_rst) >>> displacement = simulation.displacement() >>> # stress, elastic_strain (...) can also be called. ``` -------------------------------- ### Fix setuptools installation error Source: https://github.com/ansys/pydpf-post/blob/main/doc/source/user_guide/troubleshooting.rst Use this command to resolve 'python_requires' errors when installing older PyDPF libraries with pip. ```shell pip uninstall -y packaging; pip uninstall -y setuptools; pip install "setuptools<67.0.0" ``` -------------------------------- ### Load Solution and Get Stress Source: https://github.com/ansys/pydpf-post/blob/main/doc/source/user_guide/accessing_results.rst Instantiate the legacy `Solution` object and then the `Stress` result object. This is specific to structural analysis result files (RST). ```python >>> from ansys.dpf import post >>> from ansys.dpf.post import examples >>> solution = post.load_solution(examples.multishells_rst) >>> stress = solution.stress() ``` -------------------------------- ### Load MAPDL Results (Ansys 2023 R1+) Source: https://github.com/ansys/pydpf-post/blob/main/doc/source/getting_started/demo.rst Use this code to load an MAPDL result file when Ansys 2023 R1 or later is installed. A DPF server starts automatically. This example extracts displacement results. ```python >>> from ansys.dpf import post >>> from ansys.dpf.post import examples >>> simulation = post.load_simulation(examples.download_crankshaft()) >>> displacement = simulation.displacement() >>> print(displacement) ``` ```none results U set_id 3 node comp 4872 X -3.41e-05 Y 1.54e-03 Z -2.64e-06 9005 X -5.56e-05 Y 1.44e-03 Z 5.31e-06 ... ``` ```python >>> displacement.plot() ``` -------------------------------- ### Load Solution and Get Displacement Source: https://github.com/ansys/pydpf-post/blob/main/doc/source/user_guide/accessing_results.rst Instantiate the legacy `Solution` object and then the `Displacement` result object. This is specific to structural analysis result files (RST). ```python >>> from ansys.dpf import post >>> from ansys.dpf.post import examples >>> solution = post.load_solution(examples.multishells_rst) >>> displacement = solution.displacement() ``` -------------------------------- ### Load MAPDL Results (Ansys 2021 R1 - 2022 R2) Source: https://github.com/ansys/pydpf-post/blob/main/doc/source/getting_started/demo.rst Use this code to load an MAPDL result file when Ansys 2021 R1 through 2022 R2 is installed. This starts the legacy PyDPF-Post tools. This example extracts and plots stress results. ```python >>> from ansys.dpf import post >>> from ansys.dpf.post import examples >>> solution = post.load_solution(examples.download_crankshaft()) >>> stress = solution.stress() >>> stress.eqv.plot_contour(show_edges=False) ``` -------------------------------- ### Get Elastic Strain Data Source: https://github.com/ansys/pydpf-post/blob/main/doc/source/user_guide/accessing_results.rst Access the elastic strain result object. This code snippet demonstrates how to obtain the `ElasticStrain` object from a `Solution` object. ```python >>> from ansys.dpf import post >>> from ansys.dpf.post import examples >>> solution = post.load_solution(examples.multishells_rst) >>> elastic_strain = solution.elastic_strain() ``` -------------------------------- ### Get Y Displacement Data Source: https://github.com/ansys/pydpf-post/blob/main/doc/source/user_guide/accessing_results.rst Access the y-component of the displacement field and retrieve its data. This requires a `Displacement` result object obtained from a `Solution` object. ```python >>> from ansys.dpf import post >>> from ansys.dpf.post import examples >>> solution = post.load_solution(examples.multishells_rst) >>> displacement = solution.displacement() >>> u_y = displacement.y >>> u_y.get_data_at_field() ``` -------------------------------- ### Get Elastic Strain XY Data Source: https://github.com/ansys/pydpf-post/blob/main/doc/source/user_guide/accessing_results.rst Accesses the xy component of elastic strain data. Ensure the elastic_strain object is already instantiated. ```python e_yy = elastic_strain.xy e_yy.get_data_at_field() ``` -------------------------------- ### Access X-component of ElectricField Source: https://github.com/ansys/pydpf-post/blob/main/doc/source/user_guide/accessing_results.rst After instantiating the electric field result object, access its 'x' subresult to get the x-component data. This is useful for vector fields. ```python >>> from ansys.dpf import post >>> from ansys.dpf.post import examples >>> solution = post.load_solution(examples.multishells_rst) >>> electric_field = solution.electric_field() >>> electric_field_x = electric_field.x >>> electric_field_x.get_data_at_field() ``` -------------------------------- ### Get YY Stress Data Source: https://github.com/ansys/pydpf-post/blob/main/doc/source/user_guide/accessing_results.rst Access the yy component of the stress tensor and retrieve its data. This requires a `Stress` result object obtained from a `Solution` object. ```python >>> from ansys.dpf import post >>> from ansys.dpf.post import examples >>> solution = post.load_solution(examples.multishells_rst) >>> stress = solution.stress() >>> s_yy = stress.yy >>> s_yy.get_data_at_field() ``` -------------------------------- ### Browse all simulation metadata Source: https://github.com/ansys/pydpf-post/blob/main/doc/source/user_guide/accessing_file_metadata.rst Instantiate the Simulation object to load a result file and then print the object to display all available metadata. ```python >>> from ansys.dpf import post >>> from ansys.dpf.post import examples >>> simulation = post.load_simulation(examples.multishells_rst) >>> print(simulation) Static Mechanical Simulation. ``` -------------------------------- ### Load a Result File with DpfSolution Source: https://github.com/ansys/pydpf-post/blob/main/doc/source/api/solution.rst Use this snippet to load a result file and obtain a DpfSolution object, which is the entry point for further data exploration. ```python >>> from ansys.dpf import post >>> from ansys.dpf.post import examples >>> solution = post.load_solution(examples.multishells_rst) ``` -------------------------------- ### Postprocess Fluid Simulations Source: https://context7.com/ansys/pydpf-post/llms.txt Load Fluent `.cas`/`.dat` or `.flprj` files using `FluidSimulation` to access fluid results like velocity, pressure, and temperature. Ensure you have the correct Fluent files. ```python from ansys.dpf import post from ansys.dpf.post import examples fluid_files = examples.download_fluent_axial_comp() # Load from Fluent CAS/DAT files simulation = post.FluidSimulation( cas=fluid_files["cas"], dat=fluid_files["dat"], ) print(simulation) # Explore available zones and mesh metadata print(simulation.cell_zones) print(simulation.face_zones) print(simulation.mesh_info) # lightweight; does not load the full mesh # Species and phases print(simulation.species) print(simulation.phases) # Inspect available results print(simulation.result_info) print(simulation.result_info["enthalpy"]) # Extract enthalpy for all zones → one data column per zone enthalpy = simulation.enthalpy() enthalpy.plot() # Filter by zone IDs enthalpy_zones = simulation.enthalpy(zone_ids=[13, 28]) print(enthalpy_zones) # Filter by cell IDs enthalpy_cells = simulation.enthalpy(cell_ids=[1, 2, 3]) # Velocity magnitude velocity = simulation.velocity() print(velocity) ``` -------------------------------- ### Accessing Displacement, Stress, and Elastic Strain Results Source: https://github.com/ansys/pydpf-post/blob/main/doc/source/api/result_object.rst Demonstrates how to load a solution and then access specific result types like displacement, stress, and elastic strain. ```APIDOC ## Accessing Result Data ### Description This example shows how to load a solution file and retrieve specific result objects for displacement, stress, and elastic strain. ### Method Python SDK ### Endpoint N/A (SDK Method) ### Parameters N/A ### Request Example ```python from ansys.dpf import post from ansys.dpf.post import examples solution = post.load_solution(examples.multishells_rst) # Access Displacement result displacement = solution.displacement() # Access Stress result stress = solution.stress() # Access Elastic Strain result elastic_strain = solution.elastic_strain() ``` ### Response #### Success Response The methods return specific result objects (e.g., Displacement, Stress, ElasticStrain) that allow further interaction with the result data. #### Response Example ```python # displacement object # stress object # elastic_strain object ``` ``` -------------------------------- ### Load solution with physics and analysis types Source: https://github.com/ansys/pydpf-post/blob/main/doc/source/user_guide/troubleshooting.rst Set the 'physics_type' and 'analysis_type' arguments for the 'load_solution()' method to avoid Invalid UTF-8 errors and ensure the result file is read. ```python from ansys.dpf import post solution = post.load_solution('file.rst', physics_type='mechanical', analysis_type='transient') ``` -------------------------------- ### Postprocess Transient Mechanical Simulations Source: https://context7.com/ansys/pydpf-post/llms.txt Use `TransientMechanicalSimulation` to postprocess time-domain mechanical analyses. It supports multi-step queries and animations. Ensure you have the necessary simulation files to initialize. ```python from ansys.dpf import post from ansys.dpf.post import examples simulation = post.TransientMechanicalSimulation(examples.find_msup_transient()) # Show available time steps print(simulation.set_ids) print(simulation.time_freq_support) # Displacement at all time steps with animation displacement = simulation.displacement(all_sets=True) displacement.animate(deform=True, title="U") # X-component animation x_disp = simulation.displacement(all_sets=True, components=["X"]) x_disp.animate(deform=True, title="UX") # Displacement at specific set IDs displacement_subset = simulation.displacement(set_ids=simulation.set_ids[5:]) # Displacement at specific time values (in model units) disp_at_time = simulation.displacement(times=[0.01, 0.02, 0.05]) # Elastic strain at specific load step and sub-steps (load_step=1, sub_steps=[1,2]) strain = simulation.elastic_strain_nodal(load_steps=(1, [1, 2])) # Von Mises equivalent strain animated over all steps strain_eqv = simulation.elastic_strain_eqv_von_mises_nodal(all_sets=True) strain_eqv.animate(deform=True, title="E_eqv") ``` -------------------------------- ### Loading a Result File Source: https://github.com/ansys/pydpf-post/blob/main/doc/source/api/solution.rst This code snippet demonstrates how to load a result file using the ``load_solution`` function from the ``ansys.dpf.post`` library. ```APIDOC ## Loading a Result File ### Description This code snippet demonstrates how to load a result file using the ``load_solution`` function from the ``ansys.dpf.post`` library. ### Method ```python from ansys.dpf import post from ansys.dpf.post import examples solution = post.load_solution(examples.multishells_rst) ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **solution** (DpfSolution) - An instance of the ``DpfSolution`` class representing the loaded result file. #### Response Example None ``` -------------------------------- ### Accessing Displacement, Stress, and Elastic Strain Results Source: https://github.com/ansys/pydpf-post/blob/main/doc/source/api/result_object.rst Load a solution file and access displacement, stress, and elastic strain result objects. Ensure the 'ansys.dpf.post' and 'ansys.dpf.post.examples' modules are imported. ```python >>> from ansys.dpf import post >>> from ansys.dpf.post import examples >>> solution = post.load_solution(examples.multishells_rst) Displacement result object >>> displacement = solution.displacement() Stress result object >>> stress = solution.stress() Elastic strain result object >>> elastic_strain = solution.elastic_strain() ``` -------------------------------- ### Load Simulation Result File on Linux Source: https://github.com/ansys/pydpf-post/blob/main/doc/source/user_guide/post_processing.rst Loads a simulation result file using the Simulation object. Ensure the path is correct for your Linux system. ```python >>> simulation = post.load_simulation('/home/user/file.rst') ``` -------------------------------- ### Load Simulation Result File with PyDPF-Post Source: https://context7.com/ansys/pydpf-post/llms.txt Use `post.load_simulation` as the primary entry point to load simulation results. It can auto-detect the simulation type or accept an explicit `simulation_type`. You can also connect to a remote DPF server. ```python from ansys.dpf import post from ansys.dpf.post import examples from ansys.dpf.post.common import AvailableSimulationTypes # Auto-detect simulation type from file metadata simulation = post.load_simulation(examples.find_static_rst()) print(simulation) # Explicitly specify the simulation type for better IDE support simulation = post.load_simulation( examples.find_static_rst(), simulation_type=AvailableSimulationTypes.static_mechanical, ) # Equivalent: use the concrete class directly simulation = post.StaticMechanicalSimulation(examples.find_static_rst()) # Connect to a remote DPF server import ansys.dpf.core as dpf server = dpf.connect_to_server(ip="192.168.1.10", port=50052) simulation = post.load_simulation(examples.find_static_rst(), server=server) ``` -------------------------------- ### Postprocess Harmonic Mechanical Simulations Source: https://context7.com/ansys/pydpf-post/llms.txt Use `HarmonicMechanicalSimulation` for frequency-domain (harmonic response) analyses. It supports complex amplitude results. Ensure the correct simulation files are loaded. ```python from ansys.dpf import post from ansys.dpf.post import examples simulation = post.HarmonicMechanicalSimulation(examples.download_all_kinds_of_complexity()) # Available frequency sets print(simulation.set_ids) # Displacement amplitude at all frequencies displacement = simulation.displacement(all_sets=True) print(displacement) # Z-component at a specific frequency set z_disp = simulation.displacement(components=["Z"], set_ids=[3]) z_disp.plot() # Velocity and acceleration at last frequency (default) velocity = simulation.velocity() acceleration = simulation.acceleration() # Stress at specific sets stress = simulation.stress(set_ids=[1, 2, 3]) print(stress) ``` -------------------------------- ### Instantiate Simulation subclasses directly Source: https://github.com/ansys/pydpf-post/blob/main/doc/source/user_guide/troubleshooting.rst Instantiate the correct Simulation subclass directly using its constructor to ensure auto-completion works in all circumstances. ```python from ansys.dpf import post static_mechanical_simulation = post.StaticMechanicalSimulation('file.rst') # or transient_mechanical_simulation = post.TransientMechanicalSimulation('file.rst') # or modal_mechanical_simulation = post.ModalMechanicalSimulation('file.rst') # or harmonic_mechanical_simulation = post.HarmonicMechanicalSimulation('file.rst') ``` -------------------------------- ### Load Simulation Result File on Windows Source: https://github.com/ansys/pydpf-post/blob/main/doc/source/user_guide/post_processing.rst Loads a simulation result file using the Simulation object. Ensure the path is correct for your Windows system. ```python >>> from ansys.dpf import post >>> from ansys.dpf.post import examples >>> simulation = post.load_simulation('C:/Users/user/file.rst') ``` -------------------------------- ### DataFrame: Result Container and Manipulation Source: https://context7.com/ansys/pydpf-post/llms.txt Demonstrates how to load simulation data into a DataFrame, inspect its structure, select subsets of data based on values or positions, export to NumPy, perform aggregations, and configure display options. Requires importing `ansys.dpf.post` and `ansys.dpf.post.examples`. ```python from ansys.dpf import post from ansys.dpf.post import examples simulation = post.StaticMechanicalSimulation(examples.download_crankshaft()) df = simulation.displacement(all_sets=True) # Inspect structure print(df.columns) # MultiIndex of column labels print(df.index) # MultiIndex of row labels print(df.columns[0]) # ResultsIndex → result name + units print(df.columns[1]) # SetIndex → available set IDs print(df.index[0]) # MeshIndex → node / element IDs print(df.index[1]) # CompIndex → X, Y, Z # --- Value-based selection --- subset = df.select(set_ids=[1], node_ids=[4872, 9005], components=["X"]) print(subset) # --- Position-based selection (zero-based) --- subset2 = df.iselect(set_ids=[0], node_ids=[0, 1], components=[0]) print(subset2) # --- Export to NumPy --- # DataFrame must have a unique column label combination before calling .array single_set = df.select(set_ids=[1], components=["X"]) arr = single_set.array # numpy.ndarray shape (n_nodes,) print(arr) # --- Aggregation --- max_over_nodes = df.max() # default axis = MeshIndex max_over_time = df.max(axis="set_ids") min_over_nodes = df.min(axis="node_ids") overall_max = max_over_time.max() print(overall_max) # --- Plotting and animation --- df.plot() # 3-D plot of the last set df.animate(deform=True) # animate over all time sets # Configure display df.display_max_rows = 12 df.display_max_columns = 4 print(df) ``` -------------------------------- ### Postprocess Modal Mechanical Simulations Source: https://context7.com/ansys/pydpf-post/llms.txt Utilize `ModalMechanicalSimulation` for modal analysis postprocessing, including mode shapes and frequencies. Cyclic symmetry expansion is supported. Ensure the correct simulation file is provided. ```python from ansys.dpf import post from ansys.dpf.post import examples simulation = post.ModalMechanicalSimulation(examples.download_modal_frame()) # Explore mode frequencies print(simulation.time_freq_support) print(simulation.set_ids) # All mode shapes, normalised displacement_norm = simulation.displacement(all_sets=True, norm=True) for set_id in simulation.set_ids: displacement_norm.plot(set_ids=set_id) # Specific modes modes_disp = simulation.displacement(modes=[1, 2, 3], norm=True) # Results scoped to named selections bar1_disp = simulation.displacement(named_selections=["BAR_1"], norm=True) eqv_stress = simulation.stress_eqv_von_mises_nodal(named_selections=["_FIXEDSU"]) # Elemental stress on a named selection elemental_stress = simulation.stress_elemental(named_selections=["BAR_1"]) elemental_stress.plot() # --- Cyclic symmetry expansion --- from ansys.dpf.post import examples as ex cyclic_sim = post.ModalMechanicalSimulation(ex.find_simple_cyclic()) # Expand all sectors disp_expanded = cyclic_sim.displacement(norm=True, expand_cyclic=True) disp_expanded.plot() # Expand only sectors 1–4 stress_vm = cyclic_sim.stress_eqv_von_mises_nodal(expand_cyclic=[1, 2, 3, 4]) stress_vm.plot() # No expansion (single sector) stress_sector1 = cyclic_sim.stress_eqv_von_mises_nodal(expand_cyclic=False) ``` -------------------------------- ### Access Structural Temperature Data Source: https://github.com/ansys/pydpf-post/blob/main/doc/source/user_guide/accessing_results.rst Loads a solution and instantiates the structural temperature result object to access scalar temperature data. ```python from ansys.dpf import post from ansys.dpf.post import examples solution = post.load_solution(examples.multishells_rst) structural_temperature = solution.structural_temperature() temperature = structural_temperature.scalar temperature.get_data_at_field() ``` -------------------------------- ### Browse only mesh metadata Source: https://github.com/ansys/pydpf-post/blob/main/doc/source/user_guide/accessing_file_metadata.rst Instantiate the Simulation object to load a result file, access its mesh attribute, and print the mesh object to display only mesh metadata. ```python >>> from ansys.dpf import post >>> from ansys.dpf.post import examples >>> simulation = post.load_simulation(examples.multishells_rst) >>> mesh = simulation.mesh >>> print(mesh) DPF Mesh: 7079 nodes 4220 elements Unit: m With solid (3D) elements, shell (2D) elements, shell (3D) elements ``` -------------------------------- ### Access Heat Flux X Component Source: https://github.com/ansys/pydpf-post/blob/main/doc/source/user_guide/accessing_results.rst Loads a solution and instantiates the heat flux result object to access its X component data. ```python from ansys.dpf import post from ansys.dpf.post import examples solution = post.load_solution(examples.multishells_rst) heat_flux = solution.heat_flux() heat_flux_x = heat_flux.x heat_flux_x.get_data_at_field() ``` -------------------------------- ### Access Temperature Data from Thermal Analysis Source: https://github.com/ansys/pydpf-post/blob/main/doc/source/user_guide/accessing_results.rst Loads a solution from a thermal analysis result file and instantiates the temperature result object to access scalar temperature data. ```python from ansys.dpf import post from ansys.dpf.post import examples solution = post.load_solution(examples.steady_therm) temperature = solution.temperature() ``` -------------------------------- ### External Layer and Skin: Performance-Optimised Result Extraction Source: https://context7.com/ansys/pydpf-post/llms.txt Demonstrates how to extract results from the external layer or a skin mesh for performance optimization. This method reduces data volume by focusing on critical result values. Requires importing `ansys.dpf.post` and `ansys.dpf.post.examples`. ```python from ansys.dpf import post from ansys.dpf.post import examples simulation = post.StaticMechanicalSimulation(examples.download_crankshaft()) # External layer: all elements with at least one free face disp_ext = simulation.displacement(external_layer=True) disp_ext.plot() print(f"Nodes (ext layer): {len(disp_ext.index.mesh_index)}") print(f"Nodes (full mesh): {len(simulation.mesh.node_ids)}") # Principal stress on external layer principal_ext = simulation.stress_principal_elemental( components=[1], external_layer=True ) principal_ext.plot() # External layer on a subset of element IDs all_elems = simulation.mesh.element_ids half_elems = list(all_elems[: len(all_elems) // 2]) stress_partial_ext = simulation.stress_principal_elemental(external_layer=half_elems) # Skin (2-D surface elements connecting exterior nodes) disp_skin = simulation.displacement(skin=True) disp_skin.plot() strain_skin = simulation.elastic_strain_eqv_von_mises_nodal(external_layer=True) strain_skin.plot() ``` -------------------------------- ### post.load_simulation Source: https://context7.com/ansys/pydpf-post/llms.txt The primary entry point for loading simulation result files. It automatically detects the physics and analysis type or accepts an explicit simulation type. ```APIDOC ## post.load_simulation — Load a simulation result file ### Description The primary entry point for all result extraction. Detects the physics and analysis type automatically, or accepts an explicit `simulation_type` from `AvailableSimulationTypes`. Returns the appropriate `Simulation` subclass. ### Method ```python from ansys.dpf import post from ansys.dpf.post import examples from ansys.dpf.post.common import AvailableSimulationTypes # Auto-detect simulation type from file metadata simulation = post.load_simulation(examples.find_static_rst()) print(simulation) # Explicitly specify the simulation type for better IDE support simulation = post.load_simulation( examples.find_static_rst(), simulation_type=AvailableSimulationTypes.static_mechanical, ) # Equivalent: use the concrete class directly simulation = post.StaticMechanicalSimulation(examples.find_static_rst()) # Connect to a remote DPF server import ansys.dpf.core as dpf server = dpf.connect_to_server(ip="192.168.1.10", port=50052) simulation = post.load_simulation(examples.find_static_rst(), server=server) ``` ``` -------------------------------- ### Accessing Displacement Data Source: https://github.com/ansys/pydpf-post/blob/main/doc/source/api/result_data.rst This snippet demonstrates how to load a solution, access displacement results, and retrieve data at a specific field using the get_data_at_field method. ```APIDOC ## Accessing Displacement Data ### Description This example shows how to access displacement result values. ### Method ```python solution.displacement().vector.get_data_at_field(0) ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from ansys.dpf import post from ansys.dpf.post import examples solution = post.load_solution(examples.multishells_rst) displacement = solution.displacement() result = displacement.vector result.get_data_at_field(0) ``` ### Response #### Success Response (200) Returns a DPFArray containing the displacement data. #### Response Example ```json { "example": "DPFArray([[ 2.24894986e-04, -8.06099872e-05, -1.17079164e-04], [ 3.15660284e-04, -3.30937021e-05, -1.18384868e-04], [ 1.03798114e-04, -4.58764713e-05, -4.35029024e-05], ..., [-5.61467818e-04, -5.27197644e-04, -1.83607162e-04], [-1.09869605e-03, -1.22675467e-03, -5.62025059e-04], [-6.45438681e-04, -9.78889231e-04, -1.37273202e-04]])" } ``` ``` -------------------------------- ### Set DPF Server Context to Entry Source: https://github.com/ansys/pydpf-post/blob/main/doc/source/user_guide/server_context.rst Change the default DPF server context to 'entry' programmatically. This requires importing the 'post' module and using the 'set_default_server_context' function with 'AvailableServerContexts.entry'. ```python from ansys.dpf import post post.set_default_server_context(post.AvailableServerContexts.entry) ``` -------------------------------- ### Access Heat Flux Data Source: https://github.com/ansys/pydpf-post/blob/main/doc/source/user_guide/accessing_results.rst Loads a solution from a thermal analysis result file and instantiates the heat flux result object. ```python from ansys.dpf import post from ansys.dpf.post import examples solution = post.load_solution(examples.steady_therm) heat_flux = solution.heat_flux() ``` -------------------------------- ### Create and Use a Selection Object Source: https://context7.com/ansys/pydpf-post/llms.txt Build reusable selection objects for spatial and time/frequency filtering. Assign a selection as the simulation's active selection to implicitly filter results, or use it directly in a result call. ```python from ansys.dpf import post from ansys.dpf.post import examples simulation = post.StaticMechanicalSimulation(examples.find_static_rst()) # Create a reusable Selection selection = post.selection.Selection() selection.select_nodes(nodes=[1, 2, 3, 4, 5]) selection.select_time_freq_sets(time_freq_sets=[1]) # Assign as the simulation's default active selection simulation.active_selection = selection disp = simulation.displacement() # uses the active selection implicitly print(disp) # Deactivate when done simulation.deactivate_selection() disp_all = simulation.displacement() # no spatial/temporal filter now # Use a Selection directly in a result call result_with_selection = simulation.stress_nodal(selection=selection) print(result_with_selection) ``` -------------------------------- ### Access ElectricPotential Result Object Source: https://github.com/ansys/pydpf-post/blob/main/doc/source/user_guide/accessing_results.rst Instantiate the solution object and then the electric potential result object. This is useful for accessing scalar field data. ```python >>> from ansys.dpf import post >>> from ansys.dpf.post import examples >>> solution = post.load_solution(examples.steady_therm) >>> electric_potential = solution.electric_potential() ``` -------------------------------- ### Access Nodal Acceleration Data Source: https://github.com/ansys/pydpf-post/blob/main/doc/source/user_guide/accessing_results.rst Loads a solution and retrieves the nodal acceleration result object. Miscellaneous results can be accessed via the 'misc' attribute of the solution object. ```python from ansys.dpf import post from ansys.dpf.post import examples solution = post.load_solution(examples.multishells_rst) acceleration = solution.misc.nodal_acceleration() ``` -------------------------------- ### Access Displacement Vector Data Source: https://github.com/ansys/pydpf-post/blob/main/doc/source/api/result_data.rst Loads a solution and accesses the displacement vector data. Use get_data_at_field to retrieve specific data points. ```python >>> from ansys.dpf import post >>> from ansys.dpf.post import examples >>> solution = post.load_solution(examples.multishells_rst) >>> displacement = solution.displacement() >>> result = displacement.vector Access the data >>> result.get_data_at_field(0) DPFArray([[ 2.24894986e-04, -8.06099872e-05, -1.17079164e-04], [ 3.15660284e-04, -3.30937021e-05, -1.18384868e-04], [ 1.03798114e-04, -4.58764713e-05, -4.35029024e-05], ..., [-5.61467818e-04, -5.27197644e-04, -1.83607162e-04], [-1.09869605e-03, -1.22675467e-03, -5.62025059e-04], [-6.45438681e-04, -9.78889231e-04, -1.37273202e-04]]) ``` -------------------------------- ### Access Nodal Acceleration Y Component Source: https://github.com/ansys/pydpf-post/blob/main/doc/source/user_guide/accessing_results.rst Loads a solution and retrieves the Y component of the nodal acceleration result. Subresults like specific components can be accessed using keyword arguments. ```python from ansys.dpf import post from ansys.dpf.post import examples solution = post.load_solution(examples.multishells_rst) acceleration = solution.misc.nodal_acceleration(subresult="Y") ``` -------------------------------- ### Simulation.split_mesh_by_properties: Split Mesh by Elemental Properties Source: https://context7.com/ansys/pydpf-post/llms.txt Splits a global mesh into a `Meshes` container, grouped by specified elemental properties like material or element shape. This function requires importing `ansys.dpf.post`, `ansys.dpf.post.examples`, and `ansys.dpf.post.common.elemental_properties`. ```python from ansys.dpf import post from ansys.dpf.post import examples from ansys.dpf.post.common import elemental_properties example_path = examples.download_all_kinds_of_complexity() simulation = post.StaticMechanicalSimulation(example_path) # Split by material AND element shape, return all sub-meshes meshes = simulation.split_mesh_by_properties( properties=[elemental_properties.material, elemental_properties.element_shape] ) print(meshes) # Split and return only meshes for material=1 and shapes 0 and 1 filtered_meshes = simulation.split_mesh_by_properties( properties={ elemental_properties.material: 1, elemental_properties.element_shape: [0, 1], } ) print(filtered_meshes) ``` -------------------------------- ### StaticMechanicalSimulation Source: https://context7.com/ansys/pydpf-post/llms.txt Provides result extraction methods for linear/nonlinear static structural analyses read from .rst files. ```APIDOC ## StaticMechanicalSimulation — Static mechanical postprocessing ### Description Provides result extraction methods for linear/nonlinear static structural analyses read from `.rst` files. ### Method ```python from ansys.dpf import post from ansys.dpf.post import examples simulation = post.StaticMechanicalSimulation(examples.find_static_rst()) # Inspect available results, mesh, and named selections print(simulation.results) print(simulation.mesh) print(simulation.named_selections) print(simulation.units) # --- Displacement --- # All nodes, last set (default) displacement = simulation.displacement() print(displacement) # X-component only, specific nodes x_disp = simulation.displacement(components=["X"], node_ids=[1, 10, 100]) print(x_disp) # Norm on a subset of nodes disp_norm = simulation.displacement( node_ids=simulation.mesh.node_ids[10:], norm=True ) disp_norm.plot() # --- Stress --- # Raw elemental nodal stress tensor (default location) stress = simulation.stress() # Averaged nodal stress stress_nodal = simulation.stress_nodal() # Averaged elemental stress stress_elemental = simulation.stress_elemental() # Von Mises equivalent stress at nodes eqv_stress = simulation.stress_eqv_von_mises_nodal() eqv_stress.plot() # Principal stress components (1st principal) principal_stress = simulation.stress_principal_elemental(components=[1]) principal_stress.plot() # --- Elastic strain --- strain = simulation.elastic_strain_nodal() strain_eqv = simulation.elastic_strain_eqv_von_mises_nodal() ``` ``` -------------------------------- ### Static Mechanical Postprocessing with PyDPF-Post Source: https://context7.com/ansys/pydpf-post/llms.txt Use `StaticMechanicalSimulation` to extract results from static structural analyses. Inspect mesh, named selections, and units. Extract displacement, stress, and strain with various options for components, nodes, and averaging. ```python from ansys.dpf import post from ansys.dpf.post import examples simulation = post.StaticMechanicalSimulation(examples.find_static_rst()) # Inspect available results, mesh, and named selections print(simulation.results) print(simulation.mesh) print(simulation.named_selections) print(simulation.units) # --- Displacement --- # All nodes, last set (default) displacement = simulation.displacement() print(displacement) # X-component only, specific nodes x_disp = simulation.displacement(components=["X"], node_ids=[1, 10, 100]) print(x_disp) # Norm on a subset of nodes disp_norm = simulation.displacement( node_ids=simulation.mesh.node_ids[10:], norm=True ) disp_norm.plot() # --- Stress --- # Raw elemental nodal stress tensor (default location) stress = simulation.stress() # Averaged nodal stress stress_nodal = simulation.stress_nodal() # Averaged elemental stress stress_elemental = simulation.stress_elemental() # Von Mises equivalent stress at nodes eqv_stress = simulation.stress_eqv_von_mises_nodal() eqv_stress.plot() # Principal stress components (1st principal) principal_stress = simulation.stress_principal_elemental(components=[1]) principal_stress.plot() # --- Elastic strain --- strain = simulation.elastic_strain_nodal() strain_eqv = simulation.elastic_strain_eqv_von_mises_nodal() ``` -------------------------------- ### Access ElectricField Result Object Source: https://github.com/ansys/pydpf-post/blob/main/doc/source/user_guide/accessing_results.rst Instantiate the solution object and then the electric field result object. This is useful for accessing vector field data. ```python >>> from ansys.dpf import post >>> from ansys.dpf.post import examples >>> solution = post.load_solution(examples.electric_therm) >>> electric_field = solution.electric_field() ``` -------------------------------- ### Simulation.mesh: Mesh Exploration Source: https://context7.com/ansys/pydpf-post/llms.txt Access mesh properties such as node and element IDs, element types, connectivity, and named selections. This snippet requires importing `ansys.dpf.post` and `ansys.dpf.post.examples`. ```python from ansys.dpf import post from ansys.dpf.post import examples simulation = post.StaticMechanicalSimulation(examples.find_static_rst()) mesh = simulation.mesh print(mesh) # Node and element ID arrays node_ids = mesh.node_ids element_ids = mesh.element_ids print(f"Nodes: {len(node_ids)}, Elements: {len(element_ids)}") # Named selections scoped to the mesh print(mesh.named_selections) # Node coordinates and element connectivity nodes = mesh.nodes # NodeListByIndex elems = mesh.elements # ElementListByIndex first_elem = elems[0] print(first_elem.type, first_elem.id, first_elem.node_ids) # Plot the mesh simulation.plot() ``` -------------------------------- ### Access Temperature Scalar Field Source: https://github.com/ansys/pydpf-post/blob/main/doc/source/user_guide/accessing_results.rst Loads a solution and instantiates the temperature result object to access its scalar field data. ```python from ansys.dpf import post from ansys.dpf.post import examples solution = post.load_solution(examples.multishells_rst) temperature = solution.temperature() temp = temperature.scalar temp.get_data_at_field() ``` -------------------------------- ### Export Fields Container to HDF5 using PyDPF-Core Operator Source: https://github.com/ansys/pydpf-post/blob/main/doc/source/user_guide/extending_to_core.rst Utilize the 'serialize_to_hdf5' operator from PyDPF-Core to export a fields container to an HDF5 file. This requires setting up the operator and its input connections. ```python from ansys.dpf import post from ansys.dpf.post import examples solution = post.load_solution(examples.multishells_rst) displacement = solution.displacement() norm = displacement.norm fields_container = norm.result_fields_container from ansys.dpf import core h5_operator = core.Operator("serialize_to_hdf5") h5_operator.inputs.mesh.connect(solution.mesh) h5_operator.inputs.file_path.connect("hdf5_example.h5") h5_operator.inputs.data.connect(fields_container) h5_operator.eval() ``` -------------------------------- ### Plot Normal Stresses Source: https://github.com/ansys/pydpf-post/blob/main/doc/source/user_guide/plotting.rst Plots the XX component of nodal stress. Note that plotting raw data at Gauss points is not directly available; data must be averaged at nodes or elements. Ensure the simulation object is loaded and the stress data is extracted. ```python Instantiate the simulation object >>> from ansys.dpf import post >>> from ansys.dpf.post import examples >>> simulation = post.load_simulation(examples.download_crankshaft()) Extract the XX stress data >>> stress_xx = simulation.stress_nodal(components=["XX"]) Plot the data and save the image >>> stress_xx.plot(screenshot="crankshaft_stress_xx.png") ``` -------------------------------- ### Access Scalar Data of ElectricPotential Source: https://github.com/ansys/pydpf-post/blob/main/doc/source/user_guide/accessing_results.rst After instantiating the electric potential result object, access its 'scalar' attribute to retrieve the scalar data. This is useful for scalar fields. ```python >>> from ansys.dpf import post >>> from ansys.dpf.post import examples >>> solution = post.load_solution(examples.multishells_rst) >>> electric_potential = solution.electric_potential() >>> ep = electric_potential.scalar >>> ep.get_data_at_field() ``` -------------------------------- ### Export Fields Container to VTK using PyDPF-Core Operator Source: https://github.com/ansys/pydpf-post/blob/main/doc/source/user_guide/extending_to_core.rst Use the 'vtk_export' operator from PyDPF-Core to export a fields container to a VTK file. Ensure the necessary imports and connections are made. ```python from ansys.dpf import post from ansys.dpf.post import examples solution = post.load_solution(examples.multishells_rst) displacement = solution.displacement() norm = displacement.norm fields_container = norm.result_fields_container from ansys.dpf import core vtk_operator = core.Operator("vtk_export") vtk_operator.inputs.mesh.connect(solution.mesh) vtk_operator.inputs.file_path.connect("vtk_example.vtk") vtk_operator.inputs.fields1.connect(fields_container) vtk_operator.run() ``` -------------------------------- ### Plot Von Mises Stress (Ansys 2023 R1+) Source: https://github.com/ansys/pydpf-post/blob/main/doc/source/getting_started/demo.rst Extracts and plots equivalent Von Mises stress results from a loaded simulation using PyDPF-Post for Ansys 2023 R1 and later. ```python >>> stress_eqv = simulation.stress_eqv_von_mises_nodal() >>> stress_eqv.plot() ``` -------------------------------- ### Plot Total Deformation Source: https://github.com/ansys/pydpf-post/blob/main/doc/source/user_guide/plotting.rst Plots the norm of the displacement vector field. Ensure the simulation object is loaded and the displacement data is extracted. ```python Instantiate the solution object >>> from ansys.dpf import post >>> from ansys.dpf.post import examples >>> simulation = post.load_simulation(examples.download_crankshaft()) Instantiate a dataframe object containing the displacement norm data >>> displacement_norm = simulation.displacement(norm=True) Plot the data and save the image >>> displacement_norm.plot(screenshot="crankshaft_disp.png") ``` -------------------------------- ### Compute Min/Max on DataFrame Source: https://context7.com/ansys/pydpf-post/llms.txt Compute element-wise minimum and maximum across any axis of a DataFrame. The `axis` parameter can be 'node_ids' or 'set_ids' to specify the aggregation dimension. ```python from ansys.dpf import post from ansys.dpf.post import examples simulation = post.StaticMechanicalSimulation(examples.download_crankshaft()) displacement = simulation.displacement(all_sets=True) # Maximum value per component per time step (reduce over all nodes) max_per_step = displacement.max() # axis defaults to MeshIndex print(max_per_step) max_per_step_explicit = displacement.max(axis="node_ids") print(max_per_step_explicit) # Maximum value per node per component across all time steps max_per_node = displacement.max(axis="set_ids") print(max_per_node) # Overall scalar maximum overall_max = displacement.max(axis="set_ids").max() print(overall_max) # Minimum min_per_step = displacement.min() min_per_node = displacement.min(axis="set_ids") overall_min = min_per_node.min() print(overall_min) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.