How do I calculate element face normal of a solid element?
Ayush Kumar
Member, Moderator, Employee Posts: 467
✭✭✭✭
Answers
-
For 22R2 and above:
import mech_dpf import Ans.DataProcessing as dpf analysis = Model.Analyses[0] model = dpf.DataSources(analysis.ResultFileName) # Element ID for which you want a element face normal element_id = 1596 # Get Mesh op = dpf.operators.mesh.mesh_provider() # operator instanciation op.inputs.data_sources.Connect(model) my_mesh = op.outputs.mesh.GetData() nodal_scoping = dpf.Scoping(Location="Nodal") nodal_scoping.Ids = my_mesh.ElementById(element_id).NodeIds # Extract Skin mesh from solid mesh skin_mesh = dpf.operators.mesh.skin(mesh=my_mesh) skin_mesh.inputs.mesh_scoping.Connect(nodal_scoping) skin_meshed_region = skin_mesh.outputs.mesh.GetData() # Get corresponding skin mesh element(s) element_scoping = dpf.Scoping(Location="Elemental") solid_element_index = my_mesh.ElementIds.IndexOf(element_id) # Calculate normal to the element face normal = dpf.operators.geo.normals_provider_nl() normal.inputs.mesh.Connect(skin_meshed_region) normal_vec_out_field = normal.outputs.field.GetData() # Get all normal vectors to the element face(s) skin_element_ids = skin_meshed_region.ElementScoping.Ids normal_vectors = [normal_vec_out_field.GetEntityDataById(skin_element) for skin_element in skin_element_ids]
for 2021R2:
import mech_dpf import Ans.DataProcessing as dpf analysis = Model.Analyses[0] model = dpf.DataSources(analysis.ResultFileName) # Element ID for which you want a element face normal element_id = 1596 # Get Mesh op = dpf.operators.mesh.mesh_provider() # operator instanciation op.inputs.data_sources.Connect(model) my_mesh = op.outputs.mesh.GetData() # Extract Skin mesh from solid mesh skin_mesh = dpf.operators.mesh.skin(mesh=my_mesh) skin_meshed_region = skin_mesh.outputs.mesh.GetData() """ Skin mesh to solid mesh mapper. This is needed becauses DPF creates new element IDs for skin mesh. The location of solid element and corresponding skin mesh element is same, therefore a mapper based on the location. """ skin_mesh_mapper = skin_mesh.outputs.property_field_new_elements_to_old.GetData() # Get corresponding skin mesh element(s) element_scoping = dpf.Scoping(Location="Elemental") solid_element_index = my_mesh.ElementIds.IndexOf(element_id) indexes = [] for index in range(len(skin_mesh_mapper.Data)): if skin_mesh_mapper.Data[index] == solid_element_index: indexes.append(index) element_scoping.Ids = [skin_mesh_mapper.Scoping.Ids[index] for index in indexes] # Calculate normal to the element face normal = dpf.operators.geo.normals_provider_nl() normal.inputs.mesh.Connect(skin_meshed_region) normal.inputs.mesh_scoping.Connect(element_scoping) normal_vec_out_field = normal.outputs.field.GetData() # Get all normal vectors to the element face(s) normal_vectors = [normal_vec_out_field.GetEntityDataById(skin_element) for skin_element in element_scoping.Ids]
3