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

Feat/exposure of material names #353

Merged
merged 26 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ec05643
Fix broken link, and port changes from 0.3.1 back to develop
roosre Sep 14, 2023
6a0bbbd
Merge branch 'main' of https://github.com/ansys/pydpf-composites
roosre Sep 21, 2023
d9f3db9
add `material_names` as property to the CompositeModel which returns …
roosre Sep 22, 2023
fe3c22e
add unit test
roosre Sep 22, 2023
4994770
apply pre-commit patch
roosre Sep 22, 2023
a60ac4a
apply pre-commit patch
roosre Sep 22, 2023
ba0587b
Fix typo
roosre Sep 25, 2023
8cca3cc
code style checks
roosre Sep 25, 2023
b8f9c35
code style checks
roosre Sep 25, 2023
8c91b31
code style checks
roosre Sep 25, 2023
e5c1b12
code style checks
roosre Sep 25, 2023
e8c91f7
code style checks
roosre Sep 25, 2023
c4bb351
code style checks
roosre Sep 25, 2023
2a3f261
run new test only if the latest server version is used.
roosre Sep 25, 2023
9127c8f
Update src/ansys/dpf/composites/layup_info/_layup_info.py
roosre Sep 25, 2023
453353a
Update src/ansys/dpf/composites/layup_info/_layup_info.py
roosre Sep 25, 2023
01c7b2f
Update src/ansys/dpf/composites/layup_info/_layup_info.py
roosre Sep 25, 2023
4d924c1
Update src/ansys/dpf/composites/layup_info/_layup_info.py
roosre Sep 25, 2023
a910500
Update src/ansys/dpf/composites/layup_info/_layup_info.py
roosre Sep 25, 2023
223292c
Update documentation
roosre Sep 25, 2023
de75ee1
Merge remote-tracking branch 'origin/feat/exposure_of_material_names'…
roosre Sep 25, 2023
88941d2
Merge branch 'main' into feat/exposure_of_material_names
roosre Sep 25, 2023
0e3468d
code style checks
roosre Sep 26, 2023
dd4b092
Merge remote-tracking branch 'origin/feat/exposure_of_material_names'…
roosre Sep 26, 2023
1b9d662
code style checks
roosre Sep 26, 2023
66f745f
fix documentation
roosre Sep 26, 2023
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
6 changes: 1 addition & 5 deletions examples/006_filter_composite_data_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@
from ansys.dpf.composites.composite_model import CompositeModel
from ansys.dpf.composites.constants import Spot, Sym3x3TensorComponent
from ansys.dpf.composites.example_helper import get_continuous_fiber_example_files
from ansys.dpf.composites.layup_info import (
AnalysisPlyInfoProvider,
get_all_analysis_ply_names,
get_dpf_material_id_by_analyis_ply_map,
)
from ansys.dpf.composites.layup_info import AnalysisPlyInfoProvider, get_all_analysis_ply_names
from ansys.dpf.composites.select_indices import (
get_selected_indices,
get_selected_indices_by_analysis_ply,
Expand Down
26 changes: 26 additions & 0 deletions src/ansys/dpf/composites/_composite_model_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,32 @@ def material_operators(self) -> MaterialOperators:
"""Material operators."""
return self._material_operators

@property
def material_names(self) -> Dict[str, int]:
"""
Material name to DPF material ID map.

Can be used to filter analysis plies or element layers.
roosre marked this conversation as resolved.
Show resolved Hide resolved
"""
try:
roosre marked this conversation as resolved.
Show resolved Hide resolved
helper_op = dpf.Operator("composite::materials_container_helper")
except Exception as exc:
raise RuntimeError(
f"Operator composite::materials_container_helper doesn't exist. "
f"This could be because the server version is 2024 R1-pre0. Please use "
roosre marked this conversation as resolved.
Show resolved Hide resolved
f"the latest preview or the unified installer. Error: {exc}"
) from exc

helper_op.inputs.materials_container(self._material_operators.material_provider.outputs)
string_field = helper_op.outputs.material_names()
material_ids = string_field.scoping.ids

names = {}
for mat_id in material_ids:
names[string_field.data[string_field.scoping.index(mat_id)]] = mat_id

return names

@_deprecated_composite_definition_label
def get_mesh(self, composite_definition_label: Optional[str] = None) -> MeshedRegion:
"""Get the underlying DPF meshed region.
Expand Down
9 changes: 9 additions & 0 deletions src/ansys/dpf/composites/_composite_model_impl_2023r2.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,15 @@ def material_operators(self) -> MaterialOperators:
"""Material operators."""
return self._material_operators

@property
def material_names(self) -> Dict[str, int]:
"""Get material name to DPF material ID map."""
raise NotImplementedError(
"material_names is not implemented"
" for this version of DPF. Please upgrade to 7.0 (2024 R1)"
" or later."
)

def get_layup_operator(self, composite_definition_label: Optional[str] = None) -> Operator:
"""Get the lay-up operator.

Expand Down
5 changes: 5 additions & 0 deletions src/ansys/dpf/composites/composite_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ def material_operators(self) -> MaterialOperators:
"""Material operators."""
return self._implementation.material_operators

@property
def material_names(self) -> Dict[str, int]:
"""Get material name to DPF material ID map."""
roosre marked this conversation as resolved.
Show resolved Hide resolved
return self._implementation.material_names

def get_mesh(self, composite_definition_label: Optional[str] = None) -> MeshedRegion:
"""Get the underlying DPF meshed region.

Expand Down
2 changes: 2 additions & 0 deletions src/ansys/dpf/composites/layup_info/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
get_all_analysis_ply_names,
get_analysis_ply_index_to_name_map,
get_dpf_material_id_by_analyis_ply_map,
get_dpf_material_id_by_analysis_ply_map,
get_element_info_provider,
)

Expand All @@ -25,6 +26,7 @@
"get_all_analysis_ply_names",
"get_analysis_ply_index_to_name_map",
"get_dpf_material_id_by_analyis_ply_map",
"get_dpf_material_id_by_analysis_ply_map",
"get_element_info_provider",
"material_properties",
"material_operators",
Expand Down
32 changes: 32 additions & 0 deletions src/ansys/dpf/composites/layup_info/_layup_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from dataclasses import dataclass
from typing import Any, Collection, Dict, List, Optional, Sequence, Union, cast
from warnings import warn

import ansys.dpf.core as dpf
from ansys.dpf.core import DataSources, MeshedRegion, Operator, PropertyField
Expand Down Expand Up @@ -200,6 +201,37 @@ def get_dpf_material_id_by_analyis_ply_map(
data_source_or_streams_provider:
DPF data source with rst file or streams_provider. The streams provider is
available from :attr:`.CompositeModel.core_model` (under metadata.streams_provider).

Note
----
Cache the output because the computation can be performance critical.
roosre marked this conversation as resolved.
Show resolved Hide resolved
"""
warn(
"`get_dpf_material_id_by_analyis_ply_map` is deprecated. "
"Please use `get_dpf_material_id_by_analysis_ply_map`.",
category=DeprecationWarning,
stacklevel=2,
)
return get_dpf_material_id_by_analysis_ply_map(mesh, data_source_or_streams_provider)


def get_dpf_material_id_by_analysis_ply_map(
mesh: MeshedRegion,
data_source_or_streams_provider: Union[DataSources, Operator],
) -> Dict[str, np.int64]:
"""Get Dict that maps analysis ply names to dpf_material_ids.
roosre marked this conversation as resolved.
Show resolved Hide resolved

Parameters
----------
mesh
DPF Meshed region enriched with lay-up information
roosre marked this conversation as resolved.
Show resolved Hide resolved
data_source_or_streams_provider:
DPF data source with rst file or streams_provider. The streams provider is
roosre marked this conversation as resolved.
Show resolved Hide resolved
available from :attr:`.CompositeModel.core_model` (under metadata.streams_provider).
roosre marked this conversation as resolved.
Show resolved Hide resolved

Note
----
Cache the output because the computation can be performance critical.
roosre marked this conversation as resolved.
Show resolved Hide resolved
"""
# Note: The stream_provider_or_data_source is not strictly needed for this workflow
# We just need it because get_element_info_provider provider needs it (which needs
roosre marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
14 changes: 13 additions & 1 deletion tests/composite_model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from ansys.dpf.composites.layup_info import LayerProperty, get_analysis_ply_index_to_name_map
from ansys.dpf.composites.layup_info.material_properties import MaterialProperty
from ansys.dpf.composites.result_definition import FailureMeasureEnum
from ansys.dpf.composites.server_helpers import version_older_than
from ansys.dpf.composites.server_helpers import version_equal_or_later, version_older_than

from .helper import Timer

Expand Down Expand Up @@ -83,6 +83,18 @@ def test_basic_functionality_of_composite_model(dpf_server, data_files, distribu

assert [ply["id"] for ply in sampling_point.analysis_plies] == analysis_ply_ids

if version_equal_or_later(dpf_server, "7.0"):
ref_material_names = [
"Epoxy Carbon UD (230 GPa) Prepreg",
"Epoxy Carbon Woven (230 GPa) Wet",
"Honeycomb",
"Structural Steel",
]
mat_names = composite_model.material_names
assert len(mat_names) == len(ref_material_names)
for mat_name in ref_material_names:
assert mat_name in mat_names.keys()

timer.add("After getting properties")

timer.summary()
Expand Down
4 changes: 2 additions & 2 deletions tests/material_properties_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
AnalysisPlyInfoProvider,
get_all_analysis_ply_names,
get_analysis_ply_index_to_name_map,
get_dpf_material_id_by_analyis_ply_map,
get_dpf_material_id_by_analysis_ply_map,
get_element_info_provider,
)
from ansys.dpf.composites.layup_info.material_operators import get_material_operators
Expand All @@ -26,7 +26,7 @@ def test_get_analysis_ply_material_id_map(dpf_server):
files = get_basic_shell_files()
setup_result = setup_operators(dpf_server, files)

material_map = get_dpf_material_id_by_analyis_ply_map(
material_map = get_dpf_material_id_by_analysis_ply_map(
setup_result.mesh, setup_result.streams_provider
)

Expand Down
Loading