Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug while processing ACP's imported solid models #469

Merged
merged 18 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
14 changes: 14 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,28 @@ 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 which are linked
to homogeneous elements only are currently skipped.
roosre marked this conversation as resolved.
Show resolved Hide resolved
"""
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
58 changes: 49 additions & 9 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 @@ -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,46 @@ 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."""
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,
]:
roosre marked this conversation as resolved.
Show resolved Hide resolved
field = failure_result.get_field({FAILURE_LABEL: failure_output})
if version_older_than(dpf_server, "9.0"):
# old servers 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:
assert field.size == 21
60 changes: 60 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,62 @@ 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):
"""
Imported solid models are slightly different if compared with shell parts
roosre marked this conversation as resolved.
Show resolved Hide resolved
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 feature used the skin of the
roosre marked this conversation as resolved.
Show resolved Hide resolved
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 which are all
roosre marked this conversation as resolved.
Show resolved Hide resolved
"""
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
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_older_than(dpf_server, "9.0"):
# old servers 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:
assert field.size == 60
Loading
Loading