Name selection for 3D design in spaceclaim

Member Posts: 11
Name Dropper First Comment
**

i want to give name selection to design I have attached. in name selection I want to give porous name to all spheres and domain to the remaining(excluding all spheres) part.
this task I want to do using script in spaceclaim
anyone can help me please

Welcome!

It looks like you're new here. Sign in or register to get started.

Answers

  • Member, Moderator, Employee Posts: 311
    50 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭

    Hi

    Perhaps this helps:

    https://discuss.ansys.com/discussion/comment/4633#Comment_4633

    All the best

    Erik

  • Member Posts: 11
    Name Dropper First Comment
    **

    Python Script, API Version = V23

    import clr
    import random
    from SpaceClaim.Api.V23 import *

    por = []
    grain = []

    min_radius = 0.065 ## in mm
    max_radius = 0.085 ## in mm
    sphe = []
    spheres = []

    def generate_circles(volume, face, min_radius, max_radius):

    1. v = 0
    2. x =0
    3. while v < volume:
    4. x = x+1
    5. isOverlap = True
    6. while isOverlap:
    7. radius = random.uniform(min_radius, max_radius)
    8. x_center = random.uniform(-0.5 + radius, 0.5 - radius)
    9. y_center = random.uniform(-0.5 + radius, 0.5 - radius)
    10. z_center = random.uniform(radius, 1 - radius)
    11. isOverlap = False
    12. for j in range(len(spheres)):
    13. xr = x_center - spheres[j][0]
    14. yr = y_center - spheres[j][1]
    15. zr = z_center - spheres[j][2]
    16. d = radius + spheres[j][3]
    17. d1 = ((xr) ** 2 + (yr) ** 2 + (zr) ** 2) ** 0.5
    18. if d1 < d:
    19. isOverlap = True
    20. break
    21. if not isOverlap:
    22. origin = Point.Create(MM(x_center), MM(y_center), MM(z_center))
    23. sphere = SphereBody.Create(origin, MM(radius))
    24. sphe.append(sphere)
    25. v += (4/3) * 3.14 * (radius) ** 3
    26. new_sphere = [x_center, y_center, z_center, radius]
    27. spheres.append(new_sphere)
    28. return x

    making geometry

    porous = (0,0.01,0.1,0.15,0.2) ## Vol %

    validation paper: Simulation of heat transfer in hollow-glass-bead-filled polypropylene composites by finite element method

    for i in range(1): # define number of geometry to be generated
    porosity = porous[2]
    #porosity = random.uniform(0.1, 0.1)
    area = 1*porosity
    # Set Sketch Plane
    sectionPlane = Plane.PlaneXY
    result = ViewHelper.SetSketchPlane(sectionPlane, Info1)
    # EndBlock

    1. # Sketch Rectangle
    2. point1 = Point2D.Create(MM(-0.5),MM(0.5))
    3. point2 = Point2D.Create(MM(0.5),MM(0.5))
    4. point3 = Point2D.Create(MM(0.5),MM(-0.5))
    5. result1 = SketchRectangle.Create(point1, point2, point3)
    6. # EndBlock
    7.  
    8. # Solidify Sketch
    9. mode = InteractionMode.Solid
    10. result = ViewHelper.SetViewMode(mode, Info2)
    11. # EndBlock
    12. # Extrude 1 Face
    13. selection = Face3
    14. options = ExtrudeFaceOptions()
    15. options.ExtrudeType = ExtrudeType.Add
    16. result = ExtrudeFaces.Execute(selection, MM(1), options, Info7)
    17. # EndBlock
    18. # Create New Part
    19. selection = Part1
    20. result = ComponentHelper.CreateNewComponent(selection, Info3)
    21. # EndBlock
    22.  
    23. # Set Sketch Plane
    24. #selection = Face1
    25. #result = ViewHelper.SetSketchPlane(selection, Info4)
    26. # EndBlock
    27.  
    28.  
    29. # Function to generate random non-overlapping circles#########################
    30.  
    31. x = generate_circles(area,sectionPlane,min_radius,max_radius)
    32. por.append(porosity)
    33. grain.append(x)
    34. ################################################################
    35. # Solidify Sketch
    36. mode = InteractionMode.Solid
    37. result = ViewHelper.SetViewMode(mode, Info5)
    38. # Intersect Bodies
    39. targets = Body2
    40. tools = Body1
    41. options = MakeSolidsOptions()
    42. result = Combine.Intersect(targets, tools, options, Info9)
    43. # EndBlock
    44.  
    45. # Name selection
    46. sel = Selection.Create(Face6)
    47. sel.CreateAGroup("inlet") # inletFace8
    48.  
    49. sel = Selection.Create(Face7)
    50. sel.CreateAGroup("outlet") # outlet
    51.  
    52. sel = Selection.Create(Face8)
    53. sel.CreateAGroup("wall1") # upper side wall
    54.  
    55. sel = Selection.Create(Face9)
    56. sel.CreateAGroup("wall2") # down side wall
    57.  
    58. sel = Selection.Create(Face10)
    59. sel.CreateAGroup("wall3") # Yp wall
    60.  
    61. sel = Selection.Create(Face11)
    62. sel.CreateAGroup("wall4") # Yn wall
    63.  
    64. mys=[]
    65. mye = []
    66. vmin= 4.e-08 # min. volume of spheres
    67. vmax = 4e-01 # max. volume of spheres
    68. assembly = GetRootPart()
    69. bodies=assembly.Bodies
    70.  
    71. for body in bodies:
    72. if body.GetMaster().Shape.IsClosed==True: # check it is a solid body and not surface body
    73. s=body.Shape
    74. vol=s.Volume
    75. if vol >=vmin and vol <=vmax:
    76.  
    77. mys.append(body)
    78. else:
    79. mye.append(body)
    80.  
    81.  
    82. primarySelection = Selection.Create(mys)
    83. secondarySelection = Selection.Empty()
    84. resultmys = NamedSelection.Create(primarySelection, secondarySelection)
    85. NamedSelection.Rename("Group1", "Spheres")
    86.  
    87. Selection.Clear()
    88. # Create Named Selection Group
    89. primarySelection = Body3
    90. secondarySelection = Selection.Empty()
    91. result = NamedSelection.Create(primarySelection, secondarySelection)
    92. # EndBlock
    93.  
    94. # Rename Named Selection
    95. result = NamedSelection.Rename("Group1", "domain")
    96. # EndBlock
    97. #Exclude items from physics
    98. selection = Component1
    99. suppress = True
    100. ViewHelper.SetSuppressForPhysics(selection, suppress)
    101. #EndBlock
  • Member Posts: 11
    Name Dropper First Comment
    **

    i have written the above code but only one sphere is selecting in porous medium

    I thing it is happening because of all spheres are not intersecting with cube so can you provide me the code how to intersect the spheres and cube

Welcome!

It looks like you're new here. Sign in or register to get started.