From ec056433445b21fd88c61924d0d3478d1c9969be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Roos?= Date: Thu, 14 Sep 2023 16:23:01 +0200 Subject: [PATCH 01/22] Fix broken link, and port changes from 0.3.1 back to develop --- README.rst | 16 ++++++++-------- doc/source/index.rst | 6 ++++-- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/README.rst b/README.rst index 6776ffedc..d7b45fbca 100644 --- a/README.rst +++ b/README.rst @@ -34,13 +34,13 @@ PyDPF Composites PyDPF Composites enables the post-processing of composite structures based on -`Ansys DPF`_ and the DPF Composites plugin. It implements classes on top of -DPF Composites operators and data accessors for short fiber and layered -composites (layered shell and solid elements). This module can be used to -postprocess fiber reinforced plastics and layered composites, and to implement -custom failure criteria and computation. For information demonstrating -the behavior and usage of PyDPF Composites, see `Examples`_ in the DPF Composite -documentation. +`Ansys DPF`_ and the DPF Composites plugin. So it is a Python wrapper which +implements classes on top of DPF Composites operators and data accessors for +short fiber and layered composites (layered shell and solid elements). This +module can be used to postprocess fiber reinforced plastics and layered +composites, and to implement custom failure criteria and computation. For +information demonstrating the behavior and usage of PyDPF Composites, +see `Examples`_ in the DPF Composite documentation. .. START_MARKER_FOR_SPHINX_DOCS @@ -195,6 +195,6 @@ released versions. .. _pytest: https://docs.pytest.org/en/stable/ .. _Sphinx: https://www.sphinx-doc.org/en/master/ .. _tox: https://tox.wiki/ -.. _Examples: https://composites.dpf.docs.pyansys.com/dev/examples/index.html +.. _Examples: https://composites.dpf.docs.pyansys.com/version/stable/examples/index.html .. _Getting The DPF Server Docker Image: https://composites.dpf.docs.pyansys.com/version/stable/intro.html#getting-the-dpf-server-docker-image .. _Ansys DPF: https://dpf.docs.pyansys.com/version/stable/ \ No newline at end of file diff --git a/doc/source/index.rst b/doc/source/index.rst index d499f9862..15620cdb2 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -11,10 +11,11 @@ PyDPF Composites ---------------- -PyDPF Composites is a Python wrapper for Ansys DPF composites. It implements +PyDPF Composites enables the post-processing of composite structures based on +`Ansys DPF`_ and the DPF Composites plugin. It implements classes on top of DPF Composites operators and data accessors for short fiber and layered composites (layered shell and solid elements). This module -can be used to postprocess fiber reinforced plastics and layered composites and +can be used to postprocess fiber reinforced plastics and layered composites, and to implement custom failure criteria and computation. .. grid:: 1 1 2 2 @@ -73,3 +74,4 @@ Limitations .. _Ansys Workbench: https://download.ansys.com/Current%20Release .. _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 .. _Compatibility: https://dpf.docs.pyansys.com/version/stable/getting_started/compatibility.html +.. _Ansys DPF: https://dpf.docs.pyansys.com/version/stable/ From d9f3db970596c4a2ca1a8ab0aab6f1a4bb9435a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Roos?= Date: Fri, 22 Sep 2023 08:03:16 +0200 Subject: [PATCH 02/22] add `material_names` as property to the CompositeModel which returns a dict[dpf mat id, material name]. --- .../dpf/composites/_composite_model_impl.py | 19 +++++++++++++++++++ .../_composite_model_impl_2023r2.py | 9 +++++++++ src/ansys/dpf/composites/composite_model.py | 5 +++++ 3 files changed, 33 insertions(+) diff --git a/src/ansys/dpf/composites/_composite_model_impl.py b/src/ansys/dpf/composites/_composite_model_impl.py index d10cc73fb..2f264103a 100644 --- a/src/ansys/dpf/composites/_composite_model_impl.py +++ b/src/ansys/dpf/composites/_composite_model_impl.py @@ -144,6 +144,25 @@ 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. + """ + helper_op = dpf.Operator("composite::materials_container_helper") + 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. diff --git a/src/ansys/dpf/composites/_composite_model_impl_2023r2.py b/src/ansys/dpf/composites/_composite_model_impl_2023r2.py index bd5f3c4d4..c6515063d 100644 --- a/src/ansys/dpf/composites/_composite_model_impl_2023r2.py +++ b/src/ansys/dpf/composites/_composite_model_impl_2023r2.py @@ -193,6 +193,15 @@ def material_operators(self) -> MaterialOperators: """Material operators.""" return self._material_operators + @property + def material_names(self) -> Dict[str, int]: + """Material ID to name 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. diff --git a/src/ansys/dpf/composites/composite_model.py b/src/ansys/dpf/composites/composite_model.py index 5e4bb49b1..06a17b9da 100644 --- a/src/ansys/dpf/composites/composite_model.py +++ b/src/ansys/dpf/composites/composite_model.py @@ -106,6 +106,11 @@ def material_operators(self) -> MaterialOperators: """Material operators.""" return self._implementation.material_operators + @property + def material_names(self) -> Dict[str, int]: + """Material ID to name map""" + return self._implementation.material_names + def get_mesh(self, composite_definition_label: Optional[str] = None) -> MeshedRegion: """Get the underlying DPF meshed region. From fe3c22e21720fd8853b92b2f923331a3d282a3d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Roos?= Date: Fri, 22 Sep 2023 08:15:35 +0200 Subject: [PATCH 03/22] add unit test --- tests/composite_model_test.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/composite_model_test.py b/tests/composite_model_test.py index 04b13aa89..015ed795b 100644 --- a/tests/composite_model_test.py +++ b/tests/composite_model_test.py @@ -83,6 +83,17 @@ 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 + ref_material_names = { + 'Epoxy Carbon UD (230 GPa) Prepreg': 3, + 'Epoxy Carbon Woven (230 GPa) Wet': 2, + 'Honeycomb': 4, + 'Structural Steel': 1 + } + mat_names = composite_model.material_names + assert len(mat_names) == len(ref_material_names) + for mat_name, dpf_mat_id in ref_material_names.items(): + assert mat_names[mat_name] == dpf_mat_id + timer.add("After getting properties") timer.summary() From 4994770094a97f1667ee6f743c5d2de0c67a692b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Roos?= Date: Fri, 22 Sep 2023 13:21:22 +0200 Subject: [PATCH 04/22] apply pre-commit patch --- src/ansys/dpf/composites/_composite_model_impl.py | 10 ++++++++-- tests/composite_model_test.py | 8 ++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/ansys/dpf/composites/_composite_model_impl.py b/src/ansys/dpf/composites/_composite_model_impl.py index 2f264103a..5f659cada 100644 --- a/src/ansys/dpf/composites/_composite_model_impl.py +++ b/src/ansys/dpf/composites/_composite_model_impl.py @@ -151,7 +151,14 @@ def material_names(self) -> Dict[str, int]: Can be used to filter analysis plies or element layers. """ - helper_op = dpf.Operator("composite::materials_container_helper") + try: + helper_op = dpf.Operator("composite::materials_container_helper") + except: + raise RuntimeError( + "Operator composite::materials_container_helper does not exist in the registry " + " of 2024 R1-pre0. Please use the latest preview or the unified installer." + ) + helper_op.inputs.materials_container(self._material_operators.material_provider.outputs) string_field = helper_op.outputs.material_names() material_ids = string_field.scoping.ids @@ -162,7 +169,6 @@ def material_names(self) -> Dict[str, int]: return names - @_deprecated_composite_definition_label def get_mesh(self, composite_definition_label: Optional[str] = None) -> MeshedRegion: """Get the underlying DPF meshed region. diff --git a/tests/composite_model_test.py b/tests/composite_model_test.py index 015ed795b..585980c2d 100644 --- a/tests/composite_model_test.py +++ b/tests/composite_model_test.py @@ -84,10 +84,10 @@ 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 ref_material_names = { - 'Epoxy Carbon UD (230 GPa) Prepreg': 3, - 'Epoxy Carbon Woven (230 GPa) Wet': 2, - 'Honeycomb': 4, - 'Structural Steel': 1 + "Epoxy Carbon UD (230 GPa) Prepreg": 3, + "Epoxy Carbon Woven (230 GPa) Wet": 2, + "Honeycomb": 4, + "Structural Steel": 1, } mat_names = composite_model.material_names assert len(mat_names) == len(ref_material_names) From a60ac4aa19ef785a544e8955d658b77faf59f260 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Roos?= Date: Fri, 22 Sep 2023 14:11:11 +0200 Subject: [PATCH 05/22] apply pre-commit patch --- src/ansys/dpf/composites/_composite_model_impl.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ansys/dpf/composites/_composite_model_impl.py b/src/ansys/dpf/composites/_composite_model_impl.py index 5f659cada..c104a94bf 100644 --- a/src/ansys/dpf/composites/_composite_model_impl.py +++ b/src/ansys/dpf/composites/_composite_model_impl.py @@ -155,8 +155,9 @@ def material_names(self) -> Dict[str, int]: helper_op = dpf.Operator("composite::materials_container_helper") except: raise RuntimeError( - "Operator composite::materials_container_helper does not exist in the registry " - " of 2024 R1-pre0. Please use the latest preview or the unified installer." + "Operator composite::materials_container_helper doesn't exist. " + "This could be because the server version is 2024 R1-pre0. " + "Please use the latest preview or the unified installer." ) helper_op.inputs.materials_container(self._material_operators.material_provider.outputs) From ba0587b41533c9fe067ea13deb93bfa3254c1b84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Roos?= Date: Mon, 25 Sep 2023 08:29:02 +0200 Subject: [PATCH 06/22] Fix typo --- examples/006_filter_composite_data_example.py | 2 +- .../dpf/composites/layup_info/__init__.py | 2 ++ .../dpf/composites/layup_info/_layup_info.py | 31 +++++++++++++++++++ tests/material_properties_test.py | 4 +-- 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/examples/006_filter_composite_data_example.py b/examples/006_filter_composite_data_example.py index 32bef8815..c999311ca 100644 --- a/examples/006_filter_composite_data_example.py +++ b/examples/006_filter_composite_data_example.py @@ -27,7 +27,7 @@ from ansys.dpf.composites.layup_info import ( AnalysisPlyInfoProvider, get_all_analysis_ply_names, - get_dpf_material_id_by_analyis_ply_map, + get_dpf_material_id_by_analysis_ply_map, ) from ansys.dpf.composites.select_indices import ( get_selected_indices, diff --git a/src/ansys/dpf/composites/layup_info/__init__.py b/src/ansys/dpf/composites/layup_info/__init__.py index f7cd49679..355e913c0 100644 --- a/src/ansys/dpf/composites/layup_info/__init__.py +++ b/src/ansys/dpf/composites/layup_info/__init__.py @@ -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, ) @@ -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", diff --git a/src/ansys/dpf/composites/layup_info/_layup_info.py b/src/ansys/dpf/composites/layup_info/_layup_info.py index c76041d73..fb236dc64 100644 --- a/src/ansys/dpf/composites/layup_info/_layup_info.py +++ b/src/ansys/dpf/composites/layup_info/_layup_info.py @@ -200,6 +200,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. + """ + 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. + + Parameters + ---------- + mesh + DPF Meshed region enriched with lay-up information + 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. """ # 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 diff --git a/tests/material_properties_test.py b/tests/material_properties_test.py index aa3b1896e..84ebea7fc 100644 --- a/tests/material_properties_test.py +++ b/tests/material_properties_test.py @@ -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 @@ -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 ) From 8cca3cc5995d304d7fb1fe872c5d35c3f5a95b70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Roos?= Date: Mon, 25 Sep 2023 13:28:23 +0200 Subject: [PATCH 07/22] code style checks --- src/ansys/dpf/composites/_composite_model_impl_2023r2.py | 2 +- src/ansys/dpf/composites/layup_info/_layup_info.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ansys/dpf/composites/_composite_model_impl_2023r2.py b/src/ansys/dpf/composites/_composite_model_impl_2023r2.py index c6515063d..c0151158f 100644 --- a/src/ansys/dpf/composites/_composite_model_impl_2023r2.py +++ b/src/ansys/dpf/composites/_composite_model_impl_2023r2.py @@ -195,7 +195,7 @@ def material_operators(self) -> MaterialOperators: @property def material_names(self) -> Dict[str, int]: - """Material ID to name map""" + """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)" diff --git a/src/ansys/dpf/composites/layup_info/_layup_info.py b/src/ansys/dpf/composites/layup_info/_layup_info.py index fb236dc64..adb6c219c 100644 --- a/src/ansys/dpf/composites/layup_info/_layup_info.py +++ b/src/ansys/dpf/composites/layup_info/_layup_info.py @@ -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 From b8f9c35acf3f622ceae3003e9a5a642bd8ec47a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Roos?= Date: Mon, 25 Sep 2023 13:29:28 +0200 Subject: [PATCH 08/22] code style checks --- examples/006_filter_composite_data_example.py | 1 - src/ansys/dpf/composites/composite_model.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/006_filter_composite_data_example.py b/examples/006_filter_composite_data_example.py index c999311ca..33615aa48 100644 --- a/examples/006_filter_composite_data_example.py +++ b/examples/006_filter_composite_data_example.py @@ -27,7 +27,6 @@ from ansys.dpf.composites.layup_info import ( AnalysisPlyInfoProvider, get_all_analysis_ply_names, - get_dpf_material_id_by_analysis_ply_map, ) from ansys.dpf.composites.select_indices import ( get_selected_indices, diff --git a/src/ansys/dpf/composites/composite_model.py b/src/ansys/dpf/composites/composite_model.py index 06a17b9da..b54bf27cf 100644 --- a/src/ansys/dpf/composites/composite_model.py +++ b/src/ansys/dpf/composites/composite_model.py @@ -108,7 +108,7 @@ def material_operators(self) -> MaterialOperators: @property def material_names(self) -> Dict[str, int]: - """Material ID to name map""" + """Get material name to DPF material ID map.""" return self._implementation.material_names def get_mesh(self, composite_definition_label: Optional[str] = None) -> MeshedRegion: From 8c91b3132b27277c69c4e9102436f0ee9285f98c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Roos?= Date: Mon, 25 Sep 2023 13:30:24 +0200 Subject: [PATCH 09/22] code style checks --- examples/006_filter_composite_data_example.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/examples/006_filter_composite_data_example.py b/examples/006_filter_composite_data_example.py index 33615aa48..948af928f 100644 --- a/examples/006_filter_composite_data_example.py +++ b/examples/006_filter_composite_data_example.py @@ -24,10 +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, -) +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, From e5c1b1261cbe894d41519bd5d2ab0c1bee262732 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Roos?= Date: Mon, 25 Sep 2023 13:31:52 +0200 Subject: [PATCH 10/22] code style checks --- src/ansys/dpf/composites/_composite_model_impl.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ansys/dpf/composites/_composite_model_impl.py b/src/ansys/dpf/composites/_composite_model_impl.py index c104a94bf..8b47cf24c 100644 --- a/src/ansys/dpf/composites/_composite_model_impl.py +++ b/src/ansys/dpf/composites/_composite_model_impl.py @@ -153,11 +153,12 @@ def material_names(self) -> Dict[str, int]: """ try: helper_op = dpf.Operator("composite::materials_container_helper") - except: + except Exception as exc: raise RuntimeError( "Operator composite::materials_container_helper doesn't exist. " "This could be because the server version is 2024 R1-pre0. " - "Please use the latest preview or the unified installer." + "Please use the latest preview or the unified installer. " + f"Error: {exc}" ) helper_op.inputs.materials_container(self._material_operators.material_provider.outputs) From e8c91f7aac22f88666e9426d2b19ec021f68ab99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Roos?= Date: Mon, 25 Sep 2023 13:37:30 +0200 Subject: [PATCH 11/22] code style checks --- src/ansys/dpf/composites/_composite_model_impl.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/ansys/dpf/composites/_composite_model_impl.py b/src/ansys/dpf/composites/_composite_model_impl.py index 8b47cf24c..2d57f4302 100644 --- a/src/ansys/dpf/composites/_composite_model_impl.py +++ b/src/ansys/dpf/composites/_composite_model_impl.py @@ -154,12 +154,9 @@ def material_names(self) -> Dict[str, int]: try: helper_op = dpf.Operator("composite::materials_container_helper") except Exception as exc: - raise RuntimeError( - "Operator composite::materials_container_helper doesn't exist. " - "This could be because the server version is 2024 R1-pre0. " - "Please use the latest preview or the unified installer. " - f"Error: {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 " + 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() From c4bb351bc8b775c6f48aad90f9ae28b49af06471 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Roos?= Date: Mon, 25 Sep 2023 13:41:34 +0200 Subject: [PATCH 12/22] code style checks --- .../dpf/composites/_composite_model_impl.py | 8 +++++--- tests/composite_model_test.py | 16 ++++++++-------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/ansys/dpf/composites/_composite_model_impl.py b/src/ansys/dpf/composites/_composite_model_impl.py index 2d57f4302..84c9557c3 100644 --- a/src/ansys/dpf/composites/_composite_model_impl.py +++ b/src/ansys/dpf/composites/_composite_model_impl.py @@ -154,9 +154,11 @@ def material_names(self) -> Dict[str, int]: try: 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 " - f"the latest preview or the unified installer. Error: {exc}") from 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 " + 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() diff --git a/tests/composite_model_test.py b/tests/composite_model_test.py index 585980c2d..4f3ee4668 100644 --- a/tests/composite_model_test.py +++ b/tests/composite_model_test.py @@ -83,16 +83,16 @@ 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 - ref_material_names = { - "Epoxy Carbon UD (230 GPa) Prepreg": 3, - "Epoxy Carbon Woven (230 GPa) Wet": 2, - "Honeycomb": 4, - "Structural Steel": 1, - } + 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, dpf_mat_id in ref_material_names.items(): - assert mat_names[mat_name] == dpf_mat_id + for mat_name in ref_material_names: + assert mat_name in mat_names.keys() timer.add("After getting properties") From 2a3f2617d5403591c838a58d8b32ed3a3662d185 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Roos?= Date: Mon, 25 Sep 2023 13:57:37 +0200 Subject: [PATCH 13/22] run new test only if the latest server version is used. --- tests/composite_model_test.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/tests/composite_model_test.py b/tests/composite_model_test.py index 4f3ee4668..76cba588b 100644 --- a/tests/composite_model_test.py +++ b/tests/composite_model_test.py @@ -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 @@ -83,16 +83,17 @@ 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 - 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() + 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") From 9127c8f627b68ad87f857245b55f797db5253cdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Roos?= <105842014+roosre@users.noreply.github.com> Date: Mon, 25 Sep 2023 22:29:51 +0200 Subject: [PATCH 14/22] Update src/ansys/dpf/composites/layup_info/_layup_info.py Co-authored-by: Kathy Pippert <84872299+PipKat@users.noreply.github.com> --- src/ansys/dpf/composites/layup_info/_layup_info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ansys/dpf/composites/layup_info/_layup_info.py b/src/ansys/dpf/composites/layup_info/_layup_info.py index adb6c219c..06b6cb263 100644 --- a/src/ansys/dpf/composites/layup_info/_layup_info.py +++ b/src/ansys/dpf/composites/layup_info/_layup_info.py @@ -226,7 +226,7 @@ def get_dpf_material_id_by_analysis_ply_map( mesh DPF Meshed region enriched with lay-up information data_source_or_streams_provider: - DPF data source with rst file or streams_provider. The streams provider is + DPF data source with RST file or streams provider. The streams provider is available from :attr:`.CompositeModel.core_model` (under metadata.streams_provider). Note From 453353afed29ad73329dd4701535f00cb8612e72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Roos?= <105842014+roosre@users.noreply.github.com> Date: Mon, 25 Sep 2023 22:30:17 +0200 Subject: [PATCH 15/22] Update src/ansys/dpf/composites/layup_info/_layup_info.py Co-authored-by: Kathy Pippert <84872299+PipKat@users.noreply.github.com> --- src/ansys/dpf/composites/layup_info/_layup_info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ansys/dpf/composites/layup_info/_layup_info.py b/src/ansys/dpf/composites/layup_info/_layup_info.py index 06b6cb263..bd2d957d0 100644 --- a/src/ansys/dpf/composites/layup_info/_layup_info.py +++ b/src/ansys/dpf/composites/layup_info/_layup_info.py @@ -227,7 +227,7 @@ def get_dpf_material_id_by_analysis_ply_map( DPF Meshed region enriched with lay-up information 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). + available from the :attr:`.CompositeModel.core_model` attribute (under ``metadata.streams_provider``). Note ---- From 01c7b2f01f9a3e0cc38beccbdff06e7f5980fd77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Roos?= <105842014+roosre@users.noreply.github.com> Date: Mon, 25 Sep 2023 22:30:28 +0200 Subject: [PATCH 16/22] Update src/ansys/dpf/composites/layup_info/_layup_info.py Co-authored-by: Kathy Pippert <84872299+PipKat@users.noreply.github.com> --- src/ansys/dpf/composites/layup_info/_layup_info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ansys/dpf/composites/layup_info/_layup_info.py b/src/ansys/dpf/composites/layup_info/_layup_info.py index bd2d957d0..71a632eba 100644 --- a/src/ansys/dpf/composites/layup_info/_layup_info.py +++ b/src/ansys/dpf/composites/layup_info/_layup_info.py @@ -219,7 +219,7 @@ 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. + """Get the dictionary that maps analysis ply names to DPF material IDs. Parameters ---------- From 4d924c1c347fbf9fbe2702f81b06955f092d9782 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Roos?= <105842014+roosre@users.noreply.github.com> Date: Mon, 25 Sep 2023 22:30:37 +0200 Subject: [PATCH 17/22] Update src/ansys/dpf/composites/layup_info/_layup_info.py Co-authored-by: Kathy Pippert <84872299+PipKat@users.noreply.github.com> --- src/ansys/dpf/composites/layup_info/_layup_info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ansys/dpf/composites/layup_info/_layup_info.py b/src/ansys/dpf/composites/layup_info/_layup_info.py index 71a632eba..7624bbf49 100644 --- a/src/ansys/dpf/composites/layup_info/_layup_info.py +++ b/src/ansys/dpf/composites/layup_info/_layup_info.py @@ -204,7 +204,7 @@ def get_dpf_material_id_by_analyis_ply_map( Note ---- - Cache the output because the computation can be performance critical. + Cache the output because the computation can be performance-critical. """ warn( "`get_dpf_material_id_by_analyis_ply_map` is deprecated. " From a910500377eab0c8c769bd5253a2267fce567289 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Roos?= <105842014+roosre@users.noreply.github.com> Date: Mon, 25 Sep 2023 22:36:39 +0200 Subject: [PATCH 18/22] Update src/ansys/dpf/composites/layup_info/_layup_info.py Co-authored-by: Kathy Pippert <84872299+PipKat@users.noreply.github.com> --- src/ansys/dpf/composites/layup_info/_layup_info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ansys/dpf/composites/layup_info/_layup_info.py b/src/ansys/dpf/composites/layup_info/_layup_info.py index 7624bbf49..63c68f7fc 100644 --- a/src/ansys/dpf/composites/layup_info/_layup_info.py +++ b/src/ansys/dpf/composites/layup_info/_layup_info.py @@ -231,7 +231,7 @@ def get_dpf_material_id_by_analysis_ply_map( Note ---- - Cache the output because the computation can be performance critical. + Cache the output because the computation can be performance-critical. """ # 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 From 223292cdf41a0caf5895ac6f8eb33f9db9260cf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Roos?= Date: Mon, 25 Sep 2023 22:36:56 +0200 Subject: [PATCH 19/22] Update documentation --- src/ansys/dpf/composites/_composite_model_impl.py | 8 +++++--- .../dpf/composites/_composite_model_impl_2023r2.py | 11 ++++++----- src/ansys/dpf/composites/layup_info/_layup_info.py | 2 +- src/ansys/dpf/composites/unit_system.py | 5 ++--- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/ansys/dpf/composites/_composite_model_impl.py b/src/ansys/dpf/composites/_composite_model_impl.py index 84c9557c3..ddd6dc2cd 100644 --- a/src/ansys/dpf/composites/_composite_model_impl.py +++ b/src/ansys/dpf/composites/_composite_model_impl.py @@ -149,15 +149,17 @@ def material_names(self) -> Dict[str, int]: """ Material name to DPF material ID map. - Can be used to filter analysis plies or element layers. + This property can be used to filter analysis plies + or element layers. """ try: 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 " - f"the latest preview or the unified installer. Error: {exc}" + f"This could be because the server version is 2024 R1-pre0. The " + f"latest preview or the unified installer can be used instead. " + f"Error: {exc}" ) from exc helper_op.inputs.materials_container(self._material_operators.material_provider.outputs) diff --git a/src/ansys/dpf/composites/_composite_model_impl_2023r2.py b/src/ansys/dpf/composites/_composite_model_impl_2023r2.py index c0151158f..244e14b22 100644 --- a/src/ansys/dpf/composites/_composite_model_impl_2023r2.py +++ b/src/ansys/dpf/composites/_composite_model_impl_2023r2.py @@ -143,7 +143,7 @@ def __init__( warn( "The post-processing of composite models with multiple lay-up" " definitions (assemblies) is deprecated with DPF servers older than 7.0" - " (2024 R1). Please use DPF server 7.0 or later.", + " (2024 R1). DPF server 7.0 or later should be used instead.", DeprecationWarning, stacklevel=2, ) @@ -198,8 +198,8 @@ 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." + " for this version of DPF. DPF server 7.0 (2024 R1)" + " or later should be used instead." ) def get_layup_operator(self, composite_definition_label: Optional[str] = None) -> Operator: @@ -559,8 +559,9 @@ def get_all_layered_element_ids(self) -> Sequence[int]: """Get all layered element IDs.""" raise NotImplementedError( "get_all_layered_element_ids is not implemented" - " for this version of DPF. Please upgrade to 7.0 (2024 R1)" - " or later. Use get_all_layered_element_ids_for_composite_definition_label" + " for this version of DPF. DPF server 7.0 (2024 R1)" + " or later should be used instead. Use " + "get_all_layered_element_ids_for_composite_definition_label" " instead." ) diff --git a/src/ansys/dpf/composites/layup_info/_layup_info.py b/src/ansys/dpf/composites/layup_info/_layup_info.py index adb6c219c..2a5ac9fb6 100644 --- a/src/ansys/dpf/composites/layup_info/_layup_info.py +++ b/src/ansys/dpf/composites/layup_info/_layup_info.py @@ -208,7 +208,7 @@ def get_dpf_material_id_by_analyis_ply_map( """ warn( "`get_dpf_material_id_by_analyis_ply_map` is deprecated. " - "Please use `get_dpf_material_id_by_analysis_ply_map`.", + " and was replaced by `get_dpf_material_id_by_analysis_ply_map`.", category=DeprecationWarning, stacklevel=2, ) diff --git a/src/ansys/dpf/composites/unit_system.py b/src/ansys/dpf/composites/unit_system.py index ec0377c65..3782fb87a 100644 --- a/src/ansys/dpf/composites/unit_system.py +++ b/src/ansys/dpf/composites/unit_system.py @@ -41,9 +41,8 @@ def get_unit_system( if default_unit_system is None: raise RuntimeError( "The result file does not specify a unit system." - " Please define a default unit system. " - "A default unit system can be passed when " - "creating a CompositeModel." + " A default unit system must be defined.. " + "It can be passed when creating a CompositeModel." ) return default_unit_system else: From 0e3468dcebef7088a208e91f7024771d55b3ab10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Roos?= Date: Tue, 26 Sep 2023 06:44:34 +0200 Subject: [PATCH 20/22] code style checks --- examples/006_filter_composite_data_example.py | 2 +- src/ansys/dpf/composites/layup_info/_layup_info.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/006_filter_composite_data_example.py b/examples/006_filter_composite_data_example.py index 948af928f..f6fc7b868 100644 --- a/examples/006_filter_composite_data_example.py +++ b/examples/006_filter_composite_data_example.py @@ -119,7 +119,7 @@ # Note: It is not possible to get a DPF material ID for a # given material name. It is only possible to get a DPF material # ID from an analysis ply. -material_map = get_dpf_material_id_by_analyis_ply_map( +material_map = get_dpf_material_id_by_analysis_ply_map( composite_model.get_mesh(), data_source_or_streams_provider=composite_model.data_sources.rst ) ud_material_id = material_map["P1L1__ud_patch ns1"] diff --git a/src/ansys/dpf/composites/layup_info/_layup_info.py b/src/ansys/dpf/composites/layup_info/_layup_info.py index 4e6b68bcc..06969e553 100644 --- a/src/ansys/dpf/composites/layup_info/_layup_info.py +++ b/src/ansys/dpf/composites/layup_info/_layup_info.py @@ -227,7 +227,8 @@ def get_dpf_material_id_by_analysis_ply_map( DPF Meshed region enriched with lay-up information data_source_or_streams_provider: DPF data source with RST file or streams provider. The streams provider is - available from the :attr:`.CompositeModel.core_model` attribute (under ``metadata.streams_provider``). + available from the :attr:`.CompositeModel.core_model` attribute + (under ``metadata.streams_provider``). Note ---- From 1b9d6629691c75ffd54652de1e98855a9056f7da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Roos?= Date: Tue, 26 Sep 2023 06:56:12 +0200 Subject: [PATCH 21/22] code style checks --- examples/006_filter_composite_data_example.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/examples/006_filter_composite_data_example.py b/examples/006_filter_composite_data_example.py index f6fc7b868..d8c2f169a 100644 --- a/examples/006_filter_composite_data_example.py +++ b/examples/006_filter_composite_data_example.py @@ -24,7 +24,11 @@ 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 +from ansys.dpf.composites.layup_info import ( + AnalysisPlyInfoProvider, + get_all_analysis_ply_names, + get_dpf_material_id_by_analysis_ply_map, +) from ansys.dpf.composites.select_indices import ( get_selected_indices, get_selected_indices_by_analysis_ply, @@ -119,7 +123,7 @@ # Note: It is not possible to get a DPF material ID for a # given material name. It is only possible to get a DPF material # ID from an analysis ply. -material_map = get_dpf_material_id_by_analysis_ply_map( +material_names = get_dpf_material_id_by_analysis_ply_map( composite_model.get_mesh(), data_source_or_streams_provider=composite_model.data_sources.rst ) ud_material_id = material_map["P1L1__ud_patch ns1"] From 66f745ffa9d62a88b5faf5ae37a7f058b77c813e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Roos?= Date: Tue, 26 Sep 2023 07:04:33 +0200 Subject: [PATCH 22/22] fix documentation --- examples/006_filter_composite_data_example.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/006_filter_composite_data_example.py b/examples/006_filter_composite_data_example.py index d8c2f169a..fb832e296 100644 --- a/examples/006_filter_composite_data_example.py +++ b/examples/006_filter_composite_data_example.py @@ -123,7 +123,7 @@ # Note: It is not possible to get a DPF material ID for a # given material name. It is only possible to get a DPF material # ID from an analysis ply. -material_names = get_dpf_material_id_by_analysis_ply_map( +material_map = get_dpf_material_id_by_analysis_ply_map( composite_model.get_mesh(), data_source_or_streams_provider=composite_model.data_sources.rst ) ud_material_id = material_map["P1L1__ud_patch ns1"]