.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/modeling_features/006-layup-thickness-definitions.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_006-layup-thickness-definitions.py: .. _thickness_definition_example: Thickness definition ==================== This example shows how the thickness of a ply can be defined by a geometry or a lookup table. The example only shows the PyACP part of the setup. For a complete composite analysis, see :ref:`pymapdl_workflow_example`. .. GENERATED FROM PYTHON SOURCE LINES 36-40 Import modules -------------- Import the standard library and third-party dependencies. .. GENERATED FROM PYTHON SOURCE LINES 40-46 .. code-block:: Python import pathlib import tempfile import numpy as np import pyvista .. GENERATED FROM PYTHON SOURCE LINES 47-48 Import the PyACP dependencies. .. GENERATED FROM PYTHON SOURCE LINES 48-53 .. code-block:: Python from ansys.acp.core import PhysicalDimension, ThicknessType, launch_acp from ansys.acp.core.extras import FLAT_PLATE_SOLID_CAMERA, ExampleKeys, get_example_file .. GENERATED FROM PYTHON SOURCE LINES 55-57 Start ACP and load the model ---------------------------- .. GENERATED FROM PYTHON SOURCE LINES 59-60 Get the example file from the server. .. GENERATED FROM PYTHON SOURCE LINES 60-64 .. code-block:: Python tempdir = tempfile.TemporaryDirectory() WORKING_DIR = pathlib.Path(tempdir.name) input_file = get_example_file(ExampleKeys.MINIMAL_FLAT_PLATE, WORKING_DIR) .. GENERATED FROM PYTHON SOURCE LINES 65-66 Launch the PyACP server and connect to it. .. GENERATED FROM PYTHON SOURCE LINES 66-68 .. code-block:: Python acp = launch_acp() .. GENERATED FROM PYTHON SOURCE LINES 69-71 Load the model from the input file. This example's input file contains a flat plate with a single ply. .. GENERATED FROM PYTHON SOURCE LINES 71-81 .. code-block:: Python model = acp.import_model(input_file) print(model.unit_system) # Plot the nominal ply thickness. modeling_ply = model.modeling_groups["modeling_group"].modeling_plies["ply"] model.update() assert model.elemental_data.thickness is not None model.elemental_data.thickness.get_pyvista_mesh(mesh=model.mesh).plot(show_edges=True) .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/modeling_features/images/sphx_glr_006-layup-thickness-definitions_001.png :alt: 006 layup thickness definitions :srcset: /examples/modeling_features/images/sphx_glr_006-layup-thickness-definitions_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_006-layup-thickness-definitions_001.vtksz .. rst-class:: sphx-glr-script-out .. code-block:: none mks .. GENERATED FROM PYTHON SOURCE LINES 82-84 Define the thickness from a geometry ------------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 86-87 Add the solid geometry to the model that defines the thickness. .. GENERATED FROM PYTHON SOURCE LINES 87-95 .. code-block:: Python thickness_geometry_file = get_example_file(ExampleKeys.THICKNESS_GEOMETRY, WORKING_DIR) thickness_geometry = model.create_cad_geometry() thickness_geometry.refresh(thickness_geometry_file) # Note: It is important to update the model here, because the root_shapes of the # cad_geometry are not available until the model is updated. model.update() .. GENERATED FROM PYTHON SOURCE LINES 96-97 Create a virtual geometry from the CAD geometry. .. GENERATED FROM PYTHON SOURCE LINES 97-101 .. code-block:: Python thickness_virtual_geometry = model.create_virtual_geometry( name="thickness_virtual_geometry", cad_components=thickness_geometry.root_shapes.values() ) .. GENERATED FROM PYTHON SOURCE LINES 102-103 Set the thickness type to ``FROM_GEOMETRY`` and define the virtual geometry. .. GENERATED FROM PYTHON SOURCE LINES 103-106 .. code-block:: Python modeling_ply.thickness_type = ThicknessType.FROM_GEOMETRY modeling_ply.thickness_geometry = thickness_virtual_geometry .. GENERATED FROM PYTHON SOURCE LINES 107-108 Plot the ply thickness together with the geometry defining the thickness. .. GENERATED FROM PYTHON SOURCE LINES 108-123 .. code-block:: Python model.update() assert model.elemental_data.thickness is not None plotter = pyvista.Plotter() # Plot the surface of the geometry geometry_polydata = thickness_geometry.visualization_mesh.to_pyvista() plotter.add_mesh(geometry_polydata, color="grey", opacity=0.05) # Plot the edges of the geometry edges = geometry_polydata.extract_feature_edges() plotter.add_mesh(edges, color="white", line_width=4) plotter.add_mesh(edges, color="black", line_width=2) # Plot the ply thickness plotter.add_mesh(model.elemental_data.thickness.get_pyvista_mesh(mesh=model.mesh), show_edges=True) plotter.camera_position = FLAT_PLATE_SOLID_CAMERA plotter.show() .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/modeling_features/images/sphx_glr_006-layup-thickness-definitions_002.png :alt: 006 layup thickness definitions :srcset: /examples/modeling_features/images/sphx_glr_006-layup-thickness-definitions_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_006-layup-thickness-definitions_002.vtksz .. GENERATED FROM PYTHON SOURCE LINES 124-126 Define the thickness from a lookup table ---------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 128-133 Create the data for the lookup table. Make a 20x20 grid of points to define a thickness function on. In this example, the mesh of the lookup table is finer than the finite element mesh, and the thickness is interpolated onto the finite element mesh. Note that the plate lies in the xz plane and the thickness is defined in the y direction. .. GENERATED FROM PYTHON SOURCE LINES 133-139 .. code-block:: Python plate_side_length = 0.01 num_points = 3 x_coordinates = np.linspace(0, plate_side_length, num_points) z_coordinates = np.linspace(0, plate_side_length, num_points) xx, zz = np.meshgrid(x_coordinates, z_coordinates) .. GENERATED FROM PYTHON SOURCE LINES 140-141 Create a thickness that equals the distance to the center of the plate. .. GENERATED FROM PYTHON SOURCE LINES 141-145 .. code-block:: Python center_x = 0.005 center_z = 0.005 thickness = np.sqrt((xx - center_x) ** 2 + (zz - center_z) ** 2).ravel() .. GENERATED FROM PYTHON SOURCE LINES 146-148 Create the point coordinates for the lookup table. The y coordinate is always zero. .. GENERATED FROM PYTHON SOURCE LINES 148-157 .. code-block:: Python points = np.stack( [ xx.ravel(), np.zeros(xx.ravel().shape), zz.ravel(), ], axis=1, ) .. GENERATED FROM PYTHON SOURCE LINES 158-159 Now you have a list of point coordinates: .. GENERATED FROM PYTHON SOURCE LINES 159-161 .. code-block:: Python print(points) .. rst-class:: sphx-glr-script-out .. code-block:: none [[0. 0. 0. ] [0.005 0. 0. ] [0.01 0. 0. ] [0. 0. 0.005] [0.005 0. 0.005] [0.01 0. 0.005] [0. 0. 0.01 ] [0.005 0. 0.01 ] [0.01 0. 0.01 ]] .. GENERATED FROM PYTHON SOURCE LINES 162-163 And the corresponding thickness values. .. GENERATED FROM PYTHON SOURCE LINES 163-165 .. code-block:: Python print(thickness) .. rst-class:: sphx-glr-script-out .. code-block:: none [0.00707107 0.005 0.00707107 0.005 0. 0.005 0.00707107 0.005 0.00707107] .. GENERATED FROM PYTHON SOURCE LINES 166-167 Create the lookup table and add the coordinates and thickness data. .. GENERATED FROM PYTHON SOURCE LINES 167-173 .. code-block:: Python lookup_table = model.create_lookup_table_3d() lookup_table.columns["Location"].data = points thickness_column = lookup_table.create_column( data=thickness, physical_dimension=PhysicalDimension.LENGTH ) .. GENERATED FROM PYTHON SOURCE LINES 174-175 Set the thickness type to ``FROM_TABLE`` and assign the thickness column. .. GENERATED FROM PYTHON SOURCE LINES 175-178 .. code-block:: Python modeling_ply.thickness_type = ThicknessType.FROM_TABLE modeling_ply.thickness_field = thickness_column .. GENERATED FROM PYTHON SOURCE LINES 179-180 Plot the ply thickness. .. GENERATED FROM PYTHON SOURCE LINES 180-183 .. code-block:: Python model.update() assert model.elemental_data.thickness is not None model.elemental_data.thickness.get_pyvista_mesh(mesh=model.mesh).plot(show_edges=True) .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/modeling_features/images/sphx_glr_006-layup-thickness-definitions_003.png :alt: 006 layup thickness definitions :srcset: /examples/modeling_features/images/sphx_glr_006-layup-thickness-definitions_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_006-layup-thickness-definitions_003.vtksz .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 5.759 seconds) .. _sphx_glr_download_examples_modeling_features_006-layup-thickness-definitions.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 006-layup-thickness-definitions.ipynb <006-layup-thickness-definitions.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 006-layup-thickness-definitions.py <006-layup-thickness-definitions.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 006-layup-thickness-definitions.zip <006-layup-thickness-definitions.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_