Thickness definition example#

This example shows how the thickness of a ply can be defined by a geometry or a lookup table. The example only shows the PyACP part of the setup. For a complete composite analysis, see Basic PyACP workflow example.

Import modules#

Import the standard library and third-party dependencies.

import pathlib
import tempfile

import numpy as np
import pyvista

Import the PyACP dependencies.

from ansys.acp.core import ACPWorkflow, DimensionType, ThicknessType, example_helpers, launch_acp
from ansys.acp.core.example_helpers import ExampleKeys, get_example_file

Start ACP and load the model#

Get the example file from the server.

tempdir = tempfile.TemporaryDirectory()
WORKING_DIR = pathlib.Path(tempdir.name)
input_file = get_example_file(ExampleKeys.MINIMAL_FLAT_PLATE, WORKING_DIR)

Launch the PyACP server and connect to it.

acp = launch_acp()

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.

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)


# Plot the nominal ply thickness.
modeling_ply = model.modeling_groups["modeling_group"].modeling_plies["ply"]
model.update()
assert model.elemental_data.thickness is not None
model.elemental_data.thickness.get_pyvista_mesh(mesh=model.mesh).plot(show_edges=True)
005 thickness definitions
/tmp/tmp_lsb_84t
mks

Define the thickness from a geometry#

Add the solid geometry to the model that defines the thickness.

thickness_geometry_file = example_helpers.get_example_file(
    example_helpers.ExampleKeys.THICKNESS_GEOMETRY, WORKING_DIR
)
thickness_geometry = workflow.add_cad_geometry_from_local_file(thickness_geometry_file)

# Note: It is important to update the model here, because the root_shapes of the
# cad_geometry are not available until the model is updated.
model.update()

Create a virtual geometry from the CAD geometry.

thickness_virtual_geometry = model.create_virtual_geometry(
    name="thickness_virtual_geometry", cad_components=thickness_geometry.root_shapes.values()
)

Set the thickness type to FROM_GEOMETRY and define the virtual geometry.

modeling_ply.thickness_type = ThicknessType.FROM_GEOMETRY
modeling_ply.thickness_geometry = thickness_virtual_geometry

Plot the ply thickness together with the geometry defining the thickness.

model.update()
assert model.elemental_data.thickness is not None
plotter = pyvista.Plotter()
# Plot the surface of the geometry
geometry_polydata = thickness_geometry.visualization_mesh.to_pyvista()
plotter.add_mesh(geometry_polydata, color="grey", opacity=0.05)
# Plot the edges of the geometry
edges = geometry_polydata.extract_feature_edges()
plotter.add_mesh(edges, color="white", line_width=4)
plotter.add_mesh(edges, color="black", line_width=2)
# Plot the ply thickness
plotter.add_mesh(model.elemental_data.thickness.get_pyvista_mesh(mesh=model.mesh), show_edges=True)

plotter.show()
005 thickness definitions

Define the thickness from a lookup table#

Create the data for the lookup table. Make a 20x20 grid of points to define a thickness function on. In this example, the mesh of the lookup table is finer than the finite element mesh, and the thickness is interpolated onto the finite element mesh. Note that the plate lies in the xz plane and the thickness is defined in the y direction.

Create a thickness that equals the distance to the center of the plate.

center_x = 0.005
center_z = 0.005
thickness = np.sqrt((xx - center_x) ** 2 + (zz - center_z) ** 2).ravel()

Create the point coordinates for the lookup table. The y coordinate is always zero.

points = np.stack(
    [
        xx.ravel(),
        np.zeros(xx.ravel().shape),
        zz.ravel(),
    ],
    axis=1,
)

Now you have a list of point coordinates:

print(points)
[[0.    0.    0.   ]
 [0.005 0.    0.   ]
 [0.01  0.    0.   ]
 [0.    0.    0.005]
 [0.005 0.    0.005]
 [0.01  0.    0.005]
 [0.    0.    0.01 ]
 [0.005 0.    0.01 ]
 [0.01  0.    0.01 ]]

And the corresponding thickness values.

print(thickness)
[0.00707107 0.005      0.00707107 0.005      0.         0.005
 0.00707107 0.005      0.00707107]

Create the lookup table and add the coordinates and thickness data.

lookup_table = model.create_lookup_table_3d()
lookup_table.columns["Location"].data = points
thickness_column = lookup_table.create_column(data=thickness, dimension_type=DimensionType.LENGTH)

Set the thickness type to FROM_TABLE and assign the thickness column.

modeling_ply.thickness_type = ThicknessType.FROM_TABLE
modeling_ply.thickness_field = thickness_column

Plot the ply thickness.

model.update()
assert model.elemental_data.thickness is not None
model.elemental_data.thickness.get_pyvista_mesh(mesh=model.mesh).plot(show_edges=True)
005 thickness definitions

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

Gallery generated by Sphinx-Gallery