.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "examples/modeling_features/010-sandwich-panel-layup.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_examples_modeling_features_010-sandwich-panel-layup.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_examples_modeling_features_010-sandwich-panel-layup.py:


.. _sandwich_panel_example:

Sandwich panel
==============

This example defines a composite lay-up for a sandwich panel using PyACP.
It only shows the PyACP part of the setup. For a complete composite analysis,
see :ref:`pymapdl_workflow_example`.

.. GENERATED FROM PYTHON SOURCE LINES 35-38

------------------

Import the standard library and third-party dependencies.

.. GENERATED FROM PYTHON SOURCE LINES 38-41

.. code-block:: Python

    import pathlib
    import tempfile








.. GENERATED FROM PYTHON SOURCE LINES 42-43

Import the PyACP dependencies.

.. GENERATED FROM PYTHON SOURCE LINES 43-56

.. code-block:: Python

    from ansys.acp.core import (
        FabricWithAngle,
        Lamina,
        PlyType,
        get_directions_plotter,
        launch_acp,
        print_model,
    )
    from ansys.acp.core.extras import ExampleKeys, get_example_file
    from ansys.acp.core.material_property_sets import ConstantEngineeringConstants, ConstantStrainLimits










.. GENERATED FROM PYTHON SOURCE LINES 58-60

Start ACP and load the model
----------------------------

.. GENERATED FROM PYTHON SOURCE LINES 62-63

Get the example file from the server.

.. 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.BASIC_FLAT_PLATE_DAT, WORKING_DIR)








.. GENERATED FROM PYTHON SOURCE LINES 68-69

Launch the ACP 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

Define the input file and import it into ACP.

.. GENERATED FROM PYTHON SOURCE LINES 73-80

.. code-block:: Python


    model = acp.import_model(
        input_file,
        format="ansys:cdb",
    )
    print(model.unit_system)





.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    mks




.. GENERATED FROM PYTHON SOURCE LINES 81-82

Visualize the loaded mesh.

.. GENERATED FROM PYTHON SOURCE LINES 82-85

.. 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_010-sandwich-panel-layup_001.png
        :alt: 010 sandwich panel layup
        :srcset: /examples/modeling_features/images/sphx_glr_010-sandwich-panel-layup_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_010-sandwich-panel-layup_001.vtksz






.. GENERATED FROM PYTHON SOURCE LINES 86-88

Create the sandwich materials
-----------------------------

.. GENERATED FROM PYTHON SOURCE LINES 90-91

Create the UD material and  its corresponding fabric.

.. GENERATED FROM PYTHON SOURCE LINES 91-118

.. code-block:: Python

    engineering_constants_ud = ConstantEngineeringConstants.from_orthotropic_constants(
        E1=5e10, E2=1e10, E3=1e10, nu12=0.28, nu13=0.28, nu23=0.3, G12=5e9, G23=4e9, G31=4e9
    )

    strain_limit = 0.01
    strain_limits = ConstantStrainLimits.from_orthotropic_constants(
        eXc=-strain_limit,
        eYc=-strain_limit,
        eZc=-strain_limit,
        eXt=strain_limit,
        eYt=strain_limit,
        eZt=strain_limit,
        eSxy=strain_limit,
        eSyz=strain_limit,
        eSxz=strain_limit,
    )

    ud_material = model.create_material(
        name="UD",
        ply_type=PlyType.REGULAR,
        engineering_constants=engineering_constants_ud,
        strain_limits=strain_limits,
    )

    ud_fabric = model.create_fabric(name="UD", material=ud_material, thickness=0.002)









.. GENERATED FROM PYTHON SOURCE LINES 119-121

Create a multi-axial stackup and a sublaminate. Stackups and sublaminates help quickly
build repeating laminates.

.. GENERATED FROM PYTHON SOURCE LINES 121-141

.. code-block:: Python


    biax_carbon_ud = model.create_stackup(
        name="Biax_Carbon_UD",
        fabrics=(
            FabricWithAngle(ud_fabric, -45),
            FabricWithAngle(ud_fabric, 45),
        ),
    )


    sublaminate = model.create_sublaminate(
        name="Sublaminate",
        materials=(
            Lamina(biax_carbon_ud, 0),
            Lamina(ud_fabric, 90),
            Lamina(biax_carbon_ud, 0),
        ),
    )









.. GENERATED FROM PYTHON SOURCE LINES 142-143

Create the core material and its corresponding fabric.

.. GENERATED FROM PYTHON SOURCE LINES 143-154

.. code-block:: Python

    engineering_constants_core = ConstantEngineeringConstants.from_isotropic_constants(E=8.5e7, nu=0.3)

    core = model.create_material(
        name="Core",
        ply_type=PlyType.ISOTROPIC_HOMOGENEOUS_CORE,
        engineering_constants=engineering_constants_core,
        strain_limits=strain_limits,
    )

    core_fabric = model.create_fabric(name="core", material=ud_material, thickness=0.015)








.. GENERATED FROM PYTHON SOURCE LINES 155-157

Create the Lay-up
-----------------

.. GENERATED FROM PYTHON SOURCE LINES 159-160

Define a rosette and oriented selection set. Plot the orientations.

.. GENERATED FROM PYTHON SOURCE LINES 160-174

.. code-block:: Python

    rosette = model.create_rosette(origin=(0.0, 0.0, 0.0), dir1=(1.0, 0.0, 0.0), dir2=(0.0, 1.0, 0.0))

    oss = model.create_oriented_selection_set(
        name="oss",
        orientation_point=(0.0, 0.0, 0.0),
        orientation_direction=(0.0, 1.0, 0),
        element_sets=[model.element_sets["All_Elements"]],
        rosettes=[rosette],
    )

    model.update()
    plotter = get_directions_plotter(model=model, components=[oss.elemental_data.orientation])
    plotter.show()








.. tab-set::



   .. tab-item:: Static Scene



            
     .. image-sg:: /examples/modeling_features/images/sphx_glr_010-sandwich-panel-layup_002.png
        :alt: 010 sandwich panel layup
        :srcset: /examples/modeling_features/images/sphx_glr_010-sandwich-panel-layup_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_010-sandwich-panel-layup_002.vtksz






.. GENERATED FROM PYTHON SOURCE LINES 175-176

Create the modeling plies which define the lay-up of the sandwich panel.

.. GENERATED FROM PYTHON SOURCE LINES 176-201

.. code-block:: Python

    modeling_group = model.create_modeling_group(name="modeling_group")

    bottom_ply = modeling_group.create_modeling_ply(
        name="bottom_ply",
        ply_angle=0,
        ply_material=sublaminate,
        oriented_selection_sets=[oss],
    )

    core_ply = modeling_group.create_modeling_ply(
        name="core_ply",
        ply_angle=0,
        ply_material=core_fabric,
        oriented_selection_sets=[oss],
    )


    top_ply = modeling_group.create_modeling_ply(
        name="top_ply",
        ply_angle=90,
        ply_material=ud_fabric,
        oriented_selection_sets=[oss],
        number_of_layers=3,
    )








.. GENERATED FROM PYTHON SOURCE LINES 202-203

Update and print the model.

.. GENERATED FROM PYTHON SOURCE LINES 203-205

.. code-block:: Python

    model.update()
    print_model(model)




.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    'ACP Lay-up Model'
        Materials
            '1'
            'UD'
            'Core'
        Fabrics
            'UD'
            'core'
        Stackups
            'Biax_Carbon_UD'
        Sublaminates
            'Sublaminate'
        Element Sets
            'All_Elements'
        Edge Sets
            '_FIXEDSU'
        Rosettes
            '12'
            'Rosette'
        Oriented Selection Sets
            'oss'
        Modeling Groups
            'modeling_group'
                Modeling Plies
                    'bottom_ply'
                        Production Plies
                            'P1__bottom_ply'
                                Analysis Plies
                                    'P1L1__bottom_ply'
                                    'P1L2__bottom_ply'
                            'P2__bottom_ply'
                                Analysis Plies
                                    'P2L1__bottom_ply'
                            'P3__bottom_ply'
                                Analysis Plies
                                    'P3L1__bottom_ply'
                                    'P3L2__bottom_ply'
                    'core_ply'
                        Production Plies
                            'P1__core_ply'
                                Analysis Plies
                                    'P1L1__core_ply'
                    'top_ply'
                        Production Plies
                            'P1__top_ply'
                                Analysis Plies
                                    'P1L1__top_ply'
                            'P2__top_ply'
                                Analysis Plies
                                    'P2L1__top_ply'
                            'P3__top_ply'
                                Analysis Plies
                                    'P3L1__top_ply'

    /home/runner/.cache/pypoetry/virtualenvs/ansys-acp-core-O77fA6pn-py3.12/lib/python3.12/site-packages/ansys/mapdl/core/launcher.py:822: UserWarning: The environment variable 'PYMAPDL_START_INSTANCE' is set, hence the argument 'start_instance' is overwritten.
      warnings.warn(
    /home/runner/.cache/pypoetry/virtualenvs/ansys-acp-core-O77fA6pn-py3.12/lib/python3.12/site-packages/ansys/mapdl/core/component.py:174: SyntaxWarning: invalid escape sequence '\>'
      """Collection of MAPDL components.





.. rst-class:: sphx-glr-timing

   **Total running time of the script:** (0 minutes 9.521 seconds)


.. _sphx_glr_download_examples_modeling_features_010-sandwich-panel-layup.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: 010-sandwich-panel-layup.ipynb <010-sandwich-panel-layup.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: 010-sandwich-panel-layup.py <010-sandwich-panel-layup.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: 010-sandwich-panel-layup.zip <010-sandwich-panel-layup.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_