Skip to content

Commit

Permalink
Fix bug while processing ACP's imported solid models (#469)
Browse files Browse the repository at this point in the history
* Fix bug while processing analysis plies of imported solid models.

* update unit test

---------

Co-authored-by: Kathy Pippert <[email protected]>
  • Loading branch information
roosre and PipKat authored Jun 12, 2024
1 parent 77ffadc commit e6cea95
Show file tree
Hide file tree
Showing 14 changed files with 2,452 additions and 13 deletions.
3 changes: 1 addition & 2 deletions examples/010_harmonic_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
import matplotlib.pyplot as plt

from ansys.dpf.composites.composite_model import CompositeModel
from ansys.dpf.composites.constants import FailureOutput
from ansys.dpf.composites.constants import FAILURE_LABEL, FailureOutput
from ansys.dpf.composites.example_helper import get_continuous_fiber_example_files
from ansys.dpf.composites.failure_criteria import (
CombinedFailureCriterion,
Expand Down Expand Up @@ -119,7 +119,6 @@
# This is a bit confusing, but DPF uses the same label for Frequency and Time
FREQ_LABEL = "time"
PHASE_LABEL = "phase"
FAILURE_LABEL = "failure_label"
all_phases_and_freqs_failure_value_fc = dpf.FieldsContainer()
all_phases_and_freqs_failure_value_fc.labels = [FREQ_LABEL, PHASE_LABEL]

Expand Down
16 changes: 16 additions & 0 deletions src/ansys/dpf/composites/layup_info/_layup_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,14 +324,30 @@ def get_analysis_ply_index_to_name_map(
----------
mesh
DPF Meshed region enriched with lay-up information
.. note::
Analysis plies of ACP's imported solid model that are linked only
to homogeneous elements are currently skipped.
"""
analysis_ply_name_to_index_map = {}
with mesh.property_field("layer_to_analysis_ply").as_local_field() as local_field:
element_ids = local_field.scoping.ids
for analysis_ply_name in get_all_analysis_ply_names(mesh):
analysis_ply_property_field = _get_analysis_ply(
mesh, analysis_ply_name, skip_check=True
)
first_element_id = analysis_ply_property_field.scoping.id(0)
# analysis plies which represent a filler ply are ignored because
# they are linked to homogeneous elements only. So, they are not
# part of layer_to_analysis_ply. This filler plies can occur in
# imported solid models.
# The analysis ply indices can be retrieved from
# analysis_ply_property_field as soon as the
# properties of PropertyField are available in Python.
if first_element_id not in element_ids:
continue

analysis_ply_indices: list[int] = local_field.get_entity_data_by_id(first_element_id)

layer_index = analysis_ply_property_field.get_entity_data(0)[0]
Expand Down
2 changes: 1 addition & 1 deletion src/ansys/dpf/composites/server_helpers/_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class _DpfVersionInfo:
"9.0": _DpfVersionInfo(
"9.0",
"2025 R1 pre 0",
"DPF Composites: exposure of ply type.",
"DPF Composites: exposure of ply type and support of imported solid models.",
),
}

Expand Down
67 changes: 57 additions & 10 deletions tests/composite_model_scoping_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import pytest

from ansys.dpf.composites.composite_model import CompositeModel, CompositeScope
from ansys.dpf.composites.constants import FailureOutput
from ansys.dpf.composites.constants import FAILURE_LABEL, FailureOutput
from ansys.dpf.composites.data_sources import get_composite_files_from_workbench_result_folder
from ansys.dpf.composites.failure_criteria import (
CombinedFailureCriterion,
Expand All @@ -35,7 +35,7 @@
MaxStressCriterion,
)
from ansys.dpf.composites.layup_info import get_all_analysis_ply_names
from ansys.dpf.composites.server_helpers._versions import version_older_than
from ansys.dpf.composites.server_helpers._versions import version_equal_or_later, version_older_than

from .helper import get_basic_shell_files

Expand All @@ -49,13 +49,13 @@ def test_composite_model_element_scope(dpf_server, data_files):

composite_scope = CompositeScope(elements=[1, 3])
failure_container = composite_model.evaluate_failure_criteria(cfc, composite_scope)
irfs = failure_container.get_field({"failure_label": FailureOutput.FAILURE_VALUE})
irfs = failure_container.get_field({FAILURE_LABEL: FailureOutput.FAILURE_VALUE})
min_id = irfs.scoping.ids[np.argmin(irfs.data)]
max_id = irfs.scoping.ids[np.argmax(irfs.data)]

composite_scope = CompositeScope(elements=[min_id, max_id])
max_container = composite_model.evaluate_failure_criteria(cfc, composite_scope)
max_irfs = max_container.get_field({"failure_label": FailureOutput.FAILURE_VALUE})
max_irfs = max_container.get_field({FAILURE_LABEL: FailureOutput.FAILURE_VALUE})
assert len(max_irfs.data) == 2
assert max_irfs.get_entity_data_by_id(min_id)[0] == pytest.approx(min(irfs.data), 1e-8)
assert max_irfs.get_entity_data_by_id(max_id)[0] == pytest.approx(max(irfs.data), 1e-8)
Expand All @@ -78,7 +78,7 @@ def test_composite_model_named_selection_scope(dpf_server, data_files, distribut

scope = CompositeScope(named_selections=[ns_name])
failure_container = composite_model.evaluate_failure_criteria(cfc, scope)
irfs = failure_container.get_field({"failure_label": FailureOutput.FAILURE_VALUE})
irfs = failure_container.get_field({FAILURE_LABEL: FailureOutput.FAILURE_VALUE})
assert len(irfs.data) == 2
assert irfs.get_entity_data_by_id(2) == pytest.approx(1.4792790331384016, 1e-8)
assert irfs.get_entity_data_by_id(3) == pytest.approx(1.3673715033617213, 1e-8)
Expand Down Expand Up @@ -118,8 +118,8 @@ def test_composite_model_ply_scope(dpf_server):

scope = CompositeScope(plies=ply_ids)
failure_container = composite_model.evaluate_failure_criteria(cfc, scope)
irfs = failure_container.get_field({"failure_label": FailureOutput.FAILURE_VALUE})
modes = failure_container.get_field({"failure_label": FailureOutput.FAILURE_MODE})
irfs = failure_container.get_field({FAILURE_LABEL: FailureOutput.FAILURE_VALUE})
modes = failure_container.get_field({FAILURE_LABEL: FailureOutput.FAILURE_MODE})

if version_older_than(dpf_server, "7.0"):
# the old implementation did not allow to distinguish between plies of the different parts.
Expand Down Expand Up @@ -194,8 +194,8 @@ def test_composite_model_named_selection_and_ply_scope(dpf_server, data_files, d

scope = CompositeScope(named_selections=[ns_name], plies=ply_ids)
failure_container = composite_model.evaluate_failure_criteria(cfc, scope)
irfs = failure_container.get_field({"failure_label": FailureOutput.FAILURE_VALUE})
modes = failure_container.get_field({"failure_label": FailureOutput.FAILURE_MODE})
irfs = failure_container.get_field({FAILURE_LABEL: FailureOutput.FAILURE_VALUE})
modes = failure_container.get_field({FAILURE_LABEL: FailureOutput.FAILURE_MODE})
assert len(irfs.data) == 2
assert len(modes.data) == 2
expected_irfs_by_id = {2: 0.49282684, 3: 0.32568454}
Expand Down Expand Up @@ -230,6 +230,53 @@ def test_composite_model_time_scope(dpf_server):
for time, expected_max_irf in time_id_and_expected_max_irf.items():
scope = CompositeScope(time=time)
failure_container = composite_model.evaluate_failure_criteria(cfc, scope)
irfs = failure_container.get_field({"failure_label": FailureOutput.FAILURE_VALUE})
irfs = failure_container.get_field({FAILURE_LABEL: FailureOutput.FAILURE_VALUE})
assert len(irfs.data) == 4
assert max(irfs.data) == pytest.approx(expected_max_irf, abs=1e-6)


def test_ply_wise_scoping_in_assembly_with_imported_solid_model(dpf_server):
"""Ensure that the ply-wise scoping works in combination with the reference surface plot."""
if version_older_than(dpf_server, "8.0"):
pytest.xfail("Not supported because of limitations in the handling of assemblies.")

result_folder = pathlib.Path(__file__).parent / "data" / "assembly_imported_solid_model"
composite_files = get_composite_files_from_workbench_result_folder(result_folder)

# Create a composite model
composite_model = CompositeModel(composite_files, dpf_server)

plies = [
"Setup 2_shell::P1L1__ModelingPly.2",
"Setup_solid::P1L1__ModelingPly.2",
"Setup 3_solid::P1L1__ModelingPly.1",
]

# Evaluate combined failure criterion
combined_failure_criterion = CombinedFailureCriterion(failure_criteria=[MaxStressCriterion()])
failure_result = composite_model.evaluate_failure_criteria(
combined_criterion=combined_failure_criterion, composite_scope=CompositeScope(plies=plies)
)

# check the on reference surface data
for failure_output in [
FailureOutput.FAILURE_VALUE_REF_SURFACE,
FailureOutput.FAILURE_MODE_REF_SURFACE,
FailureOutput.MAX_GLOBAL_LAYER_IN_STACK,
FailureOutput.MAX_LOCAL_LAYER_IN_ELEMENT,
FailureOutput.MAX_SOLID_ELEMENT_ID,
]:
field = failure_result.get_field({FAILURE_LABEL: failure_output})

if version_equal_or_later(dpf_server, "9.0"):
assert field.size == 21
elif version_equal_or_later(dpf_server, "8.0"):
# Servers of the 2024 R2 series do not extract the reference surface
# of imported solid models. So the reference surface mesh
# contains only the shell elements and reference surface of the
# standard solid model.
assert field.size == 12
else:
# Servers before 8.0 are not tested because of several limitations:
# handling of assemblies, reference surface not supported
assert False
70 changes: 70 additions & 0 deletions tests/composite_model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from ansys.dpf.composites.layup_info import (
LayerProperty,
LayupModelContextType,
get_all_analysis_ply_names,
get_analysis_ply_index_to_name_map,
)
from ansys.dpf.composites.layup_info.material_properties import MaterialMetadata, MaterialProperty
Expand Down Expand Up @@ -539,3 +540,72 @@ def test_failure_criteria_evaluation_default_unit_system(dpf_server):
cfc = CombinedFailureCriterion("max stress", failure_criteria=[MaxStressCriterion()])

failure_container = composite_model.evaluate_failure_criteria(cfc)


def test_composite_model_with_imported_solid_model_assembly(dpf_server):
"""
Tests the show on reference surface option for imported solid models.
Imported solid models are slightly different if compared with shell parts
and standard solid models. For instance, they have analysis plies which are
not linked to a layered elements. These are called filler plies.
In addition, the `show on reference surface` option uses the skin of the
imported solid mesh instead of a predefined reference surface.
This general test ensures that the composite model can handle these.
The model has one shell part, one standard solid model and
an imported solid model.
"""
result_folder = pathlib.Path(__file__).parent / "data" / "assembly_imported_solid_model"
composite_files = get_composite_files_from_workbench_result_folder(result_folder)

# Create a composite model
composite_model = CompositeModel(composite_files, dpf_server)

# ensure that all analysis plies are available, also the filler plies
# The initial version of DPF Composites had limitations in the handling
# of assemblies and so the test is skipped for old versions of the server.
if version_equal_or_later(dpf_server, "7.0"):
analysis_plies = get_all_analysis_ply_names(composite_model.get_mesh())
ref_plies = [
"Setup 2_shell::P1L1__ModelingPly.2",
"Setup_solid::P1L1__ModelingPly.2",
"Setup 3_solid::P1L1__ModelingPly.1",
"Setup 3_solid::P1L1__ModelingPly.3",
"Setup 3_solid::filler_Epoxy Carbon Woven (230 GPa) Prepreg",
"Setup 3_solid::P1L1__ModelingPly.2",
"Setup 2_shell::P1L1__ModelingPly.1",
"Setup_solid::P1L1__ModelingPly.1",
]
assert set(analysis_plies) == set(ref_plies)

# Evaluate combined failure criterion
combined_failure_criterion = CombinedFailureCriterion(failure_criteria=[MaxStressCriterion()])
failure_result = composite_model.evaluate_failure_criteria(combined_failure_criterion)

irf_field = failure_result.get_field({FAILURE_LABEL: FailureOutput.FAILURE_VALUE})
assert irf_field.size == 84

# check the on reference surface data
for failure_output in [
FailureOutput.FAILURE_VALUE_REF_SURFACE,
FailureOutput.FAILURE_MODE_REF_SURFACE,
FailureOutput.MAX_GLOBAL_LAYER_IN_STACK,
FailureOutput.MAX_LOCAL_LAYER_IN_ELEMENT,
FailureOutput.MAX_SOLID_ELEMENT_ID,
]:
field = failure_result.get_field({FAILURE_LABEL: failure_output})
if version_equal_or_later(dpf_server, "9.0"):
assert field.size == 60
elif version_equal_or_later(dpf_server, "8.0"):
# Servers of the 2024 R2 series do not extract the reference surface
# of imported solid models. So the reference surface mesh
# contains only the shell elements and reference surface of the
# standard solid model.
assert field.size == 18
else:
# Server of 2024 R1 and before do not support results on the reference
# surface at all. It is tested that the operator update
# completes without error nevertheless.
pass
Loading

0 comments on commit e6cea95

Please sign in to comment.