.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/modeling_features/06-ply-direction-lookup-table.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_06-ply-direction-lookup-table.py: .. _direction_definition_example: Direction definition example ============================ This example shows how to define directions from lookup tables. They can be either reference directions for oriented selection sets or draping angles for modeling plies. 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-45 .. code-block:: Python import pathlib import tempfile import numpy as np .. GENERATED FROM PYTHON SOURCE LINES 46-47 Import the PyACP dependencies. .. GENERATED FROM PYTHON SOURCE LINES 47-59 .. code-block:: Python from ansys.acp.core import ( ACPWorkflow, DimensionType, DrapingType, LookUpTableColumnValueType, PlyType, RosetteSelectionMethod, get_directions_plotter, launch_acp, ) from ansys.acp.core.extras import ExampleKeys, get_example_file .. GENERATED FROM PYTHON SOURCE LINES 60-62 Start ACP and load the model ---------------------------- .. GENERATED FROM PYTHON SOURCE LINES 64-65 Get the example file from the server. .. GENERATED FROM PYTHON SOURCE LINES 65-69 .. code-block:: Python tempdir = tempfile.TemporaryDirectory() WORKING_DIR = pathlib.Path(tempdir.name) input_file = get_example_file(ExampleKeys.BASIC_FLAT_PLATE_DAT, WORKING_DIR) .. GENERATED FROM PYTHON SOURCE LINES 70-71 Launch the PyACP server and connect to it. .. GENERATED FROM PYTHON SOURCE LINES 71-73 .. code-block:: Python acp = launch_acp() .. GENERATED FROM PYTHON SOURCE LINES 74-78 Define the input file and instantiate an ``ACPWorkflow`` instance. The ``ACPWorkflow`` class provides convenience methods that simplify the handling. It automatically creates a model based on the input file. This example's input file contains a flat plate with a single ply. .. GENERATED FROM PYTHON SOURCE LINES 78-88 .. code-block:: Python workflow = ACPWorkflow.from_cdb_or_dat_file( acp=acp, cdb_or_dat_file_path=input_file, local_working_directory=WORKING_DIR, ) model = workflow.model print(workflow.working_directory.path) print(model.unit_system) .. rst-class:: sphx-glr-script-out .. code-block:: none /tmp/tmpul4irke5 mks .. GENERATED FROM PYTHON SOURCE LINES 89-91 Setup materials and oriented selection set ------------------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 91-93 .. code-block:: Python # .. GENERATED FROM PYTHON SOURCE LINES 94-95 Create a material and fabric. .. GENERATED FROM PYTHON SOURCE LINES 95-102 .. code-block:: Python ud_material = model.create_material( name="UD", ply_type=PlyType.REGULAR, ) fabric = model.create_fabric(name="UD", material=ud_material, thickness=0.1) .. GENERATED FROM PYTHON SOURCE LINES 103-104 Create a parallel rosette. .. GENERATED FROM PYTHON SOURCE LINES 104-106 .. code-block:: Python rosette = model.create_rosette() .. GENERATED FROM PYTHON SOURCE LINES 107-108 Create an oriented selection set (OSS) and assign the rosette. .. GENERATED FROM PYTHON SOURCE LINES 108-116 .. code-block:: Python oss = model.create_oriented_selection_set( name="oss", orientation_direction=(0.0, 1.0, 0), element_sets=[model.element_sets["All_Elements"]], rosettes=[rosette], ) .. GENERATED FROM PYTHON SOURCE LINES 117-119 Plot the orientation and reference direction of the OSS. The reference direction is defined by the rosette. .. GENERATED FROM PYTHON SOURCE LINES 119-125 .. code-block:: Python model.update() plotter = get_directions_plotter( model=model, components=[oss.elemental_data.orientation, oss.elemental_data.reference_direction] ) plotter.show() .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/modeling_features/images/sphx_glr_06-ply-direction-lookup-table_001.png :alt: 06 ply direction lookup table :srcset: /examples/modeling_features/images/sphx_glr_06-ply-direction-lookup-table_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_06-ply-direction-lookup-table_001.vtksz .. GENERATED FROM PYTHON SOURCE LINES 126-128 Define reference direction from lookup table -------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 130-131 Create a 3D lookup table to store the direction and angle corrections. .. GENERATED FROM PYTHON SOURCE LINES 131-133 .. code-block:: Python lookup_table = model.create_lookup_table_3d() .. GENERATED FROM PYTHON SOURCE LINES 134-135 Create a grid of points on the plate where the lookup table values are stored. .. GENERATED FROM PYTHON SOURCE LINES 135-150 .. code-block:: Python plate_side_length = 0.01 num_points = 10 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) points = np.stack( [ xx.ravel(), np.zeros(xx.ravel().shape), zz.ravel(), ], axis=1, ) .. GENERATED FROM PYTHON SOURCE LINES 151-152 Compute the directions tangential to circles around the point (0,0,0). .. GENERATED FROM PYTHON SOURCE LINES 152-155 .. code-block:: Python normal = np.array([0, 1, 0]) directions = np.cross(points, normal) .. GENERATED FROM PYTHON SOURCE LINES 156-157 Create the lookup table and add the direction data. .. GENERATED FROM PYTHON SOURCE LINES 157-164 .. code-block:: Python lookup_table.columns["Location"].data = points direction_column = lookup_table.create_column( data=directions, dimension_type=DimensionType.DIMENSIONLESS, value_type=LookUpTableColumnValueType.DIRECTION, ) .. GENERATED FROM PYTHON SOURCE LINES 165-166 Assign the lookup table to the OSS. .. GENERATED FROM PYTHON SOURCE LINES 166-169 .. code-block:: Python oss.rosette_selection_method = RosetteSelectionMethod.DIRECTIONS_FROM_TABULAR_VALUES oss.reference_direction_field = direction_column .. GENERATED FROM PYTHON SOURCE LINES 170-171 Plot the orientation and the reference direction of the OSS. .. GENERATED FROM PYTHON SOURCE LINES 171-177 .. code-block:: Python model.update() plotter = get_directions_plotter( model=model, components=[oss.elemental_data.orientation, oss.elemental_data.reference_direction] ) plotter.show() .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/modeling_features/images/sphx_glr_06-ply-direction-lookup-table_002.png :alt: 06 ply direction lookup table :srcset: /examples/modeling_features/images/sphx_glr_06-ply-direction-lookup-table_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_06-ply-direction-lookup-table_002.vtksz .. GENERATED FROM PYTHON SOURCE LINES 178-179 Reset the OSS so that it may use the rosette again for the reference direction. .. GENERATED FROM PYTHON SOURCE LINES 179-181 .. code-block:: Python oss.rosette_selection_method = RosetteSelectionMethod.MINIMUM_ANGLE .. GENERATED FROM PYTHON SOURCE LINES 182-187 Define draping angles from lookup table --------------------------------------- %% Compute a correction angle to define circular fiber paths. .. GENERATED FROM PYTHON SOURCE LINES 187-194 .. code-block:: Python correction_angle = np.arctan2(xx.ravel(), zz.ravel()) * 180 / np.pi angle_column_1 = lookup_table.create_column( data=correction_angle, dimension_type=DimensionType.DIMENSIONLESS, value_type=LookUpTableColumnValueType.SCALAR, ) .. GENERATED FROM PYTHON SOURCE LINES 195-196 Compute the transverse correction angle, assuming a constant shear angle of -30°. .. GENERATED FROM PYTHON SOURCE LINES 196-204 .. code-block:: Python shear_angle = -30 transverse_correction_angle = correction_angle + shear_angle angle_column_2 = lookup_table.create_column( data=transverse_correction_angle, dimension_type=DimensionType.DIMENSIONLESS, value_type=LookUpTableColumnValueType.SCALAR, ) .. GENERATED FROM PYTHON SOURCE LINES 205-206 Create a modeling ply with the angle corrections. .. GENERATED FROM PYTHON SOURCE LINES 206-217 .. code-block:: Python modeling_group = model.create_modeling_group(name="modeling_group") modeling_ply = modeling_group.create_modeling_ply( name="ply", ply_angle=0, ply_material=fabric, oriented_selection_sets=[oss], draping_type=DrapingType.TABULAR_VALUES, draping_angle_1_field=angle_column_1, draping_angle_2_field=angle_column_2, ) .. GENERATED FROM PYTHON SOURCE LINES 218-219 Plot the directions of the modeling ply. First, plot the directions without correction angles. .. GENERATED FROM PYTHON SOURCE LINES 219-229 .. code-block:: Python model.update() plotter = get_directions_plotter( model=model, components=[ modeling_ply.elemental_data.fiber_direction, modeling_ply.elemental_data.transverse_direction, ], ) plotter.show() .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/modeling_features/images/sphx_glr_06-ply-direction-lookup-table_003.png :alt: 06 ply direction lookup table :srcset: /examples/modeling_features/images/sphx_glr_06-ply-direction-lookup-table_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_06-ply-direction-lookup-table_003.vtksz .. GENERATED FROM PYTHON SOURCE LINES 230-231 Next, plot the draped directions, including the correction angles, from the lookup table. .. GENERATED FROM PYTHON SOURCE LINES 231-239 .. code-block:: Python plotter = get_directions_plotter( model=model, components=[ modeling_ply.elemental_data.draped_fiber_direction, modeling_ply.elemental_data.draped_transverse_direction, ], ) plotter.show() .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/modeling_features/images/sphx_glr_06-ply-direction-lookup-table_004.png :alt: 06 ply direction lookup table :srcset: /examples/modeling_features/images/sphx_glr_06-ply-direction-lookup-table_004.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: /home/runner/work/pyacp/pyacp/doc/source/examples/modeling_features/images/sphx_glr_06-ply-direction-lookup-table_004.vtksz .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 5.324 seconds) .. _sphx_glr_download_examples_modeling_features_06-ply-direction-lookup-table.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 06-ply-direction-lookup-table.ipynb <06-ply-direction-lookup-table.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 06-ply-direction-lookup-table.py <06-ply-direction-lookup-table.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 06-ply-direction-lookup-table.zip <06-ply-direction-lookup-table.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_