.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/modeling_features/02-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_02-simple-selection-rules.py: .. _basic_selection_rules_example: Basic selection rules example ============================= 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 ACPWorkflow, 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-73 Define the input file and instantiate an ``ACPWorkflow`` instance. The ``ACPWorkflow`` class provides convenience methods that simplify file 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 73-84 .. code-block:: Python workflow = ACPWorkflow.from_acph5_file( acp=acp, acph5_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/tmpa_av7ml_ mks .. GENERATED FROM PYTHON SOURCE LINES 85-86 Visualize the loaded mesh. .. GENERATED FROM PYTHON SOURCE LINES 86-90 .. 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_02-simple-selection-rules_001.png :alt: 02 simple selection rules :srcset: /examples/modeling_features/images/sphx_glr_02-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_02-simple-selection-rules_001.vtksz .. GENERATED FROM PYTHON SOURCE LINES 91-93 Create a Parallel Rule ---------------------- .. GENERATED FROM PYTHON SOURCE LINES 95-96 Create parallel selection rule and assign it to the existing ply. .. GENERATED FROM PYTHON SOURCE LINES 96-108 .. 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 109-110 Plot the ply thickness. .. GENERATED FROM PYTHON SOURCE LINES 110-114 .. 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_02-simple-selection-rules_002.png :alt: 02 simple selection rules :srcset: /examples/modeling_features/images/sphx_glr_02-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_02-simple-selection-rules_002.vtksz .. GENERATED FROM PYTHON SOURCE LINES 115-117 Create a Cylindrical Rule ------------------------- .. GENERATED FROM PYTHON SOURCE LINES 119-120 Create a cylindrical selection rule and add it to the ply. This will intersect the two rules. .. GENERATED FROM PYTHON SOURCE LINES 120-129 .. 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 130-131 Plot the ply thickness. .. GENERATED FROM PYTHON SOURCE LINES 131-136 .. 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_02-simple-selection-rules_003.png :alt: 02 simple selection rules :srcset: /examples/modeling_features/images/sphx_glr_02-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_02-simple-selection-rules_003.vtksz .. GENERATED FROM PYTHON SOURCE LINES 137-139 Create a Spherical Rule ----------------------- .. GENERATED FROM PYTHON SOURCE LINES 141-143 Create a spherical selection rule and assign it to the ply. Now, only the spherical rule is active. .. GENERATED FROM PYTHON SOURCE LINES 143-151 .. 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 152-153 Plot the ply thickness. .. GENERATED FROM PYTHON SOURCE LINES 153-157 .. 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_02-simple-selection-rules_004.png :alt: 02 simple selection rules :srcset: /examples/modeling_features/images/sphx_glr_02-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_02-simple-selection-rules_004.vtksz .. GENERATED FROM PYTHON SOURCE LINES 158-160 Create a Tube Rule ------------------ .. GENERATED FROM PYTHON SOURCE LINES 162-164 Create a tube selection rule and assign it to the ply. Now, only the tube rule is active. .. GENERATED FROM PYTHON SOURCE LINES 164-174 .. 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 175-176 Plot the ply thickness. .. GENERATED FROM PYTHON SOURCE LINES 176-179 .. 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_02-simple-selection-rules_005.png :alt: 02 simple selection rules :srcset: /examples/modeling_features/images/sphx_glr_02-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_02-simple-selection-rules_005.vtksz .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 5.936 seconds) .. _sphx_glr_download_examples_modeling_features_02-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: 02-simple-selection-rules.ipynb <02-simple-selection-rules.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 02-simple-selection-rules.py <02-simple-selection-rules.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 02-simple-selection-rules.zip <02-simple-selection-rules.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_