- Thank you received: 0
stl file contains multiple parts / individual material parameters needed
3 years 9 months ago #3578
by user85
Hello guys,
I have a stl file which contains 4 parts (see "test.stl" in the attachments).
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
I have a stl file which contains 4 parts (see "test.stl" in the attachments).
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
Attachments:
- christopher
- Offline
- Administrator
Less
More
- Thank you received: 101
3 years 9 months ago #3579
by christopher
Replied by christopher on topic stl file contains multiple parts / individual material parameters needed
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")
3 years 9 months ago #3581
by user85
Replied by user85 on topic stl file contains multiple parts / individual material parameters needed
Thank you very much for your helpful answer.
Here is my solution:
Best,
Max
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.134 seconds