Skip to content

Commit

Permalink
add material_names as property to the CompositeModel which returns …
Browse files Browse the repository at this point in the history
…a dict[dpf mat id, material name].
  • Loading branch information
roosre committed Sep 22, 2023
1 parent 6a0bbbd commit d9f3db9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
19 changes: 19 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,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.
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]:
"""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.
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]:
"""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.
Expand Down

0 comments on commit d9f3db9

Please sign in to comment.