11"""Helpers to get material properties."""
22from enum import Enum
3- from typing import Collection , Dict , Union , cast
3+ from typing import Collection , Dict , Set , Union , cast
44
55from ansys .dpf .core import DataSources , MeshedRegion , Operator , types
66import 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
1818class 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
149147def 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
0 commit comments