.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/gallery_examples/013_thermal_example.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_gallery_examples_013_thermal_example.py: .. _thermal_example: Thermal analysis ---------------- This example shows how to evaluate a thermal analysis. The simulation's thermal analysis results are also the input of a structural analysis. Therefore, the RST file contains temperature and structural results. The example imitates a printed circuit board (PCB) that was modeled with Ansys Composites PrepPost (ACP), using the solid model feature to generate the volume mesh. Descriptions of how to extract temperatures for a specific ply and material are provided. .. note:: When using a Workbench project, use the :func:`.get_composite_files_from_workbench_result_folder` method to obtain the input files. .. GENERATED FROM PYTHON SOURCE LINES 50-55 Set up analysis ~~~~~~~~~~~~~~~ Setting up the analysis consists of loading the required modules, connecting to the DPF server, and retrieving the example files. .. GENERATED FROM PYTHON SOURCE LINES 55-68 .. code-block:: Python import ansys.dpf.core as dpf import numpy as np from ansys.dpf.composites.composite_model import CompositeModel from ansys.dpf.composites.example_helper import get_continuous_fiber_example_files from ansys.dpf.composites.layup_info import get_all_analysis_ply_names from ansys.dpf.composites.ply_wise_data import SpotReductionStrategy, get_ply_wise_data from ansys.dpf.composites.select_indices import get_selected_indices_by_dpf_material_ids from ansys.dpf.composites.server_helpers import connect_to_or_start_server server = connect_to_or_start_server() composite_files = get_continuous_fiber_example_files(server, "thermal_solid") .. GENERATED FROM PYTHON SOURCE LINES 69-73 Initialize the model ~~~~~~~~~~~~~~~~~~~~ Initialize the composite model with the composite files and server. The model provides access to the mesh, results, lay-up, and materials. .. GENERATED FROM PYTHON SOURCE LINES 73-75 .. code-block:: Python composite_model = CompositeModel(composite_files, server) .. GENERATED FROM PYTHON SOURCE LINES 76-79 Get temperature results ~~~~~~~~~~~~~~~~~~~~~~~ The temperatures are stored under ``structural_temperature``. .. GENERATED FROM PYTHON SOURCE LINES 79-82 .. code-block:: Python temp_op = composite_model.core_model.results.structural_temperature() temperatures_fc = temp_op.outputs.fields_container() .. GENERATED FROM PYTHON SOURCE LINES 83-87 Get ply results ~~~~~~~~~~~~~~~ Extract the ply-wise results by passing the ply name to the function :func:`.get_ply_wise_data`. .. GENERATED FROM PYTHON SOURCE LINES 87-102 .. code-block:: Python all_ply_names = get_all_analysis_ply_names(composite_model.get_mesh()) print(all_ply_names) # The component of the temperature is 0 which is the default value. nodal_values = get_ply_wise_data( field=temperatures_fc, ply_name="P1L1__ModelingPly.8", mesh=composite_model.get_mesh(), spot_reduction_strategy=SpotReductionStrategy.MAX, requested_location=dpf.locations.nodal, ) composite_model.get_mesh().plot(nodal_values) .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/gallery_examples/images/sphx_glr_013_thermal_example_001.png :alt: 013 thermal example :srcset: /examples/gallery_examples/images/sphx_glr_013_thermal_example_001.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: /home/runner/work/pydpf-composites/pydpf-composites/doc/source/examples/gallery_examples/images/sphx_glr_013_thermal_example_001.vtksz .. rst-class:: sphx-glr-script-out .. code-block:: none ['P1L1__p1_2_4_6', 'P1L1__p3', 'P1L1__ModelingPly.1', 'P1L1__p5', 'P1L1__ModelingPly.6', 'P1L1__ModelingPly.5', 'P1L1__ModelingPly.4', 'P1L1__ModelingPly.2', 'P1L1__ModelingPly.7', 'P1L1__ModelingPly.8', 'P1L1__ModelingPly.3'] .. GENERATED FROM PYTHON SOURCE LINES 103-108 Get results by material ~~~~~~~~~~~~~~~~~~~~~~~ You can filter the results by material. In this example, the element-wise maximum temperature is extracted for the material `Honeycomb Aluminum Alloy`. .. GENERATED FROM PYTHON SOURCE LINES 108-130 .. code-block:: Python print(composite_model.material_names) material_id = composite_model.material_names["Honeycomb Aluminum Alloy"] # get the last result field temperatures_field = temperatures_fc[-1] material_result_field = dpf.field.Field(location=dpf.locations.elemental, nature=dpf.natures.scalar) # performance optimization: use a local field instead of a field which is pushed to the server with material_result_field.as_local_field() as local_result_field: element_ids = temperatures_field.scoping.ids for element_id in element_ids: element_info = composite_model.get_element_info(element_id) assert element_info is not None if material_id in element_info.dpf_material_ids: temp_data = temperatures_field.get_entity_data_by_id(element_id) selected_indices = get_selected_indices_by_dpf_material_ids(element_info, [material_id]) value = np.max(temp_data[selected_indices]) local_result_field.append([value], element_id) composite_model.get_mesh().plot(material_result_field) .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/gallery_examples/images/sphx_glr_013_thermal_example_002.png :alt: 013 thermal example :srcset: /examples/gallery_examples/images/sphx_glr_013_thermal_example_002.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: /home/runner/work/pydpf-composites/pydpf-composites/doc/source/examples/gallery_examples/images/sphx_glr_013_thermal_example_002.vtksz .. rst-class:: sphx-glr-script-out .. code-block:: none {'Honeycomb Aluminum Alloy': np.int32(1), 'UD Resin Epoxy/E-Glass': np.int32(2)} .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 8.302 seconds) .. _sphx_glr_download_examples_gallery_examples_013_thermal_example.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 013_thermal_example.ipynb <013_thermal_example.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 013_thermal_example.py <013_thermal_example.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 013_thermal_example.zip <013_thermal_example.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_