Skip to content

Commit d11e4be

Browse files
roosrePipKat
andauthored
Feat/material names into v0.3 (#355)
* Feat/exposure of material names (#353) * add `material_names` as property to the CompositeModel which returns a dict[dpf mat id, material name]. * add unit test * apply pre-commit patch * Update documentation --------- Co-authored-by: Kathy Pippert <[email protected]> * Fix broken link, and port changes from 0.3.1 back to develop (#350) # Conflicts: # doc/source/index.rst --------- Co-authored-by: Kathy Pippert <[email protected]>
1 parent 2fc4911 commit d11e4be

File tree

11 files changed

+109
-20
lines changed

11 files changed

+109
-20
lines changed

README.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ PyDPF Composites
3434

3535

3636
PyDPF Composites enables the post-processing of composite structures based on
37-
`Ansys DPF`_ and the DPF Composites plugin. It implements classes on top of
38-
DPF Composites operators and data accessors for short fiber and layered
39-
composites (layered shell and solid elements). This module can be used to
40-
postprocess fiber reinforced plastics and layered composites, and to implement
41-
custom failure criteria and computation. For information demonstrating
42-
the behavior and usage of PyDPF Composites, see `Examples`_ in the DPF Composite
43-
documentation.
37+
`Ansys DPF`_ and the DPF Composites plugin. So it is a Python wrapper which
38+
implements classes on top of DPF Composites operators and data accessors for
39+
short fiber and layered composites (layered shell and solid elements). This
40+
module can be used to postprocess fiber reinforced plastics and layered
41+
composites, and to implement custom failure criteria and computation. For
42+
information demonstrating the behavior and usage of PyDPF Composites,
43+
see `Examples`_ in the DPF Composite documentation.
4444

4545
.. START_MARKER_FOR_SPHINX_DOCS
4646
@@ -195,6 +195,6 @@ released versions.
195195
.. _pytest: https://docs.pytest.org/en/stable/
196196
.. _Sphinx: https://www.sphinx-doc.org/en/master/
197197
.. _tox: https://tox.wiki/
198-
.. _Examples: https://composites.dpf.docs.pyansys.com/dev/examples/index.html
198+
.. _Examples: https://composites.dpf.docs.pyansys.com/version/stable/examples/index.html
199199
.. _Getting The DPF Server Docker Image: https://composites.dpf.docs.pyansys.com/version/stable/intro.html#getting-the-dpf-server-docker-image
200200
.. _Ansys DPF: https://dpf.docs.pyansys.com/version/stable/

doc/source/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,4 @@ Limitations
7474
.. _Ansys Workbench: https://download.ansys.com/Current%20Release
7575
.. _Import of Legacy Mechanical APDL Composite Models: https://ansyshelp.ansys.com/account/secured?returnurl=/Views/Secured/corp/v231/en/acp_ug/acp_import_legacy_APDL_comp.html
7676
.. _Compatibility: https://dpf.docs.pyansys.com/version/stable/getting_started/compatibility.html
77-
.. _Ansys DPF: https://dpf.docs.pyansys.com/version/stable/
77+
.. _Ansys DPF: https://dpf.docs.pyansys.com/version/stable/

examples/006_filter_composite_data_example.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from ansys.dpf.composites.layup_info import (
2828
AnalysisPlyInfoProvider,
2929
get_all_analysis_ply_names,
30-
get_dpf_material_id_by_analyis_ply_map,
30+
get_dpf_material_id_by_analysis_ply_map,
3131
)
3232
from ansys.dpf.composites.select_indices import (
3333
get_selected_indices,
@@ -123,7 +123,7 @@
123123
# Note: It is not possible to get a DPF material ID for a
124124
# given material name. It is only possible to get a DPF material
125125
# ID from an analysis ply.
126-
material_map = get_dpf_material_id_by_analyis_ply_map(
126+
material_map = get_dpf_material_id_by_analysis_ply_map(
127127
composite_model.get_mesh(), data_source_or_streams_provider=composite_model.data_sources.rst
128128
)
129129
ud_material_id = material_map["P1L1__ud_patch ns1"]

src/ansys/dpf/composites/_composite_model_impl.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,34 @@ def material_operators(self) -> MaterialOperators:
144144
"""Material operators."""
145145
return self._material_operators
146146

147+
@property
148+
def material_names(self) -> Dict[str, int]:
149+
"""
150+
Material name to DPF material ID map.
151+
152+
This property can be used to filter analysis plies
153+
or element layers.
154+
"""
155+
try:
156+
helper_op = dpf.Operator("composite::materials_container_helper")
157+
except Exception as exc:
158+
raise RuntimeError(
159+
f"Operator composite::materials_container_helper doesn't exist. "
160+
f"This could be because the server version is 2024 R1-pre0. The "
161+
f"latest preview or the unified installer can be used instead. "
162+
f"Error: {exc}"
163+
) from exc
164+
165+
helper_op.inputs.materials_container(self._material_operators.material_provider.outputs)
166+
string_field = helper_op.outputs.material_names()
167+
material_ids = string_field.scoping.ids
168+
169+
names = {}
170+
for mat_id in material_ids:
171+
names[string_field.data[string_field.scoping.index(mat_id)]] = mat_id
172+
173+
return names
174+
147175
@_deprecated_composite_definition_label
148176
def get_mesh(self, composite_definition_label: Optional[str] = None) -> MeshedRegion:
149177
"""Get the underlying DPF meshed region.

src/ansys/dpf/composites/_composite_model_impl_2023r2.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def __init__(
143143
warn(
144144
"The post-processing of composite models with multiple lay-up"
145145
" definitions (assemblies) is deprecated with DPF servers older than 7.0"
146-
" (2024 R1). Please use DPF server 7.0 or later.",
146+
" (2024 R1). DPF server 7.0 or later should be used instead.",
147147
DeprecationWarning,
148148
stacklevel=2,
149149
)
@@ -193,6 +193,15 @@ def material_operators(self) -> MaterialOperators:
193193
"""Material operators."""
194194
return self._material_operators
195195

196+
@property
197+
def material_names(self) -> Dict[str, int]:
198+
"""Get material name to DPF material ID map."""
199+
raise NotImplementedError(
200+
"material_names is not implemented"
201+
" for this version of DPF. DPF server 7.0 (2024 R1)"
202+
" or later should be used instead."
203+
)
204+
196205
def get_layup_operator(self, composite_definition_label: Optional[str] = None) -> Operator:
197206
"""Get the lay-up operator.
198207
@@ -550,8 +559,9 @@ def get_all_layered_element_ids(self) -> Sequence[int]:
550559
"""Get all layered element IDs."""
551560
raise NotImplementedError(
552561
"get_all_layered_element_ids is not implemented"
553-
" for this version of DPF. Please upgrade to 7.0 (2024 R1)"
554-
" or later. Use get_all_layered_element_ids_for_composite_definition_label"
562+
" for this version of DPF. DPF server 7.0 (2024 R1)"
563+
" or later should be used instead. Use "
564+
"get_all_layered_element_ids_for_composite_definition_label"
555565
" instead."
556566
)
557567

src/ansys/dpf/composites/composite_model.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ def material_operators(self) -> MaterialOperators:
106106
"""Material operators."""
107107
return self._implementation.material_operators
108108

109+
@property
110+
def material_names(self) -> Dict[str, int]:
111+
"""Get material name to DPF material ID map."""
112+
return self._implementation.material_names
113+
109114
def get_mesh(self, composite_definition_label: Optional[str] = None) -> MeshedRegion:
110115
"""Get the underlying DPF meshed region.
111116

src/ansys/dpf/composites/layup_info/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
get_all_analysis_ply_names,
1212
get_analysis_ply_index_to_name_map,
1313
get_dpf_material_id_by_analyis_ply_map,
14+
get_dpf_material_id_by_analysis_ply_map,
1415
get_element_info_provider,
1516
)
1617

@@ -25,6 +26,7 @@
2526
"get_all_analysis_ply_names",
2627
"get_analysis_ply_index_to_name_map",
2728
"get_dpf_material_id_by_analyis_ply_map",
29+
"get_dpf_material_id_by_analysis_ply_map",
2830
"get_element_info_provider",
2931
"material_properties",
3032
"material_operators",

src/ansys/dpf/composites/layup_info/_layup_info.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from dataclasses import dataclass
44
from typing import Any, Collection, Dict, List, Optional, Sequence, Union, cast
5+
from warnings import warn
56

67
import ansys.dpf.core as dpf
78
from ansys.dpf.core import DataSources, MeshedRegion, Operator, PropertyField
@@ -200,6 +201,38 @@ def get_dpf_material_id_by_analyis_ply_map(
200201
data_source_or_streams_provider:
201202
DPF data source with rst file or streams_provider. The streams provider is
202203
available from :attr:`.CompositeModel.core_model` (under metadata.streams_provider).
204+
205+
Note
206+
----
207+
Cache the output because the computation can be performance-critical.
208+
"""
209+
warn(
210+
"`get_dpf_material_id_by_analyis_ply_map` is deprecated. "
211+
" and was replaced by `get_dpf_material_id_by_analysis_ply_map`.",
212+
category=DeprecationWarning,
213+
stacklevel=2,
214+
)
215+
return get_dpf_material_id_by_analysis_ply_map(mesh, data_source_or_streams_provider)
216+
217+
218+
def get_dpf_material_id_by_analysis_ply_map(
219+
mesh: MeshedRegion,
220+
data_source_or_streams_provider: Union[DataSources, Operator],
221+
) -> Dict[str, np.int64]:
222+
"""Get the dictionary that maps analysis ply names to DPF material IDs.
223+
224+
Parameters
225+
----------
226+
mesh
227+
DPF Meshed region enriched with lay-up information
228+
data_source_or_streams_provider:
229+
DPF data source with RST file or streams provider. The streams provider is
230+
available from the :attr:`.CompositeModel.core_model` attribute
231+
(under ``metadata.streams_provider``).
232+
233+
Note
234+
----
235+
Cache the output because the computation can be performance-critical.
203236
"""
204237
# Note: The stream_provider_or_data_source is not strictly needed for this workflow
205238
# We just need it because get_element_info_provider provider needs it (which needs

src/ansys/dpf/composites/unit_system.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ def get_unit_system(
4141
if default_unit_system is None:
4242
raise RuntimeError(
4343
"The result file does not specify a unit system."
44-
" Please define a default unit system. "
45-
"A default unit system can be passed when "
46-
"creating a CompositeModel."
44+
" A default unit system must be defined.. "
45+
"It can be passed when creating a CompositeModel."
4746
)
4847
return default_unit_system
4948
else:

tests/composite_model_test.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from ansys.dpf.composites.layup_info import LayerProperty, get_analysis_ply_index_to_name_map
1515
from ansys.dpf.composites.layup_info.material_properties import MaterialProperty
1616
from ansys.dpf.composites.result_definition import FailureMeasureEnum
17-
from ansys.dpf.composites.server_helpers import version_older_than
17+
from ansys.dpf.composites.server_helpers import version_equal_or_later, version_older_than
1818

1919
from .helper import Timer
2020

@@ -83,6 +83,18 @@ def test_basic_functionality_of_composite_model(dpf_server, data_files, distribu
8383

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

86+
if version_equal_or_later(dpf_server, "7.0"):
87+
ref_material_names = [
88+
"Epoxy Carbon UD (230 GPa) Prepreg",
89+
"Epoxy Carbon Woven (230 GPa) Wet",
90+
"Honeycomb",
91+
"Structural Steel",
92+
]
93+
mat_names = composite_model.material_names
94+
assert len(mat_names) == len(ref_material_names)
95+
for mat_name in ref_material_names:
96+
assert mat_name in mat_names.keys()
97+
8698
timer.add("After getting properties")
8799

88100
timer.summary()

0 commit comments

Comments
 (0)