.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/modeling_features/007-sensor.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_modeling_features_007-sensor.py: .. _sensor_example: Sensor ====== The :class:`.Sensor` capabilities to analyze the composite structure is demonstrated in this example. A sensor is used to compute the weight, area, cost, etc. of the model or specific entities such as ply material, modeling ply, etc. .. GENERATED FROM PYTHON SOURCE LINES 36-40 Import modules -------------- Import the standard library and third-party dependencies. .. GENERATED FROM PYTHON SOURCE LINES 40-45 .. code-block:: Python import pathlib import tempfile import pyvista .. GENERATED FROM PYTHON SOURCE LINES 46-47 Import the PyACP dependencies. .. GENERATED FROM PYTHON SOURCE LINES 47-52 .. code-block:: Python from ansys.acp.core import SensorType, UnitSystemType, launch_acp from ansys.acp.core.extras import RACE_CARE_NOSE_CAMERA_METER, ExampleKeys, get_example_file .. GENERATED FROM PYTHON SOURCE LINES 54-56 Start ACP and load the model ---------------------------- .. GENERATED FROM PYTHON SOURCE LINES 58-59 Get the example file from the server. .. GENERATED FROM PYTHON SOURCE LINES 59-63 .. code-block:: Python tempdir = tempfile.TemporaryDirectory() WORKING_DIR = pathlib.Path(tempdir.name) acph5_input_file = get_example_file(ExampleKeys.RACE_CAR_NOSE_ACPH5, WORKING_DIR) .. GENERATED FROM PYTHON SOURCE LINES 64-65 Launch the PyACP server and connect to it. .. GENERATED FROM PYTHON SOURCE LINES 65-67 .. code-block:: Python acp = launch_acp() .. GENERATED FROM PYTHON SOURCE LINES 68-71 Load the model from the input file which contains a formula 1 front wing with layup. The plot shows the total laminate thickness per element. .. GENERATED FROM PYTHON SOURCE LINES 71-83 .. code-block:: Python model = acp.import_model(acph5_input_file) model.unit_system = UnitSystemType.SI print(model.unit_system) model.update() thickness_data = model.elemental_data.thickness if thickness_data is not None: plotter = pyvista.Plotter() plotter.add_mesh(thickness_data.get_pyvista_mesh(model.mesh), show_edges=False) plotter.camera_position = RACE_CARE_NOSE_CAMERA_METER plotter.show() .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/modeling_features/images/sphx_glr_007-sensor_001.png :alt: 007 sensor :srcset: /examples/modeling_features/images/sphx_glr_007-sensor_001.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: /home/runner/work/pyacp/pyacp/doc/source/examples/modeling_features/images/sphx_glr_007-sensor_001.vtksz .. rst-class:: sphx-glr-script-out .. code-block:: none si .. GENERATED FROM PYTHON SOURCE LINES 84-85 Set price per area for all fabrics. .. GENERATED FROM PYTHON SOURCE LINES 85-89 .. code-block:: Python model.fabrics["UD"].area_price = 15 # $/m^2 model.fabrics["woven"].area_price = 23 # $/m^2 model.fabrics["core_4mm"].area_price = 7 # $/m^2 .. GENERATED FROM PYTHON SOURCE LINES 90-92 Sensor by area -------------- .. GENERATED FROM PYTHON SOURCE LINES 94-98 Entire Model ~~~~~~~~~~~~ The first sensor is applied to the entire model to compute for example the total weight, area of production material, and material cost. .. GENERATED FROM PYTHON SOURCE LINES 98-103 .. code-block:: Python sensor_by_area = model.create_sensor( name="By Area", sensor_type=SensorType.SENSOR_BY_AREA, entities=[model.element_sets["All_Elements"]], ) .. GENERATED FROM PYTHON SOURCE LINES 104-105 Update the model to compute the sensor values. .. GENERATED FROM PYTHON SOURCE LINES 105-117 .. code-block:: Python model.update() def print_measures(my_sensor): print(f"Price: {my_sensor.price:.2f} $") print(f"Weight: {my_sensor.weight:.2f} kg") print(f"Covered area: {my_sensor.covered_area:.2f} m²") print(f"Production ply area: {my_sensor.production_ply_area:.2f} m²") cog = my_sensor.center_of_gravity print(f"Center of gravity: ({cog[0]:.2f}, {cog[1]:.2f}, {cog[2]:.2f}) m") .. GENERATED FROM PYTHON SOURCE LINES 118-119 Print the values. The ``production ply area`` is the area of production material. .. GENERATED FROM PYTHON SOURCE LINES 119-121 .. code-block:: Python print_measures(sensor_by_area) .. rst-class:: sphx-glr-script-out .. code-block:: none Price: 208.84 $ Weight: 4.48 kg Covered area: 1.70 m² Production ply area: 11.04 m² Center of gravity: (0.42, 0.10, -0.09) m .. GENERATED FROM PYTHON SOURCE LINES 122-127 Scope to a specific component ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Compute the measures for the nose only. Note that :class:`.OrientedSelectionSet` can also be used to scope the sensor. .. GENERATED FROM PYTHON SOURCE LINES 127-137 .. code-block:: Python eset_nose = model.element_sets["els_nose"] sensor_by_area.entities = [eset_nose] model.update() print_measures(sensor_by_area) plotter = pyvista.Plotter() plotter.add_mesh(eset_nose.mesh.to_pyvista(), show_edges=False, opacity=1, color="turquoise") plotter.add_mesh(model.mesh.to_pyvista(), show_edges=False, opacity=0.2) plotter.camera_position = RACE_CARE_NOSE_CAMERA_METER plotter.show() .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/modeling_features/images/sphx_glr_007-sensor_002.png :alt: 007 sensor :srcset: /examples/modeling_features/images/sphx_glr_007-sensor_002.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: /home/runner/work/pyacp/pyacp/doc/source/examples/modeling_features/images/sphx_glr_007-sensor_002.vtksz .. rst-class:: sphx-glr-script-out .. code-block:: none Price: 25.21 $ Weight: 0.56 kg Covered area: 0.39 m² Production ply area: 1.64 m² Center of gravity: (0.09, 0.37, -0.22) m .. GENERATED FROM PYTHON SOURCE LINES 138-143 Sensor by material ------------------ A sensor can also be used to compute the amount of a certain ply material (:class:`.Fabric`, :class:`.Stackup`, :class:`.SubLaminate`). .. GENERATED FROM PYTHON SOURCE LINES 143-150 .. code-block:: Python sensor_by_material = model.create_sensor( name="By Material", sensor_type=SensorType.SENSOR_BY_MATERIAL, entities=[model.fabrics["UD"]], ) print_measures(sensor_by_area) .. rst-class:: sphx-glr-script-out .. code-block:: none Price: 25.21 $ Weight: 0.56 kg Covered area: 0.39 m² Production ply area: 1.64 m² Center of gravity: (0.09, 0.37, -0.22) m .. GENERATED FROM PYTHON SOURCE LINES 151-156 Sensor by ply ------------- A sensor can also be scoped to a specific ply or a list of plies. In this example, a ply of the suction side and a ply of the pressure side of wing 3 are selected. .. GENERATED FROM PYTHON SOURCE LINES 156-174 .. code-block:: Python mg = model.modeling_groups["wing_3"] modeling_plies = [ mg.modeling_plies["mp.wing_3.1_suction"], mg.modeling_plies["mp.wing_3.1_pressure.2"], ] sensor_by_ply = model.create_sensor( name="By Ply", sensor_type=SensorType.SENSOR_BY_PLIES, entities=modeling_plies, ) model.update() print_measures(sensor_by_ply) plotter = pyvista.Plotter() for ply in modeling_plies: plotter.add_mesh(ply.mesh.to_pyvista(), show_edges=False, opacity=1, color="turquoise") plotter.add_mesh(model.mesh.to_pyvista(), show_edges=False, opacity=0.2) plotter.camera_position = RACE_CARE_NOSE_CAMERA_METER plotter.show() .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/modeling_features/images/sphx_glr_007-sensor_003.png :alt: 007 sensor :srcset: /examples/modeling_features/images/sphx_glr_007-sensor_003.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: /home/runner/work/pyacp/pyacp/doc/source/examples/modeling_features/images/sphx_glr_007-sensor_003.vtksz .. rst-class:: sphx-glr-script-out .. code-block:: none Price: 10.86 $ Weight: 0.23 kg Covered area: 0.24 m² Production ply area: 0.47 m² Center of gravity: (0.30, 0.08, -0.10) m .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 26.384 seconds) .. _sphx_glr_download_examples_modeling_features_007-sensor.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 007-sensor.ipynb <007-sensor.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 007-sensor.py <007-sensor.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 007-sensor.zip <007-sensor.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_