.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/modeling_features/020-solid_model.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_020-solid_model.py: .. _solid_model_example: Solid Model =========== This example shows how to create and shape a solid model. The solid model implements an extrusion algorithm which creates a layered solid mesh based on the shell mesh and layup definition. This solid mesh can be further processed by :class:`.ExtrusionGuide`, :class:`.SnapToGeometry`, and :class:`.CutOffGeometry`. .. GENERATED FROM PYTHON SOURCE LINES 37-38 Import the standard library and third-party dependencies. .. GENERATED FROM PYTHON SOURCE LINES 38-43 .. code-block:: Python import pathlib import tempfile import pyvista .. GENERATED FROM PYTHON SOURCE LINES 44-45 Import the PyACP dependencies. .. GENERATED FROM PYTHON SOURCE LINES 45-59 .. code-block:: Python from ansys.acp.core import ( CADGeometry, CutOffGeometryOrientationType, EdgeSetType, ExtrusionGuideType, SnapToGeometryOrientationType, VirtualGeometry, get_directions_plotter, launch_acp, ) from ansys.acp.core.extras import FLAT_PLATE_SOLID_CAMERA, ExampleKeys, get_example_file .. GENERATED FROM PYTHON SOURCE LINES 61-63 Load a minimal model ---------------------------- .. GENERATED FROM PYTHON SOURCE LINES 63-67 .. 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 68-69 Launch the PyACP server and connect to it. .. GENERATED FROM PYTHON SOURCE LINES 69-71 .. code-block:: Python acp = launch_acp() .. GENERATED FROM PYTHON SOURCE LINES 72-73 Load the model from the input file. .. GENERATED FROM PYTHON SOURCE LINES 73-75 .. code-block:: Python model = acp.import_model(input_file) .. GENERATED FROM PYTHON SOURCE LINES 76-81 Create a simple layup --------------------- %% Add more layers to the modeling ply so that it is easier to see the effects of the selection rules. .. GENERATED FROM PYTHON SOURCE LINES 81-84 .. code-block:: Python modeling_ply = model.modeling_groups["modeling_group"].modeling_plies["ply"] modeling_ply.number_of_layers = 3 .. GENERATED FROM PYTHON SOURCE LINES 85-89 Create an initial solid model ----------------------------- By default, the layup is extruded along the normal direction of the shell mesh. .. GENERATED FROM PYTHON SOURCE LINES 89-128 .. code-block:: Python solid_model = model.create_solid_model( name="Solid Model", element_sets=[model.element_sets["All_Elements"]], ) model.update() def plot_model_with_geometry(cad_geometry: CADGeometry | None, cad_geom_opacity: float = 0.1): """Plot solid model and geometry.""" plotter = pyvista.Plotter() if cad_geometry: geom_mesh = cad_geometry.visualization_mesh.to_pyvista() plotter.add_mesh(geom_mesh, color="green", opacity=cad_geom_opacity) edges = geom_mesh.extract_feature_edges() plotter.add_mesh(edges, color="white", line_width=4) plotter.add_mesh(edges, color="black", line_width=2) plotter.add_mesh(model.solid_mesh.to_pyvista(), show_edges=True) plotter.camera_position = FLAT_PLATE_SOLID_CAMERA plotter.show() plot_model_with_geometry(None) def create_virtual_geometry_from_file( example_key: ExampleKeys, ) -> tuple[CADGeometry, VirtualGeometry]: """Create a CAD geometry and virtual geometry.""" geometry_file = get_example_file(example_key, WORKING_DIR) geometry_obj = model.create_cad_geometry() geometry_obj.refresh(geometry_file) # upload and load the geometry file model.update() virtual_geometry = model.create_virtual_geometry( name="thickness_virtual_geometry", cad_components=geometry_obj.root_shapes.values() ) return geometry_obj, virtual_geometry .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/modeling_features/images/sphx_glr_020-solid_model_001.png :alt: 020 solid model :srcset: /examples/modeling_features/images/sphx_glr_020-solid_model_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_020-solid_model_001.vtksz .. GENERATED FROM PYTHON SOURCE LINES 129-134 Snap the top to a geometry -------------------------- The :class:`.SnapToGeometry` allows to shape the bottom or top of the solid model. First, import the geometry and then add the snap-to feature to the solid model. .. GENERATED FROM PYTHON SOURCE LINES 134-145 .. code-block:: Python snap_to_geom, snap_to_virtual_geom = create_virtual_geometry_from_file(ExampleKeys.SNAP_TO_GEOMETRY) solid_model.create_snap_to_geometry( name="Snap-to Geometry", cad_geometry=snap_to_virtual_geom, orientation_type=SnapToGeometryOrientationType.TOP, oriented_selection_set=model.oriented_selection_sets["oss"], ) model.update() plot_model_with_geometry(snap_to_geom, 0.5) .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/modeling_features/images/sphx_glr_020-solid_model_002.png :alt: 020 solid model :srcset: /examples/modeling_features/images/sphx_glr_020-solid_model_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_020-solid_model_002.vtksz .. GENERATED FROM PYTHON SOURCE LINES 146-151 Shape the walls --------------- The :class:`.ExtrusionGuide` is used to shape the side walls of the solid model. The feature can be defined by a direction as shown here or through a geometry. .. GENERATED FROM PYTHON SOURCE LINES 151-169 .. code-block:: Python edge_set = model.create_edge_set( name="Edge Set", edge_set_type=EdgeSetType.BY_REFERENCE, element_set=model.element_sets["All_Elements"], limit_angle=30, origin=(0.05, 0, 0), ) solid_model.create_extrusion_guide( name="Extrusion Guide", edge_set=edge_set, extrusion_guide_type=ExtrusionGuideType.BY_DIRECTION, direction=(-0.5, 1, 0), radius=0.005, depth=0.6, ) model.update() plot_model_with_geometry(None) .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/modeling_features/images/sphx_glr_020-solid_model_003.png :alt: 020 solid model :srcset: /examples/modeling_features/images/sphx_glr_020-solid_model_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_020-solid_model_003.vtksz .. GENERATED FROM PYTHON SOURCE LINES 170-174 Cut-off an edge --------------- The :class:`.CutOffGeometry` is used to crop elements from the solid model. .. GENERATED FROM PYTHON SOURCE LINES 174-187 .. code-block:: Python cut_off_cad_geom, cut_off_virtual_geom = create_virtual_geometry_from_file( ExampleKeys.CUT_OFF_GEOMETRY_SOLID_MODEL ) solid_model.create_cut_off_geometry( name="Cut-off Geometry", cad_geometry=cut_off_virtual_geom, orientation_type=CutOffGeometryOrientationType.UP, ) model.update() plot_model_with_geometry(cut_off_cad_geom) .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/modeling_features/images/sphx_glr_020-solid_model_004.png :alt: 020 solid model :srcset: /examples/modeling_features/images/sphx_glr_020-solid_model_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_020-solid_model_004.vtksz .. GENERATED FROM PYTHON SOURCE LINES 188-193 Plot results on the solid mesh ------------------------------ The plotting capabilities also support the visualization of ply-wise results, such as directions or thicknesses as shown here. .. GENERATED FROM PYTHON SOURCE LINES 195-196 Get the analysis ply of interest .. GENERATED FROM PYTHON SOURCE LINES 196-198 .. code-block:: Python ap = solid_model.analysis_plies["P2L1__ply"] .. GENERATED FROM PYTHON SOURCE LINES 199-201 Plot fiber directions ~~~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 201-214 .. code-block:: Python direction_plotter = get_directions_plotter( model=model, mesh=ap.solid_mesh, components=[ ap.elemental_data.fiber_direction, ], length_factor=10.0, culling_factor=10, ) direction_plotter.add_mesh(model.solid_mesh.to_pyvista(), opacity=0.2, show_edges=False) direction_plotter.camera_position = FLAT_PLATE_SOLID_CAMERA direction_plotter.show() .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/modeling_features/images/sphx_glr_020-solid_model_005.png :alt: 020 solid model :srcset: /examples/modeling_features/images/sphx_glr_020-solid_model_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_020-solid_model_005.vtksz .. GENERATED FROM PYTHON SOURCE LINES 215-217 Plot thicknesses ~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 217-224 .. code-block:: Python thickness_data = ap.elemental_data.thickness thickness_pyvista_mesh = thickness_data.get_pyvista_mesh(mesh=ap.solid_mesh) # type: ignore plotter = pyvista.Plotter() plotter.add_mesh(thickness_pyvista_mesh) plotter.add_mesh(model.solid_mesh.to_pyvista(), opacity=0.2, show_edges=False) plotter.camera_position = FLAT_PLATE_SOLID_CAMERA plotter.show() .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/modeling_features/images/sphx_glr_020-solid_model_006.png :alt: 020 solid model :srcset: /examples/modeling_features/images/sphx_glr_020-solid_model_006.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: /home/runner/work/pyacp/pyacp/doc/source/examples/modeling_features/images/sphx_glr_020-solid_model_006.vtksz .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 7.462 seconds) .. _sphx_glr_download_examples_modeling_features_020-solid_model.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 020-solid_model.ipynb <020-solid_model.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 020-solid_model.py <020-solid_model.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 020-solid_model.zip <020-solid_model.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_