.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/modeling_features/003-simple-selection-rules.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_003-simple-selection-rules.py: .. _basic_selection_rules_example: Basic selection rules ===================== This example shows the basic usage of selection rules, which enable you to select elements through geometrical operations and thus to shape plies. The example only shows the PyACP part of the setup. For more advanced selection rule usage, see :ref:`advanced_selection_rules_example`. For a complete composite analysis, see :ref:`pymapdl_workflow_example`. .. GENERATED FROM PYTHON SOURCE LINES 38-42 Import modules -------------- Import the standard library and third-party dependencies. .. GENERATED FROM PYTHON SOURCE LINES 42-45 .. code-block:: Python import pathlib import tempfile .. 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 LinkedSelectionRule, launch_acp from ansys.acp.core.extras import ExampleKeys, get_example_file .. GENERATED FROM PYTHON SOURCE LINES 54-56 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-70 Load the model from the input file. .. GENERATED FROM PYTHON SOURCE LINES 70-73 .. code-block:: Python model = acp.import_model(input_file) print(model.unit_system) .. rst-class:: sphx-glr-script-out .. code-block:: none mks .. GENERATED FROM PYTHON SOURCE LINES 74-75 Visualize the loaded mesh. .. GENERATED FROM PYTHON SOURCE LINES 75-79 .. code-block:: Python mesh = model.mesh.to_pyvista() mesh.plot(show_edges=True) .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/modeling_features/images/sphx_glr_003-simple-selection-rules_001.png :alt: 003 simple selection rules :srcset: /examples/modeling_features/images/sphx_glr_003-simple-selection-rules_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_003-simple-selection-rules_001.vtksz .. GENERATED FROM PYTHON SOURCE LINES 80-82 Create a Parallel Rule ---------------------- .. GENERATED FROM PYTHON SOURCE LINES 84-85 Create parallel selection rule and assign it to the existing ply. .. GENERATED FROM PYTHON SOURCE LINES 85-97 .. code-block:: Python parallel_rule = model.create_parallel_selection_rule( name="parallel_rule", origin=(0, 0, 0), direction=(1, 0, 0), lower_limit=0.005, upper_limit=1, ) modeling_ply = model.modeling_groups["modeling_group"].modeling_plies["ply"] modeling_ply.selection_rules = [LinkedSelectionRule(parallel_rule)] .. GENERATED FROM PYTHON SOURCE LINES 98-99 Plot the ply thickness. .. GENERATED FROM PYTHON SOURCE LINES 99-103 .. 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_003-simple-selection-rules_002.png :alt: 003 simple selection rules :srcset: /examples/modeling_features/images/sphx_glr_003-simple-selection-rules_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_003-simple-selection-rules_002.vtksz .. GENERATED FROM PYTHON SOURCE LINES 104-106 Create a Cylindrical Rule ------------------------- .. GENERATED FROM PYTHON SOURCE LINES 108-109 Create a cylindrical selection rule and add it to the ply. This will intersect the two rules. .. GENERATED FROM PYTHON SOURCE LINES 109-118 .. code-block:: Python cylindrical_rule = model.create_cylindrical_selection_rule( name="cylindrical_rule", origin=(0.005, 0, 0.005), direction=(0, 1, 0), radius=0.002, ) modeling_ply.selection_rules.append(LinkedSelectionRule(cylindrical_rule)) .. GENERATED FROM PYTHON SOURCE LINES 119-120 Plot the ply thickness. .. GENERATED FROM PYTHON SOURCE LINES 120-125 .. 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_003-simple-selection-rules_003.png :alt: 003 simple selection rules :srcset: /examples/modeling_features/images/sphx_glr_003-simple-selection-rules_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_003-simple-selection-rules_003.vtksz .. GENERATED FROM PYTHON SOURCE LINES 126-128 Create a Spherical Rule ----------------------- .. GENERATED FROM PYTHON SOURCE LINES 130-132 Create a spherical selection rule and assign it to the ply. Now, only the spherical rule is active. .. GENERATED FROM PYTHON SOURCE LINES 132-140 .. code-block:: Python spherical_rule = model.create_spherical_selection_rule( name="spherical_rule", origin=(0.003, 0, 0.005), radius=0.002, ) modeling_ply.selection_rules = [LinkedSelectionRule(spherical_rule)] .. GENERATED FROM PYTHON SOURCE LINES 141-142 Plot the ply thickness. .. GENERATED FROM PYTHON SOURCE LINES 142-146 .. 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_003-simple-selection-rules_004.png :alt: 003 simple selection rules :srcset: /examples/modeling_features/images/sphx_glr_003-simple-selection-rules_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_003-simple-selection-rules_004.vtksz .. GENERATED FROM PYTHON SOURCE LINES 147-149 Create a Tube Rule ------------------ .. GENERATED FROM PYTHON SOURCE LINES 151-153 Create a tube selection rule and assign it to the ply. Now, only the tube rule is active. .. GENERATED FROM PYTHON SOURCE LINES 153-163 .. code-block:: Python tube_rule = model.create_tube_selection_rule( name="spherical_rule", # Select the pre-exsting _FIXEDSU edge which is the edge at x=0 edge_set=model.edge_sets["_FIXEDSU"], inner_radius=0.001, outer_radius=0.003, ) modeling_ply.selection_rules = [LinkedSelectionRule(tube_rule)] .. GENERATED FROM PYTHON SOURCE LINES 164-165 Plot the ply thickness. .. GENERATED FROM PYTHON SOURCE LINES 165-168 .. 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_003-simple-selection-rules_005.png :alt: 003 simple selection rules :srcset: /examples/modeling_features/images/sphx_glr_003-simple-selection-rules_005.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: /home/runner/work/pyacp/pyacp/doc/source/examples/modeling_features/images/sphx_glr_003-simple-selection-rules_005.vtksz .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 6.328 seconds) .. _sphx_glr_download_examples_modeling_features_003-simple-selection-rules.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 003-simple-selection-rules.ipynb <003-simple-selection-rules.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 003-simple-selection-rules.py <003-simple-selection-rules.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 003-simple-selection-rules.zip <003-simple-selection-rules.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_