stl file contains multiple parts / individual material parameters needed

More
3 years 8 months ago #3578 by user85
Hello guys,

I have a stl file which contains 4 parts (see "test.stl" in the attachments).

File Attachment:

File Name: test_2021-03-11.stl
File Size:141 KB



As a first step I import this file and create a ngsolve mesh. Now I can print the following information:

print("materials = ", mesh.GetMaterials()):
materials = ('default',)

print("boundaries = ", mesh.GetBoundaries()):
boundaries = ('default', 'default', 'default', 'default', 'default', 'default', 'default', 'default', 'default', 'default', 'default', 'default', 'default', 'default', 'default', 'default', 'default', 'default', 'default', 'default', 'default', 'default', 'default', 'default')

As you can see I get all 24 boundaries but only one material. How to define different material parameters for the individual parts?


Thank you for your help!

Best,
Max
More
3 years 8 months ago #3579 by christopher
You could do this in a postprocessing step: Iterate over the elements and decide by some criterion to change the element index. Then name the materials. Something like this should work:
Code:
for el in mesh.Elements3D(): if mesh[el.points[0]] < 0: el.index = 2 mesh.SetMaterial(2, "new_mat_name")
More
3 years 8 months ago #3581 by user85
Thank you very much for your helpful answer.

Here is my solution:
Code:
th = -700 # threshold for el in mesh.Elements3D(): if mesh[el.points[0]][0] < th: # I compare the x-coordinate with the threshold el.index = 2 mesh.SetMaterial(2, "mat2")

Best,
Max
Time to create page: 0.103 seconds