Skip to content

Commit 7b29e9f

Browse files
Get all material ids from the element infos instead of the analysis p… (#229)
Get all material ids from the element infos instead of the analysis plies reuse the unit system when evaluating the properties
1 parent 3e1db7e commit 7b29e9f

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

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

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
"""Helpers to get material properties."""
22
from enum import Enum
3-
from typing import Collection, Dict, Union, cast
3+
from typing import Collection, Dict, Set, Union, cast
44

55
from ansys.dpf.core import DataSources, MeshedRegion, Operator, types
66
import numpy as np
77

8-
from ._layup_info import get_dpf_material_id_by_analyis_ply_map
9-
108
__all__ = (
119
"MaterialProperty",
1210
"get_constant_property",
1311
"get_all_dpf_material_ids",
1412
"get_constant_property_dict",
1513
)
14+
from ..unit_system import UnitSystemProvider, get_unit_system
15+
from ._layup_info import get_element_info_provider
1616

1717

1818
class MaterialProperty(str, Enum):
@@ -89,7 +89,7 @@ def get_constant_property(
8989
material_property: MaterialProperty,
9090
dpf_material_id: np.int64,
9191
materials_provider: Operator,
92-
data_source_or_streams_provider: Union[DataSources, Operator],
92+
unit_system: UnitSystemProvider,
9393
) -> float:
9494
"""Get a constant material property.
9595
@@ -105,19 +105,14 @@ def get_constant_property(
105105
materials_provider:
106106
DPF Materials provider operator. This value is available from the
107107
:attr:`.CompositeModel.material_operators` attribute.
108-
data_source_or_streams_provider:
109-
Data source or streams provider that contains the RST file.
108+
unit_system:
110109
"""
111110
material_property_field = Operator("eng_data::ans_mat_property_field_provider")
112111
material_property_field.inputs.materials_container(materials_provider)
113112
material_property_field.inputs.dpf_mat_id(int(dpf_material_id))
114113
material_property_field.inputs.property_name(material_property.value)
115-
result_info_provider = Operator("ResultInfoProvider")
116-
if isinstance(data_source_or_streams_provider, DataSources):
117-
result_info_provider.inputs.data_sources(data_source_or_streams_provider)
118-
else:
119-
result_info_provider.inputs.streams_container(data_source_or_streams_provider)
120-
material_property_field.inputs.unit_system_or_result_info(result_info_provider)
114+
115+
material_property_field.inputs.unit_system_or_result_info(unit_system)
121116
properties = material_property_field.get_output(output_type=types.fields_container)
122117
assert len(properties) == 1, "Properties container has to have exactly one entry."
123118
assert len(properties[0].data) == 1, (
@@ -140,10 +135,13 @@ def get_all_dpf_material_ids(
140135
data_source_or_streams_provider:
141136
DPF data source or stream provider that contains the RST file.
142137
"""
143-
id_to_material_map = get_dpf_material_id_by_analyis_ply_map(
144-
mesh, data_source_or_streams_provider
145-
)
146-
return set(id_to_material_map.values())
138+
element_info_provider = get_element_info_provider(mesh, data_source_or_streams_provider)
139+
all_material_ids: Set["np.int64"] = set()
140+
for element_id in mesh.elements.scoping.ids:
141+
element_info = element_info_provider.get_element_info(element_id)
142+
if element_info is not None:
143+
all_material_ids.update(element_info.dpf_material_ids)
144+
return all_material_ids
147145

148146

149147
def get_constant_property_dict(
@@ -155,7 +153,7 @@ def get_constant_property_dict(
155153
"""Get a dictionary with constant properties.
156154
157155
Returns a dictionary with the DPF material ID as a key and
158-
a dictionaory with the requested properties as the value. Only constant properties
156+
a dictionary with the requested properties as the value. Only constant properties
159157
are supported. Variable properties are evaluated at their
160158
default values.
161159
Because this method can be slow to evaluate, it should not
@@ -174,6 +172,7 @@ def get_constant_property_dict(
174172
DPF meshed region enriched with lay-up information.
175173
"""
176174
properties: Dict[np.int64, Dict[MaterialProperty, float]] = {}
175+
unit_system = get_unit_system(data_source_or_streams_provider)
177176
for dpf_material_id in get_all_dpf_material_ids(
178177
mesh=mesh, data_source_or_streams_provider=data_source_or_streams_provider
179178
):
@@ -183,7 +182,7 @@ def get_constant_property_dict(
183182
material_property=material_property,
184183
dpf_material_id=dpf_material_id,
185184
materials_provider=materials_provider,
186-
data_source_or_streams_provider=data_source_or_streams_provider,
185+
unit_system=unit_system,
187186
)
188187
properties[dpf_material_id][material_property] = constant_property
189188
return properties

src/ansys/dpf/composites/unit_system.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313

1414

1515
def get_unit_system(
16-
rst_data_source: DataSources, default_unit_system: Optional[UnitSystem] = None
16+
data_source_or_streams_provider: Union[DataSources, Operator],
17+
default_unit_system: Optional[UnitSystem] = None,
1718
) -> UnitSystemProvider:
1819
"""Get unit_system from rst DataSources.
1920
@@ -23,14 +24,17 @@ def get_unit_system(
2324
2425
Parameters
2526
----------
26-
rst_data_source:
27-
DPF Data Source containing a rst file.
27+
data_source_or_streams_provider:
28+
DPF Data Source or streams provider containing a rst file.
2829
default_unit_system:
2930
Default Unit system that is used if the rst file does not contain
3031
a unit system.
3132
"""
3233
result_info_provider = Operator("ResultInfoProvider")
33-
result_info_provider.inputs.data_sources(rst_data_source)
34+
if isinstance(data_source_or_streams_provider, Operator):
35+
result_info_provider.inputs.streams_container(data_source_or_streams_provider)
36+
else:
37+
result_info_provider.inputs.data_sources(data_source_or_streams_provider)
3438

3539
# If unit system is undefined, fall back to default_unit_system
3640
if result_info_provider.outputs.result_info().unit_system == "Undefined":

0 commit comments

Comments
 (0)